Example usage for com.intellij.openapi.ui JBPopupMenu JBPopupMenu

List of usage examples for com.intellij.openapi.ui JBPopupMenu JBPopupMenu

Introduction

In this page you can find the example usage for com.intellij.openapi.ui JBPopupMenu JBPopupMenu.

Prototype

public JBPopupMenu() 

Source Link

Usage

From source file:com.android.tools.idea.avdmanager.DeviceDefinitionList.java

License:Apache License

private void possiblyShowPopup(MouseEvent e) {
    if (!e.isPopupTrigger()) {
        return;//from w  w w  .j  a va  2 s. co m
    }
    Point p = e.getPoint();
    int row = myTable.rowAtPoint(p);
    int col = myTable.columnAtPoint(p);
    if (row != -1 && col != -1) {
        JBPopupMenu menu = new JBPopupMenu();
        menu.add(createMenuItem(new CloneDeviceAction(this)));
        menu.add(createMenuItem(new EditDeviceAction(this)));
        menu.add(createMenuItem(new ExportDeviceAction(this)));
        menu.add(createMenuItem(new DeleteDeviceAction(this)));
        menu.show(myTable, p.x, p.y);
    }
}

From source file:com.android.tools.idea.editors.hierarchyview.HierarchyViewer.java

License:Apache License

public HierarchyViewer(@NotNull ViewNode node, @NotNull BufferedImage preview,
        @NotNull final PropertiesComponent propertiesComponent, @NotNull Disposable parent) {
    myRoot = node;/*from   ww w .  ja  va 2 s  .  c o m*/

    // Create UI
    // Preview
    myPreview = new ViewNodeActiveDisplay(node, preview);

    // Node tree
    myNodeTree = new RollOverTree(node);
    myNodeTree.setCellRenderer(new ViewNodeTreeRenderer());

    // Properties table
    myTableModel = new ViewNodeTableModel();
    myPropertiesTable = new JBTable(myTableModel);
    myPropertiesTable.setFillsViewportHeight(true);
    myPropertiesTable.getTableHeader().setReorderingAllowed(false);
    myPropertiesSpeedSearch = new TableSpeedSearch(myPropertiesTable, (object, cell) -> {
        if (object == null) {
            return null;
        }

        assert object instanceof String : "The model is expected to return String instances as values";
        return (String) object;
    });
    myPropertiesSpeedSearch.setComparator(new SpeedSearchComparator(false, false));

    myContentSplitter = new ThreeComponentsSplitter(false, true);
    Disposer.register(parent, myContentSplitter);

    final JScrollPane firstComponent = ScrollPaneFactory.createScrollPane(myNodeTree);
    final JScrollPane lastComponent = ScrollPaneFactory.createScrollPane(myPropertiesTable);

    myContentSplitter.setFirstComponent(firstComponent);
    myContentSplitter.setInnerComponent(myPreview);
    myContentSplitter.setLastComponent(lastComponent);

    // make sure the two side panels never show up with 0 width
    int minWidth = 20;
    setMinimumWidth(firstComponent, minWidth);
    setMinimumWidth(lastComponent, minWidth);
    myContentSplitter.setHonorComponentsMinimumSize(true);

    int width = Math.max(propertiesComponent.getInt(FIRST_COMPONENT_WIDTH, DEFAULT_WIDTH), minWidth);
    myContentSplitter.setFirstSize(width);

    width = Math.max(propertiesComponent.getInt(LAST_COMPONENT_WIDTH, DEFAULT_WIDTH), minWidth);
    myContentSplitter.setLastSize(width);

    // listen to size changes and update the saved sizes
    ComponentAdapter resizeListener = new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent componentEvent) {
            propertiesComponent.setValue(FIRST_COMPONENT_WIDTH, firstComponent.getSize().width, DEFAULT_WIDTH);
            propertiesComponent.setValue(LAST_COMPONENT_WIDTH, lastComponent.getSize().width, DEFAULT_WIDTH);
        }
    };
    firstComponent.addComponentListener(resizeListener);
    lastComponent.addComponentListener(resizeListener);

    myPreview.addViewNodeActiveDisplayListener(this);
    myNodeTree.addTreeSelectionListener(this);
    myNodeTree.addTreeHoverListener(this);

    // Expand visible nodes
    for (int i = 0; i < myNodeTree.getRowCount(); i++) {
        TreePath path = myNodeTree.getPathForRow(i);
        ViewNode n = (ViewNode) path.getLastPathComponent();
        if (n.isDrawn()) {
            myNodeTree.expandPath(path);
        }
    }

    // Select the root node
    myNodeTree.setSelectionRow(0);

    // Node popup
    myNodePopup = new JBPopupMenu();
    myNodeVisibleMenuItem = new JBCheckboxMenuItem("Show in preview");
    myNodeVisibleMenuItem.addActionListener(new ShowHidePreviewActionListener());
    myNodePopup.add(myNodeVisibleMenuItem);
    myNodeTree.addMouseListener(new NodeRightClickAdapter());
}

