Package javax.swing.tree

Examples of javax.swing.tree.DefaultTreeModel


                DcImageIcon icon = null;
                String iconBase64 = null;
                DcField field = null;
                int module;

                DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
               
                DefaultMutableTreeNode current;
                DefaultMutableTreeNode parent;
                DefaultMutableTreeNode previous;
                boolean exists = false;
               
                Map<String, Integer> items = DataManager.getKeys(DataFilters.getCurrent(getModule()));
               
                Collection<String> keys = null;
                if (DataFilters.isFilterActive(getModule())) {
                    keys = new ArrayList<String>(items.keySet());
                }
               
                while (rs.next() && !stop) {
                    int level = 0;
                    parent = top;
                   
                    for (int idx = 0; idx < fields.length; idx++) {
                     
                      field = DcModules.get(getModule()).getField(fields[idx]);
                      if (field.isUiOnly() &&
                          field.getIndex() != DcObject._SYS_MODULE &&
                          field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION &&
                          field.getFieldType() != ComponentFactory._REFERENCEFIELD)
                        continue;
                     
                       
                        if (stop) break;
                       
                        // for each level the field index is shifted to the end.
                        id = rs.getString(1);
                        module = rs.getInt(2);
                        key = field.getIndex() == DcObject._SYS_MODULE ? DcModules.get(module).getLabel() : rs.getObject((level * 3) + 3);
                        value =  field.getIndex() == DcObject._SYS_MODULE ? DcModules.get(module).getLabel() : rs.getString((level * 3) + 4);
                        iconBase64 = field.getIndex() != DcObject._SYS_MODULE ? rs.getString((level * 3) + 5) : null;
                       
                        icon = field.getIndex() == DcObject._SYS_MODULE ?
                                new DcImageIcon(DcModules.get(module).getIcon16().getImage()) :
                                iconBase64 != null ? DataManager.addIcon(String.valueOf(key), iconBase64) : null;
                       
                        if (keys != null && !keys.contains(id)) continue;
                       
                        previous = parent.getChildCount() == 0 ? null : ((DefaultMutableTreeNode) parent.getChildAt(parent.getChildCount() - 1));
                        exists = previous == null || (((NodeElementprevious.getUserObject()).getKey() == null && key != null) ? false :
                                ((NodeElementprevious.getUserObject()).getKey() == key || // empty key
                                ((NodeElementprevious.getUserObject()).getKey().equals(key);
                       
                        if (!exists) {
                            if (key == null) {
                                ne = new NodeElement(null, empty, null);
                            } else {
                                ne = new NodeElement(key, value, icon);
                            }
                           
                            ne.addItem(id, module);
                            current = new DcDefaultMutableTreeNode(ne);
                            parent.add(current);
                            parent = current;
                          
                        } else { // exists
                            existingNe =(NodeElement) previous.getUserObject();
                            existingNe.addItem(id, module);
                            model.nodeChanged(previous);
                            parent = previous;   
                        }
                       
                        if (field.getIndex() != DcObject._SYS_MODULE)
                            level++;
                    }
                }
               
                rs.close();
               
                NodeElement topElem = (NodeElement) top.getUserObject();
                topElem.setItems(items);
                model.nodeChanged(top);
               
            } catch (Exception e) {
                logger.error(e, e);
            }
        }
View Full Code Here


           
            if (icon != null) icons.put(id, Utilities.base64ToImage(icon));
            all.put(id, name);
          }
         
          DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
          int counter = 0;
          for (String parentKey : parents.keySet()) {
           
            if (stop) break;
           
            ContainerNodeElement ne = new ContainerNodeElement(parentKey, (String) parents.get(parentKey), icons.get(parentKey));
            DcDefaultMutableTreeNode current = new DcDefaultMutableTreeNode(ne);
            model.insertNodeInto(current, top, counter++);
            top.addItem(parentKey, Integer.valueOf(module.getIndex()));
            createChildren(model, parentKey, current, relations, all, icons);
          }
         
        } catch (Exception e) {
View Full Code Here

     * @param parent Existing parent
     */
    private void add(String item, int module, DcDefaultMutableTreeNode node, DcDefaultMutableTreeNode parent) {
      DcDefaultMutableTreeNode existingChild;

      DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
     
      // need to add to a collection as nodes will be removed once placed in the actual tree (!)
      Collection<DcDefaultMutableTreeNode> nodes = new ArrayList<DcDefaultMutableTreeNode>();
      for (int i = 0; i < node.getChildCount(); i++)
        nodes.add((DcDefaultMutableTreeNode) node.getChildAt(i));
     
      DcDefaultMutableTreeNode actualParent;
      for (DcDefaultMutableTreeNode child : nodes) {
          existingChild = findNode(child, parent, false);
         
          actualParent = findNode((DcDefaultMutableTreeNode) child.getParent(), getTopNode(), true);
          actualParent = actualParent == null ? parent : actualParent;
          if (existingChild == null) {
            // will be removed from the node as well:
              child.addItem(item, Integer.valueOf(module));
              insertNode(child, actualParent);
              existingChild = child;
          } else {
              existingChild.addItem(item, Integer.valueOf(module));
              model.nodeChanged(existingChild);
             
          }
          add(item, module, child, existingChild);
      }
    }
View Full Code Here

    protected void build() {
        clear();
       
        createTopNode();
       
        tree = new DcTree(new DefaultTreeModel(top));
        tree.setFont(ComponentFactory.getStandardFont());
        tree.addTreeSelectionListener(this);
       
        scroller = new JScrollPane(tree);
       
View Full Code Here

    public void reset() {
        createTree();
    }
   
    protected void setSelected(DefaultMutableTreeNode node) {
        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        TreePath treePath = new TreePath(model.getPathToRoot(node));
        tree.setSelectionPath(treePath);
        tree.expandPath(treePath);
        tree.scrollPathToVisible(treePath);
       
        currentUserObject = node.getUserObject();
View Full Code Here

    /**
     * Inserts a node. The node needs to have a valid user object defined
     * to insert it at the right position (ordering)
     */
    protected void insertNode(DefaultMutableTreeNode node, DefaultMutableTreeNode parent) {
        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
       
        NodeElement ne = (NodeElement) node.getUserObject();
       
        List<String> elements = new ArrayList<String>();
        NodeElement child;
        for (int i = 0; i < parent.getChildCount(); i++) {
            child = ((NodeElement) ((DefaultMutableTreeNode) parent.getChildAt(i)).getUserObject());
            elements.add(child.getComparableKey());
        }
       
        elements.add(ne.getComparableKey());
        Collections.sort(elements);
        int idx = elements.indexOf(ne.getComparableKey());
       
        model.insertNodeInto(node, parent, parent.getChildCount() == 0 ? 0 : idx);
       
        tree.expandPath(new TreePath(model.getPathToRoot(node)));
        tree.revalidate();
    }
View Full Code Here

    }

    public abstract void groupBy();
   
    private void removeNode(DefaultMutableTreeNode child) {
       DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
       model.removeNodeFromParent(child);
   
       // remove empty branches above (needed for the file tree panel)
       DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent();
       NodeElement ne;
       while (parent != null) {
         ne = ((NodeElement) child.getUserObject());
         if (ne.getCount() == 0 && parent.getChildCount() == 0) {
           DefaultMutableTreeNode newParent = null;

           try {
             newParent = (DefaultMutableTreeNode) parent.getParent();
           } catch (Exception e) {}
            
           try {
             model.removeNodeFromParent(parent);
             parent = newParent;
           } catch (IllegalArgumentException iae) {
                 parent = null;
           }
         } else {
View Full Code Here

  /**
   *
   */
  public Component3DTree() {
    DefaultMutableTreeNode root=new DefaultMutableTreeNode();
    model= new DefaultTreeModel(root, true);
    setModel(model);
    setCellRenderer(new SceneGraphTreeRenderer());
    setRootVisible(false);
  }
View Full Code Here

  }

  public SourceTree(DataSourcePool pool) {
      super();
      rootNode = new DefaultNode();
    treeModel = new DefaultTreeModel(rootNode);
    setModel(treeModel);
    // We don't want to see the root node, it is here to hold the other
    // interesting ones
    setRootVisible(false);
    setShowsRootHandles(true);
View Full Code Here

        // Create help tree
        rootNode = new HelpNode();

        rootTreeNode = new DefaultMutableTreeNode();
        DefaultTreeModel treeModel = new DefaultTreeModel(rootTreeNode);
        helpTree = new JTree();
        helpTree.setModel(treeModel);
        helpTree.setRootVisible(false);
        helpTree.setShowsRootHandles(true);
        helpTree.addTreeSelectionListener(this);

        // Renderer
        DefaultTreeCellRenderer  helpTreeRenderer = (DefaultTreeCellRenderer) helpTree.getCellRenderer();
        helpTreeRenderer.setOpenIcon(resources.getIcon("folderIcon"));
        helpTreeRenderer.setClosedIcon(resources.getIcon("folderIcon"));
        helpTreeRenderer.setLeafIcon(resources.getIcon("leafIcon"));

        createHelpContents();


        // Create help search panel

        // search tree
        searchRootTreeNode = new DefaultMutableTreeNode();
        searchTreeModel = new DefaultTreeModel(searchRootTreeNode);
        searchTree = new JTree();
        searchTree.setModel(searchTreeModel);
        searchTree.setRootVisible(false);
        searchTree.setShowsRootHandles(true);
        searchTree.addTreeSelectionListener(this);

        JScrollPane scrollSearchTree = new JScrollPane(searchTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );

        DefaultTreeCellRenderer  searchTreeRenderer = (DefaultTreeCellRenderer) searchTree.getCellRenderer();
        searchTreeRenderer.setOpenIcon(resources.getIcon("folderIcon"));
        searchTreeRenderer.setClosedIcon(resources.getIcon("folderIcon"));
        searchTreeRenderer.setLeafIcon(resources.getIcon("leafIcon"));


        // search field
        JToolBar  toolbar = new JToolBar();
        toolbar.setRollover(true);
        toolbar.setFloatable(false);

        bClearFilter = resources.getBox("clearFilter", this);
        bClearFilter.setEnabled(false);
        toolbar.add(bClearFilter);

        bApplyFilter = resources.getBox("applyFilter", this);
        toolbar.add(bApplyFilter);


        JLabel searchTip = new JLabel(resources.getString("filter"));
        searchField = new JTextField(15);
        searchField.addKeyListener(
                new KeyListener() {

                    public void keyPressed(KeyEvent keyEvent) {}

                    public void keyReleased(KeyEvent keyEvent) {
                        boolean enable = !searchField.getText().equals("");
                        bApplyFilter.setEnabled(enable);
                        bClearFilter.setEnabled(enable);
                    }

                    public void keyTyped(KeyEvent keyEvent) {}
                }
        );
        searchField.addActionListener(this);
       
        // HTML parser
        htmlParser = new SourceForgeHTMLParser();


        GridBagPanel helpSearchPanel = new GridBagPanel();
        helpSearchPanel.addOnCurrentRow(searchTip);
        helpSearchPanel.addOnCurrentRow(searchField, 3, true, false, false);
        helpSearchPanel.addOnCurrentRow(toolbar,1,false, false, true);
        helpSearchPanel.addOnCurrentRow(scrollSearchTree, 5, true, true, true);


        // HELP PANES
        JTabbedPane helpTreePane = new JTabbedPane();

        // Tree contents pane
        JScrollPane treeScrollPane = new JScrollPane(helpTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
        helpTreePane.addTab(resources.getString("contents"),resources.getIcon("folderIcon"),treeScrollPane, resources.getString("contentsTips"));


        // Search pane
        helpTreePane.addTab(resources.getString("search"),resources.getIcon("searchIcon"),helpSearchPanel, resources.getString("searchTips"));


        treeModel.reload();

        // Create global frame
        JSplitPane helpSlitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,helpTreePane ,scrollPane);
        helpSlitPane.setDividerLocation(300);
        Container content = getContentPane();
View Full Code Here

TOP

Related Classes of javax.swing.tree.DefaultTreeModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.