示例#1
0
文件: TreeUtil.java 项目: jexp/idea2
 private static TreePath[] removeDuplicates(final TreePath[] paths) {
   final ArrayList<TreePath> result = new ArrayList<TreePath>();
   for (final TreePath path : paths) {
     if (!result.contains(path)) result.add(path);
   }
   return result.toArray(new TreePath[result.size()]);
 }
示例#2
0
文件: TreeUtil.java 项目: jexp/idea2
 public static ArrayList<TreeNode> childrenToArray(final TreeNode node) {
   final ArrayList<TreeNode> result = new ArrayList<TreeNode>();
   for (int i = 0; i < node.getChildCount(); i++) {
     result.add(node.getChildAt(i));
   }
   return result;
 }
    protected void writeAuditTrail(String strPath, String strUser, StringBuffer sbValues) {
      BufferedReader reader = WFileUtil.openReadFile(strPath);
      String strLine;
      ArrayList aListData = WUtil.strToAList(sbValues.toString(), false, "\n");
      StringBuffer sbData = sbValues;
      String strPnl = (this instanceof DisplayTemplate) ? "Data Template " : "Data Dir ";
      if (reader == null) {
        Messages.postDebug("Error opening file " + strPath);
        return;
      }

      try {
        while ((strLine = reader.readLine()) != null) {
          // if the line in the file is not in the arraylist,
          // then that line has been deleted
          if (!aListData.contains(strLine))
            WUserUtil.writeAuditTrail(new Date(), strUser, "Deleted " + strPnl + strLine);

          // remove the lines that are also in the file or those which
          // have been deleted.
          aListData.remove(strLine);
        }

        // Traverse through the remaining new lines in the arraylist,
        // and write it to the audit trail
        for (int i = 0; i < aListData.size(); i++) {
          strLine = (String) aListData.get(i);
          WUserUtil.writeAuditTrail(new Date(), strUser, "Added " + strPnl + strLine);
        }
        reader.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
示例#4
0
文件: TreeUtil.java 项目: jexp/idea2
 public static List<TreePath> collectExpandedPaths(@NotNull final JTree tree) {
   final ArrayList<TreePath> result = new ArrayList<TreePath>();
   final Object root = tree.getModel().getRoot();
   final TreePath rootPath = new TreePath(root);
   result.addAll(collectExpandedPaths(tree, rootPath));
   return result;
 }
    /** Returns the value in the proper format: "value". */
    protected String getValue(String strUser, String strValue) {

      ArrayList aListValues = WUtil.strToAList(strValue);
      String strNewValue = "";

      if (strValue == null || strValue.trim().length() <= 0) return "";

      String strPath =
          FileUtil.openPath("SYSPROF" + File.separator + strUser)
              + File.pathSeparator
              + FileUtil.openPath("USRPROF" + File.separator + strUser);
      HashMap hmUser = WFileUtil.getHashMap(strPath);

      for (int i = 0; i < aListValues.size(); i++) {
        strNewValue = (String) aListValues.get(i);
        if (strNewValue == null) strNewValue = "";

        // if the value is of the form: $home, then parse the value
        if (hmUser != null && strNewValue.indexOf('$') >= 0) {
          strValue = WFileUtil.parseValue(strNewValue, hmUser);
          if (strValue != null && strValue.trim().length() > 0) strNewValue = strValue;
        }
      }

      return strNewValue;
    }
示例#6
0
文件: TreeUtil.java 项目: jexp/idea2
 public static List<TreePath> collectExpandedPaths(final JTree tree, TreePath path) {
   final ArrayList<TreePath> result = new ArrayList<TreePath>();
   if (!tree.isExpanded(path)) return result;
   final Object lastPathComponent = path.getLastPathComponent();
   final TreeModel model = tree.getModel();
   if (model.isLeaf(lastPathComponent)) {
     result.add(path);
   } else {
     boolean pathWasAdded = false;
     for (int i = model.getChildCount(lastPathComponent) - 1; i >= 0; i--) {
       final TreePath childPath = path.pathByAddingChild(model.getChild(lastPathComponent, i));
       if (model.isLeaf(lastPathComponent)) {
         if (!pathWasAdded) {
           result.add(path);
           pathWasAdded = true;
         }
       } else if (tree.isExpanded(childPath)) {
         result.addAll(collectExpandedPaths(tree, childPath));
       } else {
         if (!pathWasAdded) {
           result.add(path);
           pathWasAdded = true;
         }
       }
     }
   }
   return result;
 }
示例#7
0
文件: TreeUtil.java 项目: jexp/idea2
 public static TreePath getPathFromRoot(TreeNode node) {
   final ArrayList<TreeNode> path = new ArrayList<TreeNode>();
   do {
     path.add(node);
     node = node.getParent();
   } while (node != null);
   Collections.reverse(path);
   return new TreePath(path.toArray());
 }
 public Object getChild(Object parent, int index) {
   ArrayList<Field> fields = ((Variable) parent).getFields();
   Field f = (Field) fields.get(index);
   Object parentValue = ((Variable) parent).getValue();
   try {
     return new Variable(f.getType(), f.getName(), f.get(parentValue));
   } catch (IllegalAccessException e) {
     return null;
   }
 }
 private Collection<EditorSchemeAttributeDescriptor> getOrderedDescriptors(
     @NotNull ColorAndFontOptions options) {
   ArrayList<EditorSchemeAttributeDescriptor> list = ContainerUtil.newArrayList();
   for (EditorSchemeAttributeDescriptor description : options.getCurrentDescriptions()) {
     if (!description.getGroup().equals(myCategoryName)) continue;
     list.add(description);
   }
   Collections.sort(list, ATTR_COMPARATOR);
   return list;
 }
 public void selectElements(ClassMember[] elements) {
   ArrayList<TreePath> selectionPaths = new ArrayList<TreePath>();
   for (ClassMember element : elements) {
     MemberNode treeNode = myElementToNodeMap.get(element);
     if (treeNode != null) {
       selectionPaths.add(new TreePath(((DefaultMutableTreeNode) treeNode).getPath()));
     }
   }
   myTree.setSelectionPaths(selectionPaths.toArray(new TreePath[selectionPaths.size()]));
 }
  @SuppressWarnings("unchecked")
  public void resetElements(
      T[] elements,
      final @Nullable Comparator<T> sortComparator,
      final boolean restoreSelectedElements) {
    final List<T> selectedElements =
        restoreSelectedElements && mySelectedElements != null
            ? new ArrayList<T>(mySelectedElements)
            : null;
    myElements = elements;
    if (sortComparator != null) {
      myComparator = new ElementNodeComparatorWrapper(sortComparator);
    }
    mySelectedNodes.clear();
    myNodeToParentMap.clear();
    myElementToNodeMap.clear();
    myContainerNodes.clear();

    ApplicationManager.getApplication()
        .runReadAction(
            new Runnable() {
              @Override
              public void run() {
                myTreeModel = buildModel();
              }
            });

    myTree.setModel(myTreeModel);
    myTree.setRootVisible(false);

    restoreTree();

    if (myOptionControls == null) {
      myCopyJavadocCheckbox = new NonFocusableCheckBox(IdeBundle.message("checkbox.copy.javadoc"));
      if (myIsInsertOverrideVisible) {
        myInsertOverrideAnnotationCheckbox =
            new NonFocusableCheckBox(IdeBundle.message("checkbox.insert.at.override"));
        myOptionControls =
            new JCheckBox[] {myCopyJavadocCheckbox, myInsertOverrideAnnotationCheckbox};
      } else {
        myOptionControls = new JCheckBox[] {myCopyJavadocCheckbox};
      }
    }

    myTree.doLayout();
    setOKActionEnabled(myElements != null && myElements.length > 0);

    if (selectedElements != null) {
      selectElements(selectedElements.toArray(new ClassMember[selectedElements.size()]));
    }
    if (mySelectedElements == null || mySelectedElements.isEmpty()) {
      expandFirst();
    }
  }
  private static void sortNode(ParentNode node, final Comparator<ElementNode> sortComparator) {
    ArrayList<MemberNode> arrayList = new ArrayList<MemberNode>();
    Enumeration<MemberNode> children = node.children();
    while (children.hasMoreElements()) {
      arrayList.add(children.nextElement());
    }

    Collections.sort(arrayList, sortComparator);

    replaceChildren(node, arrayList);
  }
示例#13
0
文件: TreeUtil.java 项目: jexp/idea2
 public static List<TreePath> collectSelectedPaths(final JTree tree, final TreePath treePath) {
   final ArrayList<TreePath> result = new ArrayList<TreePath>();
   final TreePath[] selections = tree.getSelectionPaths();
   if (selections != null) {
     for (TreePath selection : selections) {
       if (treePath.isDescendant(selection)) {
         result.add(selection);
       }
     }
   }
   return result;
 }
  protected void restoreTree() {
    Pair<ElementNode, List<ElementNode>> selection = storeSelection();

    DefaultMutableTreeNode root = getRootNode();
    if (!myShowClasses || myContainerNodes.isEmpty()) {
      List<ParentNode> otherObjects = new ArrayList<ParentNode>();
      Enumeration<ParentNode> children = getRootNodeChildren();
      ParentNode newRoot =
          new ParentNode(
              null, new MemberChooserObjectBase(getAllContainersNodeName()), new Ref<Integer>(0));
      while (children.hasMoreElements()) {
        final ParentNode nextElement = children.nextElement();
        if (nextElement instanceof ContainerNode) {
          final ContainerNode containerNode = (ContainerNode) nextElement;
          Enumeration<MemberNode> memberNodes = containerNode.children();
          List<MemberNode> memberNodesList = new ArrayList<MemberNode>();
          while (memberNodes.hasMoreElements()) {
            memberNodesList.add(memberNodes.nextElement());
          }
          for (MemberNode memberNode : memberNodesList) {
            newRoot.add(memberNode);
          }
        } else {
          otherObjects.add(nextElement);
        }
      }
      replaceChildren(root, otherObjects);
      sortNode(newRoot, myComparator);
      if (newRoot.children().hasMoreElements()) root.add(newRoot);
    } else {
      Enumeration<ParentNode> children = getRootNodeChildren();
      while (children.hasMoreElements()) {
        ParentNode allClassesNode = children.nextElement();
        Enumeration<MemberNode> memberNodes = allClassesNode.children();
        ArrayList<MemberNode> arrayList = new ArrayList<MemberNode>();
        while (memberNodes.hasMoreElements()) {
          arrayList.add(memberNodes.nextElement());
        }
        Collections.sort(arrayList, myComparator);
        for (MemberNode memberNode : arrayList) {
          myNodeToParentMap.get(memberNode).add(memberNode);
        }
      }
      replaceChildren(root, myContainerNodes);
    }
    myTreeModel.nodeStructureChanged(root);

    defaultExpandTree();

    restoreSelection(selection);
  }
    protected void clear(JComponent comp) {
      int nCompCount = comp.getComponentCount();
      ArrayList aListComps = new ArrayList();

      for (int i = 0; i < comp.getComponentCount(); i++) {
        Component compChild = comp.getComponent(i);
        if (compChild instanceof JComponent) {
          JComponent jcomp = (JComponent) compChild;
          if (jcomp instanceof JCheckBox || jcomp instanceof JTextField) aListComps.add(comp);
          else clear(jcomp);
        }
      }
      clear(aListComps);
    }
示例#16
0
 // ////////////////////////////////////
 // DbRefreshListener SUPPORT
 //
 // Overridden
 public void refreshAfterDbUpdate(DbUpdateEvent evt) throws DbException {
   if (evt.metaField == DbObject.fComponents) { // add, remove, or move to
     // another parent
     if (evt.neighbor instanceof DbGraphicalObjectI) // optimization:
       // discard
       // immediately the
       // graphical objects
       return;
     if (evt.op == Db.REMOVE_FROM_RELN) {
       // DbObject removed or with a new parent: remove the node from
       // its old parent if loaded.
       DynamicNode node = getDynamicNode(evt.neighbor, Db.OLD_VALUE, false);
       if (node != null) removeNode(node);
     } else if (evt.op == Db.ADD_TO_RELN) {
       // DbObject added or with a new parent: if its new parent has
       // its chidren loaded,
       // add a node for the new child.
       getDynamicNode(evt.neighbor, false);
     } else { // Db.REINSERT_IN_RELN
       DynamicNode node = getDynamicNode(evt.neighbor, false);
       if ((node != null && !childrenAreSorted(evt.dbo))
           || (node != null && !node.getGroupParams().sorted)) {
         DynamicNode parentNode = (DynamicNode) node.getParent();
         updateInsertIndexInChildrenOfNode(parentNode);
         removeNodeFromParent(node);
         int index = getInsertionIndex(evt.dbo, evt.neighbor, parentNode, node);
         insertNodeInto(node, parentNode, index);
       }
     }
   }
   // name refresh
   else if (evt.metaField == DbSemanticalObject.fName || tooltipsFields.contains(evt.metaField)) {
     updateNode(evt.dbo);
   }
 }
示例#17
0
文件: TreeUtil.java 项目: jexp/idea2
 @NotNull
 public static <T> List<T> collectSelectedObjectsOfType(JTree tree, Class<T> clazz) {
   final TreePath[] selections = tree.getSelectionPaths();
   if (selections != null) {
     final ArrayList<T> result = new ArrayList<T>();
     for (TreePath selection : selections) {
       final DefaultMutableTreeNode node =
           (DefaultMutableTreeNode) selection.getLastPathComponent();
       final Object userObject = node.getUserObject();
       if (clazz.isInstance(userObject)) {
         //noinspection unchecked
         result.add((T) userObject);
       }
     }
     return result;
   }
   return Collections.emptyList();
 }
示例#18
0
文件: TreeUtil.java 项目: jexp/idea2
 public static TreePath[] selectMaximals(final TreePath[] paths) {
   if (paths == null) return new TreePath[0];
   final TreePath[] noDuplicates = removeDuplicates(paths);
   final ArrayList<TreePath> result = new ArrayList<TreePath>();
   for (final TreePath path : noDuplicates) {
     final ArrayList<TreePath> otherPaths = new ArrayList<TreePath>(Arrays.asList(noDuplicates));
     otherPaths.remove(path);
     if (!isDescendants(path, otherPaths.toArray(new TreePath[otherPaths.size()])))
       result.add(path);
   }
   return result.toArray(new TreePath[result.size()]);
 }
示例#19
0
 public Explorer() {
   super(new DynamicNode(ROOT));
   PropertiesSet preferences = PropertiesManager.getPreferencePropertiesSet();
   if (preferences != null) {
     preferences.addPrefixPropertyChangeListener(
         DisplayToolTipsOptionGroup.class,
         DisplayToolTipsOptionGroup.TOOLTIPS_FIELD_VISIBILITY_PREFIX,
         new PreferencesListener());
     Db.addDbListener(dbslistener);
     tooltipsFields.addAll(Arrays.asList(DisplayToolTipsOptionGroup.getAvailableMetaFields()));
   }
 }
示例#20
0
  protected final void loadChildren(DynamicNode node) throws DbException {
    if (node.hasLoaded() || node.isLeaf()) return;
    node.setHasLoaded();
    Object userObject = node.getUserObject();
    if (userObject == ROOT) return;
    SrVector children = new SrVector(10);
    boolean isSorted = true;
    DbObject dbParent = null;
    if (userObject == DB_RAM) {
      Db[] dbs = Db.getDbs();
      for (int i = 0; i < dbs.length; i++) {
        if (dbs[i] instanceof DbRAM) insertProjects(children, dbs[i]);
      }
    } else if (userObject instanceof Db) {
      insertProjects(children, (Db) userObject);
    } else {
      dbParent = (DbObject) userObject;
      dbParent.getDb().beginTrans(Db.READ_TRANS);
      insertComponents(children, dbParent);
      isSorted = childrenAreSorted(dbParent);
      dbParent.getDb().commitTrans();
    }

    if (isSorted) {
      children.sort(getComparator(dbParent));
    }

    ArrayList groupNodeList = new ArrayList();
    DynamicNode groupNode = null;
    Enumeration enumeration = children.elements();
    while (enumeration.hasMoreElements()) {
      DynamicNode childNode = (DynamicNode) enumeration.nextElement();
      GroupParams group = childNode.getGroupParams();
      if (group.name == null) {
        node.add(childNode);
      } else {
        if (groupNode == null) {
          groupNode = createGroupNode(group);
          node.add(groupNode);
          groupNodeList.add(groupNode);
        } else if (!groupNode.toString().equals(group.name)) {
          boolean groupFound = false;
          for (int i = 0; i < groupNodeList.size(); i++) {
            groupNode = (DynamicNode) groupNodeList.get(i);
            if (groupNode.toString().equals(group.name)) {
              groupFound = true;
              break;
            }
          }
          if (!groupFound) {
            groupNode = createGroupNode(group);
            node.add(groupNode);
            groupNodeList.add(groupNode);
          }
        }
        groupNode.add(childNode);
      }
    }
    groupNodeList.clear();
  }
  private void restoreSelection(Pair<ElementNode, List<ElementNode>> pair) {
    List<ElementNode> selectedNodes = pair.second;

    DefaultMutableTreeNode root = getRootNode();

    ArrayList<TreePath> toSelect = new ArrayList<TreePath>();
    for (ElementNode node : selectedNodes) {
      DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
      if (root.isNodeDescendant(treeNode)) {
        toSelect.add(new TreePath(treeNode.getPath()));
      }
    }

    if (!toSelect.isEmpty()) {
      myTree.setSelectionPaths(toSelect.toArray(new TreePath[toSelect.size()]));
    }

    ElementNode leadNode = pair.first;
    if (leadNode != null) {
      myTree.setLeadSelectionPath(new TreePath(((DefaultMutableTreeNode) leadNode).getPath()));
    }
  }
 private List<ActionUrl> findActionsUnderSelection() {
   final ArrayList<ActionUrl> actions = new ArrayList<ActionUrl>();
   final TreePath[] selectionPaths = myActionsTree.getSelectionPaths();
   if (selectionPaths != null) {
     for (TreePath path : selectionPaths) {
       final ActionUrl selectedUrl = CustomizationUtil.getActionUrl(path, ActionUrl.MOVE);
       final ArrayList<String> selectedGroupPath =
           new ArrayList<String>(selectedUrl.getGroupPath());
       final Object component = selectedUrl.getComponent();
       if (component instanceof Group) {
         selectedGroupPath.add(((Group) component).getName());
         for (ActionUrl action : mySelectedSchema.getActions()) {
           final ArrayList<String> groupPath = action.getGroupPath();
           final int idx = Collections.indexOfSubList(groupPath, selectedGroupPath);
           if (idx > -1) {
             actions.add(action);
           }
         }
       }
     }
   }
   return actions;
 }
  @Override
  public void dispose() {
    PropertiesComponent instance = PropertiesComponent.getInstance();
    instance.setValue(PROP_SORTED, Boolean.toString(isAlphabeticallySorted()));
    instance.setValue(PROP_SHOWCLASSES, Boolean.toString(myShowClasses));

    if (myCopyJavadocCheckbox != null) {
      instance.setValue(PROP_COPYJAVADOC, Boolean.toString(myCopyJavadocCheckbox.isSelected()));
    }

    final Container contentPane = getContentPane();
    if (contentPane != null) {
      contentPane.removeAll();
    }
    mySelectedNodes.clear();
    myElements = null;
    super.dispose();
  }
 protected void clear(ArrayList aListComps) {
   for (int i = 0; i < aListComps.size(); i++) {
     JComponent comp = (JComponent) aListComps.get(i);
     comp.removeAll();
   }
 }
    /**
     * Write the file by writing the values from the labels, and the values list.
     *
     * @param strFile the file to be written.
     * @param aListLabels arraylist of texfields of labels.
     * @param aListValues arraylist of texfields of values.
     */
    protected void writeFile(
        String strUser, String strFile, ArrayList aListLabels, ArrayList aListValues) {
      String strPath = FileUtil.openPath(strFile);
      String strLabel = "";
      String strValue = "";
      StringBuffer sbValues = new StringBuffer();
      JTextField txfLabel = null;
      JTextField txfValue = null;
      boolean bNewFile = false;
      int nFDAMode = Util.getPart11Mode();

      // if it's the part11 pnl and the mode is nonFDA,
      // then don't write the file for this panel
      // the other way is not true.
      if (this instanceof DisplayParentDirectory) {
        if ((isPart11Pnl() && nFDAMode == Util.NONFDA)) {
          return;
        }
      }

      if (strPath == null) {
        strPath = FileUtil.savePath(strFile);
        bNewFile = true;
      }

      if (strPath == null || aListLabels == null) return;

      if (aListValues == null) aListValues = new ArrayList();

      // Get the list of the textfields for values and labels.
      int nLblSize = aListLabels.size();
      int nValueSize = aListValues.size();
      ArrayList<String> labelList = new ArrayList<String>();

      // Get the value from each textfield, and add it to the buffer.
      for (int i = 0; i < nLblSize; i++) {
        txfLabel = (JTextField) aListLabels.get(i);
        txfValue = (i < nValueSize) ? (JTextField) aListValues.get(i) : null;

        strLabel = (txfLabel != null) ? txfLabel.getText() : null;
        strValue = (txfValue != null) ? txfValue.getText() : "";

        // We need to be sure they don't have two data directories with
        // the same labels.  Save the label list if we are writing to
        // the "data" file.
        if (strFile.indexOf("data") != -1) {
          if (labelList.contains(strLabel)) {
            Messages.postError(
                "The Data Directory specifications "
                    + "must not have duplicate Label names. "
                    + "The Label \""
                    + strLabel
                    + "\" is duplicated.  "
                    + "Skipping the second instance.  Please "
                    + "specify a new Label.");
            continue;
          } else labelList.add(strLabel);
        }

        if (strLabel == null || strLabel.trim().length() <= 0 || strValue.equals(INFOSTR)) continue;

        // for user template tab, don't need to parse the value
        if (!(this instanceof DisplayTemplate)) strValue = getValue(strUser, strValue);
        strLabel = strLabel.trim();
        if (strValue != null) strValue = strValue.trim();

        // sbValues.append("\"");
        sbValues.append(strLabel);
        // sbValues.append("\"  ");

        sbValues.append(File.pathSeparator);
        sbValues.append(strValue);
        sbValues.append("\n");
      }

      if (Util.isPart11Sys()) writeAuditTrail(strPath, strUser, sbValues);

      // write the data to the file.
      BufferedWriter writer = WFileUtil.openWriteFile(strPath);
      WFileUtil.writeAndClose(writer, sbValues);

      // if it's a template file, then make it writable for everyone.
      if (bNewFile) {
        String strCmd = "chmod 755 ";
        if (this instanceof DisplayTemplate) strCmd = "chmod 777 ";
        if (Util.iswindows()) strPath = UtilB.windowsPathToUnix(strPath);
        String[] cmd = {WGlobal.SHTOOLCMD, WGlobal.SHTOOLOPTION, strCmd + strPath};
        WUtil.runScriptInThread(cmd);
      }
    }
 public void addToLabel(DataField txf) {
   m_aListTxfLabel.add(txf);
 }
 public void addToValue(DataField txf) {
   m_aListTxfValue.add(txf);
 }
 public void clearArrays() {
   m_aListTxfLabel.clear();
   m_aListTxfValue.clear();
 }
 public void clearLabelArray() {
   m_aListTxfLabel.clear();
 }
 public void clearValueArray() {
   m_aListTxfValue.clear();
 }