From source file:com.android.tools.idea.editors.manifest.ManifestPanel.java

License:Apache License

private void createPopupMenu() {
    myPopup = new JBPopupMenu();
    JMenuItem gotoItem = new JBMenuItem("Go to Declaration");
    gotoItem.addActionListener(e -> {
        TreePath treePath = myTree.getSelectionPath();
        final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
        if (node != null) {
            goToDeclaration(node.getUserObject());
        }/*  w  ww .  j a va  2  s  .  c o m*/
    });
    myPopup.add(gotoItem);
    myRemoveItem = new JBMenuItem("Remove");
    myRemoveItem.addActionListener(e -> {
        TreePath treePath = myTree.getSelectionPath();
        final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();

        new WriteCommandAction.Simple(myFacet.getModule().getProject(), "Removing manifest tag",
                ManifestUtils.getMainManifest(myFacet)) {
            @Override
            protected void run() throws Throwable {
                ManifestUtils.toolsRemove(ManifestUtils.getMainManifest(myFacet), node.getUserObject());
            }
        }.execute();
    });
    myPopup.add(myRemoveItem);

    MouseListener ml = new MouseAdapter() {
        @Override
        public void mousePressed(@NotNull MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopup(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopup(e);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
                if (treePath != null) {
                    ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
                    Node attribute = node.getUserObject();
                    if (attribute instanceof Attr) {
                        goToDeclaration(attribute);
                    }
                }
            }
        }

        private void handlePopup(@NotNull MouseEvent e) {
            TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
            if (treePath == null || e.getSource() == myDetails) {
                // Use selection instead
                treePath = myTree.getSelectionPath();
            }
            if (treePath != null) {
                ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
                myRemoveItem.setEnabled(canRemove(node.getUserObject()));
                myPopup.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };
    myTree.addMouseListener(ml);
    myDetails.addMouseListener(ml);
}

From source file:com.android.tools.idea.editors.navigation.NavigationView.java

License:Apache License

public NavigationView(RenderingParameters renderingParams, NavigationModel model, SelectionModel selectionModel,
        CodeGenerator codeGenerator) {//w  w  w.j  av a  2 s . c  om
    myRenderingParams = renderingParams;
    myNavigationModel = model;
    mySelectionModel = selectionModel;
    myCodeGenerator = codeGenerator;

    setFocusable(true);
    setLayout(null);

    // Mouse listener
    MouseAdapter mouseListener = new MyMouseListener();
    addMouseListener(mouseListener);
    addMouseMotionListener(mouseListener);

    // Popup menu
    final JPopupMenu menu = new JBPopupMenu();
    final JMenuItem anItem = new JBMenuItem("New Activity...");
    anItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            Module module = myRenderingParams.facet.getModule();
            NewAndroidActivityWizard dialog = new NewAndroidActivityWizard(module, null, null);
            dialog.init();
            dialog.setOpenCreatedFiles(false);
            dialog.show();
        }
    });
    menu.add(anItem);
    setComponentPopupMenu(menu);

    // Focus listener
    addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent focusEvent) {
            repaint();
        }

        @Override
        public void focusLost(FocusEvent focusEvent) {
            repaint();
        }
    });

    // Drag and Drop listener
    final DnDManager dndManager = DnDManager.getInstance();
    dndManager.registerTarget(new MyDnDTarget(), this);

    // Key listeners
    Action remove = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setSelection(Selections.NULL);
        }
    };
    registerKeyBinding(KeyEvent.VK_DELETE, "delete", remove);
    registerKeyBinding(KeyEvent.VK_BACK_SPACE, "backspace", remove);

    // Model listener
    myNavigationModel.getListeners().add(new Listener<Event>() {
        @Override
        public void notify(@NotNull Event event) {
            if (DEBUG)
                LOG.info("NavigationView:: <listener> " + myStateCacheIsValid + " "
                        + myTransitionEditorCacheIsValid);
            if (event.operandType.isAssignableFrom(State.class)) {
                myStateCacheIsValid = false;
            }
            if (event.operandType.isAssignableFrom(Transition.class)) {
                myTransitionEditorCacheIsValid = false;
            }
            if (event == NavigationEditor.PROJECT_READ) {
                setSelection(Selections.NULL);
            }
            revalidate();
            repaint();
        }
    });
}

From source file:com.android.tools.idea.editors.theme.ThemeEditorTable.java

License:Apache License

private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
    if (row < 0 || column < 0) {
        return null;
    }/*from  w w w. j  a  v  a 2s  .  c o  m*/

    TableModel rawModel = getModel();
    if (!(rawModel instanceof AttributesTableModel)) {
        return null;
    }

    final AttributesTableModel model = (AttributesTableModel) rawModel;
    AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));

    if (contents instanceof AttributesTableModel.AttributeContents) {
        final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;

        final EditedStyleItem item = attribute.getValue();
        if (item == null) {
            return null;
        }

        final JBPopupMenu popupMenu = new JBPopupMenu();
        if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
            popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    myGoToListener.goTo(item);
                }
            });
        } else {
            final ResourceResolver resolver = myContext.getResourceResolver();
            assert resolver != null;
            final Project project = myContext.getProject();
            final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
            final File file = new File(resourceValue.getValue());

            final VirtualFileManager manager = VirtualFileManager.getInstance();
            final VirtualFile virtualFile = file.exists()
                    ? manager.findFileByUrl("file://" + file.getAbsolutePath())
                    : null;
            if (virtualFile != null) {
                popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
                        FileEditorManager.getInstance(project).openEditor(descriptor, true);
                    }
                });
            }
        }

        myJavadocAction.setCurrentItem(item);
        popupMenu.add(myJavadocAction);

        final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
        if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
            popupMenu.add(new AbstractAction("Reset value") {
                @Override
                public void actionPerformed(ActionEvent e) {
                    selectedStyle.removeAttribute(item.getQualifiedName());
                    model.fireTableCellUpdated(attribute.getRowIndex(), 0);
                }
            });
        }

        return popupMenu;
    } else if (contents instanceof AttributesTableModel.ParentAttribute) {
        final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
        if (parentStyle == null) {
            return null;
        }

        final JBPopupMenu menu = new JBPopupMenu();
        menu.add(new AbstractAction(GO_TO_DECLARATION) {
            @Override
            public void actionPerformed(ActionEvent e) {
                myGoToListener.goToParent();
            }
        });

        return menu;
    }

    return null;
}

From source file:com.android.tools.idea.editors.theme.ui.VariantsComboBox.java

License:Apache License

@NotNull
protected JPopupMenu createPopupMenu() {
    JPopupMenu menu = new JBPopupMenu();
    Border existingBorder = menu.getBorder();

    if (existingBorder != null) {
        menu.setBorder(BorderFactory.createCompoundBorder(existingBorder, VARIANT_MENU_BORDER));
    } else {/* w  w w  . j  a  va 2s .  com*/
        menu.setBorder(VARIANT_MENU_BORDER);
    }
    menu.setBackground(VARIANT_MENU_BACKGROUND_COLOR);

    int nElements = myModel.getSize();
    for (int i = 0; i < nElements; i++) {
        final Object element = myModel.getElementAt(i);
        JMenuItem item = new JBMenuItem(element.toString());
        item.setFont(ThemeEditorUtils.scaleFontForAttribute(item.getFont()));
        item.setBorder(VARIANT_ITEM_BORDER);
        if (i == 0) {
            // Pre-select the first element
            item.setArmed(true);
        }
        item.setBackground(VARIANT_MENU_BACKGROUND_COLOR);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Object selectedItem = myModel.getSelectedItem();

                if (selectedItem != null) {
                    fireItemSelectionChanged(new ItemEvent(VariantsComboBox.this, ItemEvent.ITEM_STATE_CHANGED,
                            selectedItem, ItemEvent.DESELECTED));
                }

                myModel.setSelectedItem(element);
                fireModelUpdated();

                fireItemSelectionChanged(new ItemEvent(VariantsComboBox.this, ItemEvent.ITEM_STATE_CHANGED,
                        element, ItemEvent.SELECTED));
            }
        });
        menu.add(item);
    }

    if (!myActions.isEmpty()) {
        if (nElements > 0) {
            menu.addSeparator();
        }
        for (Action action : myActions) {
            JMenuItem newMenuItem = new JBMenuItem(action);
            newMenuItem.setFont(ThemeEditorUtils.scaleFontForAttribute(newMenuItem.getFont()));
            newMenuItem.setBackground(VARIANT_MENU_BACKGROUND_COLOR);
            newMenuItem.setBorder(VARIANT_ITEM_BORDER);
            menu.add(newMenuItem);
        }
    }

    return menu;
}

