Commit 6a2b14f3 authored by arbennett's avatar arbennett
Browse files

Adding loadDefault functionality to generated items.


Signed-off-by: default avatararbennett <bennett.andr@gmail.com>
parent 850a3a58
......@@ -37,7 +37,7 @@ public class NewICEItemProjectTester {
private static final String SEP = System.getProperty("file.separator");
private static final String PROJECT_NAME = "org.eclipse.ice.newitem";
private static final int MANIFEST_LINE_COUNT = 16;
private static final int MODEL_LINE_COUNT = 235;
private static final int MODEL_LINE_COUNT = 241;
private static final int LAUNCHER_LINE_COUNT = 82;
/**
......
......@@ -82,6 +82,15 @@ public class $className$Model extends Model {
// or Model
ioService = getIOService();
// Set the Form ID info
form.setName(getName());
form.setDescription(getDescription());
form.setId(getId());
form.setItemID(getId());
loadDefault();
/* SetupForm Example:
*
* DataComponent data = new DataComponent();
......@@ -106,11 +115,6 @@ public class $className$Model extends Model {
* form.addComponent(data);
*/
// Set the Form ID info
form.setName(getName());
form.setDescription(getDescription());
form.setId(getId());
form.setItemID(getId());
}
/**
......@@ -168,6 +172,54 @@ public class $className$Model extends Model {
return retStatus;
}
/**
* Load some default dataset that's been embedded into the plugin, if one exists
*/
public void loadDefault() {
try {
// Create a filepath for the default file
String fileName = Paths.get(defaultFileName).getFileName().toString();
if (fileName.isEmpty()) {
return;
}
String defaultFilePath = project.getLocation().toOSString()
+ System.getProperty("file.separator")
+ fileName;
// Create a temporary location to load the default file
File temp = new File(defaultFilePath);
if (!temp.exists()) {
temp.createNewFile();
}
// Pull the default file from inside the plugin
URI uri = new URI(
"platform:/plugin/$packageName$/data/" + fileName);
InputStream defaultFileReader = uri.toURL().openStream();
FileOutputStream outStream = new FileOutputStream(temp);
// Write out the default file from the plugin to the temp location
int fileByte;
while ((fileByte = defaultFileReader.read()) != -1) {
outStream.write(fileByte);
}
outStream.close();
project.refreshLocal(IResource.DEPTH_INFINITE, null);
IFile inputFile = project.getFile(fileName);
form = reader.read(inputFile);
form.setName(getName());
form.setDescription(getDescription());
form.setId(getId());
} catch (URISyntaxException e) {
logger.error(getClass().getName() + " Exception!",e);
} catch (MalformedURLException e) {
logger.error(getClass().getName() + " Exception!",e);
} catch (IOException e) {
logger.error(getClass().getName() + " Exception!",e);
} catch (CoreException e) {
logger.error(getClass().getName() + " Exception!",e);
}
}
/**
* This method is called when loading a new item either via the item
......@@ -179,53 +231,7 @@ public class $className$Model extends Model {
*/
@Override
public void loadInput(String fileName) {
IFile inputFile = null;
File temp = null;
if (fileName == null) {
try {
// Create a filepath for the default file
fileName = Paths.get(defaultFileName).getFileName().toString();
if (fileName.isEmpty()) {
return;
}
String defaultFilePath = project.getLocation().toOSString()
+ System.getProperty("file.separator")
+ fileName;
// 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/$packageName$/data/" + fileName);
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(fileName);
} catch (URISyntaxException e) {
logger.error(getClass().getName() + " Exception!",e);
} catch (MalformedURLException e) {
logger.error(getClass().getName() + " Exception!",e);
} catch (IOException e) {
logger.error(getClass().getName() + " Exception!",e);
} catch (CoreException e) {
logger.error(getClass().getName() + " Exception!",e);
}
} else {
// Get the file
inputFile = project.getFile(fileName);
}
IFile inputFile = project.getFile(fileName);
form = reader.read(inputFile);
form.setName(getName());
form.setDescription(getDescription());
......
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