Commit 3142c032 authored by arbennett's avatar arbennett
Browse files

Moving `loadInput(null)` calls into `loadDefault()`.

This was done after some extensive discussion on the ICE developer
mailing list that was sparked by #233 and is related to #236

.
Signed-off-by: default avatararbennett <bennett.andr@gmail.com>
parent ca2e7014
......@@ -98,7 +98,7 @@ public class BatMLModel extends Item {
}
// Load in the default information
loadInput(null);
loadDefault();
}
}
......@@ -171,6 +171,36 @@ public class BatMLModel extends Item {
@Override
public void loadInput(String input) {
IFile xsdIFile, xmlIFile;
xsdIFile = project.getFolder("batml").getFile("electrical.xsd");
xmlIFile = project.getFile(input);
// Get the handle to the files on the local file system
xsdFile = xsdIFile.getRawLocation().makeAbsolute().toFile();
xmlFile = xmlIFile.getRawLocation().makeAbsolute().toFile();
// Create the EMFComponent
if (xsdFile != null) {
emfComp = new EMFComponent();
emfComp.load(xsdFile, xmlFile);
emfComp.getEMFTreeComposite().setName("BatML");
emfComp.setName("BatML Model Editor");
emfComp.setId(1);
} else {
emfComp = new EMFComponent();
emfComp.setName("BatML Model Editor");
emfComp.setDescription("Could not find BatML input for model creation!");
emfComp.setId(1);
}
form.addComponent(emfComp);
}
/**
* Load the schemas and default datasets from within the plugin.
*/
public void loadDefault() {
IFile xsdIFile, xmlIFile;
File temp = null;
......@@ -231,14 +261,10 @@ public class BatMLModel extends Item {
logger.error("[BatML Model] ERROR: Could not refresh project workspace!");
}
}
// Load up either a default file, or the newly imported one.
if (input == null) {
// Load up the default file
xsdIFile = project.getFolder("batml").getFile("electrical.xsd");
xmlIFile = project.getFolder("batml").getFile("electrical.xml");
} else {
xsdIFile = project.getFolder("batml").getFile("electrical.xsd");
xmlIFile = project.getFile(input);
}
// Get the handle to the files on the local file system
xsdFile = xsdIFile.getRawLocation().makeAbsolute().toFile();
......
......@@ -96,10 +96,8 @@ public class PROTEUSModel extends Item {
* which they should be retrieved.
*/
public PROTEUSModel(IProject projectSpace) {
// Call super
super(projectSpace);
}
/**
......@@ -121,7 +119,7 @@ public class PROTEUSModel extends Item {
form = new Form();
if (project != null) {
loadInput(null);
loadDefault();
}
}
......@@ -252,7 +250,6 @@ public class PROTEUSModel extends Item {
*/
@Override
public void loadInput(String name) {
// If nothing is specified, load case 6 from inside the plugin
IFile inputFile = null;
IFile templateFile = project
.getFile("PROTEUS_Model_Builder"
......@@ -307,4 +304,11 @@ public class PROTEUSModel extends Item {
form.addComponent(errorComponent);
}
}
/**
* Load the dataset that should be provided in the default location
*/
public void loadDefault() {
loadInput("PROTEUS_Model_Builder" + System.getProperty("file.separator") + "proteus_model.inp");
}
}
\ No newline at end of file
......@@ -101,7 +101,7 @@ public class VibeKVPair extends Item implements IReader, IWriter {
// If loading from the new item button we should just
// load up the default case 6 file by passing in null
if (project != null) {
loadInput(null);
loadDefault();
}
}
......@@ -232,11 +232,22 @@ public class VibeKVPair extends Item implements IReader, IWriter {
*/
@Override
public void loadInput(String name) {
IFile inputFile = inputFile = project.getFile(name);
logger.info("VibeKVPair Message: Loading" + inputFile.getFullPath().toOSString());
form = read(inputFile);
form.setName(getName());
form.setDescription(getDescription());
form.setId(getId());
form.setItemID(getId());
form.setActionList(actionItems);
}
// If nothing is specified, load case 6 from inside the plugin
/**
* Loads a default dataset that's embedded in the plugin
*/
public void loadDefault() {
IFile inputFile = null;
File temp = null;
if (name == null) {
try {
// Path to the default file
String defaultFilePath = null;
......@@ -278,7 +289,13 @@ public class VibeKVPair extends Item implements IReader, IWriter {
inputFile = ResourcesPlugin.getWorkspace().getRoot()
.getFile(new Path(defaultFilePath));
}
logger.info("VibeKVPair Message: Loading" + inputFile.getFullPath().toOSString());
form = read(inputFile);
form.setName(getName());
form.setDescription(getDescription());
form.setId(getId());
form.setItemID(getId());
form.setActionList(actionItems);
} catch (URISyntaxException e) {
System.err.println("VibeKVPair Message: "
+ "Error! Could not load the default"
......@@ -295,26 +312,6 @@ public class VibeKVPair extends Item implements IReader, IWriter {
// TODO Auto-generated catch block
logger.error(getClass().getName() + " Exception!",e);
}
} else {
// Get the file
inputFile = project.getFile(name);
}
// Load the components from the file and setup the form
logger.info("VibeKVPair Message: Loading"
+ inputFile.getFullPath().toOSString());
form = read(inputFile);
form.setName(getName());
form.setDescription(getDescription());
form.setId(getId());
form.setItemID(getId());
form.setActionList(actionItems);
// Delete default file if it was copied into the workspace
if (temp != null) {
temp.delete();
}
}
/**
......
......@@ -56,13 +56,12 @@ public class VibeModel extends Model {
*/
private String customTaggedExportString = "Export to VIBE INI format";
// The name of the example chosen
protected String exampleName; // Default for now
private ArrayList<String> actionItems;
private IIOService ioService;
/**
* A nullary constructor that delegates to the project constructor.
*/
......@@ -105,7 +104,7 @@ public class VibeModel extends Model {
// If loading from the new item button we should just
// load up the default case 6 file by passing in null
if (project != null) {
loadInput(null);
loadDefault();
}
}
......@@ -144,8 +143,8 @@ public class VibeModel extends Model {
// Make sure the form has the right amount of data
if (components.size() != 4) {
logger.info("VibeModel Message: Could not find enough data to write a complete input format." +
" 4 Components are required, but " + components.size() + " were found.");
logger.info("VibeModel Message: Could not find enough data to write a complete input format."
+ " 4 Components are required, but " + components.size() + " were found.");
retStatus = FormStatus.InfoError;
}
return retStatus;
......@@ -165,8 +164,7 @@ public class VibeModel extends Model {
if (this.customTaggedExportString.equals(actionName)) {
// Get the file from the project space to create the output
String filename = getName().replaceAll("\\s+", "_") + "_" + getId()
+ ".conf";
String filename = getName().replaceAll("\\s+", "_") + "_" + getId() + ".conf";
// Get the file path and build the URI that will be used to write
IFile outputFile = project.getFile(filename);
......@@ -185,9 +183,8 @@ public class VibeModel extends Model {
project.refreshLocal(IResource.DEPTH_ONE, null);
} catch (CoreException e) {
// Complain
System.err.println("VibeModel Message: "
+ "Failed to refresh the project space.");
logger.error(getClass().getName() + " Exception!",e);
System.err.println("VibeModel Message: " + "Failed to refresh the project space.");
logger.error(getClass().getName() + " Exception!", e);
}
// return a success
retStatus = FormStatus.Processed;
......@@ -213,15 +210,31 @@ public class VibeModel extends Model {
*/
@Override
public void loadInput(String name) {
// If nothing is specified, load case 6 from inside the plugin
IFile inputFile = null;
IFile inputFile = project.getFile(name);
// Load the components from the file and setup the form
logger.info("VibeModel Message: Loading " + inputFile.getName());
IReader reader = (IReader) ioService.getReader("IPS");
form = reader.read(inputFile);
form.setName(getName());
form.setDescription(getDescription());
form.setId(getId());
form.setItemID(getId());
form.setActionList(actionItems);
}
/**
* Provides functionality to load a file embedded in the plugin. This can be used
* when the VibeModel is created via the new item button in the ICE perspective.
*
* @return the form loaded from the file embedded in the plugin
*/
public void loadDefault() {
File temp = null;
if (name == null) {
String defaultFileName = "case_6.conf";
String defaultFilePath = project.getLocation().toOSString() + System.getProperty("file.separator")
+ defaultFileName;
try {
// Create a filepath for the default file
String defaultFilePath = project.getLocation().toOSString()
+ System.getProperty("file.separator")
+ "case_6.conf";
// Create a temporary location to load the default file
temp = new File(defaultFilePath);
if (!temp.exists()) {
......@@ -229,8 +242,7 @@ public class VibeModel extends Model {
}
// Pull the default file from inside the plugin
URI uri = new URI(
"platform:/plugin/org.eclipse.ice.vibe/data/case_6.conf");
URI uri = new URI("platform:/plugin/org.eclipse.ice.vibe/data/" + defaultFileName);
InputStream reader = uri.toURL().openStream();
FileOutputStream outStream = new FileOutputStream(temp);
......@@ -241,40 +253,34 @@ public class VibeModel extends Model {
}
outStream.close();
project.refreshLocal(IResource.DEPTH_INFINITE, null);
inputFile = project.getFile("case_6.conf");
} catch (URISyntaxException e) {
logger.error(getClass().getName() + " Exception!",e);
System.err.println("VibeModel Message: Error! Could not load the default"
+ " VIBE case data!");
} catch (MalformedURLException e) {
logger.error(getClass().getName() + " Exception!",e);
System.err.println("VibeModel Message: Error! Could not load the default"
+ " VIBE case data!");
} catch (IOException e) {
logger.error(getClass().getName() + " Exception!",e);
System.err.println("VibeModel Message: Error! Could not load the default"
+ " VIBE case data!");
} catch (CoreException e) {
logger.error(getClass().getName() + " Exception!",e);
System.err.println("VibeModel Message: Error! Could not load the default"
+ " VIBE case data!");
}
} else {
// Get the file
inputFile = project.getFile(name);
}
// Load the components from the file and setup the form
logger.info("VibeModel Message: Loading " + inputFile.getName());
IReader reader = (IReader) ioService.getReader("IPS"); //new IPSReader();
form = reader.read(inputFile);
IFile inputFile = project.getFile("case_6.conf");
IReader ipsReader = (IReader) ioService.getReader("IPS");
form = ipsReader.read(inputFile);
form.setName(getName());
form.setDescription(getDescription());
form.setId(getId());
form.setItemID(getId());
form.setActionList(actionItems);
} catch (URISyntaxException e) {
logger.error(getClass().getName() + " Exception!", e);
logger.error("VibeModel Message: Error! Could not load the default VIBE case data!");
} catch (MalformedURLException e) {
logger.error(getClass().getName() + " Exception!", e);
logger.error("VibeModel Message: Error! Could not load the default VIBE case data!");
} catch (IOException e) {
logger.error(getClass().getName() + " Exception!", e);
logger.error("VibeModel Message: Error! Could not load the default VIBE case data!");
} catch (CoreException e) {
logger.error(getClass().getName() + " Exception!", e);
logger.error("VibeModel Message: Error! Could not load the default VIBE case data!");
}
// Delete default file if it was copied into the workspace
if (temp != null) {
temp.delete();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment