Search in sources :

Example 6 with PopupHandler

use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.

the class ExternalProjectsViewImpl method initTree.

private void initTree() {
    myTree = new SimpleTree();
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    final ActionManager actionManager = ActionManager.getInstance();
    ActionToolbar actionToolbar = actionManager.createActionToolbar(myExternalSystemId.getReadableName() + " View Toolbar", (DefaultActionGroup) actionManager.getAction("ExternalSystemView.ActionsToolbar"), true);
    actionToolbar.setTargetComponent(myTree);
    setToolbar(actionToolbar.getComponent());
    setContent(ScrollPaneFactory.createScrollPane(myTree));
    myTree.addMouseListener(new PopupHandler() {

        public void invokePopup(final Component comp, final int x, final int y) {
            final String id = getMenuId(getSelectedNodes(ExternalSystemNode.class));
            if (id != null) {
                final ActionGroup actionGroup = (ActionGroup) actionManager.getAction(id);
                if (actionGroup != null) {
                    actionManager.createActionPopupMenu("", actionGroup).getComponent().show(comp, x, y);
                }
            }
        }

        @Nullable
        private String getMenuId(Collection<? extends ExternalSystemNode> nodes) {
            String id = null;
            for (ExternalSystemNode node : nodes) {
                String menuId = node.getMenuId();
                if (menuId == null) {
                    return null;
                }
                if (id == null) {
                    id = menuId;
                } else if (!id.equals(menuId)) {
                    return null;
                }
            }
            return id;
        }
    });
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) SimpleTree(com.intellij.ui.treeStructure.SimpleTree) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with PopupHandler

use of com.intellij.ui.PopupHandler in project intellij-plugins by JetBrains.

the class JstdServerStatusView method installLinkHandler.

private static void installLinkHandler(@NotNull JEditorPane pane) {
    final Ref<String> urlRef = Ref.create(null);
    pane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                urlRef.set(null);
            } else if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                urlRef.set(e.getDescription());
            } else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                BrowserUtil.browse(e.getDescription());
            }
        }
    });
    final CopyLinkAction copyLinkAction = new CopyLinkAction();
    final OpenLinkInBrowser openLinkInBrowserAction = new OpenLinkInBrowser();
    final DefaultActionGroup group = new DefaultActionGroup(openLinkInBrowserAction, copyLinkAction);
    pane.addMouseListener(new PopupHandler() {

        public void invokePopup(Component comp, int x, int y) {
            String url = urlRef.get();
            copyLinkAction.setUrl(url);
            openLinkInBrowserAction.setUrl(url);
            if (url != null) {
                ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group);
                popupMenu.getComponent().show(comp, x, y);
            }
        }
    });
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 8 with PopupHandler

use of com.intellij.ui.PopupHandler in project android by JetBrains.

the class ConfigureTemplateParametersStep method onEntering.

