Beispiel #1
0
 /** Method for Remove button action. */
 private void removeButtonActionPerformed(
     java.awt.event.ActionEvent evt) // GEN-FIRST:event_removeButtonActionPerformed
     { // GEN-HEADEREND:event_removeButtonActionPerformed
   try {
     javax.swing.tree.TreePath[] removedPaths = diagnosisesTree.getSelectionPaths();
     if (removedPaths != null) {
       javax.swing.tree.DefaultTreeModel treeModel =
           (javax.swing.tree.DefaultTreeModel) diagnosisesTree.getModel();
       javax.swing.tree.DefaultMutableTreeNode rootNode =
           (javax.swing.tree.DefaultMutableTreeNode) diagnosisesTree.getModel().getRoot();
       javax.swing.tree.DefaultMutableTreeNode node;
       javax.swing.tree.TreeNode[] parentNodes;
       elv.util.parameters.Diagnosis diagnosis;
       for (int i = 0; i < removedPaths.length; i++) {
         node = (javax.swing.tree.DefaultMutableTreeNode) removedPaths[i].getLastPathComponent();
         if (!node.isRoot()) {
           if (!isNodeAncestor(node, removedPaths, i)) {
             setChanged(true);
             elv.util.Util.getMainFrame().setChanged(true);
             treeModel.removeNodeFromParent(node);
             for (java.util.Enumeration e = node.preorderEnumeration(); e.hasMoreElements(); ) {
               node = (javax.swing.tree.DefaultMutableTreeNode) e.nextElement();
               diagnosis = (elv.util.parameters.Diagnosis) node.getUserObject();
               diagnosises.remove(diagnosis);
             }
           }
         }
       }
       node = rootNode;
       java.util.Enumeration e = node.preorderEnumeration();
       node = (javax.swing.tree.DefaultMutableTreeNode) e.nextElement();
       while (e.hasMoreElements()) {
         node = (javax.swing.tree.DefaultMutableTreeNode) e.nextElement();
         diagnosis = (elv.util.parameters.Diagnosis) node.getUserObject();
         parentNodes = node.getPath();
         for (int j = 1; j < parentNodes.length; j++) {
           node = (javax.swing.tree.DefaultMutableTreeNode) parentNodes[j];
           java.lang.String level = Integer.toString(node.getParent().getIndex(node) + 1);
           if (j == 1) {
             diagnosis.setParagraph(level);
           } else {
             diagnosis.setParagraph(diagnosis.getParagraph() + "." + level);
           }
         }
       }
     }
     setEnabled(isEnabled);
   } catch (java.lang.Exception exc) {
     elv.util.Error.showErrorMessage(this, exc);
   }
 } // GEN-LAST:event_removeButtonActionPerformed
Beispiel #2
0
 @SuppressWarnings("unchecked")
 private void initControls(final DefaultMutableTreeNode controlsTree) {
   controls = new Vector<IPropertyControl>();
   for (final Enumeration<DefaultMutableTreeNode> i = controlsTree.preorderEnumeration();
       i.hasMoreElements(); ) {
     final IPropertyControlCreator creator =
         (IPropertyControlCreator) i.nextElement().getUserObject();
     if (creator == null) {
       continue;
     }
     final IPropertyControl control = creator.createControl();
     controls.add(control);
   }
 }
Beispiel #3
0
  /**
   * Find all nodes that have a user-object with references to the supplied user-object
   *
   * @param referencedObject
   * @return
   */
  public List<EditableObjectNode> findReferences(Object referencedObject, MessageGroup group) {

    List<EditableObjectNode> referenceNodes = new ArrayList<EditableObjectNode>();

    // walk tree and look for references
    for (Enumeration<?> en = m_root.preorderEnumeration(); en != null && en.hasMoreElements(); ) {
      DefaultMutableTreeNode child = (DefaultMutableTreeNode) en.nextElement();
      if (child instanceof EditableObjectNode) {
        EditableObjectNode edChild = (EditableObjectNode) child;
        // skip the nodes that are not in this message group
        if (edChild.getMessageGroup() != group) {
          continue;
        }

        // skip the non-editable nodes, since these are just for show
        if (!edChild.isEditable()) {
          continue;
        }

        Object childUserObject = child.getUserObject();

        // special handling of Field, which is referenced by name in a SyntaxNode, SemanticElement
        // and BER
        if (referencedObject instanceof Field) {
          if (nodeReferencesField(child, (Field) referencedObject)) {
            referenceNodes.add(edChild);
            continue;
          }
        }

        // Special handling of an MdmiDatatype, which is referenced in a list by a DataRule
        if (referencedObject instanceof MdmiDatatype && childUserObject instanceof DataRule) {
          if (((DataRule) childUserObject).getDatatypes().contains(referencedObject)) {
            referenceNodes.add(edChild);
          }
          continue;
        }

        // inspect user object to determine if it has any references
        if (hasReferenceTo(childUserObject, referencedObject)) {
          referenceNodes.add(edChild);
        }
      }
    }
    return referenceNodes;
  }
  public void build(
      StampTree stampTree, JPopupMenu popup, JComponent cmp, TransferHandler handler) {

    if (parents == null) {
      parents = new HashMap<Object, JMenu>(10, 0.75f);
    } else {
      parents.clear();
    }

    this.popup = popup;

    rootNode = (DefaultMutableTreeNode) stampTree.getModel().getRoot();
    Enumeration e = rootNode.preorderEnumeration();
    e.nextElement(); // consume root

    while (e.hasMoreElements()) {
      parseChildren((StampTreeNode) e.nextElement(), cmp, handler);
    }
  }
