Java Code Examples for com.intellij.ui.PopupHandler

The following examples show how to use com.intellij.ui.PopupHandler. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Crucible4IDEA   Source File: CommentsTree.java    License: MIT License 6 votes vote down vote up
protected CommentsTree(@NotNull final Project project, @NotNull final Review review, @NotNull DefaultTreeModel model,
                       @Nullable final Editor editor, @Nullable final FilePath filePath) {
  super(model);
  myReview = review;
  setExpandableItemsEnabled(false);
  setRowHeight(0);
  final CommentNodeRenderer renderer = new CommentNodeRenderer(this, review, project);
  setCellRenderer(renderer);
  getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

  final DefaultActionGroup group = new DefaultActionGroup();
  final AddCommentAction replyToComment = new AddCommentAction(review, editor, filePath,
                                                               CrucibleBundle.message("crucible.add.reply"), true);
  replyToComment.setContextComponent(this);
  group.add(replyToComment);
  PopupHandler.installUnknownPopupHandler(this, group, ActionManager.getInstance());
  TreeUtil.expandAll(this);

  new MyLinkMouseListener(renderer, project, review).installOn(this);
}
 
Example 2
Source Project: consulo   Source File: IdeRootPane.java    License: Apache License 2.0 6 votes vote down vote up
private JComponent createToolbar() {
  ActionGroup group = (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_TOOLBAR);
  final ActionToolbar toolBar= myActionManager.createActionToolbar(
          ActionPlaces.MAIN_TOOLBAR,
          group,
          true
  );
  toolBar.setLayoutPolicy(ActionToolbar.WRAP_LAYOUT_POLICY);

  DefaultActionGroup menuGroup = new DefaultActionGroup();
  menuGroup.add(new ViewToolbarAction());
  menuGroup.add(new CustomizeUIAction());
  PopupHandler.installUnknownPopupHandler(toolBar.getComponent(), menuGroup, myActionManager);

  return toolBar.getComponent();
}
 
Example 3
Source Project: consulo   Source File: TypeHierarchyBrowserBase.java    License: Apache License 2.0 6 votes vote down vote up
protected void createTreeAndSetupCommonActions(@Nonnull Map<String, JTree> trees, ActionGroup group) {
  final BaseOnThisTypeAction baseOnThisTypeAction = createBaseOnThisAction();
  final JTree tree1 = createTree(true);
  PopupHandler.installPopupHandler(tree1, group, ActionPlaces.TYPE_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
  baseOnThisTypeAction
          .registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_TYPE_HIERARCHY).getShortcutSet(), tree1);
  trees.put(TYPE_HIERARCHY_TYPE, tree1);

  final JTree tree2 = createTree(true);
  PopupHandler.installPopupHandler(tree2, group, ActionPlaces.TYPE_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
  baseOnThisTypeAction
          .registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_TYPE_HIERARCHY).getShortcutSet(), tree2);
  trees.put(SUPERTYPES_HIERARCHY_TYPE, tree2);

  final JTree tree3 = createTree(true);
  PopupHandler.installPopupHandler(tree3, group, ActionPlaces.TYPE_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
  baseOnThisTypeAction
          .registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_TYPE_HIERARCHY).getShortcutSet(), tree3);
  trees.put(SUBTYPES_HIERARCHY_TYPE, tree3);
}
 
Example 4
Source Project: azure-devops-intellij   Source File: TfsTreeForm.java    License: MIT License 5 votes vote down vote up
public TfsTreeForm() {
    DataManager.registerDataProvider(tree, this);
    new TreeSpeedSearch(tree);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            selectedItem = doGetSelectedItem();
            pathField.setText(selectedItem != null ? selectedItem.path : null);
            eventDispatcher.getMulticaster().selectionChanged();
        }
    });
    PopupHandler.installPopupHandler(tree, POPUP_ACTION_GROUP, ActionPlaces.REMOTE_HOST_DIALOG_POPUP);
    setMessage(null, false);
}
 
Example 5
Source Project: railways   Source File: LabelWithCopy.java    License: MIT License 5 votes vote down vote up
public LabelWithCopy() {
    addMouseListener(new PopupHandler() {
        @Override
        public void invokePopup(Component comp, int x, int y) {
            ActionManager actMgr = ActionManager.getInstance();
            ActionGroup group = (ActionGroup) ActionManager.getInstance()
                    .getAction("railways.CopyMenu");

            ActionPopupMenu popupMenu =
                    actMgr.createActionPopupMenu(ActionPlaces.UNKNOWN, group);
            popupMenu.getComponent().show(comp, x, y);
        }
    });
}
 