@Override
protected void onEntering() {
    // The Model TemplateHandle may have changed, rebuild the panel
    resetPanel();
    final TemplateHandle templateHandle = getModel().getTemplateHandle();
    ApplicationManager.getApplication().invokeLater(() -> {
        // We want to set the label's text AFTER the wizard has been packed. Otherwise, its
        // width calculation gets involved and can really stretch out some wizards if the label is
        // particularly long (see Master/Detail Activity for example).
        myTemplateDescriptionLabel.setText(WizardUtils.toHtmlString(Strings.nullToEmpty(templateHandle.getMetadata().getDescription())));
    }, ModalityState.any());
    final IconProperty thumb = new IconProperty(myTemplateThumbLabel);
    BoolProperty thumbVisibility = new VisibleProperty(myTemplateThumbLabel);
    myBindings.bind(thumb, new Expression<Optional<Icon>>(myThumbPath) {

        @NotNull
        @Override
        public Optional<Icon> get() {
            return myThumbnailsCache.getUnchecked(new File(templateHandle.getRootPath(), myThumbPath.get()));
        }
    });
    myBindings.bind(thumbVisibility, new Expression<Boolean>(thumb) {

        @NotNull
        @Override
        public Boolean get() {
            return thumb.get().isPresent();
        }
    });
    myThumbPath.set(getDefaultThumbnailPath());
    final TextProperty parameterDescription = new TextProperty(myParameterDescriptionLabel);
    myBindings.bind(new VisibleProperty(myFooterSeparator), new Expression<Boolean>(parameterDescription) {

        @NotNull
        @Override
        public Boolean get() {
            return !parameterDescription.get().isEmpty();
        }
    });
    Module module = myFacet == null ? null : myFacet.getModule();
    final Collection<Parameter> parameters = templateHandle.getMetadata().getParameters();
    for (final Parameter parameter : parameters) {
        RowEntry row = createRowForParameter(module, parameter);
        final ObservableValue<?> property = row.getProperty();
        if (property != null) {
            property.addListener(sender -> {
                if (myEvaluationState != EvaluationState.EVALUATING) {
                    myUserValues.put(parameter, property.get());
                    enqueueEvaluateParameters();
                }
            });
            final ActionGroup resetParameterGroup = new ActionGroup() {

                @NotNull
                @Override
                public AnAction[] getChildren(@Nullable AnActionEvent e) {
                    return new AnAction[] { new ResetParameterAction(parameter) };
                }
            };
            row.getComponent().addMouseListener(new PopupHandler() {

                @Override
                public void invokePopup(Component comp, int x, int y) {
                    ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, resetParameterGroup).getComponent().show(comp, x, y);
                }
            });
        }
        myParameterRows.put(parameter, row);
        row.addToPanel(myParametersPanel);
    }
    if (mySourceSets.size() > 1) {
        RowEntry row = new RowEntry<>("Target Source Set", new SourceSetComboProvider(mySourceSets));
        row.setEnabled(mySourceSets.size() > 1);
        row.addToPanel(myParametersPanel);
        //noinspection unchecked
        SelectedItemProperty<AndroidSourceSet> sourceSet = (SelectedItemProperty<AndroidSourceSet>) row.getProperty();
        // SourceSetComboProvider always sets this
        assert sourceSet != null;
        myBindings.bind(getModel().getSourceSet(), new OptionalToValuePropertyAdapter<>(sourceSet));
        sourceSet.addListener(sender -> enqueueEvaluateParameters());
    }
    myValidatorPanel.registerValidator(myInvalidParameterMessage, message -> (message.isEmpty() ? Validator.Result.OK : new Validator.Result(Validator.Severity.ERROR, message)));
    // TODO: This code won't be needed until we migrate this enough to support
    // NewAndroidApplication/template.xml and NewAndroidLibrary/template.xml
    // Add it in then. Probably we can add an optional validator API to ComponentProvider? Then we
    // could move this code into EnumComboProvider and it won't be a hack anymore.
    //
    // if (value instanceof ApiComboBoxItem) {
    //  ApiComboBoxItem selectedItem = (ApiComboBoxItem)value;
    //
    //  if (minApi != null && selectedItem.minApi > minApi.getFeatureLevel()) {
    //    setErrorHtml(String.format("The \"%s\" option for %s requires a minimum API level of %d",
    //                               selectedItem.label, param.name, selectedItem.minApi));
    //    return false;
    //  }
    //  if (buildApi != null && selectedItem.minBuildApi > buildApi) {
    //    setErrorHtml(String.format("The \"%s\" option for %s requires a minimum API level of %d",
    //                               selectedItem.label, param.name, selectedItem.minBuildApi));
    //    return false;
    //  }
    //}
    evaluateParameters();
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) NotNull(org.jetbrains.annotations.NotNull) IconProperty(com.android.tools.idea.ui.properties.swing.IconProperty) VisibleProperty(com.android.tools.idea.ui.properties.swing.VisibleProperty) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) Module(com.intellij.openapi.module.Module) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) Validator(com.android.tools.idea.ui.validation.Validator) AndroidSourceSet(com.android.tools.idea.npw.project.AndroidSourceSet)

Example 9 with PopupHandler

use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.

the class SelectLocationStep method init.

protected void init() {
    final DefaultActionGroup fileSystemActionGroup = createFileSystemActionGroup();
    myFileSystemToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, fileSystemActionGroup, true);
    final JTree tree = myFileSystemTree.getTree();
    tree.getSelectionModel().addTreeSelectionListener(myTreeSelectionListener);
    tree.setCellRenderer(new NodeRenderer());
    tree.addMouseListener(new PopupHandler() {

        public void invokePopup(Component comp, int x, int y) {
            final ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UPDATE_POPUP, fileSystemActionGroup);
            popupMenu.getComponent().show(comp, x, y);
        }
    });
    tree.addSelectionPath(tree.getPathForRow(0));
    new FileDrop(tree, new FileDrop.Target() {

        public FileChooserDescriptor getDescriptor() {
            return myChooserDescriptor;
        }

        public boolean isHiddenShown() {
            return myFileSystemTree.areHiddensShown();
        }

        public void dropFiles(final List<VirtualFile> files) {
            if (files.size() > 0) {
                selectInTree(files.toArray(new VirtualFile[files.size()]));
            }
        }
    });
    super.init();
}
Also used : NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) FileDrop(com.intellij.openapi.fileChooser.ex.FileDrop) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PopupHandler(com.intellij.ui.PopupHandler) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 10 with PopupHandler

