def handleMouseEvent(self, event): if event.isPopupTrigger(): loadMenu = JMenuItem("Load .proto") loadMenu.addActionListener(self.tab.listener) popup = JPopupMenu() popup.add(loadMenu) if self.tab.descriptors: deserializeAsMenu = JMenu("Deserialize As...") popup.addSeparator() popup.add(deserializeAsMenu) for pb2, descriptors in self.tab.descriptors.iteritems(): subMenu = JMenu(pb2) deserializeAsMenu.add(subMenu) for name, descriptor in descriptors.iteritems(): protoMenu = JMenuItem(name) protoMenu.addActionListener( DeserializeProtoActionListener(self.tab, descriptor)) subMenu.add(protoMenu) popup.show(event.getComponent(), event.getX(), event.getY()) return
def createToCContextMenu(mapContext, selectedLayer): # TOC.java menu = JPopupMenu() ep = ToolsLocator.getExtensionPointManager().get("View_TocActions") from org.gvsig.app.project.documents.view.toc.actions import ZoomAlTemaTocMenuEntry #from org.gvsig.app.project.documents.view.ViewManager import ContextMenuActionAdapterToExtensionBuilder #ep.append("ZoomAlTema", "", ZoomAlTemaTocMenuEntry()) tocItem = TocItemLeaf(None, selectedLayer.getName(),selectedLayer.getShapeType()) nodeValue = DefaultMutableTreeNode(tocItem) #menu = FPopupMenu(mapContext, nodeValue) #return menu activesLayers = mapContext.getLayers().getActives() actions = [] for epx in ep.iterator(): action = epx.create() actions.append([action,action.getGroupOrder(), action.getGroup(), action.getOrder()]) sortedActions = sorted(actions, key = lambda x: (x[1], x[2],x[3])) group = None z = ZoomAlTemaTocMenuEntry() z.setMapContext(mapContext) zitem = LayerMenuItem(z, selectedLayer,tocItem, mapContext) menu.add(zitem) menu.addSeparator() for actionList in sortedActions: action = actionList[0] if action.isVisible(tocItem, activesLayers): #(layer,)): if group == None: pass elif group != action.getGroup(): menu.addSeparator() group = action.getGroup() if isinstance(action, AbstractTocContextMenuAction): action.setMapContext(mapContext) if action.isEnabled(tocItem, activesLayers): newItem = LayerMenuItem(action, selectedLayer, tocItem, mapContext) menu.add(newItem) else: newItem = LayerMenuItem(action, selectedLayer, tocItem, mapContext) newItem.setEnabled(False) menu.add(newItem) return menu