Example 6
Source Project: nosql4idea   Source File: MongoResultPanel.java    License: Apache License 2.0 5 votes vote down vote up
void buildPopupMenu() {
    DefaultActionGroup actionPopupGroup = new DefaultActionGroup("MongoResultPopupGroup", true);
    if (ApplicationManager.getApplication() != null) {
        actionPopupGroup.add(new EditMongoDocumentAction(this));
        actionPopupGroup.add(new CopyResultAction(this));
    }

    PopupHandler.installPopupHandler(resultTableView, actionPopupGroup, "POPUP", ActionManager.getInstance());
}
 
Example 7
Source Project: nosql4idea   Source File: MongoEditionPanel.java    License: Apache License 2.0 5 votes vote down vote up
void buildPopupMenu() {
    DefaultActionGroup actionPopupGroup = new DefaultActionGroup("MongoEditorPopupGroup", true);
    if (ApplicationManager.getApplication() != null) {
        actionPopupGroup.add(new AddKeyAction(this));
        actionPopupGroup.add(new AddValueAction(this));
        actionPopupGroup.add(new DeleteKeyAction(this));
    }

    PopupHandler.installPopupHandler(editTableView, actionPopupGroup, "POPUP", ActionManager.getInstance());
}
 
Example 8
Source Project: consulo   Source File: StatisticsPanel.java    License: Apache License 2.0 5 votes vote down vote up
public StatisticsPanel(final Project project, final TestFrameworkRunningModel model) {
  myProject = project;
  myTableModel = new StatisticsTableModel();
  myStatisticsTableView.setModelAndUpdateColumns(myTableModel);
  myFrameworkRunningModel = model;

  final Runnable gotoSuiteOrParentAction = createGotoSuiteOrParentAction();
  new DoubleClickListener() {
    @Override
    protected boolean onDoubleClick(MouseEvent e) {
      gotoSuiteOrParentAction.run();
      return true;
    }
  }.installOn(myStatisticsTableView);

  // Fire selection changed and move focus on SHIFT+ENTER
  final KeyStroke shiftEnterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK);
  SMRunnerUtil.registerAsAction(shiftEnterKey, "select-test-proxy-in-test-view",
                          new Runnable() {
                            public void run() {
                              showSelectedProxyInTestsTree();
                            }
                          },
                          myStatisticsTableView);

  // Expand selected or go to parent on ENTER
  final KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
  SMRunnerUtil.registerAsAction(enterKey, "go-to-selected-suite-or-parent",
                          gotoSuiteOrParentAction,
                          myStatisticsTableView);
  // Contex menu in Table
  PopupHandler.installPopupHandler(myStatisticsTableView, IdeActions.GROUP_TESTTREE_POPUP, ActionPlaces.TESTTREE_VIEW_POPUP);
  // set this statistic tab as dataprovider for test's table view
  DataManager.registerDataProvider(myStatisticsTableView, this);
}
 
Example 9
Source Project: consulo   Source File: DesktopEditorErrorPanel.java    License: Apache License 2.0 5 votes vote down vote up
public void setPopupHandler(@Nullable PopupHandler handler) {
  if (myHandler != null) {
    removeMouseListener(myHandler);
  }

  if (handler != null) {
    myHandler = handler;
    addMouseListener(handler);
  }
}
 
