コード例 #1
0
  public static void showTestResultsToolWindow(
      @NotNull final Project project, @NotNull final String message, boolean solved) {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    ToolWindow window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
    if (window == null) {
      toolWindowManager.registerToolWindow(
          StudyTestResultsToolWindowFactoryKt.ID, true, ToolWindowAnchor.BOTTOM);
      window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
      new StudyTestResultsToolWindowFactory().createToolWindowContent(project, window);
    }

    final Content[] contents = window.getContentManager().getContents();
    for (Content content : contents) {
      final JComponent component = content.getComponent();
      if (component instanceof ConsoleViewImpl) {
        ((ConsoleViewImpl) component).clear();
        if (!solved) {
          ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.ERROR_OUTPUT);
        } else {
          ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.NORMAL_OUTPUT);
        }
        window.setAvailable(true, () -> {});
        window.show(() -> {});
        return;
      }
    }
  }
コード例 #2
0
  @Nullable
  public static GradleProjectStructureTreeModel getProjectStructureTreeModel(
      @NotNull Project project) {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    final ToolWindow toolWindow = toolWindowManager.getToolWindow(GradleConstants.TOOL_WINDOW_ID);
    if (toolWindow == null) {
      return null;
    }

    final ContentManager contentManager = toolWindow.getContentManager();
    if (contentManager == null) {
      return null;
    }

    for (Content content : contentManager.getContents()) {
      final JComponent component = content.getComponent();
      if (component instanceof DataProvider) {
        final Object data =
            ((DataProvider) component).getData(GradleDataKeys.SYNC_TREE_MODEL.getName());
        if (data instanceof GradleProjectStructureTreeModel) {
          return (GradleProjectStructureTreeModel) data;
        }
      }
    }
    return null;
  }
コード例 #3
0
 private void doSelectModuleOrGroup(final Object toSelect, final boolean requestFocus) {
   ToolWindowManager windowManager = ToolWindowManager.getInstance(myProject);
   final Runnable runnable =
       new Runnable() {
         @Override
         public void run() {
           ProjectView projectView = ProjectView.getInstance(myProject);
           if (requestFocus) {
             projectView.changeView(getId(), getSubId());
           }
           ((BaseProjectTreeBuilder) getTreeBuilder())
               .selectInWidth(
                   toSelect,
                   requestFocus,
                   new Condition<AbstractTreeNode>() {
                     @Override
                     public boolean value(final AbstractTreeNode node) {
                       return node instanceof AbstractModuleNode
                           || node instanceof ModuleGroupNode
                           || node instanceof AbstractProjectNode;
                     }
                   });
         }
       };
   if (requestFocus) {
     windowManager.getToolWindow(ToolWindowId.PROJECT_VIEW).activate(runnable);
   } else {
     runnable.run();
   }
 }
コード例 #4
0
 private void registerToolWindow(@NotNull final ToolWindowManager toolWindowManager) {
   try {
     Method method =
         toolWindowManager
             .getClass()
             .getDeclaredMethod(
                 "registerToolWindow",
                 String.class,
                 JComponent.class,
                 ToolWindowAnchor.class,
                 boolean.class,
                 boolean.class,
                 boolean.class);
     method.setAccessible(true);
     method.invoke(
         toolWindowManager,
         StudyToolWindowFactory.STUDY_TOOL_WINDOW,
         null,
         ToolWindowAnchor.LEFT,
         true,
         true,
         true);
   } catch (Exception e) {
     final ToolWindow toolWindow =
         toolWindowManager.getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW);
     if (toolWindow == null) {
       toolWindowManager.registerToolWindow(
           StudyToolWindowFactory.STUDY_TOOL_WINDOW,
           true,
           ToolWindowAnchor.RIGHT,
           myProject,
           true);
     }
   }
 }
