Пример #1
0
 public void setFile(NetcdfFile ds) {
   if (ds != currentDataset) {
     currentDataset = ds;
     model = new DatasetTreeModel(ds);
     tree.setModel(model);
   }
 }
  private void init() {
    JPanel quickSearchPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));

    final TreeModel treeModel = explorer.getTreeModel();
    final QuickTreeFilterField field =
        new QuickTreeFilterField(treeModel) {
          protected FilterableTreeModel createDisplayTreeModel(TreeModel treeModel) {
            return new FilterableTreeModel(treeModel) {
              @Override
              protected void configureListModelWrapper(ListModelWrapper wrapper, Object node) {

                if (node instanceof DefaultMutableTreeNode) {
                  // ImageFileExplorer.LazyNode inode = (ImageFileExplorer.LazyNode) node;
                  DefaultMutableTreeNode inode = (DefaultMutableTreeNode) node;
                  boolean expanded = explorer.getJTree().isExpanded(new TreePath(inode.getPath()));
                  if (inode.isLeaf() || expanded) {
                    super.configureListModelWrapper(wrapper, node);
                  }
                }
              }
            };
          }
        };

    field.setSearchingDelay(200);
    quickSearchPanel.add(field);

    JPanel treePanel = new JPanel(new BorderLayout(2, 2));

    field.setTree(explorer.getJTree());
    SearchableUtils.installSearchable(field.getTree());

    JTree tree = field.getTree();
    tree.setModel(field.getDisplayTreeModel());
    DataTipManager.get().register(tree);

    treePanel.add(explorer.getComponent());

    mainPanel.add(treePanel);
    mainPanel.add(quickSearchPanel, BorderLayout.BEFORE_FIRST_LINE);

    EventBus.subscribeStrongly(
        DataSourceStatusEvent.class,
        new EventSubscriber<DataSourceStatusEvent>() {
          @Override
          public void onEvent(DataSourceStatusEvent event) {
            explorer.getJTree().repaint();
          }
        });

    mainPanel.putClientProperty(IActionProvider.KEY, this);
  }
  public final void changeView(@NotNull final String typeName) {
    myCurrentViewType = typeName;

    final PsiElement element = mySmartPsiElementPointer.getElement();
    if (element == null || !isApplicableElement(element)) {
      return;
    }

    if (myContent != null) {
      final String displayName = getContentDisplayName(typeName, element);
      if (displayName != null) {
        myContent.setDisplayName(displayName);
      }
    }

    myCardLayout.show(myTreePanel, typeName);

    if (!myBuilders.containsKey(typeName)) {
      try {
        setWaitCursor();
        // create builder
        final JTree tree = myType2TreeMap.get(typeName);
        final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode(""));
        tree.setModel(model);

        final HierarchyTreeStructure structure = createHierarchyTreeStructure(typeName, element);
        if (structure == null) {
          return;
        }
        final Comparator<NodeDescriptor> comparator = getComparator();
        final HierarchyTreeBuilder builder =
            new HierarchyTreeBuilder(myProject, tree, model, structure, comparator);

        myBuilders.put(typeName, builder);
        Disposer.register(this, builder);
        Disposer.register(builder, () -> myBuilders.remove(typeName));

        final HierarchyNodeDescriptor descriptor = structure.getBaseDescriptor();
        builder.select(descriptor, () -> builder.expand(descriptor, null));
      } finally {
        restoreCursor();
      }
    }

    getCurrentTree().requestFocus();
  }
