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

Commit

Permalink
Added a context menu for setting the VisIt plot representation type.
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Deyton <deytonjh@ornl.gov>
  • Loading branch information
Jordan Deyton committed Apr 17, 2015
1 parent 4615191 commit bdac549
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
Expand Up @@ -630,14 +630,10 @@ public void run() {
dispose();
}
};
contextMenuManager.add(removeAction);

// Add a separator between the remove and set plot type MenuItems.
contextMenuManager.add(new Separator());

// Create the root ActionTree for setting the plot category and
// type.
ActionTree plotTypeTree = new ActionTree("Set Plot Type");
final ActionTree plotTypeTree = new ActionTree("Set Plot Type");
try {
// Add an ActionTree for each category, and then add ActionTree
// leaf
Expand Down Expand Up @@ -675,7 +671,10 @@ public void run() {
} catch (Exception e) {
e.printStackTrace();
}
// Add the ActionTree to the context Menu.

// Add the items to the context menu.
contextMenuManager.add(removeAction);
contextMenuManager.add(new Separator());
contextMenuManager.add(plotTypeTree.getContributionItem());

// Set the context Menu for the plot Composite.
Expand Down
1 change: 1 addition & 0 deletions src/org.eclipse.ice.viz.service.visit/META-INF/MANIFEST.MF
Expand Up @@ -5,6 +5,7 @@ Bundle-SymbolicName: org.eclipse.ice.viz.service.visit;singleton:=true
Bundle-Version: 2.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: gov.lbnl.visit.swt,
org.eclipse.ice.client.common,
org.eclipse.ice.client.widgets.viz.service,
org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.datastructures.form,
Expand Down
Expand Up @@ -5,10 +5,16 @@
import gov.lbnl.visit.swt.VisItSwtConnection;
import gov.lbnl.visit.swt.VisItSwtWidget;

import org.eclipse.ice.client.common.ActionTree;
import org.eclipse.ice.viz.service.connections.ConnectionPlotRender;
import org.eclipse.ice.viz.service.connections.IConnectionAdapter;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;

import visit.java.client.ViewerMethods;

Expand Down Expand Up @@ -64,6 +70,13 @@ public class VisItPlotRender extends ConnectionPlotRender<VisItSwtConnection> {
*/
private VisItSwtWidget canvas;

/**
* An ActionTree for populating the context menu with a list of allowed
* representations. This should be updated (as necessary) when the context
* menu is opened.
*/
private final ActionTree repTree;

/**
* The default constructor.
*
Expand All @@ -82,6 +95,10 @@ public VisItPlotRender(Composite parent, VisItPlot plot) {
// implementation to access the plot representations.
this.plot = plot;

// Create the ActionTree that will contain the representations for the
// current plot category.
repTree = new ActionTree("Representation");

return;
}

Expand Down Expand Up @@ -128,8 +145,32 @@ protected Composite createPlotComposite(Composite parent, int style,
// canvas.
new VisItMouseManager(canvas);

// Set the canvas' context Menu to the parent's.
canvas.setMenu(parent.getMenu());
// Set up the canvas' context Menu.
MenuManager menuManager = new MenuManager();
// If the parent context Menu is not available, create a new one.
Menu menu = parent.getMenu();
if (menu == null) {
menu = menuManager.createContextMenu(canvas);
// TODO Populate the "Set Plot Type" menu with the plot categories
// and types in case it's not already available.
}

// FIXME There may be a better way to do this...
// When the Menu is about to be shown, add the representation options to
// it.
menu.addMenuListener(new MenuListener() {
@Override
public void menuHidden(MenuEvent e) {
// Nothing to do.
}

@Override
public void menuShown(MenuEvent e) {
repTree.getContributionItem().fill((Menu) e.widget, -1);
}
});

canvas.setMenu(menu);

return canvas;
}
Expand Down Expand Up @@ -210,6 +251,21 @@ protected void updatePlotComposite(Composite plotComposite,
widget.addPlot(representation, type);
widget.drawPlots();

// Rebuild the VisIt representation tree based on the current
// category (if the category actually changed).
if (!category.equals(plotCategory)) {
repTree.removeAll();
for (final String rep : plot.getRepresentations(category)) {
repTree.add(new ActionTree(new Action(rep) {
@Override
public void run() {
setPlotRepresentation(rep);
refresh();
}
}));
}
}

// Change the record of the current plot category and type for this
// PlotRender.
plotCategory = category;
Expand Down

0 comments on commit bdac549

Please sign in to comment.