コード例 #1
0
 @Nullable
 private SimpleNode visit(SimpleNode simpleNode, DomElement domElement) {
   boolean validCandidate = false;
   if (simpleNode instanceof AbstractDomElementNode) {
     final DomElement nodeElement = ((AbstractDomElementNode) simpleNode).getDomElement();
     if (nodeElement != null) {
       validCandidate = !(simpleNode instanceof DomElementsGroupNode);
       if (validCandidate && nodeElement.equals(domElement)) {
         return simpleNode;
       }
       if (!(nodeElement instanceof MergedObject) && !isParent(nodeElement, domElement)) {
         return null;
       }
     }
   }
   final Object[] childElements = myBuilder.getTreeStructure().getChildElements(simpleNode);
   if (childElements.length == 0 && validCandidate) { // leaf
     return simpleNode;
   }
   for (Object child : childElements) {
     SimpleNode result = visit((SimpleNode) child, domElement);
     if (result != null) {
       return result;
     }
   }
   return validCandidate ? simpleNode : null;
 }
コード例 #2
0
 private void queueUpdateByProblem() {
   if (Registry.is("projectView.showHierarchyErrors")) {
     if (myTreeBuilder != null) {
       myTreeBuilder.queueUpdate();
     }
   }
 }
コード例 #3
0
 private void queueUpdate(final VirtualFile file) {
   if (file == null) return;
   if (getProject().isDisposed()) return;
   ApplicationManager.getApplication()
       .invokeLater(
           () -> {
             if (getProject().isDisposed()) return;
             if (!file.isValid() || isRightFile(file)) {
               myBuilder.updateFromRoot();
             }
           });
 }
コード例 #4
0
 private void select(String type, String name) {
   for (ResourceGroup group : myGroups) {
     if (type.equalsIgnoreCase(group.getName())) {
       for (ResourceItem item : group.getItems()) {
         if (name.equals(item.toString())) {
           myTreeBuilder.select(item);
           return;
         }
       }
       return;
     }
   }
 }
コード例 #5
0
 @Override
 public ActionCallback getReady(@NotNull Object requestor) {
   if (myTreeBuilder == null || myTreeBuilder.isDisposed()) return new ActionCallback.Rejected();
   return myTreeBuilder.getUi().getReady(requestor);
 }
コード例 #6
0
  protected DomModelTreeView(
      DomElement rootElement, DomManager manager, SimpleTreeStructure treeStructure) {
    myDomManager = manager;
    myRootElement = rootElement;
    myTree = new SimpleTree(new DefaultTreeModel(new DefaultMutableTreeNode()));
    myTree.setRootVisible(isRootVisible());
    myTree.setShowsRootHandles(true);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    ToolTipManager.sharedInstance().registerComponent(myTree);
    TreeUtil.installActions(myTree);

    myBuilder =
        new AbstractTreeBuilder(
            myTree,
            (DefaultTreeModel) myTree.getModel(),
            treeStructure,
            WeightBasedComparator.INSTANCE,
            false);
    Disposer.register(this, myBuilder);

    myBuilder.setNodeDescriptorComparator(null);

    myBuilder.initRootNode();

    add(myTree, BorderLayout.CENTER);

    myTree.addTreeExpansionListener(
        new TreeExpansionListener() {
          @Override
          public void treeExpanded(TreeExpansionEvent event) {
            final SimpleNode simpleNode = myTree.getNodeFor(event.getPath());

            if (simpleNode instanceof AbstractDomElementNode) {
              ((AbstractDomElementNode) simpleNode).setExpanded(true);
            }
          }

          @Override
          public void treeCollapsed(TreeExpansionEvent event) {
            final SimpleNode simpleNode = myTree.getNodeFor(event.getPath());

            if (simpleNode instanceof AbstractDomElementNode) {
              ((AbstractDomElementNode) simpleNode).setExpanded(false);
              simpleNode.update();
            }
          }
        });

    myDomManager.addDomEventListener(
        new DomChangeAdapter() {
          @Override
          protected void elementChanged(DomElement element) {
            if (element.isValid()) {
              queueUpdate(DomUtil.getFile(element).getVirtualFile());
            } else if (element instanceof DomFileElement) {
              final XmlFile xmlFile = ((DomFileElement) element).getFile();
              queueUpdate(xmlFile.getVirtualFile());
            }
          }
        },
        this);

    final Project project = myDomManager.getProject();
    DomElementAnnotationsManager.getInstance(project)
        .addHighlightingListener(
            new DomElementAnnotationsManager.DomHighlightingListener() {
              @Override
              public void highlightingFinished(@NotNull DomFileElement element) {
                if (element.isValid()) {
                  queueUpdate(DomUtil.getFile(element).getVirtualFile());
                }
              }
            },
            this);

    myTree.setPopupGroup(getPopupActions(), DOM_MODEL_TREE_VIEW_POPUP);
  }
