예제 #1
0
  public ServersToolWindowContent(@NotNull Project project) {
    super(new BorderLayout());
    myProject = project;

    myTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    myTree = new Tree(myTreeModel);
    myTree.setRootVisible(false);

    myTree.setShowsRootHandles(true);
    myTree.setCellRenderer(new NodeRenderer());
    myTree.setLineStyleAngled();

    getMainPanel().add(createToolbar(), BorderLayout.WEST);
    Splitter splitter = new Splitter(false, 0.3f);
    splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree, SideBorder.LEFT));
    myPropertiesPanelLayout = new CardLayout();
    myPropertiesPanel = new JPanel(myPropertiesPanelLayout);
    myMessageLabel = new JLabel(EMPTY_SELECTION_MESSAGE, SwingConstants.CENTER);
    myPropertiesPanel.add(MESSAGE_CARD, new Wrapper(myMessageLabel));
    splitter.setSecondComponent(myPropertiesPanel);
    getMainPanel().add(splitter, BorderLayout.CENTER);

    setupBuilder(project);

    for (RemoteServersViewContributor contributor :
        RemoteServersViewContributor.EP_NAME.getExtensions()) {
      contributor.setupTree(myProject, myTree, myBuilder);
    }

    myTree.addTreeSelectionListener(
        new TreeSelectionListener() {
          @Override
          public void valueChanged(TreeSelectionEvent e) {
            onSelectionChanged();
          }
        });
    new DoubleClickListener() {
      @Override
      protected boolean onDoubleClick(MouseEvent event) {
        Set<ServersTreeStructure.RemoteServerNode> nodes = getSelectedRemoteServerNodes();
        if (nodes.size() == 1) {
          RemoteServer<?> server = nodes.iterator().next().getValue();
          ServerConnectionManager.getInstance().getOrCreateConnection(server);
          return true;
        }
        return false;
      }
    }.installOn(myTree);
  }
  private void initTree(Tree tree) {
    tree.setCellRenderer(new MyTreeCellRenderer());
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setLineStyleAngled();

    TreeUtil.installActions(tree);
    SmartExpander.installOn(tree);
    new TreeSpeedSearch(tree);
    tree.addTreeWillExpandListener(
        new TreeWillExpandListener() {
          @Override
          public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            ((PackageDependenciesNode) event.getPath().getLastPathComponent()).sortChildren();
          }

          @Override
          public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {}
        });

    PopupHandler.installUnknownPopupHandler(
        tree, createTreePopupActions(), ActionManager.getInstance());
  }
예제 #3
0
파일: TreeView.java 프로젝트: jexp/idea2
  private JPanel createPanel() {
    createModel();
    myTree = new MyTree();
    myTree.setLineStyleAngled();
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.updateUI();
    myTree.setLargeModel(true);

    myTree.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
              OpenSourceUtil.openSourcesFrom(
                  DataManager.getInstance().getDataContext(myTree), false);
            }
          }
        });

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

    EditSourceOnDoubleClickHandler.install(myTree);

    myAutoScrollToSourceHandler.install(myTree);

    myOccurenceNavigatorSupport =
        new OccurenceNavigatorSupport(myTree) {
          protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
            if (!(node instanceof MessageNode)) {
              return null;
            }
            MessageNode messageNode = (MessageNode) node;
            AntBuildMessageView.MessageType type = messageNode.getType();

            if (type != AntBuildMessageView.MessageType.MESSAGE
                && type != AntBuildMessageView.MessageType.ERROR) {
              return null;
            }

            if (!isValid(messageNode.getFile())) {
              return null;
            }

            return new OpenFileDescriptor(
                myProject, messageNode.getFile(), messageNode.getOffset());
          }

          @Nullable
          public String getNextOccurenceActionName() {
            return AntBundle.message("ant.execution.next.error.warning.action.name");
          }

          @Nullable
          public String getPreviousOccurenceActionName() {
            return AntBundle.message("ant.execution.previous.error.warning.action.name");
          }
        };

    JPanel panel = new JPanel(new BorderLayout());

    JScrollPane scrollPane = MessageTreeRenderer.install(myTree);
    panel.add(scrollPane, BorderLayout.CENTER);
    return panel;
  }