コード例 #5
0
  private void registerToolwindow(@NotNull final Executor executor) {
    final String toolWindowId = executor.getToolWindowId();
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
    if (toolWindowManager == null) return; // headless environment
    if (toolWindowManager.getToolWindow(toolWindowId) != null) {
      return;
    }

    final ToolWindow toolWindow =
        toolWindowManager.registerToolWindow(
            toolWindowId, true, ToolWindowAnchor.BOTTOM, this, true);

    final ContentManager contentManager = toolWindow.getContentManager();
    class MyDataProvider implements DataProvider {
      private int myInsideGetData = 0;

      public Object getData(String dataId) {
        myInsideGetData++;
        try {
          if (PlatformDataKeys.HELP_ID.is(dataId)) {
            return executor.getHelpId();
          } else {
            return myInsideGetData == 1
                ? DataManager.getInstance()
                    .getDataContext(contentManager.getComponent())
                    .getData(dataId)
                : null;
          }
        } finally {
          myInsideGetData--;
        }
      }
    }
    contentManager.addDataProvider(new MyDataProvider());

    toolWindow.setIcon(executor.getToolWindowIcon());
    new ContentManagerWatcher(toolWindow, contentManager);
    contentManager.addContentManagerListener(
        new ContentManagerAdapter() {
          public void selectionChanged(final ContentManagerEvent event) {
            final Content content = event.getContent();
            final RunContentDescriptor descriptor =
                content != null ? getRunContentDescriptorByContent(content) : null;
            getSyncPublisher().contentSelected(descriptor, executor);
          }
        });
    myToolwindowIdToContentManagerMap.put(toolWindowId, contentManager);
    Disposer.register(
        contentManager,
        new Disposable() {
          public void dispose() {
            unregisterToolwindow(toolWindowId);
          }
        });
    myToolwindowIdZbuffer.addLast(toolWindowId);
  }
コード例 #6
0
 public void ensureVisible(Project project) {
   if (project == null) return;
   ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
   if (toolWindowManager != null) {
     ToolWindow toolWindow = toolWindowManager.getToolWindow(ToolWindowId.CVS);
     if (toolWindow != null) {
       toolWindow.activate(null, false);
     }
   }
 }
コード例 #7
0
 public void ensureVisible(Project project) {
   if (project == null) {
     return;
   }
   ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
   if (toolWindowManager != null) {
     ToolWindow toolWindow = toolWindowManager.getToolWindow(COMMIT_LOGS_TOOLWINDOW_ID);
     if (toolWindow != null) {
       toolWindow.activate(null);
     }
   }
 }
コード例 #8
0
  @Override
  public void disposeComponent() {
    releaseEditor();
    myMappings.disposeMe();
    myConnect.disconnect();
    Disposer.dispose(myAnnotationLocalChangesListener);
    myContentManager = null;

    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
    if (toolWindowManager != null && toolWindowManager.getToolWindow(ToolWindowId.VCS) != null) {
      toolWindowManager.unregisterToolWindow(ToolWindowId.VCS);
    }
  }
コード例 #9
0
 public static List<ActivateToolWindowAction> getToolWindowActions(@NotNull Project project) {
   ActionManager actionManager = ActionManager.getInstance();
   ToolWindowManager manager = ToolWindowManager.getInstance(project);
   List<ActivateToolWindowAction> result = ContainerUtil.newArrayList();
   for (String id : manager.getToolWindowIds()) {
     if (!manager.getToolWindow(id).isShowStripeButton()) continue;
     String actionId = ActivateToolWindowAction.getActionIdForToolWindow(id);
     AnAction action = actionManager.getAction(actionId);
     if (action instanceof ActivateToolWindowAction) {
       result.add((ActivateToolWindowAction) action);
     }
   }
   Collections.sort(result, COMPARATOR);
   return result;
 }
コード例 #10
0
  @Nullable
  public static ToolWindow ensureToolWindowContentInitialized(
      @NotNull Project project, @NotNull ProjectSystemId externalSystemId) {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    if (toolWindowManager == null) return null;

    final ToolWindow toolWindow =
        toolWindowManager.getToolWindow(externalSystemId.getReadableName());
    if (toolWindow == null) return null;

    if (toolWindow instanceof ToolWindowImpl) {
      ((ToolWindowImpl) toolWindow).ensureContentInitialized();
    }
    return toolWindow;
  }
コード例 #11
0
  @Nullable
  private ToolWindow getWindow(AnActionEvent event) {
    if (myWindow != null) return myWindow;

    Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
    if (project == null) return null;

    ToolWindowManager manager = ToolWindowManager.getInstance(project);

    final ToolWindow window = manager.getToolWindow(manager.getActiveToolWindowId());
    if (window == null) return null;

    final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(event.getDataContext());
    if (context == null) return null;

    return SwingUtilities.isDescendingFrom(window.getComponent(), context) ? window : null;
  }