From source file:com.android.tools.idea.run.DeviceChooser.java

License:Apache License

public DeviceChooser(boolean multipleSelection, @NotNull final Action okAction, @NotNull AndroidFacet facet,
        @NotNull IAndroidTarget projectTarget, @Nullable Predicate<IDevice> filter) {
    myFilter = filter;//  w  w  w. j  a  va  2s . c  o m
    myMinSdkVersion = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
    myProjectTarget = projectTarget;
    mySupportedAbis = facet.getAndroidModel() instanceof AndroidModuleModel
            ? ((AndroidModuleModel) facet.getAndroidModel()).getSelectedVariant().getMainArtifact()
                    .getAbiFilters()
            : null;

    // Currently, we only look at whether the device supports the watch feature.
    // We may not want to search the device for every possible feature, but only a small subset of important
    // features, starting with hardware type watch.
    if (LaunchUtils.isWatchFeatureRequired(facet)) {
        myRequiredHardwareFeatures = EnumSet.of(IDevice.HardwareFeature.WATCH);
    } else {
        myRequiredHardwareFeatures = EnumSet.noneOf(IDevice.HardwareFeature.class);
    }

    myDeviceTable = new JBTable();
    myPanel = ScrollPaneFactory.createScrollPane(myDeviceTable);
    myPanel.setPreferredSize(JBUI.size(550, 220));

    myDeviceTable.setModel(new MyDeviceTableModel(EMPTY_DEVICE_ARRAY));
    myDeviceTable.setSelectionMode(multipleSelection ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
            : ListSelectionModel.SINGLE_SELECTION);
    myDeviceTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (myProcessSelectionFlag) {
                fireSelectedDevicesChanged();
            }
        }
    });
    new DoubleClickListener() {
        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (myDeviceTable.isEnabled() && okAction.isEnabled()) {
                okAction.actionPerformed(null);
                return true;
            }
            return false;
        }
    }.installOn(myDeviceTable);

    myDeviceTable.setDefaultRenderer(LaunchCompatibility.class, new LaunchCompatibilityRenderer());
    myDeviceTable.setDefaultRenderer(IDevice.class,
            new DeviceRenderer.DeviceNameRenderer(facet.getAvdManagerSilently()));
    myDeviceTable.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && okAction.isEnabled()) {
                okAction.actionPerformed(null);
            }
        }
    });
    myDeviceTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                int i = myDeviceTable.rowAtPoint(e.getPoint());
                if (i >= 0) {
                    Object serial = myDeviceTable.getValueAt(i, SERIAL_COLUMN_INDEX);
                    final String serialString = serial.toString();
                    // Add a menu to copy the serial key.
                    JBPopupMenu popupMenu = new JBPopupMenu();
                    Action action = new AbstractAction("Copy Serial Number") {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            CopyPasteManager.getInstance().setContents(new StringSelection(serialString));
                        }
                    };
                    popupMenu.add(action);
                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            }
            super.mouseReleased(e);
        }
    });
    setColumnWidth(myDeviceTable, DEVICE_NAME_COLUMN_INDEX, "Samsung Galaxy Nexus Android 4.1 (API 17)");
    setColumnWidth(myDeviceTable, DEVICE_STATE_COLUMN_INDEX, "offline");
    setColumnWidth(myDeviceTable, COMPATIBILITY_COLUMN_INDEX, "Compatible");
    setColumnWidth(myDeviceTable, SERIAL_COLUMN_INDEX, "123456");

    // Do not recreate columns on every model update - this should help maintain the column sizes set above
    myDeviceTable.setAutoCreateColumnsFromModel(false);

    // Allow sorting by columns (in lexicographic order)
    myDeviceTable.setAutoCreateRowSorter(true);

    // the device change notifications from adb can sometimes be noisy (esp. when a device is [dis]connected)
    // we use this merging queue to collapse multiple updates to one
    myUpdateQueue = new MergingUpdateQueue("android.device.chooser", UPDATE_DELAY_MILLIS, true, null, this,
            null, Alarm.ThreadToUse.POOLED_THREAD);

    AndroidDebugBridge.addDebugBridgeChangeListener(this);
    AndroidDebugBridge.addDeviceChangeListener(this);
}