use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.

the class AutomaticRenamingDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTable.setModel(myTableModel);
    myTableModel.getSpaceAction().register();
    myTableModel.addTableModelListener(e -> handleChanges());
    myTable.addMouseListener(new PopupHandler() {

        @Override
        public void invokePopup(Component comp, int x, int y) {
            final int[] selectionRows = myTable.getSelectedRows();
            if (selectionRows != null) {
                compoundPopup().show(comp, x, y);
            }
        }
    });
    final TableColumnModel columnModel = myTable.getColumnModel();
    columnModel.getColumn(CHECK_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
    TableUtil.setupCheckboxColumn(columnModel.getColumn(CHECK_COLUMN));
    columnModel.getColumn(NEW_NAME_COLUMN).setCellEditor(new StringTableCellEditor(myProject));
    mySelectAllButton.addActionListener(e -> {
        for (int i = 0; i < myShouldRename.length; i++) {
            myShouldRename[i] = true;
        }
        fireDataChanged();
    });
    myUnselectAllButton.addActionListener(e -> {
        for (int i = 0; i < myShouldRename.length; i++) {
            myShouldRename[i] = false;
        }
        fireDataChanged();
    });
    myListSelectionListener = e -> {
        myUsageFileLabel.setText("");
        int index = myTable.getSelectionModel().getLeadSelectionIndex();
        if (index != -1) {
            PsiNamedElement element = myRenames[index];
            UsageInfo usageInfo = new UsageInfo(element);
            myUsagePreviewPanel.updateLayout(Collections.singletonList(usageInfo));
            final PsiFile containingFile = element.getContainingFile();
            if (containingFile != null) {
                final VirtualFile virtualFile = containingFile.getVirtualFile();
                if (virtualFile != null) {
                    myUsageFileLabel.setText(virtualFile.getName());
                }
            }
        } else {
            myUsagePreviewPanel.updateLayout(null);
        }
    };
    myTable.getSelectionModel().addListSelectionListener(myListSelectionListener);
    myPanelForPreview.add(myUsagePreviewPanel, BorderLayout.CENTER);
    myUsagePreviewPanel.updateLayout(null);
    myPanelForPreview.add(myUsageFileLabel, BorderLayout.NORTH);
    mySplitPane.setDividerLocation(0.5);
    GuiUtils.replaceJSplitPaneWithIDEASplitter(myPanel);
    if (myTableModel.getRowCount() != 0) {
        myTable.getSelectionModel().addSelectionInterval(0, 0);
    }
    return myPanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PopupHandler(com.intellij.ui.PopupHandler) PsiNamedElement(com.intellij.psi.PsiNamedElement) TableColumnModel(javax.swing.table.TableColumnModel) StringTableCellEditor(com.intellij.refactoring.ui.StringTableCellEditor) PsiFile(com.intellij.psi.PsiFile) BooleanTableCellRenderer(com.intellij.ui.BooleanTableCellRenderer) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

PopupHandler (com.intellij.ui.PopupHandler)11 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 KeyAdapter (java.awt.event.KeyAdapter)2 KeyEvent (java.awt.event.KeyEvent)2 MouseAdapter (java.awt.event.MouseAdapter)2 AndroidSourceSet (com.android.tools.idea.npw.project.AndroidSourceSet)1 IconProperty (com.android.tools.idea.ui.properties.swing.IconProperty)1 SelectedItemProperty (com.android.tools.idea.ui.properties.swing.SelectedItemProperty)1 TextProperty (com.android.tools.idea.ui.properties.swing.TextProperty)1 VisibleProperty (com.android.tools.idea.ui.properties.swing.VisibleProperty)1 Validator (com.android.tools.idea.ui.validation.Validator)1 OccurenceNavigatorSupport (com.intellij.ide.OccurenceNavigatorSupport)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 ActionPopupMenu (com.intellij.openapi.actionSystem.ActionPopupMenu)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1