Пример #1
0
 /** Updates the contents of the right panel. */
 private void updateEntryPane() {
   ViewPositions pos = Utilities.getViewPositions(entryPane);
   TreePath[] paths = treePane.getTree().getSelectionPaths();
   TreePath path = null;
   if ((paths != null) && (paths.length == 1)) {
     path = paths[0];
   }
   lastIndexTreePath = path;
   if (path != null) {
     Object node = path.getLastPathComponent();
     if (node instanceof IndexTreeNode) {
       entryPane.updateStandardIndex(((IndexTreeNode) node).getIndex());
     } else if (node instanceof VLVIndexTreeNode) {
       entryPane.updateVLVIndex(((VLVIndexTreeNode) node).getIndex());
     } else if (node == standardIndexes) {
       String backendName = (String) backends.getSelectedItem();
       entryPane.updateBackendIndexes(backendName);
     } else if (node == vlvIndexes) {
       String backendName = (String) backends.getSelectedItem();
       entryPane.updateBackendVLVIndexes(backendName);
     } else {
       entryPane.displayVoid();
     }
   } else {
     if ((paths != null) && (paths.length > 1)) {
       entryPane.displayMultiple();
     } else {
       entryPane.displayVoid();
     }
   }
   Utilities.updateViewPositions(pos);
 }
Пример #2
0
 /** {@inheritDoc} */
 public void setInfo(ControlPanelInfo info) {
   super.setInfo(info);
   treePane.setInfo(info);
   entryPane.setInfo(info);
   info.addIndexModifiedListener(this);
 }
Пример #3
0
  /** {@inheritDoc} */
  private Component createSplitPane() {
    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    pane.setOpaque(true); // content panes must be opaque

    treePane = new TreePanel();
    Utilities.setBorder(treePane, new EmptyBorder(10, 0, 10, 0));

    entryPane = new IndexBrowserRightPanel();
    treeScroll = Utilities.createScrollPane(treePane);

    entryPane.addIndexSelectionListener(
        new IndexSelectionListener() {
          /** {@inheritDoc} */
          public void indexSelected(IndexSelectionEvent ev) {
            AbstractIndexDescriptor index = ev.getIndex();
            TreeNode parentNode;
            if (index instanceof IndexDescriptor) {
              parentNode = standardIndexes;
            } else {
              parentNode = vlvIndexes;
            }
            DefaultTreeModel model = (DefaultTreeModel) treePane.getTree().getModel();
            int n = model.getChildCount(parentNode);
            for (int i = 0; i < n; i++) {
              AbstractIndexTreeNode node = (AbstractIndexTreeNode) model.getChild(parentNode, i);
              if (node.getName().equals(index.getName())) {
                TreePath newSelectionPath = new TreePath(node.getPath());
                treePane.getTree().setSelectionPath(newSelectionPath);
                treePane.getTree().scrollPathToVisible(newSelectionPath);
                break;
              }
            }
          }
        });

    //  Create a split pane
    pane.setLeftComponent(treeScroll);
    pane.setRightComponent(entryPane);
    pane.setResizeWeight(0.0);

    treePane
        .getTree()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              /** {@inheritDoc} */
              public void valueChanged(TreeSelectionEvent ev) {
                if (!ignoreSelectionEvents) {
                  TreePath[] paths = treePane.getTree().getSelectionPaths();

                  if (entryPane.mustCheckUnsavedChanges()) {
                    ignoreSelectionEvents = true;
                    treePane.getTree().setSelectionPath(lastIndexTreePath);
                    switch (entryPane.checkUnsavedChanges()) {
                      case DO_NOT_SAVE:
                        break;
                      case SAVE:
                        break;
                      case CANCEL:
                        ignoreSelectionEvents = false;
                        return;
                    }
                    if (paths != null) {
                      treePane.getTree().setSelectionPaths(paths);
                    } else {
                      treePane.getTree().clearSelection();
                    }
                    ignoreSelectionEvents = false;
                  }

                  boolean deletableElementsSelected = false;
                  boolean nonDeletableElementsSelected = false;
                  if (paths != null) {
                    for (TreePath path : paths) {
                      Object node = path.getLastPathComponent();
                      if (node instanceof IndexTreeNode) {
                        IndexDescriptor index = ((IndexTreeNode) node).getIndex();
                        if (index.isDatabaseIndex()) {
                          nonDeletableElementsSelected = true;
                        } else {
                          deletableElementsSelected = true;
                        }
                      } else if (node instanceof VLVIndexTreeNode) {
                        deletableElementsSelected = true;
                      }
                    }
                  }
                  deleteMenuItem.setEnabled(
                      deletableElementsSelected && !nonDeletableElementsSelected);
                  updateEntryPane();
                }
              }
            });
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Tree root");
    for (DefaultMutableTreeNode node : categoryNodes) {
      root.add(node);
    }
    DefaultTreeModel model = new DefaultTreeModel(root);
    JTree tree = treePane.getTree();
    tree.setModel(model);
    tree.setRootVisible(false);
    tree.setVisibleRowCount(20);
    tree.expandPath(new TreePath(root));
    tree.setCellRenderer(new IndexTreeCellRenderer());
    addPopupMenu();

    treeScroll.setPreferredSize(
        new Dimension(
            2 * treeScroll.getPreferredSize().width, 8 * treeScroll.getPreferredSize().height));
    entryPane.setBorder(getRightPanelBorder());
    entryPane.setPreferredSize(
        new Dimension(
            (treeScroll.getPreferredSize().width * 5) / 2, treeScroll.getPreferredSize().height));
    pane.setDividerLocation(treeScroll.getPreferredSize().width);
    entryPane.displayVoid();
    return pane;
  }