Beispiel #1
0
  private int compare(DefaultMutableTreeNode node1, DefaultMutableTreeNode node2) {
    SearchTOCItem item1, item2;
    double confidence1, confidence2;
    int hits1, hits2;

    item1 = (SearchTOCItem) node1.getUserObject();
    confidence1 = item1.getConfidence();
    hits1 = item1.hitCount();

    item2 = (SearchTOCItem) node2.getUserObject();
    confidence2 = item2.getConfidence();
    hits2 = item2.hitCount();

    // confidence is a penality. The lower the better
    if (confidence1 > confidence2) {
      // node1 is less than node2
      return -1;
    } else if (confidence1 < confidence2) {
      // node1 is greater than node2
      return 1;
    } else {
      // confidences are the same check the hits
      if (hits1 < hits2) {
        // node1 is less than node2
        return -1;
      } else if (hits1 > hits2) {
        // node2 is greater than node2
        return 1;
      }
    }
    // nodes1 and nodes2 are equivalent
    return 0;
  }
  @Override
  public void treeNodesChanged(TreeModelEvent e) {
    if (adjusting) {
      return;
    }
    adjusting = true;
    TreePath parent = e.getTreePath();
    Object[] children = e.getChildren();
    DefaultTreeModel model = (DefaultTreeModel) e.getSource();

    DefaultMutableTreeNode node;
    CheckBoxNode c; // = (CheckBoxNode)node.getUserObject();
    if (children != null && children.length == 1) {
      node = (DefaultMutableTreeNode) children[0];
      c = (CheckBoxNode) node.getUserObject();
      onCheckboxStatusChanged(node);
      DefaultMutableTreeNode n = (DefaultMutableTreeNode) parent.getLastPathComponent();
      while (n != null) {
        updateParentUserObject(n);
        DefaultMutableTreeNode tmp = (DefaultMutableTreeNode) n.getParent();
        if (tmp == null) {
          break;
        } else {
          n = tmp;
        }
      }
      model.nodeChanged(n);
    } else {
      node = (DefaultMutableTreeNode) model.getRoot();
      c = (CheckBoxNode) node.getUserObject();
    }
    updateAllChildrenUserObject(node, c.status);
    model.nodeChanged(node);
    adjusting = false;
  }
 private void updateParentUserObject(DefaultMutableTreeNode parent) {
   String label = ((CheckBoxNode) parent.getUserObject()).label;
   int selectedCount = 0;
   int indeterminateCount = 0;
   Enumeration children = parent.children();
   while (children.hasMoreElements()) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
     CheckBoxNode check = (CheckBoxNode) node.getUserObject();
     if (check.status == Status.INDETERMINATE) {
       indeterminateCount++;
       break;
     }
     if (check.status == Status.SELECTED) {
       selectedCount++;
     }
   }
   onCheckboxStatusChanged(parent);
   if (indeterminateCount > 0) {
     parent.setUserObject(new CheckBoxNode(label));
   } else if (selectedCount == 0) {
     parent.setUserObject(new CheckBoxNode(label, Status.DESELECTED));
   } else if (selectedCount == parent.getChildCount()) {
     parent.setUserObject(new CheckBoxNode(label, Status.SELECTED));
   } else {
     parent.setUserObject(new CheckBoxNode(label));
   }
 }
Beispiel #4
0
  /**
   * get the children of this group in the tree (recursive call)
   *
   * @param root of the tree
   * @return a list of the children of the group or null if no children (to be initialized by
   *     caller)
   */
  public ArrayList<PDLGroup> getChildren(DefaultMutableTreeNode root, ArrayList<PDLGroup> list) {

    PDLGroup rootGroup = (PDLGroup) root.getUserObject();
    String rootGroupName = rootGroup.getName();
    if (this.name.equals(rootGroupName)) {
      @SuppressWarnings("rawtypes")
      Enumeration children = root.children();
      while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        list.add((PDLGroup) child.getUserObject());
      }
      return list;
    } else {

      @SuppressWarnings("rawtypes")
      Enumeration children = root.children();
      if (children != null) {
        while (children.hasMoreElements()) {
          ArrayList<PDLGroup> l =
              getChildren((DefaultMutableTreeNode) children.nextElement(), list);

          if (l != null) return l;
        }
      }
    }

    return null;
  }