Пример #4
0
  /** Constructor. */
  public DatasetTreeView() {
    // the catalog tree
    tree =
        new JTree() {
          public JToolTip createToolTip() {
            return new MultilineTooltip();
          }
        };
    tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(null, false)));
    tree.setCellRenderer(new MyTreeCellRenderer());

    tree.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            int selRow = tree.getRowForLocation(e.getX(), e.getY());
            if (selRow != -1) {
              TreeNode node = (TreeNode) tree.getLastSelectedPathComponent();
              if (node instanceof VariableNode) {
                VariableIF v = ((VariableNode) node).var;
                firePropertyChangeEvent(new PropertyChangeEvent(this, "Selection", null, v));
              }
            }

            if ((selRow != -1) && (e.getClickCount() == 2)) {
              // acceptSelected();
            }
          }
        });

    tree.putClientProperty("JTree.lineStyle", "Angled");
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setToggleClickCount(1);
    ToolTipManager.sharedInstance().registerComponent(tree);

    // layout
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);
  }
  public CustomizableActionsPanel() {

    //noinspection HardCodedStringLiteral
    Group rootGroup = new Group("root", null, null);
    final DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootGroup);
    DefaultTreeModel model = new DefaultTreeModel(root);
    myActionsTree.setModel(model);

    myActionsTree.setRootVisible(false);
    myActionsTree.setShowsRootHandles(true);
    UIUtil.setLineStyleAngled(myActionsTree);
    myActionsTree.setCellRenderer(new MyTreeCellRenderer());

    setButtonsDisabled();
    final ActionManager actionManager = ActionManager.getInstance();
    myActionsTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              public void valueChanged(TreeSelectionEvent e) {
                final TreePath[] selectionPaths = myActionsTree.getSelectionPaths();
                final boolean isSingleSelection =
                    selectionPaths != null && selectionPaths.length == 1;
                myAddActionButton.setEnabled(isSingleSelection);
                if (isSingleSelection) {
                  final DefaultMutableTreeNode node =
                      (DefaultMutableTreeNode) selectionPaths[0].getLastPathComponent();
                  String actionId = getActionId(node);
                  if (actionId != null) {
                    final AnAction action = actionManager.getAction(actionId);
                    myEditIconButton.setEnabled(
                        action != null && action.getTemplatePresentation() != null);
                  } else {
                    myEditIconButton.setEnabled(false);
                  }
                } else {
                  myEditIconButton.setEnabled(false);
                }
                myAddSeparatorButton.setEnabled(isSingleSelection);
                myRemoveActionButton.setEnabled(selectionPaths != null);
                if (selectionPaths != null) {
                  for (TreePath selectionPath : selectionPaths) {
                    if (selectionPath.getPath() != null && selectionPath.getPath().length <= 2) {
                      setButtonsDisabled();
                      return;
                    }
                  }
                }
                myMoveActionUpButton.setEnabled(isMoveSupported(myActionsTree, -1));
                myMoveActionDownButton.setEnabled(isMoveSupported(myActionsTree, 1));
                myRestoreDefaultButton.setEnabled(!findActionsUnderSelection().isEmpty());
              }
            });

    myAddActionButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath selectionPath = myActionsTree.getLeadSelectionPath();
            if (selectionPath != null) {
              DefaultMutableTreeNode node =
                  (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
              final FindAvailableActionsDialog dlg = new FindAvailableActionsDialog();
              dlg.show();
              if (dlg.isOK()) {
                final Set<Object> toAdd = dlg.getTreeSelectedActionIds();
                if (toAdd == null) return;
                for (final Object o : toAdd) {
                  final ActionUrl url =
                      new ActionUrl(
                          ActionUrl.getGroupPath(new TreePath(node.getPath())),
                          o,
                          ActionUrl.ADDED,
                          node.getParent().getIndex(node) + 1);
                  addCustomizedAction(url);
                  ActionUrl.changePathInActionsTree(myActionsTree, url);
                  if (o instanceof String) {
                    DefaultMutableTreeNode current = new DefaultMutableTreeNode(url.getComponent());
                    current.setParent((DefaultMutableTreeNode) node.getParent());
                    editToolbarIcon((String) o, current);
                  }
                }
                ((DefaultTreeModel) myActionsTree.getModel()).reload();
              }
            }
            TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
          }
        });

    myEditIconButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            myRestoreAllDefaultButton.setEnabled(true);
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath selectionPath = myActionsTree.getLeadSelectionPath();
            if (selectionPath != null) {
              EditIconDialog dlg =
                  new EditIconDialog((DefaultMutableTreeNode) selectionPath.getLastPathComponent());
              dlg.show();
              if (dlg.isOK()) {
                myActionsTree.repaint();
              }
            }
            TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
          }
        });

    myAddSeparatorButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath selectionPath = myActionsTree.getLeadSelectionPath();
            if (selectionPath != null) {
              DefaultMutableTreeNode node =
                  (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
              final ActionUrl url =
                  new ActionUrl(
                      ActionUrl.getGroupPath(selectionPath),
                      Separator.getInstance(),
                      ActionUrl.ADDED,
                      node.getParent().getIndex(node) + 1);
              ActionUrl.changePathInActionsTree(myActionsTree, url);
              addCustomizedAction(url);
              ((DefaultTreeModel) myActionsTree.getModel()).reload();
            }
            TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
          }
        });

    myRemoveActionButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath[] selectionPath = myActionsTree.getSelectionPaths();
            if (selectionPath != null) {
              for (TreePath treePath : selectionPath) {
                final ActionUrl url = CustomizationUtil.getActionUrl(treePath, ActionUrl.DELETED);
                ActionUrl.changePathInActionsTree(myActionsTree, url);
                addCustomizedAction(url);
              }
              ((DefaultTreeModel) myActionsTree.getModel()).reload();
            }
            TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
          }
        });

    myMoveActionUpButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath[] selectionPath = myActionsTree.getSelectionPaths();
            if (selectionPath != null) {
              for (TreePath treePath : selectionPath) {
                final ActionUrl url = CustomizationUtil.getActionUrl(treePath, ActionUrl.MOVE);
                final int absolutePosition = url.getAbsolutePosition();
                url.setInitialPosition(absolutePosition);
                url.setAbsolutePosition(absolutePosition - 1);
                ActionUrl.changePathInActionsTree(myActionsTree, url);
                addCustomizedAction(url);
              }
              ((DefaultTreeModel) myActionsTree.getModel()).reload();
              TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
              for (TreePath path : selectionPath) {
                myActionsTree.addSelectionPath(path);
              }
            }
          }
        });

    myMoveActionDownButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myActionsTree);
            final TreePath[] selectionPath = myActionsTree.getSelectionPaths();
            if (selectionPath != null) {
              for (int i = selectionPath.length - 1; i >= 0; i--) {
                TreePath treePath = selectionPath[i];
                final ActionUrl url = CustomizationUtil.getActionUrl(treePath, ActionUrl.MOVE);
                final int absolutePosition = url.getAbsolutePosition();
                url.setInitialPosition(absolutePosition);
                url.setAbsolutePosition(absolutePosition + 1);
                ActionUrl.changePathInActionsTree(myActionsTree, url);
                addCustomizedAction(url);
              }
              ((DefaultTreeModel) myActionsTree.getModel()).reload();
              TreeUtil.restoreExpandedPaths(myActionsTree, expandedPaths);
              for (TreePath path : selectionPath) {
                myActionsTree.addSelectionPath(path);
              }
            }
          }
        });

    myRestoreAllDefaultButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mySelectedSchema.copyFrom(new CustomActionsSchema());
            patchActionsTreeCorrespondingToSchema(root);
            myRestoreAllDefaultButton.setEnabled(false);
          }
        });

    myRestoreDefaultButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List<ActionUrl> otherActions =
                new ArrayList<ActionUrl>(mySelectedSchema.getActions());
            otherActions.removeAll(findActionsUnderSelection());
            mySelectedSchema.copyFrom(new CustomActionsSchema());
            for (ActionUrl otherAction : otherActions) {
              mySelectedSchema.addAction(otherAction);
            }
            final List<TreePath> treePaths = TreeUtil.collectExpandedPaths(myActionsTree);
            patchActionsTreeCorrespondingToSchema(root);
            restorePathsAfterTreeOptimization(treePaths);
            myRestoreDefaultButton.setEnabled(false);
          }
        });

    patchActionsTreeCorrespondingToSchema(root);

    myTreeExpansionMonitor = TreeExpansionMonitor.install(myActionsTree);
  }
    protected JComponent createCenterPanel() {
      Group rootGroup =
          ActionsTreeUtil.createMainGroup(
              null, null, QuickListsManager.getInstance().getAllQuickLists());
      DefaultMutableTreeNode root = ActionsTreeUtil.createNode(rootGroup);
      DefaultTreeModel model = new DefaultTreeModel(root);
      myTree = new Tree();
      myTree.setModel(model);
      myTree.setCellRenderer(new MyTreeCellRenderer());
      final ActionManager actionManager = ActionManager.getInstance();

      mySetIconButton = new JButton(IdeBundle.message("button.set.icon"));
      mySetIconButton.setEnabled(false);
      mySetIconButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              final TreePath selectionPath = myTree.getSelectionPath();
              if (selectionPath != null) {
                doSetIcon(
                    (DefaultMutableTreeNode) selectionPath.getLastPathComponent(),
                    myTextField.getText(),
                    getContentPane());
                myTree.repaint();
              }
            }
          });
      myTextField = createBrowseField();
      myTextField
          .getTextField()
          .getDocument()
          .addDocumentListener(
              new DocumentAdapter() {
                protected void textChanged(DocumentEvent e) {
                  enableSetIconButton(actionManager);
                }
              });
      JPanel northPanel = new JPanel(new BorderLayout());
      northPanel.add(myTextField, BorderLayout.CENTER);
      final JLabel label = new JLabel(IdeBundle.message("label.icon.path"));
      label.setLabelFor(myTextField.getChildComponent());
      northPanel.add(label, BorderLayout.WEST);
      northPanel.add(mySetIconButton, BorderLayout.EAST);
      northPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
      JPanel panel = new JPanel(new BorderLayout());
      panel.add(northPanel, BorderLayout.NORTH);

      panel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
      myTree
          .getSelectionModel()
          .addTreeSelectionListener(
              new TreeSelectionListener() {
                public void valueChanged(TreeSelectionEvent e) {
                  enableSetIconButton(actionManager);
                  final TreePath selectionPath = myTree.getSelectionPath();
                  if (selectionPath != null) {
                    final DefaultMutableTreeNode node =
                        (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
                    final String actionId = getActionId(node);
                    if (actionId != null) {
                      final String iconPath = mySelectedSchema.getIconPath(actionId);
                      myTextField.setText(FileUtil.toSystemDependentName(iconPath));
                    }
                  }
                }
              });
      return panel;
    }