From source file:com.android.tools.idea.ui.resourcechooser.StateListPicker.java

License:Apache License

@NotNull
private JBPopupMenu createAlphaPopupMenu(@NotNull final ResourceHelper.StateListState state,
        @NotNull final StateComponent stateComponent) {
    JBPopupMenu popupMenu = new JBPopupMenu();
    final JMenuItem deleteAlpha = new JMenuItem("Delete alpha");
    popupMenu.add(deleteAlpha);//from w ww. j a v a2 s .  com
    deleteAlpha.setVisible(!StringUtil.isEmpty(state.getAlpha()));

    final JMenuItem createAlpha = new JMenuItem("Create alpha");
    popupMenu.add(createAlpha);
    createAlpha.setVisible(StringUtil.isEmpty(state.getAlpha()));

    deleteAlpha.addActionListener(e -> {
        stateComponent.getAlphaComponent().setVisible(false);
        stateComponent.setAlphaValue(null);
        state.setAlpha(null);
        updateIcon(stateComponent);
        deleteAlpha.setVisible(false);
        createAlpha.setVisible(true);
    });

    createAlpha.addActionListener(e -> {
        AlphaActionListener listener = stateComponent.getAlphaActionListener();
        if (listener == null) {
            return;
        }
        listener.actionPerformed(
                new ActionEvent(stateComponent.getAlphaComponent(), ActionEvent.ACTION_PERFORMED, null));
        if (!StringUtil.isEmpty(state.getAlpha())) {
            stateComponent.getAlphaComponent().setVisible(true);
            createAlpha.setVisible(false);
            deleteAlpha.setVisible(true);
        }
    });

    return popupMenu;
}

From source file:com.gogh.plugin.config.QueryOnlineConfig.java

License:Apache License

private void setComponentPopupWindow() {
    JBPopupMenu menu = new JBPopupMenu();

    final JBMenuItem copy = new JBMenuItem("Copy", IconLoader.getIcon(ICON.ICON_COPY_DARK));
    copy.addActionListener(e -> {//from   w w  w  .j  a  v  a  2  s.co m
        String selectedText = resultText.getSelectedText();
        if (!IString.isEmpty(selectedText)) {
            CopyPasteManager copyPasteManager = CopyPasteManager.getInstance();
            copyPasteManager.setContents(new StringSelection(selectedText));
        }
    });

    final JBMenuItem query = new JBMenuItem("Translate", IconLoader.getIcon(ICON.ICON_16));
    query.addActionListener(e -> query(resultText.getSelectedText()));

    menu.add(copy);
    menu.add(query);

    menu.addPopupMenuListener(new PopupMenuListenerAdapter() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            boolean hasSelectedText = !IString.isEmpty(resultText.getSelectedText());
            copy.setEnabled(hasSelectedText);
            query.setEnabled(hasSelectedText);
        }
    });

    resultText.setComponentPopupMenu(menu);
}

From source file:com.igormaznitsa.ideamindmap.editor.MindMapPanelControllerImpl.java

License:Apache License