Beispiel #5
0
  private static DefaultMutableTreeNode findMatchedChild(
      DefaultMutableTreeNode parent, PathElement pathElement) {

    for (int j = 0; j < parent.getChildCount(); j++) {
      final TreeNode child = parent.getChildAt(j);
      if (!(child instanceof DefaultMutableTreeNode)) continue;
      final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
      final Object userObject = childNode.getUserObject();
      if (pathElement.matchedWithByObject(userObject)) return childNode;
    }

    for (int j = 0; j < parent.getChildCount(); j++) {
      final TreeNode child = parent.getChildAt(j);
      if (!(child instanceof DefaultMutableTreeNode)) continue;
      final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
      final Object userObject = childNode.getUserObject();
      if (!(userObject instanceof NodeDescriptor)) continue;
      final NodeDescriptor nodeDescriptor = (NodeDescriptor) userObject;
      if (pathElement.matchedWith(nodeDescriptor)) return childNode;
    }

    if (parent.getChildCount() > 0) {
      int index = pathElement.myItemIndex;
      if (index >= parent.getChildCount()) {
        index = parent.getChildCount() - 1;
      }
      final TreeNode child = parent.getChildAt(index);
      if (child instanceof DefaultMutableTreeNode) {
        return (DefaultMutableTreeNode) child;
      }
    }

    return null;
  }
Beispiel #6
0
 @Override
 public String convertValueToText(
     Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
   String s = super.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
   String newProp = jEdit.getProperty(HIGHLIGHT_PROP);
   if (newProp == null || newProp.isEmpty()) return s;
   DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
   while (node != null && !(node.getUserObject() instanceof HyperSearchOperationNode)) {
     node = (DefaultMutableTreeNode) node.getParent();
   }
   if (node == null) return s;
   if (!newProp.equals(prop)) {
     prop = newProp;
     Font f = (resultTree != null) ? resultTree.getFont() : UIManager.getFont("Tree.font");
     styleTag = HtmlUtilities.style2html(prop, f);
   }
   SearchMatcher matcher = ((HyperSearchOperationNode) node.getUserObject()).getSearchMatcher();
   int i = s.indexOf(": ");
   if (i > 0) i += 2;
   else i = 0;
   Match m;
   List<Integer> matches = new ArrayList<Integer>();
   while ((m = matcher.nextMatch(s.substring(i), true, true, true, false)) != null) {
     matches.add(i + m.start);
     matches.add(i + m.end);
     i += m.end;
   }
   return HtmlUtilities.highlightString(s, styleTag, matches);
 }
Beispiel #7
0
  /**
   * Remove this node from the model.
   *
   * @param node
   * @param model
   */
  private void removeFromModel(DefaultMutableTreeNode node, DefaultTreeModel model) {
    model.removeNodeFromParent(node);
    nodeTable.remove(node.getUserObject());

    // remove the type branch if there are no more children
    switch (treeMode) {
      case TYPE:
        String typeString = ((GeoElement) node.getUserObject()).getObjectType();
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) typeNodesMap.get(typeString);

        // this has been the last node
        if (parent.getChildCount() == 0) {
          typeNodesMap.remove(typeString);
          model.removeNodeFromParent(parent);
        }
        break;
      case LAYER:
        int layer = ((GeoElement) node.getUserObject()).getLayer();
        parent = (DefaultMutableTreeNode) layerNodesMap.get(layer);

        // this has been the last node
        if (parent.getChildCount() == 0) {
          layerNodesMap.remove(layer);
          model.removeNodeFromParent(parent);
        }

        break;
    }
  }
