Commit 51b54a1c authored by Robert Smith's avatar Robert Smith

Merge remote-tracking branch 'origin/2.2.2' into next

parents 612525ac 382df19e
...@@ -15,4 +15,7 @@ Export-Package: org.eclipse.ice.io.csv, ...@@ -15,4 +15,7 @@ Export-Package: org.eclipse.ice.io.csv,
Bundle-Vendor: Oak Ridge National Laboratory Bundle-Vendor: Oak Ridge National Laboratory
Import-Package: org.eclipse.core.resources, Import-Package: org.eclipse.core.resources,
org.eclipse.core.runtime, org.eclipse.core.runtime,
org.eclipse.jface.dialogs,
org.eclipse.swt.widgets,
org.eclipse.ui,
org.slf4j org.slf4j
...@@ -23,6 +23,8 @@ import java.util.Iterator; ...@@ -23,6 +23,8 @@ import java.util.Iterator;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ice.datastructures.entry.IEntry; import org.eclipse.ice.datastructures.entry.IEntry;
import org.eclipse.ice.datastructures.entry.StringEntry; import org.eclipse.ice.datastructures.entry.StringEntry;
import org.eclipse.ice.datastructures.form.DataComponent; import org.eclipse.ice.datastructures.form.DataComponent;
...@@ -30,6 +32,10 @@ import org.eclipse.ice.datastructures.form.Form; ...@@ -30,6 +32,10 @@ import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.MasterDetailsComponent; import org.eclipse.ice.datastructures.form.MasterDetailsComponent;
import org.eclipse.ice.datastructures.form.TableComponent; import org.eclipse.ice.datastructures.form.TableComponent;
import org.eclipse.ice.io.serializable.IReader; import org.eclipse.ice.io.serializable.IReader;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -128,7 +134,7 @@ public class IPSReader implements IReader { ...@@ -128,7 +134,7 @@ public class IPSReader implements IReader {
// Read in each of the ports individually // Read in each of the ports individually
String name = ""; String name = "";
while (!name.equals("TIME_LOOP")) { while (!name.equals("TIME_LOOP")) {
DataComponent ipsComponent = loadComponent(iniIterator); DataComponent ipsComponent = loadComponent(iniIterator, true);
name = ipsComponent.getName(); name = ipsComponent.getName();
if (!name.equals("TIME_LOOP")) { if (!name.equals("TIME_LOOP")) {
ipsComponents.add(ipsComponent); ipsComponents.add(ipsComponent);
...@@ -321,8 +327,9 @@ public class IPSReader implements IReader { ...@@ -321,8 +327,9 @@ public class IPSReader implements IReader {
// Make sure that we are not at the end of the file // Make sure that we are not at the end of the file
if (!it.hasNext()) { if (!it.hasNext()) {
System.err.println( logger.error(
"IPS Reader Message: Reached unexpected " + "end of file while reading the global configuration."); "IPS Reader Message: Reached unexpected " + "end of file while reading the global configuration.");
createErrorDialog();
return null; return null;
} }
...@@ -364,8 +371,9 @@ public class IPSReader implements IReader { ...@@ -364,8 +371,9 @@ public class IPSReader implements IReader {
// loadGlobalConfiguration() method the current line that the iterator // loadGlobalConfiguration() method the current line that the iterator
// is at should be [PORTS] // is at should be [PORTS]
if (!it.hasNext()) { if (!it.hasNext()) {
System.err.println("Reached unexpected end of file while trying to " logger.error("Reached unexpected end of file while trying to "
+ "locate the Ports Table. Please check your input file and " + "try again."); + "locate the Ports Table. Please check your input file and " + "try again.");
createErrorDialog();
return null; return null;
} }
...@@ -382,8 +390,9 @@ public class IPSReader implements IReader { ...@@ -382,8 +390,9 @@ public class IPSReader implements IReader {
// in, so make sure that we've not accidentally parsed over the entire // in, so make sure that we've not accidentally parsed over the entire
// thing. If we have, tell the user that their file may be incorrect. // thing. If we have, tell the user that their file may be incorrect.
if (!it.hasNext()) { if (!it.hasNext()) {
System.err.println("Reached unexpected end of file while trying to " + "read the Ports Table. " logger.error("Reached unexpected end of file while trying to " + "read the Ports Table. "
+ "Please check your input file and try again."); + "Please check your input file and try again.");
createErrorDialog();
return null; return null;
} }
...@@ -430,9 +439,10 @@ public class IPSReader implements IReader { ...@@ -430,9 +439,10 @@ public class IPSReader implements IReader {
String implementation = line.split(" = ", 2)[1]; String implementation = line.split(" = ", 2)[1];
row.get(1).setValue(implementation); row.get(1).setValue(implementation);
} else { } else {
System.err.println( logger.error(
"Unexpected token after ports entry, " + "check your input file and try again."); "Unexpected token after ports entry, " + "check your input file and try again.");
System.exit(1); createErrorDialog();
return null;
} }
// Found a complete port entry, now remove the port from the // Found a complete port entry, now remove the port from the
...@@ -446,8 +456,8 @@ public class IPSReader implements IReader { ...@@ -446,8 +456,8 @@ public class IPSReader implements IReader {
// Make sure that we are not at the end of the file // Make sure that we are not at the end of the file
if (!it.hasNext()) { if (!it.hasNext()) {
System.err logger.error("IPS Reader Message: Reached unexpected " + "end of file while reading the ports table.");
.println("IPS Reader Message: Reached unexpected " + "end of file while reading the ports table."); createErrorDialog();
return null; return null;
} }
...@@ -461,15 +471,27 @@ public class IPSReader implements IReader { ...@@ -461,15 +471,27 @@ public class IPSReader implements IReader {
* *
* @param it * @param it
* Iterator over the lines of the INI file as an ArrayList * Iterator over the lines of the INI file as an ArrayList
* @param fromFile
* True if the iterator is for the file the reader is parsing or false if the iterator is for a standalone set of strings which are to be parsed by themselves.
* @return A DataComponent containing information for one of the port * @return A DataComponent containing information for one of the port
* entries. * entries.
*/ */
private DataComponent loadComponent(Iterator<String> it) { private DataComponent loadComponent(Iterator<String> it, boolean fromFile) {
// Create the port component and a generic entry // Create the port component and a generic entry
DataComponent portComponent = new DataComponent(); DataComponent portComponent = new DataComponent();
IEntry entry; IEntry entry;
String[] splitLine = null; String[] splitLine = null;
//The local line that is being parsed
String line;
//Get the line for the file or from the iterator, as appropriate for the source
if(fromFile){
line = this.line;
} else{
line = it.next();
}
// Scan until we get to the next port component // Scan until we get to the next port component
while (!line.contains("[") && !line.contains("]") && it.hasNext()) { while (!line.contains("[") && !line.contains("]") && it.hasNext()) {
line = it.next(); line = it.next();
...@@ -505,6 +527,11 @@ public class IPSReader implements IReader { ...@@ -505,6 +527,11 @@ public class IPSReader implements IReader {
portComponent.addEntry(entry); portComponent.addEntry(entry);
} }
//If we have parsed all the lines from a standalone data set, stop parsing
if(!fromFile && !it.hasNext()){
return portComponent;
}
// Read in another line // Read in another line
line = it.next(); line = it.next();
...@@ -518,11 +545,17 @@ public class IPSReader implements IReader { ...@@ -518,11 +545,17 @@ public class IPSReader implements IReader {
foundNextPort = true; foundNextPort = true;
} }
} }
//If we loaded from the file, set the overall current line to the last line parsed
if(fromFile){
this.line = line;
}
// Make sure that we are not at the end of the file // Make sure that we are not at the end of the file
if (!it.hasNext()) { if (!it.hasNext()) {
System.err.println( logger.error(
"IPS Reader Message: Reached unexpected " + "end of file while reading the port configuration."); "IPS Reader Message: Reached unexpected " + "end of file while reading the port configuration.");
createErrorDialog();
return null; return null;
} }
...@@ -569,14 +602,29 @@ public class IPSReader implements IReader { ...@@ -569,14 +602,29 @@ public class IPSReader implements IReader {
populatePortMap(); populatePortMap();
} }
ArrayList<String> portData;
// Add in the missing definitions // Add in the missing definitions
for (String port : allowedPortList) { for (String port : allowedPortList) {
portTemplates.add(loadComponent(portMap.get(port).iterator())); portTemplates.add(loadComponent(portMap.get(port).iterator(), false));
}
//The list of portTemplates, re-ordered to match that of the allowedPortNames
ArrayList<DataComponent> orderedPortTemplates = new ArrayList<DataComponent>();
//Add the corresponding template for each port name to the list
for(String port : allowedPortNames){
for(DataComponent template : portTemplates){
if(port.equals(template.getName())){
orderedPortTemplates.add(template);
break;
}
}
} }
// Recreate the overall list & Set the template // Recreate the overall list & Set the template
allowedPortList = new ArrayList<String>(Arrays.asList(allowedPortNames)); allowedPortList = new ArrayList<String>(Arrays.asList(allowedPortNames));
masterDetails.setTemplates(allowedPortList, portTemplates); masterDetails.setTemplates(allowedPortList, orderedPortTemplates);
// Add the ports to the MasterDetailsComponent // Add the ports to the MasterDetailsComponent
for (DataComponent data : ipsComponents) { for (DataComponent data : ipsComponents) {
...@@ -590,6 +638,28 @@ public class IPSReader implements IReader { ...@@ -590,6 +638,28 @@ public class IPSReader implements IReader {
return masterDetails; return masterDetails;
} }
/**
* Open an error dialog to alert the user that a problem occurred while reading the file.
*/
private void createErrorDialog(){
//Open the error dialog
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
ErrorDialog.openError(new Shell(Display.getDefault()),
"Error Reading VIBE Input File",
"File import failed.",
new Status(IStatus.ERROR,
"org.eclipse.ice.io",
"Reached an unexpected end of file while parsing input."));
return;
}
});
return;
}
/** /**
* Load the Time Loop Data from the INI file and return the data as a * Load the Time Loop Data from the INI file and return the data as a
* DataComponent. Each parameter in the section is added to the * DataComponent. Each parameter in the section is added to the
...@@ -608,8 +678,9 @@ public class IPSReader implements IReader { ...@@ -608,8 +678,9 @@ public class IPSReader implements IReader {
// Scan until we get to the next port component // Scan until we get to the next port component
if (!it.hasNext()) { if (!it.hasNext()) {
System.err.println("Unexpectedly reached the end of file. " logger.error("Unexpectedly reached the end of file. "
+ "Please check the INI file you have chosen and" + " try again."); + "Please check the INI file you have chosen and" + " try again.");
createErrorDialog();
return null; return null;
} }
...@@ -718,7 +789,7 @@ public class IPSReader implements IReader { ...@@ -718,7 +789,7 @@ public class IPSReader implements IReader {
portMap.put("DUALFOIL", portLines); portMap.put("DUALFOIL", portLines);
//CHARTRAN_THERMAL_DRIVER definitions //CHARTRAN_THERMAL_DRIVER definitions
String[] ctdStrings = { "CHARTRAN_THERMAL_DRIVER", "CLASS = DRIVERS", String[] ctdStrings = { "[CHARTRAN_THERMAL_DRIVER]", "CLASS = DRIVERS",
"SUB_CLASS = CHARTRAN_THERMAL", "SUB_CLASS = CHARTRAN_THERMAL",
"NAME = Driver", "NAME = Driver",
"NPROC = 1", "NPROC = 1",
...@@ -732,7 +803,7 @@ public class IPSReader implements IReader { ...@@ -732,7 +803,7 @@ public class IPSReader implements IReader {
portMap.put("CHARTRAN_THERMAL_DRIVER", portLines); portMap.put("CHARTRAN_THERMAL_DRIVER", portLines);
//AMPERES definitions //AMPERES definitions
String[] ampereStrings = { "AMPERES", "CLASS = THERMAL", String[] ampereStrings = { "[AMPERES]", "CLASS = THERMAL",
"SUB_CLASS =", "SUB_CLASS =",
"NAME = Amperes", "NAME = Amperes",
"NPROC = 1", "NPROC = 1",
......
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