diff --git a/src/org.eclipse.ice.caebat/src/org/eclipse/ice/caebat/launcher/CaebatLauncher.java b/src/org.eclipse.ice.caebat/src/org/eclipse/ice/caebat/launcher/CaebatLauncher.java index 3db34a464..175b92d8e 100644 --- a/src/org.eclipse.ice.caebat/src/org/eclipse/ice/caebat/launcher/CaebatLauncher.java +++ b/src/org.eclipse.ice.caebat/src/org/eclipse/ice/caebat/launcher/CaebatLauncher.java @@ -12,14 +12,13 @@ *******************************************************************************/ package org.eclipse.ice.caebat.launcher; -import java.io.InputStream; import java.util.ArrayList; -import java.util.Scanner; import javax.xml.bind.annotation.XmlRootElement; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.ice.datastructures.ICEObject.IUpdateable; -import org.eclipse.ice.datastructures.ICEObject.IUpdateableListener; import org.eclipse.ice.datastructures.form.AllowedValueType; import org.eclipse.ice.datastructures.form.DataComponent; import org.eclipse.ice.datastructures.form.Entry; @@ -28,11 +27,6 @@ import org.eclipse.ice.io.ips.IPSReader; import org.eclipse.ice.io.ips.IPSWriter; import org.eclipse.ice.item.jobLauncher.JobLauncher; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; /** * @@ -51,7 +45,7 @@ public class CaebatLauncher extends JobLauncher { * The execution command */ private String fullExecCMD; - + /** * The default CAEBAT home directory. */ @@ -155,7 +149,7 @@ public void setupForm() { protected void setup() { this.setName("Use custom key-value pair file?"); this.tag = "MODE"; - this.setDescription("Time loop's mode. Can be Regular (true) or Explicit (false)"); + this.setDescription("Allows the use of a customized KV Pair file generated by ICE"); this.defaultValue = "false"; this.value = this.defaultValue; this.allowedValues = new ArrayList(); @@ -193,25 +187,6 @@ protected void setup() { */ public FormStatus process(String actionName) { - // begin-user-code - /* - * This section will be used in future iterations String separator = - * System.getProperty("file.separator"); IPSReader reader = new - * IPSReader(); IPSWriter writer = new IPSWriter(); - * - * DataComponent fileComponent = (DataComponent) form.getComponent(1); - * Entry inputFileEntry = fileComponent.retrieveEntry("Input File"); - * - * IPath fileIPath = new Path(project.getLocation().toOSString() + - * separator + inputFileEntry.getValue()); IFile inputFile = - * ResourcesPlugin.getWorkspace().getRoot().getFile(fileIPath); - * ArrayList simRootMatches = reader.findAll(inputFile, - * "SIM_ROOT=.*"); dataDir = - * simRootMatches.get(0).getName().split("=")[1]; - * - * writer.replace(inputFile, "SIM_ROOT=.*", "SIM_ROOT=" + - * getLaunchDirectory()); - */ // Local Declarations String separator = System.getProperty("file.separator"); IPSReader reader = new IPSReader(); @@ -272,13 +247,11 @@ public FormStatus process(String actionName) { String mvKVPairFile = ""; if (kvPairFileEntry.getValue() != "false") { String kvFileName = fileComponent.retrieveEntry("Key-value pair file").getValue(); - writer.replace(inputFile, "input_keyvalue", kvFileName); + //writer.replace(inputFile, "input_keyvalue", kvFileName); setKVPerms = "chmod 775 " + kvFileName + " && "; backupKVFile = "mv input/input_keyvalue input/input_keyvalue.bak && "; mvKVPairFile = "mv " + kvFileName + " input/input_keyvalue && "; } - - // Pull some information from the form TableComponent hostTable = (TableComponent) form.getComponent(4); @@ -313,18 +286,18 @@ public FormStatus process(String actionName) { */ public void update(IUpdateable component) { refreshProjectSpace(); - super.update(component); - - // Determine whether the file selector needs to be added to or removed from the form - if (component.getName() == "Use custom key-value pair file?" - && ((Entry) component).getValue() == "true") { - addInputType("Key-value pair file", "keyValueFile", - "Key-value pair with case parameters", ".dat"); - } else if (component.getName() == "Use custom key-value pair file?" - && ((Entry) component).getValue() == "false") { - removeInputType("Key-value pair file"); - } - + if (component instanceof Entry) { + // Determine whether the file selector needs to be added to or removed from the form + if (component.getName() == "Use custom key-value pair file?" + && ((Entry) component).getValue() == "true") { + addInputType("Key-value pair file", "keyValueFile", + "Key-value pair with case parameters", ".dat"); + } else if (component.getName() == "Use custom key-value pair file?" + && ((Entry) component).getValue() == "false") { + DataComponent fileComponent = (DataComponent) form.getComponent(1); + fileComponent.deleteEntry("Key-value pair file"); + } + } } /** diff --git a/src/org.eclipse.ice.io/src/org/eclipse/ice/io/ips/IPSReader.java b/src/org.eclipse.ice.io/src/org/eclipse/ice/io/ips/IPSReader.java index f97e2ba17..ec091a35b 100644 --- a/src/org.eclipse.ice.io/src/org/eclipse/ice/io/ips/IPSReader.java +++ b/src/org.eclipse.ice.io/src/org/eclipse/ice/io/ips/IPSReader.java @@ -107,12 +107,15 @@ public Form read(IFile ifile) { ArrayList names = new ArrayList(); // Read in each of the ports individually - for (int i = 0; i < numberPorts; i++) { + String name = ""; + while (!name.equals("TIME_LOOP")) { DataComponent ipsComponent = loadComponent(iniIterator); - ipsComponents.add(ipsComponent); - names.add(ipsComponent.getName()); + name = ipsComponent.getName(); + if (!name.equals("TIME_LOOP")) { + ipsComponents.add(ipsComponent); + names.add(ipsComponent.getName()); + } } - // Build a MasterDetailsComponent out of the DataComponents MasterDetailsComponent portsMaster = buildMasterDetailsComponent(ipsComponents); @@ -462,6 +465,10 @@ private DataComponent loadComponent(Iterator it) { portComponent.setId(currID); currID++; + if (portComponent.getName().equals("TIME_LOOP")) { + return portComponent; + } + // Read parameters until reaching a whitespace line that separates ports while (line.trim().length() > 0) { // The format in this section is: KEY = VALUE # Comment @@ -518,7 +525,7 @@ private MasterDetailsComponent buildMasterDetailsComponent( .setDescription("Setup for each of the ports in the simulation."); String portName; int masterId; - + // Set the allowed ports so that users don't try to go too far and end // up with settings that don't exist String[] allowedPortNames = { "INIT", "INIT_STATE", "AMPERES_THERMAL", @@ -594,10 +601,6 @@ private DataComponent loadTimeLoopComponent(Iterator it) { return null; } - while (!line.contains("[TIME_LOOP]") && it.hasNext()) { - line = it.next(); - } - // Pull the port name and start parsing through the parameters timeLoopData.setName("Time Loop Data"); timeLoopData.setDescription(""); diff --git a/src/org.eclipse.ice.viz/src/org/eclipse/ice/viz/visit/VisitPlotViewer.java b/src/org.eclipse.ice.viz/src/org/eclipse/ice/viz/visit/VisitPlotViewer.java index f29a8a813..d632ac457 100644 --- a/src/org.eclipse.ice.viz/src/org/eclipse/ice/viz/visit/VisitPlotViewer.java +++ b/src/org.eclipse.ice.viz/src/org/eclipse/ice/viz/visit/VisitPlotViewer.java @@ -38,18 +38,20 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StyledCellLabelProvider; import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PlatformUI; @@ -84,9 +86,14 @@ public class VisitPlotViewer extends ViewPart implements private final Map entryMap; /** - * A List of all plotted Entries. + * A List of all plot-able Entries. */ - private final List plottedEntries; + private final List plotEntries; + + /** + * The current Entry that is plotted, or null if none is plotted. + */ + private Entry plottedEntry; /** * A List containing the ICEResource for each of the currently plotted @@ -155,7 +162,7 @@ public VisitPlotViewer() { entryMap = new HashMap(); // Initialize the lists for the selected plots. - plottedEntries = new ArrayList(); + plotEntries = new ArrayList(); entryResources = new ArrayList(); // Initialize the Map of variable types to plot types @@ -199,18 +206,11 @@ public void createPartControl(Composite parent) { plotTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); // Add the selection listener - plotTypeCombo.addSelectionListener(new SelectionListener() { - + plotTypeCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { selectedPlotType = plotTypeCombo.getText(); - drawSelection(); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - selectedPlotType = plotTypeCombo.getText(); - drawSelection(); + drawSelection(new StructuredSelection(plottedEntry)); } }); @@ -223,7 +223,7 @@ public void widgetDefaultSelected(SelectionEvent e) { // Initialize the TreeViewer. plotTreeViewer = new TreeViewer(partComposite, SWT.H_SCROLL - | SWT.V_SCROLL | SWT.BORDER); + | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI); // The TreeViewer should grab all horizontal AND vertical space. plotTreeViewer.getControl().setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true)); @@ -251,25 +251,30 @@ public void setFocus() { /** * Refreshes the content in the {@link #plotTreeViewer}. */ - private void refreshPlotViewer() { + private void refreshPlotTreeViewer() { // Sync with the display - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - // If possible, reset the plotTreeViewer's input. - if (plotTreeViewer != null) { - - System.out.println("VisitPlotViewer message: " - + "Refreshing TreeViewer."); - - // Reset the input for the plotTreeViewer. The viewer just - // takes an array of Entry objects. - plotTreeViewer.setInput(plottedEntries.toArray()); - - plotTreeViewer.refresh(); - plotTreeViewer.getTree().redraw(); + if (plotTreeViewer != null) { + final TreeViewer plotTreeViewer = this.plotTreeViewer; + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (plotTreeViewer != null) { + // Reset the input for the plotTreeViewer. The viewer + // just takes an array of Entry objects. + plotTreeViewer.setInput(plotEntries.toArray()); + + plotTreeViewer.refresh(); + + // If possible, force a redraw of the TreeViewer's Tree. + Tree plotTree = plotTreeViewer.getTree(); + if (plotTree != null && !plotTree.isDisposed()) { + plotTree.redraw(); + } + } + return; } - } - }); + }); + } return; } @@ -362,7 +367,7 @@ private void createActions() { // Create a delete button and add it to the tool bar deletePlotAction = new DeletePlotAction(this); toolBarManager.add(deletePlotAction); - deletePlotAction.setEnabled(!plottedEntries.isEmpty()); + deletePlotAction.setEnabled(!plotEntries.isEmpty()); // Create an add button and add it to the tool bar addPlotAction = new AddVisitPlotAction(this); @@ -494,7 +499,7 @@ public void addPlot(Entry entry) { && entry == entryMap.get(entry.getId())) { // Add this entry to our bookkeeping. - plottedEntries.add(entry); + plotEntries.add(entry); entryResources.add(resource); // Mark the entry as being plotted. @@ -504,7 +509,7 @@ public void addPlot(Entry entry) { + entry.getName() + "\"."); // Update the plotViewer. - refreshPlotViewer(); + refreshPlotTreeViewer(); } return; @@ -522,8 +527,8 @@ public void removePlot(Entry entry) { if (entry != null && "true".equals(entry.getValue())) { // Get the index of the entry in the list of plotted entries. int index = -1; - for (int i = 0; i < plottedEntries.size(); i++) { - if (entry == plottedEntries.get(i)) { + for (int i = 0; i < plotEntries.size(); i++) { + if (entry == plotEntries.get(i)) { index = i; break; } @@ -532,7 +537,7 @@ public void removePlot(Entry entry) { if (index > -1) { // Remove the resource and entry from our bookkeeping. entryResources.remove(index); - plottedEntries.remove(index); + plotEntries.remove(index); System.out.println("VisitPlotViewer message: Removing plot \"" + entry.getName() + "\"."); @@ -540,20 +545,20 @@ public void removePlot(Entry entry) { // Mark the plot as not plotted. entry.setValue("false"); - // FIXME - This definitely needs a better way to access the - // VisIt widget. - IEditorPart editorPart = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getActivePage() - .getActiveEditor(); - VisitEditor editor = (VisitEditor) editorPart; - VisItSwtWidget widget = editor.getVizWidget(); - widget.activate(); - - // Delete an existing plot - widget.getViewerMethods().deleteActivePlots(); - // Update the plotViewer. - refreshPlotViewer(); + refreshPlotTreeViewer(); + + // If the deleted plot was the plotted one, we need to clear the + // plot view. + if (entry == plottedEntry) { + // Unset the plotted Entry. + plottedEntry = null; + + // Activate the VisIt widget so we can clear the plot. + VisItSwtWidget widget = getPlotWidget(); + widget.activate(); + widget.getViewerMethods().deleteActivePlots(); + } } } return; @@ -571,8 +576,8 @@ public void drawPlot(Entry entry) { if (entry != null && "true".equals(entry.getValue())) { // Get the index of the entry in the list of plotted entries. int index = -1; - for (int i = 0; i < plottedEntries.size(); i++) { - if (entry == plottedEntries.get(i)) { + for (int i = 0; i < plotEntries.size(); i++) { + if (entry == plotEntries.get(i)) { index = i; break; } @@ -584,16 +589,12 @@ public void drawPlot(Entry entry) { System.out.println("VisitPlotViewer message: Drawing plot \"" + entry.getName() + "\"." + entry.getParent()); - // FIXME - This definitely needs a better way to access the - // VisIt widget. - IEditorPart editorPart = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getActivePage() - .getActiveEditor(); - VisitEditor editor = (VisitEditor) editorPart; - VisItSwtWidget widget = editor.getVizWidget(); - widget.activate(); + // Store a reference to the plotted Entry. + plottedEntry = entry; - // Delete an existing plot + // Activate the VisIt widget so we can clear the plot. + VisItSwtWidget widget = getPlotWidget(); + widget.activate(); widget.getViewerMethods().deleteActivePlots(); // Add the plot to the widget. @@ -650,20 +651,15 @@ public void removeSelection() { /** * Draws all plots selected in {@link #plotTreeViewer}. */ - public void drawSelection() { - // Get the selection from the plotTreeViewer. It should at least be - // an IStructuredSelection (a parent interface of TreeSelections). - ISelection selection = plotTreeViewer.getSelection(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection) selection; + public void drawSelection(IStructuredSelection selection) { + if (selection != null && !selection.isEmpty()) { // Create a List of entries to be plotted. List entries = new ArrayList(); // Loop over the selected elements and add any Entry to the List // of entries to be plotted. - for (Iterator iter = structuredSelection.iterator(); iter - .hasNext();) { + for (Iterator iter = selection.iterator(); iter.hasNext();) { Object object = iter.next(); if (object instanceof Entry) { entries.add((Entry) object); @@ -676,7 +672,6 @@ public void drawSelection() { drawPlot(entry); } } - return; } @@ -730,9 +725,6 @@ public void selectionChanged(SelectionChangedEvent event) { // Update the plot type selection Combo. updatePlotTypeCombo(); - // Draw the selection on single clicks - drawSelection(); - // Enable the DeletePlotAction if possible. ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { @@ -754,13 +746,10 @@ public void selectionChanged(SelectionChangedEvent event) { * The DoubleClickEvent that fired this method. */ public void doubleClick(DoubleClickEvent event) { - - // FIXME Consider using double-clicks to draw in a new window. For now, - // just draw in the same window. - // Update the plot type selection Combo. - updatePlotTypeCombo(); - - drawSelection(); + ISelection selection = event.getSelection(); + if (selection instanceof IStructuredSelection) { + drawSelection((IStructuredSelection) selection); + } } // ----------------------------------------- // @@ -802,4 +791,15 @@ private void updatePlotTypeCombo() { } } + /** + * Gets the widget used to render the plot. + * + * @return The VisItSwtWidget in the Plot View/Editor. + */ + private VisItSwtWidget getPlotWidget() { + IEditorPart editorPart = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + VisitEditor editor = (VisitEditor) editorPart; + return editor.getVizWidget(); + } }