Пример #7
0
 public void clear() {
   currentDataset = null;
   model = null;
   tree.setModel(null);
 }
Пример #8
0
  private ClientWindow(String name) {
    setTitle("ClientWindow");
    setContentPane(WindowPanel);
    pack();

    clientFacade = ClientFacade.getClientFacadeByClientName(name);
    NameLabel.setText(clientFacade.getClientName());

    productItemMap = clientFacade.getProductList();
    FormOrderPanel.setVisible(false);

    tableModel = new ProductsTableModel();
    ProductsTable.setModel(tableModel);

    root = new DefaultMutableTreeNode("ClientOrders");

    generateOrdersTree();

    OrdersTree.setModel(new DefaultTreeModel(root));
    OrdersTree.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
              TreePath pathSelected = OrdersTree.getSelectionPath();
              if (OrdersTree.isPathSelected(pathSelected)
                  && OrdersTree.getModel().isLeaf(pathSelected.getLastPathComponent())) {
                ManagerPopupMenu managerPopupMenu = new ManagerPopupMenu();
                managerPopupMenu.getJPopupMenu().show(e.getComponent(), e.getX(), e.getY());
              }
            }
          }
        });
    OrdersTree.setShowsRootHandles(true);
    OrdersTree.setRootVisible(true);

    OrdersTree.getSelectionModel()
        .addTreeSelectionListener(
            e -> {
              DefaultMutableTreeNode selectedNode =
                  (DefaultMutableTreeNode) OrdersTree.getLastSelectedPathComponent();
              if (selectedNode.isLeaf()) {
                if (!((String) selectedNode.getUserObject()).equals("ClientOrders")) {
                  List<ProductRow> productRowList =
                      clientFacade.getProductRowsByOrder(
                          clientFacade.getValidDate((String) selectedNode.getUserObject()));
                  productRowList
                      .stream()
                      .forEach(
                          productRow ->
                              ClientWindow.this.tableModel.addRow(
                                  productRow.getId(),
                                  productRow.getType(),
                                  productRow.getPrice(),
                                  productRow.getNumber()));

                  ProductsTable.revalidate();
                }
              }
            });

    Font font = new Font("Verdana", Font.PLAIN, 12);
    jMenuBar = new JMenuBar();
    jMenu = new JMenu("Actions");

    JMenuItem jCreateProviderOrderItem = new JMenuItem("Создать заказ");
    jCreateProviderOrderItem.setFont(font);
    jCreateProviderOrderItem.addActionListener(e -> openClientOrderForm());
    jMenu.add(jCreateProviderOrderItem);

    jMenu.addSeparator();

    JMenuItem jCloseItem = new JMenuItem("Закрыть");
    jCloseItem.setFont(font);
    jCloseItem.addActionListener(e -> close());
    jMenu.add(jCloseItem);

    jMenuBar.add(jMenu);
    MenuPanel.add(jMenuBar);

    OrderOkButton.addActionListener(e -> createClientOrder());
    OrderCancelButton.addActionListener(e -> closeClientOrderForm());
    TypeComboBox.addItemListener(e -> setPriceByType());
    AddProductButton.addActionListener(
        e -> {
          if (productItemList == null) {
            productItemList = new HashMap<String, ProductItem>();
          }
          productItemList.put(
              TypeComboBox.getSelectedItem().toString(),
              new ProductItem(
                  TypeComboBox.getSelectedItem().toString(),
                  PriceTextField.getText(),
                  AmountTextField.getText()));
        });

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

    BurgerButton.addActionListener(e -> FastFoodTextArea.append(clientFacade.getBurger()));

    RunServerButton.addActionListener(e -> InfoTextArea.append(clientFacade.runServer()));

    StopServerButton.addActionListener(e -> InfoTextArea.append(clientFacade.stopServer()));
  }
Пример #9
0
 /**
  * sets the root node to the ontology label
  *
  * @param ontologyName
  */
 public void initialize(String ontologyName) {
   rootNode = new DefaultMutableTreeNode(new TermNode(ontologyName, null));
   treeModel = new DefaultTreeModel(rootNode);
   treeModel.addTreeModelListener(this);
   tree.setModel(treeModel);
 }