Beispiel #8
0
  /**
   * Gets the insert position for newGeo to insert it in alphabetical order in parent node. Note:
   * all children of parent must have instances of GeoElement as user objects.
   *
   * @param mode
   */
  public static final int getInsertPosition(
      DefaultMutableTreeNode parent, GeoElement newGeo, SortMode mode) {
    // label of inserted geo
    // String newLabel = newGeo.getLabel();

    // standard case: binary search
    int left = 0;
    int right = parent.getChildCount();
    if (right == 0) return right;

    // bigger then last?
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getLastChild();
    // String nodeLabel = ((GeoElement) node.getUserObject()).getLabel();
    GeoElement geo2 = ((GeoElement) node.getUserObject());
    if (compare(newGeo, geo2, mode)) return right;

    // binary search
    while (right > left) {
      int middle = (left + right) / 2;
      node = (DefaultMutableTreeNode) parent.getChildAt(middle);
      // nodeLabel = ((GeoElement) node.getUserObject()).getLabel();
      geo2 = ((GeoElement) node.getUserObject());

      if (!compare(newGeo, geo2, mode)) {
        right = middle;
      } else {
        left = middle + 1;
      }
    }

    // insert at correct position
    return right;
  }
  private void jTree1MouseClicked1(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_jTree1MouseClicked1

    if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1) {
      DefaultMutableTreeNode tn =
          (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();

      if (tn.getChildCount() > 0) return;

      /*if (!jTree1.isCollapsed( jTree1.getSelectionPath() ))
      {
          jTree1.collapsePath( jTree1.getSelectionPath() );
          return;
      }
           *
           */
      if (tn.getUserObject() instanceof TreeJRField) {
        TreeJRField jrf = (TreeJRField) tn.getUserObject();
        if (!jrf.getObj().isPrimitive() && !jrf.getObj().getName().startsWith("java.lang.")) {
          exploreBean(
              tn,
              jrf.getObj().getName(),
              isPathOnDescription()
                  ? Misc.nvl(jrf.getField().getDescription(), "")
                  : Misc.nvl(jrf.getField().getName(), ""));
        }
      }
    }
  } // GEN-LAST:event_jTree1MouseClicked1
  private ArrayList<?> updateSelectedGeos(TreePath[] selPath) {
    selectionList.clear();

    if (selPath != null) {
      // add all selected paths
      for (int i = 0; i < selPath.length; i++) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath[i].getLastPathComponent();

        if (node == node.getRoot()) {
          // root: add all objects
          selectionList.clear();
          selectionList.addAll(app.getKernel().getConstruction().getGeoSetLabelOrder());
          i = selPath.length;
        } else if (node.getParent() == node.getRoot()) {
          // type node: select all children
          for (int k = 0; k < node.getChildCount(); k++) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(k);
            selectionList.add(child.getUserObject());
          }
        } else {
          // GeoElement
          selectionList.add(node.getUserObject());
        }
      }
    }

    return selectionList;
  }
  /**
   * Copies all the mod files from the profileModDir to the factorioModDir.
   *
   * @param profileModDir The profileDir to copy mods from.
   * @param factorioModDir The factorioDir to copy mods to.
   * @param selectedNode The TreeNode that is currently selected.
   */
  private void copyAllEnabledMods(
      File profileModDir, File factorioModDir, DefaultMutableTreeNode selectedNode) {
    // Let's copy all enabled mods!

    // Get the selected node.
    Enumeration<DefaultMutableTreeNode> children = selectedNode.children(); // Get it's children.
    while (children.hasMoreElements()) {
      DefaultMutableTreeNode node = children.nextElement(); // Get the next element.
      ModManagerWindow.CheckBoxNode checkBox =
          (ModManagerWindow.CheckBoxNode) node.getUserObject(); // Get the checkbox.
      String name = checkBox.getText(); // Get the text from the checkbox.
      if (name.equals("base") || !checkBox.isSelected())
        continue; // If it is the "base" mod, ignore it (it's always on)

      // Get the file with the name of the mod and then copy it from the profile dir to the mods
      // dir.
      File file =
          FileUtils.findFileWithPartName(
              profileModDir, ((ModManagerWindow.CheckBoxNode) node.getUserObject()).getText());
      try {
        Files.copy(
            file.toPath(),
            Paths.get(
                factorioModDir.getPath()
                    + "/"
                    + file.getPath().substring(file.getPath().lastIndexOf('\\'))));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  /**
   * Scroll to the error specified by the given tree path, or do nothing if no error is specified.
   *
   * @param treePath the tree path to scroll to.
   */
  private void scrollToError(final TreePath treePath) {
    final DefaultMutableTreeNode treeNode =
        (DefaultMutableTreeNode) treePath.getLastPathComponent();
    if (treeNode == null || !(treeNode.getUserObject() instanceof ResultTreeNode)) {
      return;
    }

    final ResultTreeNode nodeInfo = (ResultTreeNode) treeNode.getUserObject();
    if (nodeInfo.getFile() == null || nodeInfo.getProblem() == null) {
      return; // no problem here :-)
    }

    final VirtualFile virtualFile = nodeInfo.getFile().getVirtualFile();
    if (virtualFile == null || !virtualFile.exists()) {
      return;
    }

    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    final FileEditor[] editor = fileEditorManager.openFile(virtualFile, true);

    if (editor.length > 0 && editor[0] instanceof TextEditor) {
      final LogicalPosition problemPos =
          new LogicalPosition(Math.max(lineFor(nodeInfo) - 1, 0), Math.max(columnFor(nodeInfo), 0));

      final Editor textEditor = ((TextEditor) editor[0]).getEditor();
      textEditor.getCaretModel().moveToLogicalPosition(problemPos);
      textEditor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
    }
  }
  /*
   * Adds a field to the format being composed
   */
  public void addField() {
    DefaultMutableTreeNode node =
        (DefaultMutableTreeNode) availableFieldsComp.getTree().getLastSelectedPathComponent();
    if (node == null
        || !node.isLeaf()
        || !(node.getUserObject() instanceof DataObjDataFieldWrapper)) {
      return; // not really a field that can be added, just empty or a string
    }

    Object obj = node.getUserObject();
    if (obj instanceof DataObjDataFieldWrapper) {
      DataObjDataFieldWrapper wrapper = (DataObjDataFieldWrapper) obj;
      String sep = sepText.getText();
      if (StringUtils.isNotEmpty(sep)) {
        try {
          DefaultStyledDocument doc = (DefaultStyledDocument) formatEditor.getStyledDocument();
          if (doc.getLength() > 0) {
            doc.insertString(doc.getLength(), sep, null);
          }
        } catch (BadLocationException ble) {
        }
      }
      insertFieldIntoTextEditor(wrapper);
      setHasChanged(true);
    }
  }
 /**
  * Restore opened settings node if still there.
  *
  * @param oldProps properties inserted in the old model
  * @param selPath path to the node selected in the old model
  */
 private void restoreInsertedProperties(HashMap<String, Property[]> oldProps, TreePath selPath) {
   DefaultTreeModel newModel = levelTrees.get(permissionLvl);
   // Create properties panel for every properties panel existing in the old model
   updateUsedPanels(oldProps, newModel);
   final JPanel holderPropertiesPanel = (JPanel) splitPane.getRightComponent();
   holderPropertiesPanel.removeAll();
   if (selPath != null) {
     // returns node from previous model
     DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selPath.getLastPathComponent();
     if (selectedNode.getUserObject() instanceof ClassPropertiesInfo) {
       // find selected class by name
       ClassPropertiesInfo selectedClassInfo = (ClassPropertiesInfo) selectedNode.getUserObject();
       String selectedClassInfoName = selectedClassInfo.getName();
       // see if it's still visible
       DefaultMutableTreeNode classNode;
       ClassPropertiesInfo classInfo;
       DefaultMutableTreeNode root = (DefaultMutableTreeNode) newModel.getRoot();
       int classCount = newModel.getChildCount(root);
       for (int c = 0; c < classCount; c++) {
         classNode = (DefaultMutableTreeNode) newModel.getChild(root, c);
         classInfo = (ClassPropertiesInfo) classNode.getUserObject();
         if (classInfo.getName().equalsIgnoreCase(selectedClassInfoName)) {
           tree.setSelectionPath(new TreePath(classNode.getPath()));
           c = classCount;
         }
       }
     }
   }
   holderPropertiesPanel.repaint();
 }
    @Override
    public Component getTreeCellRendererComponent(
        final JTree tree,
        final Object value,
        final boolean selected,
        final boolean expanded,
        final boolean leaf,
        final int row,
        final boolean hasFocus) {
      final LigandTreeCellRenderer component =
          (LigandTreeCellRenderer)
              super.getTreeCellRendererComponent(
                  tree, value, selected, expanded, leaf, row, hasFocus);

      ImageIcon imageIcon = null;
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;

      if (node.getUserObject() instanceof String) imageIcon = chainIcon; // top level are strings
      else if (node.getUserObject() instanceof Chain)
        imageIcon = residueIcon; // for BIRD chains, use residue icon.
      else if (node.getUserObject() instanceof Residue) imageIcon = residueIcon;

      setIcon(imageIcon);

      return component;
    }
Beispiel #16
0
    @Override
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean sel,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

      DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
      if (node.getUserObject() != null) {
        ComponentWrapper userObject = (ComponentWrapper) node.getUserObject();
        if (userObject != null) {
          Component c = userObject.component;
          for (int i = 0; i < cmpClasses.length; i++) {
            Class clazz = cmpClasses[i];
            if (clazz.isAssignableFrom(c.getClass())) {
              setIcon(cmpIcons[i]);
              return this;
            }
          }
        }
        setIcon(noneIcon);
      }
      return this;
    }
  @Override
  protected String validateAction() {

    String validate = null;

    DefaultMutableTreeNode node =
        (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
    BOMLineWrapper line = null;
    if (!(node.getUserObject() instanceof BOMLineWrapper)) {

      validate =
          "'"
              + node.getUserObject().getClass().getName()
              + "' isn't a type of 'BOMLineWrapper'(ClassCastException)";
    } else {

      line = (BOMLineWrapper) node.getUserObject();
      MProduct p = new MProduct(Env.getCtx(), line.getM_Product_ID(), null);

      if (p.getM_AttributeSet_ID() == 0) {

        validate = Services.get(IMsgBL.class).getMsg(Env.getCtx(), "PAttributeNoAttributeSet");
      }
    }

    return validate;
  }
Beispiel #18
0
 /** Gets the value for the given node at the given column. */
 public Object getValueAt(Object node, int col) {
   DefaultMutableTreeNode tree_node = (DefaultMutableTreeNode) node;
   Object value = tree_node.getUserObject();
   switch (col) {
       // Name
     case 0:
       return value;
       // Value
     case 1:
       if (value instanceof ConfigElement) {
         return null;
       } else if (value instanceof PropertyDefinition) {
         // Only provide comma delimited editing for simple types
         if (((PropertyDefinition) value).getType() != ConfigElement.class) {
           StringBuffer buffer = new StringBuffer();
           for (Enumeration e = tree_node.children(); e.hasMoreElements(); ) {
             DefaultMutableTreeNode child_node = (DefaultMutableTreeNode) e.nextElement();
             buffer.append(child_node.getUserObject());
             if (e.hasMoreElements()) {
               buffer.append(", ");
             }
           }
           return buffer.toString();
         }
         return null;
       }
       return value;
   }
   return null;
 }
Beispiel #19
0
    /**
     * This gets called whenever one of the ConfigElements we are editing removes a property value.
     */
    public void propertyValueRemoved(ConfigElementEvent evt) {
      ConfigElement src = (ConfigElement) evt.getSource();
      int idx = evt.getIndex();
      PropertyDefinition prop_def = src.getDefinition().getPropertyDefinition(evt.getProperty());
      DefaultMutableTreeNode elt_node = getNodeFor(src);

      // Get the node containing the property description under the source
      // ConfigElement node
      for (Enumeration e = elt_node.children(); e.hasMoreElements(); ) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        if (node.getUserObject().equals(prop_def)) {
          // The newly removed property value must be a child to this node
          System.out.println("Removing child " + idx + " from node: " + node.getUserObject());
          DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(idx);

          // If the child is an embedded element, stop listening to it
          if (child.getUserObject() instanceof ConfigElement) {
            ConfigElement removed_elt = (ConfigElement) child.getUserObject();
            removed_elt.removeConfigElementListener(this);
          }

          // Physically remove the child from the tree
          removeNodeFromParent(child);
        }
      }
    }
  void onOK() {
    TreePath path = m_tree.getSelectionPath();
    if (path == null) {
      JOptionPane.showMessageDialog(this, "Departement not yet been selected");
      return;
    }

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

    if (!m_isroot) {
      if (node.getChildCount() > 0) return;

      if (node.getUserObject() instanceof Organization) {
        m_org = (Organization) node.getUserObject();
        m_iResponse = JOptionPane.OK_OPTION;
        dispose();
      }
    } else {
      if (node.getUserObject() instanceof Organization) {
        m_org = (Organization) node.getUserObject();
        m_iResponse = JOptionPane.OK_OPTION;
        dispose();
      } else {
        m_org = new Organization("", "", "Department");
        m_iResponse = JOptionPane.OK_OPTION;
        dispose();
      }
    }
  }
Beispiel #21
0
 private void createPainToTree3true(
     final DefaultTreeModel treeModel, DefaultMutableTreeNode root, Collection paintCollection) {
   ArrayList a = (ArrayList) paintCollection;
   Iterator i = a.iterator();
   Person p = null;
   Person parent = null;
   DefaultMutableTreeNode parentNode = root;
   DefaultMutableTreeNode newNode;
   while (i.hasNext()) {
     p = (Person) i.next();
     int ves, ves2;
     if (parent != null) {
       parent = (Person) parentNode.getUserObject();
       ves = comparePerson(p, (Person) parentNode.getUserObject());
       ves2 = comparePersonAsString(p, (Person) parentNode.getUserObject()) + 1;
       System.out.println("ves = " + ves + " ves2= " + ves2);
       switch (ves) {
         case 0:
           {
             parentNode = root;
             parent = null;
             break;
           }
         case 1:
           {
           }
       }
     }
     newNode = new DefaultMutableTreeNode(p);
     parentNode.add(newNode);
     parent = p;
     parentNode = newNode;
   }
 }
Beispiel #22
0
  @Override
  public void dragGestureRecognized(DragGestureEvent event) {

    TreePath path = tree.getSelectionPath();
    if (path != null) {

      // Dragged node is a DefaultMutableTreeNode
      if (path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) path.getLastPathComponent();

        // This is an ObjectType node
        if (treeNode.getUserObject() instanceof ObjectType) {
          ObjectType type = (ObjectType) treeNode.getUserObject();
          Cursor cursor = null;

          if (event.getDragAction() == DnDConstants.ACTION_COPY) {
            cursor = DragSource.DefaultCopyDrop;
          }
          if (RenderManager.isGood()) {
            // The new renderer is initialized
            RenderManager.inst().startDragAndDrop(type);
            event.startDrag(cursor, new TransferableObjectType(type), RenderManager.inst());

          } else {
            event.startDrag(cursor, new TransferableObjectType(type));
          }
        }
      }
    }
  }
 @Nullable
 private static String getActionId(DefaultMutableTreeNode node) {
   return (String)
       (node.getUserObject() instanceof String
           ? node.getUserObject()
           : node.getUserObject() instanceof Pair ? ((Pair) node.getUserObject()).first : null);
 }
  public int createTreeFromMenuBar(
      javax.swing.MenuElement subElements[],
      javax.swing.tree.DefaultMutableTreeNode treeNodes,
      javax.swing.tree.DefaultMutableTreeNode topReports,
      java.lang.String reportNodeTitle,
      java.lang.String utilitiesNodeTitle) {

    for (int i = 0; i < subElements.length; i++) {

      if (subElements[i].getClass().getName() != "javax.swing.JPopupMenu") {

        javax.swing.JMenuItem abstractButton = (javax.swing.JMenuItem) subElements[i];

        if (abstractButton.isEnabled()) {

          siblingNode = new javax.swing.tree.DefaultMutableTreeNode(abstractButton.getText());

          treeNodes.add(siblingNode);

          if (treeNodes.getUserObject() == "Reports") {

            treeNodes.setUserObject(reportNodeTitle);

            topReports.add(treeNodes);
          }

          if (treeNodes.getUserObject() == "Utility") {

            treeNodes.setUserObject(utilitiesNodeTitle);

            topReports.add(treeNodes);
          }
        }
      }

      if (subElements[i].getSubElements().length > 0) {

        createTreeFromMenuBar(
            subElements[i].getSubElements(),
            siblingNode,
            topReports,
            reportNodeTitle,
            utilitiesNodeTitle);

        if (treeNodes.isLeaf()) {

          javax.swing.tree.DefaultMutableTreeNode parentNode =
              (javax.swing.tree.DefaultMutableTreeNode) siblingNode.getParent();

          siblingNode.removeFromParent();
        }
      }

      treeCount++;
    }

    return treeCount;
  }
  public void drop(DropTargetDropEvent dtde) {
    Point pt = dtde.getLocation();
    DropTargetContext dtc = dtde.getDropTargetContext();
    JTree tree = (JTree) dtc.getComponent();
    TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentpath.getLastPathComponent();

    try {
      // Transferable tr = dtde.getTransferable(); // !!! this should work, but doesn't. after one
      // click on the draggable node, this call here will not return the TransferableTreeNode that
      // is created in dragGestureRecognized()
      Transferable tr =
          ObjectInspector
              .transferNode; // therefore, we use this hack, which just stores the current
      // transferable in a static variable

      DataFlavor[] flavors = tr.getTransferDataFlavors();
      for (int i = 0; i < flavors.length; i++) {
        if (tr.isDataFlavorSupported(flavors[i])) {
          dtde.acceptDrop(dtde.getDropAction());
          TreePath p = (TreePath) tr.getTransferData(flavors[i]);
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) p.getLastPathComponent();
          DefaultTreeModel model = (DefaultTreeModel) tree.getModel();

          Object sourceObject = node.getUserObject();

          FieldWrapperObjectTree targetField = ((FieldWrapperObjectTree) parent.getUserObject());

          if (sourceObject != null) {
            if (sourceObject instanceof FieldWrapperObjectTree) {
              FieldWrapperObjectTree sourceField = (FieldWrapperObjectTree) sourceObject;

              if (sourceField.getTheField().getType().equals(targetField.getTheField().getType())) {
                targetField
                    .getTheField()
                    .set(
                        targetField.getOnObject(),
                        sourceField.getTheField().get(sourceField.getOnObject()));
              }
            } else if (sourceObject.getClass().equals(targetField.getTheField().getType())) {
              targetField.getTheField().set(targetField.getOnObject(), sourceObject);
            }

            tree.invalidate();
            tree.repaint();
          }

          dtde.dropComplete(true);
          return;
        }
      }
      dtde.rejectDrop();
    } catch (Exception e) {
      e.printStackTrace();
      // dtde.rejectDrop();
    }
  }
 @Override
 protected Transferable createTransferable(JComponent arg0) {
   DefaultMutableTreeNode node =
       (DefaultMutableTreeNode) ((JTree) arg0).getLastSelectedPathComponent();
   if (node.getUserObject() instanceof VegetableBean) {
     return new VegetableTransfer((VegetableBean) node.getUserObject());
   }
   return super.createTransferable(arg0);
 }
 private static List<String> getMenuPathElements(DefaultMutableTreeNode node) {
   ArrayList<String> pathElements = new ArrayList<String>();
   while (node != null) {
     if (node.getUserObject() instanceof JMenuItem)
       pathElements.add(((JMenuItem) node.getUserObject()).getText());
     node = (DefaultMutableTreeNode) node.getParent();
   }
   return pathElements;
 }
