public ViewFilesPanel(
      FileTypeManager fileTypeManager, ActionManager actionManager, IDEFacade facade) {
    super(new BorderLayout(2, 2));
    setOpaque(false);

    myFileTypeManager = fileTypeManager;
    myIdeFacade = facade;
    myShowReadOnly = Pico.getOptions().isSet(SHOW_READ_ONLY_KEY, true);

    myTree =
        new KirTree() {
          protected void onEnter() {
            super.onEnter();
            if (myOpenFileAction.isEnabled()) {
              myOpenFileAction.actionPerformed(null);
            }
          }
        };
    IDEAFacade.installIdeaTreeActions(myTree);
    add(ScrollPaneFactory.createScrollPane(myTree));
    add(createActionsToolbar(actionManager), BorderLayout.NORTH);

    IDEAFacade.installPopupMenu(createActionGroup(), myTree, actionManager);

    myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
    setMinimumSize(new Dimension(200, 0));
  }
 private void refreshTree() {
   myRoot = new UpdateRootNode(myUpdatedFiles, myProject, myRootName, myActionInfo);
   myRoot.rebuild(VcsConfiguration.getInstance(myProject).UPDATE_GROUP_BY_PACKAGES);
   myTreeModel = new DefaultTreeModel(myRoot);
   myRoot.setTreeModel(myTreeModel);
   myTree.setModel(myTreeModel);
   myRoot.setTree(myTree);
 }
 public void clearAllMessages() {
   for (MessageNode messageItem : myMessageItems) {
     messageItem.clearRangeMarker();
   }
   myMessageItems.clear();
   myStatusNode = null;
   createModel();
   myTree.setModel(myTreeModel);
 }
  @SuppressWarnings("unchecked")
  public void resetElements(
      T[] elements,
      final @Nullable Comparator<T> sortComparator,
      final boolean restoreSelectedElements) {
    final List<T> selectedElements =
        restoreSelectedElements && mySelectedElements != null
            ? new ArrayList<T>(mySelectedElements)
            : null;
    myElements = elements;
    if (sortComparator != null) {
      myComparator = new ElementNodeComparatorWrapper(sortComparator);
    }
    mySelectedNodes.clear();
    myNodeToParentMap.clear();
    myElementToNodeMap.clear();
    myContainerNodes.clear();

    ApplicationManager.getApplication()
        .runReadAction(
            new Runnable() {
              @Override
              public void run() {
                myTreeModel = buildModel();
              }
            });

    myTree.setModel(myTreeModel);
    myTree.setRootVisible(false);

    restoreTree();

    if (myOptionControls == null) {
      myCopyJavadocCheckbox = new NonFocusableCheckBox(IdeBundle.message("checkbox.copy.javadoc"));
      if (myIsInsertOverrideVisible) {
        myInsertOverrideAnnotationCheckbox =
            new NonFocusableCheckBox(IdeBundle.message("checkbox.insert.at.override"));
        myOptionControls =
            new JCheckBox[] {myCopyJavadocCheckbox, myInsertOverrideAnnotationCheckbox};
      } else {
        myOptionControls = new JCheckBox[] {myCopyJavadocCheckbox};
      }
    }

    myTree.doLayout();
    setOKActionEnabled(myElements != null && myElements.length > 0);

    if (selectedElements != null) {
      selectElements(selectedElements.toArray(new ClassMember[selectedElements.size()]));
    }
    if (mySelectedElements == null || mySelectedElements.isEmpty()) {
      expandFirst();
    }
  }
  public MavenArchetypesStep(MavenModuleBuilder builder, @Nullable StepAdapter step) {
    myBuilder = builder;
    myStep = step;
    Disposer.register(this, myLoadingIcon);

    myArchetypesTree = new Tree();
    myArchetypesTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
    JScrollPane archetypesScrollPane = ScrollPaneFactory.createScrollPane(myArchetypesTree);

    myArchetypesPanel.add(archetypesScrollPane, "archetypes");

    JPanel loadingPanel = new JPanel(new GridBagLayout());
    JPanel bp = new JPanel(new BorderLayout(10, 10));
    bp.add(new JLabel("Loading archetype list..."), BorderLayout.NORTH);
    bp.add(myLoadingIcon, BorderLayout.CENTER);

    loadingPanel.add(bp, new GridBagConstraints());

    myArchetypesPanel.add(ScrollPaneFactory.createScrollPane(loadingPanel), "loading");
    ((CardLayout) myArchetypesPanel.getLayout()).show(myArchetypesPanel, "archetypes");

    myUseArchetypeCheckBox.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            updateComponents();
            archetypeMayBeChanged();
          }
        });

    myAddArchetypeButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            doAddArchetype();
          }
        });

    myArchetypesTree.setRootVisible(false);
    myArchetypesTree.setShowsRootHandles(true);
    myArchetypesTree.setCellRenderer(new MyRenderer());
    myArchetypesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    myArchetypesTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              public void valueChanged(TreeSelectionEvent e) {
                updateArchetypeDescription();
                archetypeMayBeChanged();
              }
            });

    new TreeSpeedSearch(
            myArchetypesTree,
            new Convertor<TreePath, String>() {
              public String convert(TreePath path) {
                MavenArchetype info =
                    getArchetypeInfoFromPathComponent(path.getLastPathComponent());
                return info.groupId + ":" + info.artifactId + ":" + info.version;
              }
            })
        .setComparator(new SpeedSearchComparator(false));

    myArchetypeDescriptionField.setEditable(false);
    myArchetypeDescriptionField.setBackground(UIUtil.getPanelBackground());

    requestUpdate();
    updateComponents();
  }
    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);
    }
Esempio n. 7
0
 public void clearAllMessages() {
   myStatusNode = null;
   createModel();
   myTree.setModel(myTreeModel);
 }
  public GenerateByPatternDialog(Project project, PatternDescriptor[] descriptors) {
    super(project);
    myProject = project;
    setTitle("Generate by Pattern");
    setOKButtonText("Generate");

    myMap = new MultiMap<>();
    for (PatternDescriptor descriptor : descriptors) {
      myMap.putValue(descriptor.getParentId(), descriptor);
    }
    DefaultMutableTreeNode root = createNode(null);

    myTree = new SimpleTree() {};

    myTree.setRootVisible(false);
    myTree.setCellRenderer(
        new DefaultTreeCellRenderer() {
          @NotNull
          @Override
          public Component getTreeCellRendererComponent(
              @NotNull JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            Component component =
                super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

            Object object = ((DefaultMutableTreeNode) value).getUserObject();
            if (object instanceof PatternDescriptor) {
              setText(((PatternDescriptor) object).getName());
              setIcon(((PatternDescriptor) object).getIcon());
            }
            return component;
          }
        });

    myTree.setModel(new DefaultTreeModel(root));
    myTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              @Override
              public void valueChanged(@NotNull TreeSelectionEvent e) {
                update();
              }
            });
    myEditor = TemplateEditorUtil.createEditor(true, "");

    mySplitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree));
    JPanel details = new JPanel(new BorderLayout());
    details.add(myEditor.getComponent(), BorderLayout.CENTER);
    mySplitter.setSecondComponent(details);
    mySplitter.setHonorComponentsMinimumSize(true);
    mySplitter.setShowDividerControls(true);

    myTree.setSelectionRow(0);

    init();
  }