public JPopupMenu getPopupMenu(TreePath selectionPath) {
// Create the popup menu so we can add our custom items.
JPopupMenu popupMenu = new JPopupMenu();
BrowserTreeNode selectedNode = (selectionPath == null) ? null : (BrowserTreeNode) selectionPath.getLastPathComponent();
if (selectedNode instanceof GemDrawer) {
// The node represents a "module".
if (((GemDrawer)selectedNode).isNamespaceNode()) {
// a module namespace node is a 'phantom' node that does not really
// correspond to an actual module
} else {
// Add the 'Change Working Module' menu item.
ModuleName moduleName = ((GemDrawer) selectedNode).getModuleName();
Action changeModuleAction = getChangeModuleAction(moduleName);
popupMenu.add(GemCutter.makeNewMenuItem(changeModuleAction));
// Add a separator.
popupMenu.addSeparator();
// Add menu items for the workspace.
popupMenu.add(GemCutter.makeNewMenuItem(getSyncModuleAction(moduleName)));
popupMenu.add(GemCutter.makeNewMenuItem(getSyncModuleToRevisionAction(moduleName)));
popupMenu.add(GemCutter.makeNewMenuItem(getRevertModuleAction(moduleName)));
popupMenu.addSeparator();
popupMenu.add(GemCutter.makeNewMenuItem(getAddTypeDeclsToModuleAction(moduleName)));
popupMenu.add(GemCutter.makeNewMenuItem(getCleanModuleImportsAction(moduleName)));
popupMenu.add(GemCutter.makeNewMenuItem(getRenameModuleAction(moduleName)));
popupMenu.add(GemCutter.makeNewMenuItem(getRemoveModuleAction(moduleName)));
}
} else if (selectedNode instanceof GemTreeNode) {
// The node represents a gem.
// Add a 'Load Design...' menu item to load the gem design.
GemEntity gemEntity = (GemEntity) selectedNode.getUserObject();
popupMenu.add(GemCutter.makeNewMenuItem(getOpenDesignAction(gemEntity)));
popupMenu.add(GemCutter.makeNewMenuItem(getRenameGemAction(gemEntity)));
popupMenu.add(GemCutter.makeNewMenuItem(getSearchForGemAction(gemEntity)));
popupMenu.add(GemCutter.makeNewMenuItem(getSearchForGemDefinitionAction(gemEntity)));
}