Example 10
Source Project: consulo   Source File: CustomizationUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static MouseListener installPopupHandler(JComponent component, @Nonnull final String groupId, final String place) {
  if (ApplicationManager.getApplication() == null) return new MouseAdapter(){};
  PopupHandler popupHandler = new PopupHandler() {
    public void invokePopup(Component comp, int x, int y) {
      ActionGroup group = (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(groupId);
      final ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(place, group);
      popupMenu.getComponent().show(comp, x, y);
    }
  };
  component.addMouseListener(popupHandler);
  return popupHandler;
}
 
Example 11
Source Project: consulo   Source File: SourceItemsTree.java    License: Apache License 2.0 5 votes vote down vote up
public SourceItemsTree(ArtifactEditorContext editorContext, ArtifactEditorImpl artifactsEditor) {
  myArtifactsEditor = artifactsEditor;
  myBuilder = new SimpleTreeBuilder(this, this.getBuilderModel(), new SourceItemsTreeStructure(editorContext, artifactsEditor), new WeightBasedComparator(true));
  setRootVisible(false);
  setShowsRootHandles(true);
  Disposer.register(this, myBuilder);
  PopupHandler.installPopupHandler(this, createPopupGroup(), ActionPlaces.UNKNOWN, ActionManager.getInstance());
  installDnD();
}
 
Example 12
Source Project: consulo   Source File: ScopeViewPane.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JComponent createComponent() {
  myViewPanel = new ScopeTreeViewPanel(myProject);
  Disposer.register(this, myViewPanel);
  myViewPanel.initListeners();
  myViewPanel.selectScope(NamedScopesHolder.getScope(myProject, getSubId()));
  myTree = myViewPanel.getTree();
  PopupHandler.installPopupHandler(myTree, IdeActions.GROUP_SCOPE_VIEW_POPUP, ActionPlaces.SCOPE_VIEW_POPUP);
  enableDnD();

  return myViewPanel.getPanel();
}
 
Example 13
Source Project: nosql4idea   Source File: NoSqlExplorerPanel.java    License: Apache License 2.0 4 votes vote down vote up
public void installActions() {

        final TreeExpander treeExpander = new TreeExpander() {
            @Override
            public void expandAll() {
                NoSqlExplorerPanel.this.expandAll();
            }

            @Override
            public boolean canExpand() {
                return true;
            }

            @Override
            public void collapseAll() {
                NoSqlExplorerPanel.this.collapseAll();
            }

            @Override
            public boolean canCollapse() {
                return true;
            }
        };

        CommonActionsManager actionsManager = CommonActionsManager.getInstance();

        final AnAction expandAllAction = actionsManager.createExpandAllAction(treeExpander, rootPanel);
        final AnAction collapseAllAction = actionsManager.createCollapseAllAction(treeExpander, rootPanel);

        Disposer.register(this, new Disposable() {
            @Override
            public void dispose() {
                collapseAllAction.unregisterCustomShortcutSet(rootPanel);
                expandAllAction.unregisterCustomShortcutSet(rootPanel);
            }
        });


        DefaultActionGroup actionGroup = new DefaultActionGroup("NoSqlExplorerGroup", false);
        ViewCollectionValuesAction viewCollectionValuesAction = new ViewCollectionValuesAction(this);
        RefreshServerAction refreshServerAction = new RefreshServerAction(this);
        if (ApplicationManager.getApplication() != null) {
            actionGroup.add(refreshServerAction);
            actionGroup.add(new NoSqlDatabaseConsoleAction(this));
            actionGroup.add(viewCollectionValuesAction);
            actionGroup.add(expandAllAction);
            actionGroup.add(collapseAllAction);
            actionGroup.addSeparator();
            actionGroup.add(new OpenPluginSettingsAction());
        }

        GuiUtils.installActionGroupInToolBar(actionGroup, toolBarPanel, ActionManager.getInstance(), "NoSqlExplorerActions", true);

        DefaultActionGroup actionPopupGroup = new DefaultActionGroup("NoSqlExplorerPopupGroup", true);
        if (ApplicationManager.getApplication() != null) {
            actionPopupGroup.add(refreshServerAction);
            actionPopupGroup.add(viewCollectionValuesAction);
            actionPopupGroup.add(new DropCollectionAction(this));
            actionPopupGroup.add(new DropDatabaseAction(this));
        }

        PopupHandler.installPopupHandler(databaseTree, actionPopupGroup, "POPUP", ActionManager.getInstance());

        databaseTree.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent mouseEvent) {
                if (!(mouseEvent.getSource() instanceof JTree)) {
                    return;
                }

                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) databaseTree.getLastSelectedPathComponent();
                if (treeNode == null) {
                    return;
                }

                if (mouseEvent.getClickCount() == 2) {
                    if (treeNode.getUserObject() instanceof DatabaseServer && treeNode.getChildCount() == 0) {
                        reloadServerConfiguration(getSelectedServerNode(), true);
                    }
                    if (treeNode.getUserObject() instanceof MongoCollection) {
                        loadRecords();
                    }
                    if (treeNode.getUserObject() instanceof RedisDatabase) {
                        loadRecords();
                    }

                    if (treeNode.getUserObject() instanceof CouchbaseDatabase) {
                        loadRecords();
                    }
                }
            }
        });
    }
 