コード例 #12
0
 public static void updateToolWindows() {
   for (Project project : ProjectManager.getInstance().getOpenProjects()) {
     final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
     for (String id : toolWindowManager.getToolWindowIds()) {
       final ToolWindow toolWindow = toolWindowManager.getToolWindow(id);
       for (Content content : toolWindow.getContentManager().getContents()) {
         final JComponent component = content.getComponent();
         if (component != null) {
           IJSwingUtilities.updateComponentTreeUI(component);
         }
       }
       final JComponent c = toolWindow.getComponent();
       if (c != null) {
         IJSwingUtilities.updateComponentTreeUI(c);
       }
     }
   }
 }
コード例 #13
0
  /**
   * Set the requested content "selected" and show ToolWindow if it hided
   *
   * @param displayName
   * @param wait
   */
  public void showContent(String displayName, final int wait) {
    //        Project project =
    // DataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    ToolWindow wm = toolWindowManager.getToolWindow(QUERY_RESULT_PANE);

    if (wm == null) {
      wm = toolWindowManager.registerToolWindow(QUERY_RESULT_PANE, true, ToolWindowAnchor.BOTTOM);
      wm.setIcon(Icons.QUERY_RESULT_PANE);
      wm.setToHideOnEmptyContent(true);
    }

    String contentName = connectionManager.getDbUrl().getUserHostPortServiceName().toLowerCase();
    Content content = wm.getContentManager().findContent(contentName);

    if (content == null) {
      return;
    }

    wm.getContentManager().setSelectedContent(content);
    JTabbedPane tabbedPane = getTabComponent(content);
    int index = tabbedPane.indexOfTab(displayName);
    if (index == -1) {
      return;
    }

    tabbedPane.requestFocusInWindow();
    tabbedPane.setSelectedIndex(index);

    if (!wm.isVisible()) {
      wm.activate(
          new Runnable() {
            public void run() {
              try {
                Thread.sleep(wait);
              } catch (InterruptedException e1) {
              }
            }
            //            }, false);
          },
          true);
    }
  }
コード例 #14
0
 public static void ensureToolWindowInitialized(
     @NotNull Project project, @NotNull ProjectSystemId externalSystemId) {
   ToolWindowManager manager = ToolWindowManager.getInstance(project);
   if (!(manager instanceof ToolWindowManagerEx)) {
     return;
   }
   ToolWindowManagerEx managerEx = (ToolWindowManagerEx) manager;
   String id = externalSystemId.getReadableName();
   ToolWindow window = manager.getToolWindow(id);
   if (window != null) {
     return;
   }
   ToolWindowEP[] beans = Extensions.getExtensions(ToolWindowEP.EP_NAME);
   for (final ToolWindowEP bean : beans) {
     if (id.equals(bean.id)) {
       managerEx.initToolWindow(bean);
     }
   }
 }
コード例 #15
0
  @Nullable
  public static CheckStyleToolWindowPanel panelFor(final Project project) {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    if (toolWindowManager == null) {
      LOG.debug("Couldn't get tool window manager for project " + project);
      return null;
    }

    final ToolWindow toolWindow = toolWindowManager.getToolWindow(ID_TOOLWINDOW);
    if (toolWindow == null) {
      LOG.debug("Couldn't get tool window for ID " + ID_TOOLWINDOW);
      return null;
    }

    for (Content currentContent : toolWindow.getContentManager().getContents()) {
      if (currentContent.getComponent() instanceof CheckStyleToolWindowPanel) {
        return ((CheckStyleToolWindowPanel) currentContent.getComponent());
      }
    }

    LOG.debug("Could not find tool window panel on tool window with ID " + ID_TOOLWINDOW);
    return null;
  }
コード例 #16
0
  public void selectNode(@NotNull final VirtualFile file, final boolean changeView) {
    ToolWindowManager windowManager = ToolWindowManager.getInstance(getProject());
    ToolWindow projectViewToolWindow = windowManager.getToolWindow(ToolWindowId.PROJECT_VIEW);
    projectViewToolWindow.activate(
        new Runnable() {
          public void run() {
            myProjectView.changeView(getId());
            MPSTreeNode nodeToSelect = getNode(file);

            if (nodeToSelect != null) {
              TreePath treePath = new TreePath(nodeToSelect.getPath());
              getTree().setSelectionPath(treePath);
              getTree().scrollPathToVisible(treePath);
              getTree().selectNode(nodeToSelect);
              if (changeView) {
                myProjectView.changeView(getId());
              }
            } else {
              LOG.info("Can not find file " + file + " in tree.");
            }
          }
        },
        false);
  }