コード例 #7
0
 @Nullable
 private SimpleNode getNodeFor(final DomElement domElement) {
   return visit((SimpleNode) myBuilder.getTreeStructure().getRootElement(), domElement);
 }
コード例 #8
0
 public final void updateTree() {
   myBuilder.updateFromRoot();
 }
コード例 #9
0
 public void addSubtreeToUpdate(DefaultMutableTreeNode newNode) {
   AbstractTreeBuilder.getBuilderFor(this).addSubtreeToUpdate(newNode);
 }
コード例 #10
0
    public ResourcePanel(AndroidFacet facet, ResourceType[] types, boolean system) {
      myTree = new Tree();
      myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
      myTree.setScrollsOnExpand(true);
      myTree.setRootVisible(false);
      myTree.setShowsRootHandles(true);
      new DoubleClickListener() {
        @Override
        protected boolean onDoubleClick(MouseEvent e) {
          if (!myTreeBuilder.getSelectedElements(ResourceItem.class).isEmpty()) {
            close(OK_EXIT_CODE);
            return true;
          }
          return false;
        }
      }.installOn(myTree);

      ToolTipManager.sharedInstance().registerComponent(myTree);
      TreeUtil.installActions(myTree);

      myManager = facet.getResourceManager(system ? AndroidUtils.SYSTEM_RESOURCE_PACKAGE : null);
      myGroups = new ResourceGroup[types.length];

      for (int i = 0; i < types.length; i++) {
        myGroups[i] = new ResourceGroup(types[i], myManager);
      }

      myTreeBuilder =
          new AbstractTreeBuilder(
              myTree,
              (DefaultTreeModel) myTree.getModel(),
              new TreeContentProvider(myGroups),
              null);
      myTreeBuilder.initRootNode();

      TreeSelectionModel selectionModel = myTree.getSelectionModel();
      selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
      selectionModel.addTreeSelectionListener(ChooseResourceDialog.this);

      myTree.setCellRenderer(new NodeRenderer());
      new TreeSpeedSearch(myTree, TreeSpeedSearch.NODE_DESCRIPTOR_TOSTRING, true);

      myComponent = new JBSplitter(true, 0.8f);
      myComponent.setSplitterProportionKey("android.resource_dialog_splitter");

      myComponent.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree));

      myPreviewPanel = new JPanel(new CardLayout());
      myComponent.setSecondComponent(myPreviewPanel);

      myTextArea = new JTextArea(5, 20);
      myTextArea.setEditable(false);
      myPreviewPanel.add(ScrollPaneFactory.createScrollPane(myTextArea), TEXT);

      myComboTextArea = new JTextArea(5, 20);
      myComboTextArea.setEditable(false);

      myComboBox = new JComboBox();
      myComboBox.setMaximumRowCount(15);
      myComboBox.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              java.util.List<ResourceElement> resources =
                  (java.util.List<ResourceElement>) myComboBox.getClientProperty(COMBO);
              myComboTextArea.setText(
                  getResourceElementValue(resources.get(myComboBox.getSelectedIndex())));
            }
          });

      JPanel comboPanel =
          new JPanel(
              new BorderLayout(0, 1) {
                @Override
                public void layoutContainer(Container target) {
                  super.layoutContainer(target);
                  Rectangle bounds = myComboBox.getBounds();
                  Dimension size = myComboBox.getPreferredSize();
                  size.width += 20;
                  myComboBox.setBounds(
                      (int) bounds.getMaxX() - size.width, bounds.y, size.width, size.height);
                }
              });
      comboPanel.add(ScrollPaneFactory.createScrollPane(myComboTextArea), BorderLayout.CENTER);
      comboPanel.add(myComboBox, BorderLayout.SOUTH);
      myPreviewPanel.add(comboPanel, COMBO);

      myImageComponent = new JLabel();
      myImageComponent.setHorizontalAlignment(SwingConstants.CENTER);
      myImageComponent.setVerticalAlignment(SwingConstants.CENTER);
      myPreviewPanel.add(myImageComponent, IMAGE);

      myNoPreviewComponent = new JLabel("No Preview");
      myNoPreviewComponent.setHorizontalAlignment(SwingConstants.CENTER);
      myNoPreviewComponent.setVerticalAlignment(SwingConstants.CENTER);
      myPreviewPanel.add(myNoPreviewComponent, NONE);
    }
コード例 #11
0
 @Nullable
 private static <T> T getSelectedElement(AbstractTreeBuilder treeBuilder, Class<T> elementClass) {
   Set<T> elements = treeBuilder.getSelectedElements(elementClass);
   return elements.isEmpty() ? null : elements.iterator().next();
 }