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 { ...@@ -98,7 +98,7 @@ public class BatMLModel extends Item {
} }
// Load in the default information // Load in the default information
loadInput(null); loadDefault();
} }
} }
...@@ -171,6 +171,36 @@ public class BatMLModel extends Item { ...@@ -171,6 +171,36 @@ public class BatMLModel extends Item {
@Override @Override
public void loadInput(String input) { 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; IFile xsdIFile, xmlIFile;
File temp = null; File temp = null;
...@@ -231,14 +261,10 @@ public class BatMLModel extends Item { ...@@ -231,14 +261,10 @@ public class BatMLModel extends Item {
logger.error("[BatML Model] ERROR: Could not refresh project workspace!"); 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"); xsdIFile = project.getFolder("batml").getFile("electrical.xsd");
xmlIFile = project.getFolder("batml").getFile("electrical.xml"); 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 // Get the handle to the files on the local file system
xsdFile = xsdIFile.getRawLocation().makeAbsolute().toFile(); xsdFile = xsdIFile.getRawLocation().makeAbsolute().toFile();
......
...@@ -96,10 +96,8 @@ public class PROTEUSModel extends Item { ...@@ -96,10 +96,8 @@ public class PROTEUSModel extends Item {
* which they should be retrieved. * which they should be retrieved.
*/ */
public PROTEUSModel(IProject projectSpace) { public PROTEUSModel(IProject projectSpace) {
// Call super // Call super
super(projectSpace); super(projectSpace);
} }
/** /**
...@@ -121,7 +119,7 @@ public class PROTEUSModel extends Item { ...@@ -121,7 +119,7 @@ public class PROTEUSModel extends Item {
form = new Form(); form = new Form();
if (project != null) { if (project != null) {
loadInput(null); loadDefault();
} }
} }
...@@ -252,7 +250,6 @@ public class PROTEUSModel extends Item { ...@@ -252,7 +250,6 @@ public class PROTEUSModel extends Item {
*/ */
@Override @Override
public void loadInput(String name) { public void loadInput(String name) {
// If nothing is specified, load case 6 from inside the plugin
IFile inputFile = null; IFile inputFile = null;
IFile templateFile = project IFile templateFile = project
.getFile("PROTEUS_Model_Builder" .getFile("PROTEUS_Model_Builder"
...@@ -307,4 +304,11 @@ public class PROTEUSModel extends Item { ...@@ -307,4 +304,11 @@ public class PROTEUSModel extends Item {
form.addComponent(errorComponent); 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 { ...@@ -101,7 +101,7 @@ public class VibeKVPair extends Item implements IReader, IWriter {
// If loading from the new item button we should just // If loading from the new item button we should just
// load up the default case 6 file by passing in null // load up the default case 6 file by passing in null
if (project != null) { if (project != null) {
loadInput(null); loadDefault();
} }
} }
...@@ -232,91 +232,88 @@ public class VibeKVPair extends Item implements IReader, IWriter { ...@@ -232,91 +232,88 @@ public class VibeKVPair extends Item implements IReader, IWriter {
*/ */
@Override @Override
public void loadInput(String name) { public void loadInput(String name) {
IFile inputFile = inputFile = project.getFile(name);
// If nothing is specified, load case 6 from inside the plugin logger.info("VibeKVPair Message: Loading" + inputFile.getFullPath().toOSString());
IFile inputFile = null;
File temp = null;
if (name == null) {
try {
// Path to the default file
String defaultFilePath = null;
// Create a filepath for the default file
if (project != null) {
defaultFilePath = project.getLocation().toOSString()
+ System.getProperty("file.separator")
+ "case_6.dat";
} else {
defaultFilePath = ResourcesPlugin.getWorkspace().getRoot()
.getLocation().toOSString()
+ System.getProperty("file.separator")
+ "case_6.dat";
}
// Create a temporary location to load the default file
temp = new File(defaultFilePath);
if (!temp.exists()) {
temp.createNewFile();
}
// Pull the default file from inside the plugin
URI uri = new URI(
"platform:/plugin/org.eclipse.ice.vibe/data/case_6.dat");
InputStream reader = uri.toURL().openStream();
FileOutputStream outStream = new FileOutputStream(temp);
// Write out the default file from the plugin to the temp
// location
int fileByte;
while ((fileByte = reader.read()) != -1) {
outStream.write(fileByte);
}
outStream.close();
if (project != null) {
inputFile = project.getFile("case_6.dat");
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} else {
inputFile = ResourcesPlugin.getWorkspace().getRoot()
.getFile(new Path(defaultFilePath));
}
} catch (URISyntaxException e) {
System.err.println("VibeKVPair Message: "
+ "Error! Could not load the default"
+ " Vibe case data!");
} catch (MalformedURLException e) {
System.err.println("VibeKVPair Message: "
+ "Error! Could not load the default"
+ " Vibe case data!");
} catch (IOException e) {
System.err.println("VibeKVPair Message: "
+ "Error! Could not load the default"
+ " Vibe case data!");
} catch (CoreException e) {
// 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 = read(inputFile);
form.setName(getName()); form.setName(getName());
form.setDescription(getDescription()); form.setDescription(getDescription());
form.setId(getId()); form.setId(getId());
form.setItemID(getId()); form.setItemID(getId());
form.setActionList(actionItems); form.setActionList(actionItems);
}
/**
* Loads a default dataset that's embedded in the plugin
*/
public void loadDefault() {
IFile inputFile = null;
File temp = null;
try {
// Path to the default file
String defaultFilePath = null;
// Create a filepath for the default file
if (project != null) {
defaultFilePath = project.getLocation().toOSString()
+ System.getProperty("file.separator")
+ "case_6.dat";
} else {
defaultFilePath = ResourcesPlugin.getWorkspace().getRoot()
.getLocation().toOSString()
+ System.getProperty("file.separator")
+ "case_6.dat";
}
// Create a temporary location to load the default file
temp = new File(defaultFilePath);
if (!temp.exists()) {
temp.createNewFile();
}
// Delete default file if it was copied into the workspace // Pull the default file from inside the plugin
if (temp != null) { URI uri = new URI(
temp.delete(); "platform:/plugin/org.eclipse.ice.vibe/data/case_6.dat");
InputStream reader = uri.toURL().openStream();
FileOutputStream outStream = new FileOutputStream(temp);
// Write out the default file from the plugin to the temp
// location
int fileByte;
while ((fileByte = reader.read()) != -1) {
outStream.write(fileByte);
}
outStream.close();
if (project != null) {
inputFile = project.getFile("case_6.dat");
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} else {
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"
+ " Vibe case data!");
} catch (MalformedURLException e) {
System.err.println("VibeKVPair Message: "
+ "Error! Could not load the default"
+ " Vibe case data!");
} catch (IOException e) {
System.err.println("VibeKVPair Message: "
+ "Error! Could not load the default"
+ " Vibe case data!");
} catch (CoreException e) {
// TODO Auto-generated catch block
logger.error(getClass().getName() + " Exception!",e);
} }
} }
/** /**
* Reads in the KV Pair file to a form. * Reads in the KV Pair file to a form.
* *
......
...@@ -55,13 +55,12 @@ public class VibeModel extends Model { ...@@ -55,13 +55,12 @@ public class VibeModel extends Model {
* </p> * </p>
*/ */
private String customTaggedExportString = "Export to VIBE INI format"; 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 ArrayList<String> actionItems;
private IIOService ioService; private IIOService ioService;
/** /**
* A nullary constructor that delegates to the project constructor. * A nullary constructor that delegates to the project constructor.
...@@ -101,14 +100,14 @@ public class VibeModel extends Model { ...@@ -101,14 +100,14 @@ public class VibeModel extends Model {
setIOService(new IOService()); setIOService(new IOService());
ioService = getIOService(); ioService = getIOService();
} }
// If loading from the new item button we should just // If loading from the new item button we should just
// load up the default case 6 file by passing in null // load up the default case 6 file by passing in null
if (project != null) { if (project != null) {
loadInput(null); loadDefault();
} }
} }
/** /**
* <p> * <p>
* This operation overrides the Item.setupItemInfo() operation. * This operation overrides the Item.setupItemInfo() operation.
...@@ -144,8 +143,8 @@ public class VibeModel extends Model { ...@@ -144,8 +143,8 @@ public class VibeModel extends Model {
// Make sure the form has the right amount of data // Make sure the form has the right amount of data
if (components.size() != 4) { if (components.size() != 4) {
logger.info("VibeModel Message: Could not find enough data to write a complete input format." + logger.info("VibeModel Message: Could not find enough data to write a complete input format."
" 4 Components are required, but " + components.size() + " were found."); + " 4 Components are required, but " + components.size() + " were found.");
retStatus = FormStatus.InfoError; retStatus = FormStatus.InfoError;
} }
return retStatus; return retStatus;
...@@ -165,8 +164,7 @@ public class VibeModel extends Model { ...@@ -165,8 +164,7 @@ public class VibeModel extends Model {
if (this.customTaggedExportString.equals(actionName)) { if (this.customTaggedExportString.equals(actionName)) {
// Get the file from the project space to create the output // Get the file from the project space to create the output
String filename = getName().replaceAll("\\s+", "_") + "_" + getId() String filename = getName().replaceAll("\\s+", "_") + "_" + getId() + ".conf";
+ ".conf";
// Get the file path and build the URI that will be used to write // Get the file path and build the URI that will be used to write
IFile outputFile = project.getFile(filename); IFile outputFile = project.getFile(filename);
...@@ -185,9 +183,8 @@ public class VibeModel extends Model { ...@@ -185,9 +183,8 @@ public class VibeModel extends Model {
project.refreshLocal(IResource.DEPTH_ONE, null); project.refreshLocal(IResource.DEPTH_ONE, null);
} catch (CoreException e) { } catch (CoreException e) {
// Complain // Complain
System.err.println("VibeModel Message: " System.err.println("VibeModel Message: " + "Failed to refresh the project space.");
+ "Failed to refresh the project space."); logger.error(getClass().getName() + " Exception!", e);
logger.error(getClass().getName() + " Exception!",e);
} }
// return a success // return a success
retStatus = FormStatus.Processed; retStatus = FormStatus.Processed;
...@@ -213,67 +210,76 @@ public class VibeModel extends Model { ...@@ -213,67 +210,76 @@ public class VibeModel extends Model {
*/ */
@Override @Override
public void loadInput(String name) { public void loadInput(String name) {
// If nothing is specified, load case 6 from inside the plugin IFile inputFile = project.getFile(name);
IFile inputFile = null;
File temp = null;
if (name == null) {
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()) {
temp.createNewFile();
}
// Pull the default file from inside the plugin
URI uri = new URI(
"platform:/plugin/org.eclipse.ice.vibe/data/case_6.conf");
InputStream reader = uri.toURL().openStream();
FileOutputStream outStream = new FileOutputStream(temp);
// Write out the default file from the plugin to the temp location
int fileByte;
while ((fileByte = reader.read()) != -1) {
outStream.write(fileByte);
}
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 // Load the components from the file and setup the form
logger.info("VibeModel Message: Loading " + inputFile.getName()); logger.info("VibeModel Message: Loading " + inputFile.getName());
IReader reader = (IReader) ioService.getReader("IPS"); //new IPSReader(); IReader reader = (IReader) ioService.getReader("IPS");
form = reader.read(inputFile); form = reader.read(inputFile);
form.setName(getName()); form.setName(getName());
form.setDescription(getDescription()); form.setDescription(getDescription());
form.setId(getId()); form.setId(getId());
form.setItemID(getId()); form.setItemID(getId());
form.setActionList(actionItems); 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;
String defaultFileName = "case_6.conf";
String defaultFilePath = project.getLocation().toOSString() + System.getProperty("file.separator")
+ defaultFileName;
try {
// Create a temporary location to load the default file
temp = new File(defaultFilePath);
if (!temp.exists()) {
temp.createNewFile();
}
// Pull the default file from inside the plugin
URI uri = new URI("platform:/plugin/org.eclipse.ice.vibe/data/" + defaultFileName);
InputStream reader = uri.toURL().openStream();
FileOutputStream outStream = new FileOutputStream(temp);
// Write out the default file from the plugin to the temp location
int fileByte;
while ((fileByte = reader.read()) != -1) {
outStream.write(fileByte);
}
outStream.close();
project.refreshLocal(IResource.DEPTH_INFINITE, null);
// Load the components from the file and setup the form
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 // Delete default file if it was copied into the workspace
if (temp != null) { if (temp != null) {
......
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