Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Added a ToolBar to the ParaViewPlotRender so that the plot's category
Browse files Browse the repository at this point in the history
and type can be changed.

Signed-off-by: Jordan Deyton <deytonjh@ornl.gov>
  • Loading branch information
Jordan Deyton committed Mar 10, 2015
1 parent 618a9f4 commit d9a283c
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/org.eclipse.ice.viz.service.paraview/META-INF/MANIFEST.MF
Expand Up @@ -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,
Expand Down
Expand Up @@ -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;
Expand All @@ -17,6 +27,8 @@ public class ParaViewPlotRender extends ConnectionPlotRender<VtkWebClient> {

// TODO Use a thread to throttle the resize events.

private List<ActionTree> actions;

/**
* The default constructor.
*
Expand All @@ -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(
Expand All @@ -67,7 +98,7 @@ public void controlResized(ControlEvent e) {
}
});

return composite;
return plotContainer;
}

/*
Expand All @@ -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.
* <p>
* <b>Note:</b> This method should only be called once, and should be called
* at plot creation time.
* </p>
*
* @param toolBar
* The {@code ToolBarManager} that will be populated.
*/
private void fillToolBar(ToolBarManager toolBar) {
actions = new ArrayList<ActionTree>();

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<String, String[]> plotTypes = plot.getPlotTypes();
for (Entry<String, String[]> 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)
*
Expand All @@ -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;
}

/*
Expand Down

0 comments on commit d9a283c

Please sign in to comment.