Example 14
Source Project: consulo   Source File: DiffPanelImpl.java    License: Apache License 2.0 4 votes vote down vote up
public void onContentChangedIn(EditorSource source) {
  myDiffUpdater.contentRemoved(source);
  final EditorEx editor = source.getEditor();
  if (myIsHorizontal && source.getSide() == FragmentSide.SIDE1 && editor != null) {
    editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);
  }
  DiffSideView viewSide = getSideView(source.getSide());
  viewSide.setEditorSource(getProject(), source);
  Disposer.dispose(myScrollSupport);
  if (editor == null) {
    if (!myDisposed) {
      rediff();
    }
    return;
  }

  final MouseListener mouseListener = PopupHandler.installUnknownPopupHandler(editor.getContentComponent(), new MergeActionGroup(this, source.getSide()), ActionManager.getInstance());
  myDiffUpdater.contentAdded(source);
  editor.getSettings().setLineNumbersShown(true);
  editor.getSettings().setFoldingOutlineShown(false);
  editor.getFoldingModel().setFoldingEnabled(false);
  ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeVisible(true);

  Editor editor1 = getEditor(FragmentSide.SIDE1);
  Editor editor2 = getEditor(FragmentSide.SIDE2);
  if (editor1 != null && editor2 != null && myIsSyncScroll) {
    myScrollSupport.install(new EditingSides[]{this});
  }

  final VisibleAreaListener visibleAreaListener = mySplitter.getVisibleAreaListener();
  final ScrollingModel scrollingModel = editor.getScrollingModel();
  if (visibleAreaListener != null) {
    scrollingModel.addVisibleAreaListener(visibleAreaListener);
    scrollingModel.addVisibleAreaListener(myVisibleAreaListener);
  }
  myFontSizeSynchronizer.synchronize(editor);
  source.addDisposable(new Disposable() {
    public void dispose() {
      myFontSizeSynchronizer.stopSynchronize(editor);
    }
  });
  source.addDisposable(new Disposable() {
    public void dispose() {
      if (visibleAreaListener != null) {
        scrollingModel.removeVisibleAreaListener(visibleAreaListener);
        scrollingModel.removeVisibleAreaListener(myVisibleAreaListener);
      }
      editor.getContentComponent().removeMouseListener(mouseListener);
    }
  });
}
 
Example 15
Source Project: consulo   Source File: EditorMarkupModel.java    License: Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
void setErrorPanelPopupHandler(@Nonnull PopupHandler handler);
 
Example 16
Source Project: consulo   Source File: NewErrorTreeViewPanel.java    License: Apache License 2.0 4 votes vote down vote up
public NewErrorTreeViewPanel(Project project, String helpId, boolean createExitAction, boolean createToolbar, @Nullable Runnable rerunAction) {
  myProject = project;
  myHelpId = helpId;
  myConfiguration = ErrorTreeViewConfiguration.getInstance(project);
  setLayout(new BorderLayout());

  myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() {
    @Override
    protected boolean isAutoScrollMode() {
      return myConfiguration.isAutoscrollToSource();
    }

    @Override
    protected void setAutoScrollMode(boolean state) {
      myConfiguration.setAutoscrollToSource(state);
    }
  };

  myMessagePanel = new JPanel(new BorderLayout());

  myErrorViewStructure = new ErrorViewStructure(project, canHideWarningsOrInfos());
  DefaultMutableTreeNode root = new DefaultMutableTreeNode();
  root.setUserObject(myErrorViewStructure.createDescriptor(myErrorViewStructure.getRootElement(), null));
  final DefaultTreeModel treeModel = new DefaultTreeModel(root);
  myTree = new Tree(treeModel) {
    @Override
    public void setRowHeight(int i) {
      super.setRowHeight(0);
      // this is needed in order to make UI calculate the height for each particular row
    }
  };
  myBuilder = new ErrorViewTreeBuilder(myTree, treeModel, myErrorViewStructure);

  myExporterToTextFile = new ErrorViewTextExporter(myErrorViewStructure);
  myOccurenceNavigatorSupport = new MyOccurenceNavigatorSupport(myTree);

  myAutoScrollToSourceHandler.install(myTree);
  TreeUtil.installActions(myTree);
  UIUtil.setLineStyleAngled(myTree);
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  myTree.setLargeModel(true);

  JScrollPane scrollPane = NewErrorTreeRenderer.install(myTree);
  scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
  myMessagePanel.add(scrollPane, BorderLayout.CENTER);

  if (createToolbar) {
    add(createToolbarPanel(rerunAction), BorderLayout.WEST);
  }

  add(myMessagePanel, BorderLayout.CENTER);

  myTree.addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        navigateToSource(false);
      }
    }
  });

  myTree.addMouseListener(new PopupHandler() {
    @Override
    public void invokePopup(Component comp, int x, int y) {
      popupInvoked(comp, x, y);
    }
  });

  EditSourceOnDoubleClickHandler.install(myTree);
}
 
Example 17
Source Project: consulo   Source File: ChangesListView.java    License: Apache License 2.0 4 votes vote down vote up
public void setMenuActions(final ActionGroup menuGroup) {
  PopupHandler.installPopupHandler(this, menuGroup, ActionPlaces.CHANGES_VIEW_POPUP, ActionManager.getInstance());
  editSourceRegistration();
}