Beispiel #5
0
  /** Method for Add button action. */
  private void addButtonActionPerformed(
      java.awt.event.ActionEvent evt) // GEN-FIRST:event_addButtonActionPerformed
      { // GEN-HEADEREND:event_addButtonActionPerformed
    try {
      javax.swing.JTree allDiagnosisesTree = new javax.swing.JTree();
      allDiagnosisesTree.setRootVisible(false);
      allDiagnosisesTree.setShowsRootHandles(true);
      allDiagnosisesTree.setCellRenderer(new elv.util.Util.DefaultTreeCellRenderer());
      allDiagnosisesTree.setModel(
          new javax.swing.tree.DefaultTreeModel(new javax.swing.tree.DefaultMutableTreeNode()) {

            /** Overridden constructor. */
            {
              javax.swing.tree.DefaultMutableTreeNode nodeLevels[] =
                  new javax.swing.tree.DefaultMutableTreeNode[10];
              javax.swing.tree.DefaultMutableTreeNode node = null;
              nodeLevels[0] =
                  new javax.swing.tree.DefaultMutableTreeNode(parameterType.getDefault());
              java.util.Vector<elv.util.parameters.Diagnosis> diagnosises =
                  parameterType.getAllDiagnosises();
              for (elv.util.parameters.Diagnosis iteratorDiagnosis : diagnosises) {
                node = new javax.swing.tree.DefaultMutableTreeNode(iteratorDiagnosis);
                nodeLevels[iteratorDiagnosis.getParagraphLevel()] = node;
                nodeLevels[iteratorDiagnosis.getParagraphLevel() - 1].add(node);
              }
              setRoot(nodeLevels[0]);
            }
          });
      javax.swing.JScrollPane allDiagnosisesScrollPane = new javax.swing.JScrollPane();
      allDiagnosisesScrollPane.setViewportView(allDiagnosisesTree);
      int returnOption =
          elv.util.Option.okCancel(allDiagnosisesScrollPane, parameterType.getTitle());
      if (returnOption == javax.swing.JOptionPane.OK_OPTION
          && allDiagnosisesTree.getSelectionPaths() != null) {
        javax.swing.tree.DefaultTreeModel treeModel =
            (javax.swing.tree.DefaultTreeModel) diagnosisesTree.getModel();
        javax.swing.tree.DefaultMutableTreeNode rootNode =
            (javax.swing.tree.DefaultMutableTreeNode) diagnosisesTree.getModel().getRoot();
        javax.swing.tree.DefaultMutableTreeNode node;
        javax.swing.tree.TreeNode[] parentNodes;
        elv.util.parameters.Diagnosis diagnosis;
        for (int i = 0; i < allDiagnosisesTree.getSelectionPaths().length; i++) {
          node =
              (javax.swing.tree.DefaultMutableTreeNode)
                  allDiagnosisesTree.getSelectionPaths()[i].getLastPathComponent();
          if (!isNodeChild(node, rootNode)) {
            setChanged(true);
            elv.util.Util.getMainFrame().setChanged(true);
            treeModel.insertNodeInto(node, rootNode, rootNode.getChildCount());
            if (i == 0) {
              diagnosisesTree.scrollPathToVisible(new javax.swing.tree.TreePath(node.getPath()));
            }
            for (java.util.Enumeration e = node.preorderEnumeration(); e.hasMoreElements(); ) {
              node = (javax.swing.tree.DefaultMutableTreeNode) e.nextElement();
              diagnosis = (elv.util.parameters.Diagnosis) node.getUserObject();
              parentNodes = node.getPath();
              for (int j = 1; j < parentNodes.length; j++) {
                node = (javax.swing.tree.DefaultMutableTreeNode) parentNodes[j];
                java.lang.String level = Integer.toString(node.getParent().getIndex(node) + 1);
                if (j == 1) {
                  diagnosis.setParagraph(level);
                } else {
                  diagnosis.setParagraph(diagnosis.getParagraph() + "." + level);
                }
              }
              diagnosises.add(diagnosis);
            }
          }
        }
      }
    } catch (java.lang.Exception exc) {
      elv.util.Error.showErrorMessage(this, exc);
    }
  } // GEN-LAST:event_addButtonActionPerformed