@Override
public JPopupMenu makePopUpForMindMapPanel(final MindMapPanel source, final Point point,
        final AbstractElement element, final ElementPart partUnderMouse) {
    final JBPopupMenu result = new JBPopupMenu();

    if (element != null) {
        final JBMenuItem editText = new JBMenuItem(BUNDLE.getString("MMDGraphEditor.makePopUp.miEditText"),
                AllIcons.PopUp.EDITTEXT);
        editText.addActionListener(new ActionListener() {

            @Override/*from   w ww .j  av a 2 s . c o m*/
            public void actionPerformed(ActionEvent e) {
                editor.getMindMapPanel().startEdit(element);
            }
        });

        result.add(editText);

        final JBMenuItem addChild = new JBMenuItem(BUNDLE.getString("MMDGraphEditor.makePopUp.miAddChild"),
                AllIcons.PopUp.ADD);
        addChild.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                editor.getMindMapPanel().makeNewChildAndStartEdit(element.getModel(), null);
            }
        });

        result.add(addChild);
    }

    if (element != null || this.editor.getMindMapPanel().hasSelectedTopics()) {
        final JBMenuItem deleteItem = new JBMenuItem(this.editor.getMindMapPanel().hasSelectedTopics()
                ? BUNDLE.getString("MMDGraphEditor.makePopUp.miRemoveSelectedTopics")
                : BUNDLE.getString("MMDGraphEditor.makePopUp.miRemoveTheTopic"), AllIcons.PopUp.DELETE);
        deleteItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (editor.getMindMapPanel().hasSelectedTopics()) {
                    editor.getMindMapPanel().deleteSelectedTopics();
                } else {
                    editor.getMindMapPanel().deleteTopics(element.getModel());
                }
            }
        });

        result.add(deleteItem);
    }

    if (element != null || this.editor.getMindMapPanel().hasOnlyTopicSelected()) {
        final Topic theTopic = this.editor.getMindMapPanel().getFirstSelected() == null
                ? (element != null ? element.getModel() : null)
                : this.editor.getMindMapPanel().getFirstSelected();
        if (theTopic != null && theTopic.getParent() != null) {
            final JBMenuItem cloneItem = new JBMenuItem(
                    this.editor.getMindMapPanel().hasSelectedTopics()
                            ? BUNDLE.getString("MMDGraphEditor.makePopUp.miCloneSelectedTopic")
                            : BUNDLE.getString("MMDGraphEditor.makePopUp.miCloneTheTopic"),
                    AllIcons.PopUp.CLONE);
            cloneItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    editor.getMindMapPanel().cloneTopic(theTopic);
                }
            });

            result.add(cloneItem);
        }
    }

    if (element != null) {
        if (result.getComponentCount() > 0) {
            result.add(new JSeparator());
        }

        final Topic topic = element.getModel();

        final JBMenuItem editText = new JBMenuItem(topic.getExtras().containsKey(Extra.ExtraType.NOTE)
                ? BUNDLE.getString("MMDGraphEditor.makePopUp.miEditNote")
                : BUNDLE.getString("MMDGraphEditor.makePopUp.miAddNote"), AllIcons.PopUp.NOTE);
        editText.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                editTextForTopic(topic);
                editor.getMindMapPanel().requestFocus();
            }
        });

        result.add(editText);

        final JBMenuItem editLink = new JBMenuItem(topic.getExtras().containsKey(Extra.ExtraType.LINK)
                ? BUNDLE.getString("MMDGraphEditor.makePopUp.miEditURI")
                : BUNDLE.getString("MMDGraphEditor.makePopUp.miAddURI"), AllIcons.PopUp.URL);
        editLink.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                editLinkForTopic(topic);
                editor.getMindMapPanel().requestFocus();
            }
        });

        result.add(editLink);

        final JBMenuItem editTopicLink = new JBMenuItem(topic.getExtras().containsKey(Extra.ExtraType.TOPIC)
                ? BUNDLE.getString("MMDGraphEditor.makePopUp.miEditTransition")
                : BUNDLE.getString("MMDGraphEditor.makePopUp.miAddTransition"), AllIcons.PopUp.TOPIC);
        editTopicLink.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                editTopicLinkForTopic(topic);
                editor.getMindMapPanel().requestFocus();
            }
        });

        result.add(editTopicLink);

        final JBMenuItem editFileLink = new JBMenuItem(topic.getExtras().containsKey(Extra.ExtraType.FILE)
                ? BUNDLE.getString("MMDGraphEditor.makePopUp.miEditFile")
                : BUNDLE.getString("MMDGraphEditor.makePopUp.miAddFile"), AllIcons.PopUp.FILE);
        editFileLink.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                editFileLinkForTopic(topic);
                editor.getMindMapPanel().requestFocus();
            }
        });

        result.add(editFileLink);
    }

    if (element != null || source.hasSelectedTopics()) {
        if (result.getComponentCount() > 0) {
            result.add(new JSeparator());
        }

        final Topic[] topics;
        final String name;
        if (source.hasSelectedTopics()) {
            topics = source.getSelectedTopics();
            name = String.format(BUNDLE.getString("MMDGraphEditor.makePopUp.miColorsForSelected"),
                    topics.length);
        } else {
            topics = new Topic[] { element.getModel() };
            name = BUNDLE.getString("MMDGraphEditor.makePopUp.miColorsForTopic");
        }

        final JBMenuItem colors = new JBMenuItem(name, AllIcons.PopUp.COLORS);
        colors.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                processColorDialogForTopics(source, topics);
            }
        });

        result.add(colors);
    }

    if (result.getComponentCount() > 0) {
        result.add(new JSeparator());
    }

    final JBMenuItem expandAll = new JBMenuItem(BUNDLE.getString("MMDGraphEditor.makePopUp.miExpandAll"),
            AllIcons.PopUp.EXPANDALL);
    expandAll.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            editor.getMindMapPanel().collapseOrExpandAll(false);
        }

    });

    final JBMenuItem collapseAll = new JBMenuItem(BUNDLE.getString("MMDGraphEditor.makePopUp.miCollapseAll"),
            AllIcons.PopUp.COLLAPSEALL);
    collapseAll.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editor.getMindMapPanel().collapseOrExpandAll(true);
        }

    });

    final JCheckBoxMenuItem showJumps = new JCheckBoxMenuItem(
            BUNDLE.getString("MMDGraphEditor.makePopUp.miShowJumps"), AllIcons.PopUp.SHOWJUMPS,
            source.isShowJumps());
    showJumps.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editor.getMindMapPanel().setShowJumps(showJumps.isSelected());
        }
    });

    result.add(showJumps);
    result.add(expandAll);
    result.add(collapseAll);

    if (result.getComponentCount() > 0) {
        result.add(new JSeparator());
    }
    final JMenu exportMenu = new JMenu(BUNDLE.getString("MMDGraphEditor.makePopUp.miExportMapAs"));
    exportMenu.setIcon(AllIcons.PopUp.EXPORT);
    for (final Exporters e : Exporters.values()) {
        final AbstractMindMapExporter exp = e.getExporter();
        final JBMenuItem item = new JBMenuItem(exp.getName());
        item.setToolTipText(exp.getReference());
        item.setIcon(exp.getIcon());
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                try {
                    final JComponent options = exp.makeOptions();
                    if (options != null) {
                        if (!getDialogProvider().msgOkCancel(exp.getName(), options)) {
                            return;
                        }
                    }
                    exp.doExport(editor.getMindMapPanel(), options, null);
                    IdeaUtils.showPopup(
                            String.format(BUNDLE.getString("MMDGraphEditor.makePopUp.msgExportedSuccessfuly"),
                                    exp.getName()),
                            MessageType.INFO);
                } catch (Exception ex) {
                    LOGGER.error("Error during map export", ex); //NOI18N
                    IdeaUtils.showPopup(BUNDLE.getString("MMDGraphEditor.makePopUp.errMsgCantExport"),
                            MessageType.ERROR);
                }
            }
        });
        exportMenu.add(item);
    }
    result.add(exportMenu);

    result.add(new JSeparator());

    JBMenuItem printPreviewMenu = new JBMenuItem(BUNDLE.getString("MMDGraphEditor.makePopUp.miPrintPreview"),
            AllIcons.PopUp.PRINTER);
    printPreviewMenu.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final MMDPrintPanel panel = new MMDPrintPanel(
                    new IdeaMMDPrintPanelAdaptor(getEditor().getProject()), getEditor().getMindMapPanel());
            IdeaUtils.plainMessageClose(getEditor().getProject(), "Print mind map", panel);
        }
    });

    result.add(printPreviewMenu);

    JBMenuItem optionsMenu = new JBMenuItem(BUNDLE.getString("MMDGraphEditor.makePopUp.miOptions"),
            AllIcons.PopUp.OPTIONS);
    optionsMenu.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            startOptionsEdit();
        }
    });

    result.add(optionsMenu);

    JBMenuItem infoMenu = new JBMenuItem(BUNDLE.getString("MMDGraphEditor.makePopUp.miAbout"),
            AllIcons.PopUp.INFO);
    infoMenu.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            showAbout();
        }
    });

    result.add(infoMenu);

    return result;
}