Beispiel #28
0
    public void valueChanged(TreeSelectionEvent arg0) {

      DefaultMutableTreeNode curTreeNode =
          (DefaultMutableTreeNode) ((MyTree) arg0.getSource()).getLastSelectedPathComponent();
      if (curTreeNode == null) return;

      if (!(curTreeNode.getUserObject() instanceof Caliber)) {
        return;
      }
      Caliber cal = (Caliber) curTreeNode.getUserObject();

      // 数据源组合框
      dataSourceCbx.setValue(cal.getACal().getSourceID());

      // 根据字段列名得到字段类型
      // cbxFieldName.setSelectedIndex(-1);
      JComboBox cbxFieldNameTmp = (JComboBox) cbxFieldName.getEditor();
      int count = cbxFieldNameTmp.getItemCount();
      String value;
      for (int i = 0; i < count; i++) {
        value = ((FComboBoxItem) cbxFieldNameTmp.getItemAt(i)).getValue().toString();
        if (value.substring(0, value.indexOf(":")).equals(cal.getACal().getSourceColID())) {
          cbxFieldName.setSelectedIndex(i);
          break;
        }
      }

      // 字段名称组合框
      // cbxFieldName.setValue(cal.getACal().getSourceColID());
      // 比较类型
      cbxCompare.setValue(cal.getACal().getCompareType());

      // 根据sFieldEname返回字段类型
      String sFieldTyp = getFieldType();
      // 根据字段类型判断参数加不加引号(')
      // 条件值
      if (DefinePub.checkCharVal(sFieldTyp)) {
        String paraValue = cal.getACal().getValue();
        // 判断是不是in或not in比较符
        if (CompareType.IN_TYPE.equalsIgnoreCase(cal.getACal().getCompareType())
            || CompareType.NOTIN_TYPE.equalsIgnoreCase(cal.getACal().getCompareType())) {
          // 去掉左右括号
          paraValue = paraValue.substring(1, paraValue.length() - 1);
          // 去掉逗号旁的引号
          paraValue = paraValue.replaceAll("','", ",");
        }
        // 去掉最外层引号
        cbxWhereValue.setValue(paraValue.substring(1, paraValue.length() - 1));

      } else {
        cbxWhereValue.setValue(cal.getACal().getValue());
      }

      // 定义条件类型
      if (!Common.isNullStr(cal.getACal().getJoinBefore()))
        frdoType.setValue(cal.getACal().getJoinBefore());
    }
Beispiel #29
0
 public static Icon getMenuItemIcon(String menuItemKey) {
   final DefaultMutableTreeNode treeNode = getMenuBuilder().get(menuItemKey);
   if (treeNode == null
       || !treeNode.isLeaf()
       || !(treeNode.getUserObject() instanceof JMenuItem)) {
     return null;
   }
   final JMenuItem menuItem = (JMenuItem) treeNode.getUserObject();
   return menuItem.getIcon();
 }
 @Override
 public void valueChanged(TreeSelectionEvent e) {
   TreePath treePath = e.getPath();
   DefaultMutableTreeNode node = (DefaultMutableTreeNode) (treePath.getLastPathComponent());
   if (node.getUserObject() instanceof Trigger) {
     Trigger trigger = (Trigger) (node.getUserObject());
     tcd.setVisibleTrigger(trigger);
   } else {
     tcd.setVisibleTrigger(null);
   }
 }