def main(*args): menu = JPopupMenu() ep = ToolsLocator.getExtensionPointManager().get("View_TocActions") layer = gvsig.currentLayer() tocItem = TocItemLeaf(None, layer.getName(), layer.getShapeType()) for x in ep.iterator(): action = x.create() print "action", action continue if action.isVisible(tocItem, (layer, )): print action menu.add(MenuItem(action, layer, tocItem)) else: print "*** else:", action
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
def selfRegisterPreferences(): extensionPointsManager = ToolsLocator.getExtensionPointManager() ep = extensionPointsManager.add("AplicationPreferences", "") ep.append("fieldExpression", "", FieldCalculatorToolPreferences())