Java Code Examples for com.intellij.openapi.actionSystem.ActionManager#createActionToolbar()

The following examples show how to use com.intellij.openapi.actionSystem.ActionManager#createActionToolbar() . 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 File: PantsConsoleViewPanel.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private JPanel createToolbarPanel() {
  AnAction closeMessageViewAction = new StopAction();

  DefaultActionGroup leftUpdateableActionGroup = new DefaultActionGroup();
  leftUpdateableActionGroup.add(closeMessageViewAction);

  JPanel toolbarPanel = new JPanel(new BorderLayout());
  ActionManager actionManager = ActionManager.getInstance();
  ActionToolbar leftToolbar = actionManager.createActionToolbar(ActionPlaces.COMPILER_MESSAGES_TOOLBAR, leftUpdateableActionGroup, false);
  toolbarPanel.add(leftToolbar.getComponent(), BorderLayout.WEST);

  return toolbarPanel;
}
 
Example 2
Source File: TitleWithToolbar.java    From consulo with Apache License 2.0 5 votes vote down vote up
public TitleWithToolbar(@Nonnull String title,
                        @Nonnull String actionGroupId,
                        @Nonnull String place,
                        @Nonnull JComponent targetComponent)
{
  super(new GridBagLayout());
  ActionManager actionManager = ActionManager.getInstance();
  ActionGroup group = (ActionGroup)actionManager.getAction(actionGroupId);
  ActionToolbar actionToolbar = actionManager.createActionToolbar(place, group, true);
  actionToolbar.setTargetComponent(targetComponent);
  actionToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);

  add(new MyTitleComponent(title), new GridBag().weightx(1).anchor(GridBagConstraints.WEST).fillCellHorizontally());
  add(actionToolbar.getComponent(), new GridBag().anchor(GridBagConstraints.CENTER));
}
 
Example 3
Source File: DependencyViewer.java    From gradle-view with Apache License 2.0 4 votes vote down vote up
public DependencyViewer(Project p, ToolWindow t) {
    super(true, true);
    this.project = p;
    this.toolWindow = t;
    this.splitter = new Splitter(false, 0.75f);
    this.information = new JTextArea();
    this.toolingLogger = initToolingLogger();

    this.dependencyCellRenderer = new DependencyCellRenderer();
    this.dependencyCellRenderer.omittedSelected = JBColor.MAGENTA;
    this.dependencyCellRenderer.omittedUnselected = JBColor.GRAY;
    this.dependencyCellRenderer.normalSelected = JBColor.foreground();
    this.dependencyCellRenderer.normalUnselected = JBColor.BLACK;
    this.information.setEditable(false);

    this.shouldPromptForCurrentProject = true;

    // TODO clean all of this up
    GradleService gradleService = ServiceManager.getService(project, GradleService.class);
    gradleService.addListener(new ViewActionListener() {
        @Override
        public void refresh() {
            // prompt only on first use of tool panel
            if (shouldPromptForCurrentProject) {
                // ask to initialize view for this project to the current project
                if (useCurrentProjectBuild()) {
                    gradleBaseDir = project.getBasePath();
                }
                shouldPromptForCurrentProject = false;
            }

            // there's nothing to do when there is no gradleBaseDir set, instead issue a prompt
            if(gradleBaseDir == null) {
                promptForGradleBaseDir();
            }

            // initialize an empty view even if the gradleBaseDir is set while we load everything in the background
            updateView(null, null);

            new SwingWorker<GradleNode, Void>() {
                protected GradleNode doInBackground() throws Exception {
                    try {
                        Map<String, GradleNode> dependencyMap = loadProjectDependenciesFromModel(gradleBaseDir, toolingLogger);
                        GradleNode rootDependency = dependencyMap.get("root");

                        GradleNode target = dependencyCellRenderer.selectedGradleNode;
                        GradleNode selectedDependency;
                        if(target != null && target.group != null) {
                            selectedDependency = target;
                        } else {
                            selectedDependency = new GradleNode("No dependency selected");
                        }

                        updateView(rootDependency, selectedDependency);
                        return rootDependency;
                    } catch(Exception e) {
                        e.printStackTrace();
                        toolingLogger.log(ExceptionUtils.getFullStackTrace(e));
                        throw new RuntimeException(e);
                    }
                }
            }.execute();
        }

        @Override
        public void toggleShowReplaced() {
            dependencyCellRenderer.showReplaced = !dependencyCellRenderer.showReplaced;
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    splitter.repaint();
                    splitter.validate();
                }
            });
        }

        @Override
        public void reset() {
            gradleBaseDir = null;
            refresh();
        }
    });
    gradleService.refresh();

    setContent(splitter);
    final ActionManager actionManager = ActionManager.getInstance();
    ActionToolbar actionToolbar = actionManager.createActionToolbar("Gradle View Toolbar",
            (DefaultActionGroup)actionManager.getAction("GradleView.NavigatorActionsToolbar"), true);

    actionToolbar.setTargetComponent(splitter);
    setToolbar(actionToolbar.getComponent());
}