diff --git a/src/org.eclipse.ice.viz.service.paraview/META-INF/MANIFEST.MF b/src/org.eclipse.ice.viz.service.paraview/META-INF/MANIFEST.MF index b3c4bbc70..1cc3331c9 100644 --- a/src/org.eclipse.ice.viz.service.paraview/META-INF/MANIFEST.MF +++ b/src/org.eclipse.ice.viz.service.paraview/META-INF/MANIFEST.MF @@ -7,12 +7,14 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: com.kitware.vtk.web, com.kitware.vtk.web.util, org.eclipse.core.runtime.preferences;version="3.3.0", + org.eclipse.ice.client.common, org.eclipse.ice.client.widgets.viz.service, org.eclipse.ice.datastructures.ICEObject, org.eclipse.ice.datastructures.form, org.eclipse.ice.viz.service, org.eclipse.ice.viz.service.connections, org.eclipse.ice.viz.service.preferences, + org.eclipse.jface.action, org.eclipse.jface.dialogs, org.eclipse.jface.preference, org.eclipse.swt, diff --git a/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlotRender.java b/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlotRender.java index 2ddee47af..987250bb1 100644 --- a/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlotRender.java +++ b/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlotRender.java @@ -2,13 +2,23 @@ import java.awt.BorderLayout; import java.awt.Frame; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import org.eclipse.ice.client.common.ActionTree; import org.eclipse.ice.viz.service.connections.ConnectionPlotRender; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ToolBarManager; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.ToolBar; import com.kitware.vtk.web.VtkWebClient; import com.kitware.vtk.web.util.InteractiveRenderPanel; @@ -17,6 +27,8 @@ public class ParaViewPlotRender extends ConnectionPlotRender { // TODO Use a thread to throttle the resize events. + private List actions; + /** * The default constructor. * @@ -42,12 +54,31 @@ public ParaViewPlotRender(Composite parent, ParaViewPlot plot) { protected Composite createPlotComposite(Composite parent, int style, VtkWebClient connection) throws Exception { + // Create a container to hold a ToolBar and the ParaView widget. + Composite plotContainer = new Composite(parent, style); + plotContainer.setBackground(parent.getBackground()); + plotContainer.setFont(parent.getFont()); + GridLayout gridLayout = new GridLayout(); + // Get rid of the default margins (5 px on top, bottom, left, right). + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + plotContainer.setLayout(gridLayout); + + // Create a ToolBar. + ToolBarManager toolBarManager = new ToolBarManager(); + ToolBar toolBar = toolBarManager.createControl(plotContainer); + toolBar.setBackground(parent.getBackground()); + toolBar.setFont(parent.getFont()); + toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + fillToolBar(toolBarManager); + // Since the ParaView widget is built on AWT, we will need to use the // SWT_AWT bridge below. // Create the Composite that will contain the embedded ParaView widget. - final Composite composite = new Composite(parent, SWT.EMBEDDED + final Composite composite = new Composite(plotContainer, SWT.EMBEDDED | SWT.DOUBLE_BUFFERED); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // Create the ParaView widget. final InteractiveRenderPanel renderPanel = new InteractiveRenderPanel( @@ -67,7 +98,7 @@ public void controlResized(ControlEvent e) { } }); - return composite; + return plotContainer; } /* @@ -85,6 +116,71 @@ protected void updatePlotComposite(Composite plotComposite, return; } + /** + * Fills the specified {@code ToolBar} with actions that can be used to + * update the rendered plot. + *

+ * Note: This method should only be called once, and should be called + * at plot creation time. + *

+ * + * @param toolBar + * The {@code ToolBarManager} that will be populated. + */ + private void fillToolBar(ToolBarManager toolBar) { + actions = new ArrayList(); + + ActionTree plotTypesTree = new ActionTree("Plot Types"); + actions.add(plotTypesTree); + + // Create an ActionTree for the available plot categories and types. + // Selecting one of the leaf nodes should set the category and type for + // the associated plot. + try { + Map plotTypes = plot.getPlotTypes(); + for (Entry entry : plotTypes.entrySet()) { + // Create a tree for the category and add it to the main plot + // type tree. It should contain all of the available types for + // the category. + final String category = entry.getKey(); + ActionTree categoryTree = new ActionTree(category); + plotTypesTree.add(categoryTree); + + // For each plot type in this category, add an ActionTree that, + // when clicked, updates the plot category and type. + for (final String type : entry.getValue()) { + ActionTree typeTree = new ActionTree(new Action(type) { + @Override + public void run() { + try { + plot.draw(category, type, parent); + } catch (Exception e) { + System.err + .println("IPlot error: " + + "Failed to update the plot type to category \"" + + category + "\" and type \"" + + type + "\"."); + } + } + }); + categoryTree.add(typeTree); + } + } + } catch (Exception e) { + plotTypesTree.setEnabled(false); + } + + // TODO Add widgets to change the representation. + + // Populate the ToolBarManager with the ActionTrees. + for (ActionTree tree : actions) { + toolBar.add(tree.getContributionItem()); + } + toolBar.update(true); + + return; + } + /* * (non-Javadoc) * @@ -94,7 +190,15 @@ protected void updatePlotComposite(Composite plotComposite, */ @Override protected void disposePlotComposite(Composite plotComposite) { - // Nothing to do yet. + // Dispose of the ActionTrees if necessary. + if (actions != null) { + for (ActionTree tree : actions) { + tree.dispose(); + } + actions.clear(); + } + + return; } /*