Search in sources :

Example 11 with PropertyKey

use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.

the class HierarchyEditor method treeNodesChanged.

/**
     * The next four methods implement the TreeModelListener interface
     * to deal with changes to the tree.
     */
public void treeNodesChanged(TreeModelEvent e) {
    // name change
    Object[] path = e.getPath();
    int[] indices = e.getChildIndices();
    Object[] children = e.getChildren();
    PropertyKey parent = treeModel.getPropKey(useProps, path);
    String previousName, newName;
    int index;
    for (int i = 0; i < indices.length; i++) {
        previousName = useProps.getChildName(parent, indices[i]);
        newName = children[i].toString();
        index = indices[i];
        String newNameTrimmed = newName.trim();
        if (!newName.equals(newNameTrimmed)) {
            // Use the trimmed name
            treeModel.useTreeModelListener(false);
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeModel.getChild(e.getTreePath().getLastPathComponent(), index);
            node.setUserObject(newNameTrimmed);
            treeModel.nodeChanged(node);
            treeModel.useTreeModelListener(true);
        } else if (newNameIsAcceptable(parent, newName)) {
            useProps.setChildKey(parent, newName, index);
            setDirty(true);
        } else {
            // Revert back to the old name.
            treeModel.useTreeModelListener(false);
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeModel.getChild(e.getTreePath().getLastPathComponent(), index);
            node.setUserObject(previousName);
            treeModel.nodeChanged(node);
            treeModel.useTreeModelListener(true);
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Example 12 with PropertyKey

use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.

the class HierarchyEditor method copyTemplate.

public TreeNode copyTemplate(DefaultMutableTreeNode destParent, String templateName) {
    //recursive copy of node, children and properties
    PropertyKey parent = treeModel.getPropKey(useProps, destParent.getPath());
    PropertyKey templateKey = templates.getRootChildByName(templateName);
    int newIndex = useProps.getNumChildren(parent);
    // See if should be adding at other index...
    // if parent specifies allowed children
    Prop val = useProps.pget(parent);
    String status, allowedChild;
    if ((val != null) && ((status = val.getStatus()) != null)) {
        int idx1 = status.indexOf(ALLOWED_CHILD);
        int idx2 = status.indexOf(REQUIRED_PARENT);
        if (idx1 >= 0) {
            if (idx2 < 0)
                idx2 = status.length();
            StringTokenizer st = new StringTokenizer(status.substring(idx1 + 1, idx2), String.valueOf(ALLOWED_CHILD));
            while (st.hasMoreTokens()) {
                allowedChild = st.nextToken();
                // if parent specifies THIS child
                if (allowedChild.startsWith(templateName)) {
                    idx1 = allowedChild.indexOf("(");
                    idx2 = allowedChild.indexOf(")");
                    // if parent specifies index
                    if (idx1 >= 0 && idx2 >= 0) {
                        // change index
                        idx1 = Integer.valueOf(allowedChild.substring(idx1 + 1, idx2)).intValue();
                        newIndex = ((idx1 < 0) ? (newIndex + idx1) : idx1);
                    }
                    // exit while loop
                    break;
                }
            }
        }
    }
    // now add it
    useProps.addChildKey(parent, useProps.pget(parent).uniqueChildName(templateName), newIndex);
    useProps.copyFrom(templates, templateKey, useProps.getChildKey(parent, newIndex));
    // clear and reload the tree (NEEDS WORK)
    treeModel.useTreeModelListener(false);
    treeModel.reload(useProps);
    expandRoot();
    treeModel.useTreeModelListener(true);
    treeModel.nodeStructureChanged(destParent);
    return (TreeNode) treeModel.getChild(destParent, newIndex);
}
Also used : StringTokenizer(java.util.StringTokenizer) Prop(net.sourceforge.processdash.hier.Prop) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Example 13 with PropertyKey

use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.

the class HierarchyEditor method valueChanged.

/**
     * The next method implement the TreeSelectionListener interface
     * to deal with changes to the tree selection.
     */
public void valueChanged(TreeSelectionEvent e) {
    TreePath tp = (e == null ? tree.getSelectionPath() : e.getNewLeadSelectionPath());
    if (tp == null) {
        // deselection
        deleteMenuItem.setEnabled(false);
        moveUpAction.setEnabled(false);
        moveDownAction.setEnabled(false);
        adjustMenu(false, true, false, null, null, null);
        addTemplateMenu.setEnabled(false);
        return;
    }
    Object[] path = tp.getPath();
    PropertyKey key = treeModel.getPropKey(useProps, path);
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tp.getLastPathComponent();
    moveUpAction.setEnabled(moveUpIsLegal(node));
    moveDownAction.setEnabled(moveDownIsLegal(node));
    // Place code to update selection-sensitive field(s) here.
    Prop val = useProps.pget(key);
    String status = val.getStatus();
    if (status == null)
        status = "";
    int parseIndex = 0;
    boolean moveable = true;
    boolean editable = true;
    boolean deletable = true;
    boolean allowsSiblings = true;
    boolean allowsChildren = true;
    Vector allowedChildren = null;
    if ((status.length() > 0) && (status.charAt(0) == NO_MOVE_CHAR)) {
        moveable = false;
        parseIndex++;
        if ((status.length() > 1) && (status.charAt(1) == NO_EDIT_CHAR)) {
            editable = false;
            parseIndex++;
        }
    } else if ((status.length() > 0) && (status.charAt(0) == NO_EDIT_CHAR)) {
        editable = false;
        parseIndex++;
    }
    if (// top two levels (root & 1st sub) static
    path.length <= 1)
        deletable = false;
    else if (!editable && !moveable)
        deletable = status.startsWith("" + NO_MOVE_CHAR + NO_EDIT_CHAR + DELETE_OK_CHAR);
    deleteMenuItem.setEnabled(deletable);
    cutAction.setEnabled(deletable);
    String pStatus = useProps.pget(key.getParent()).getStatus();
    if ((pStatus != null) && (pStatus.indexOf(ALLOWED_CHILD) >= 0))
        allowsSiblings = false;
    if ((parseIndex = status.indexOf(ALLOWED_CHILD)) >= 0) {
        // can only add specified templates
        allowsChildren = false;
        // non-null implies REQUIRED match
        allowedChildren = new Vector();
        int lastChar = status.indexOf(REQUIRED_PARENT);
        if (lastChar < 0)
            lastChar = status.length();
        if (lastChar > parseIndex + 1) {
            // at least one allowed, make list...
            StringTokenizer st = new StringTokenizer(status.substring(parseIndex + 1, lastChar), String.valueOf(ALLOWED_CHILD));
            String sDebug, childID;
            int endIndex;
            while (st.hasMoreElements()) {
                sDebug = st.nextToken();
                endIndex = sDebug.indexOf("(");
                if (endIndex < 0)
                    endIndex = sDebug.length();
                childID = sDebug.substring(0, endIndex);
                PropertyKey childKey = templates.getByID(childID);
                // or if the given template is rename-able,
                if (childKey == null || (val.isUniqueChildName(Prop.unqualifiedName(childKey.name())) || templateIsMalleable(childKey)))
                    // then it's okay to allow adding this template.
                    allowedChildren.addElement(childID);
            //        System.out.println("Allowing Template " +
            //                           sDebug.substring (0, endIndex));
            }
        }
    }
    String valID = val.getID();
    if (valID == null)
        valID = "";
    adjustMenu(allowsSiblings, allowsChildren, editable, allowedChildren, valID, key.path());
}
Also used : StringTokenizer(java.util.StringTokenizer) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Prop(net.sourceforge.processdash.hier.Prop) Vector(java.util.Vector) PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Example 14 with PropertyKey

use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.

the class AddTaskDialog method validateInputsAndPerformTaskAddition.

private boolean validateInputsAndPerformTaskAddition() {
    // make certain they entered a task name. If not, display an error.
    String name = taskName.getText().trim();
    if (name.length() == 0) {
        displayError(resources.getString("Errors.Name_Missing"));
        return false;
    }
    // See if another task already exists with that name.
    PropertyKey newNode = new PropertyKey(targetParent, name);
    DashHierarchy hier = dash.getHierarchy();
    if (hier.containsKey(newNode)) {
        displayError(resources.format("Errors.Duplicate_Name_FMT", name, targetParent.path()));
        return false;
    }
    // produce a list of child names in our desired order, to indicate the
    // place where the new node should be inserted.
    List childOrder = new ArrayList();
    int numChildren = hier.getNumChildren(targetParent);
    for (int i = 0; i < numChildren; i++) {
        PropertyKey child = hier.getChildKey(targetParent, i);
        childOrder.add(child.name());
        if (child.equals(previousSibling))
            childOrder.add(name);
    }
    if (childOrder.size() == numChildren)
        childOrder = null;
    try {
        // add the new task.
        HierarchyAlterer alt = DashController.getHierarchyAlterer();
        String newTaskPath = newNode.path();
        if (taskType.templateID == null) {
            alt.addNode(newTaskPath);
        } else {
            alt.addTemplate(newTaskPath, taskType.templateID);
        }
        // the new task will initially be the last child of this parent.
        // proactively mark it as the selected child.
        hier.setSelectedChild(targetParent, numChildren);
        // is in the correct position
        if (childOrder != null)
            alt.reorderChildren(targetParent.path(), childOrder);
        // let the handler perform any follow-up work
        handler.finalizeAddedTask(newTaskPath, taskType);
        // set the new task as the active task.
        deferredSetActiveTask(newNode);
    } catch (HierarchyAlterationException e) {
        e.printStackTrace();
    }
    return true;
}
Also used : HierarchyAlterationException(net.sourceforge.processdash.hier.HierarchyAlterer.HierarchyAlterationException) HierarchyAlterer(net.sourceforge.processdash.hier.HierarchyAlterer) DashHierarchy(net.sourceforge.processdash.hier.DashHierarchy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Example 15 with PropertyKey

use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.

the class HierarchyEditor method treeNodesInserted.

public void treeNodesInserted(TreeModelEvent e) {
    // debug ("treeNodesInserted:"+e.toString());
    Object[] path = e.getPath();
    int[] indices = e.getChildIndices();
    Object[] children = e.getChildren();
    PropertyKey parent = treeModel.getPropKey(useProps, path);
    debug(((path == null) ? "null" : path.toString()) + "=>" + ((parent == null) ? "null" : parent.toString()));
    for (int nodeIdx = 0; nodeIdx < indices.length; nodeIdx++) {
        useProps.addChildKey(parent, children[nodeIdx].toString(), indices[nodeIdx]);
    }
    setDirty(true);
}
Also used : PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Aggregations

PropertyKey (net.sourceforge.processdash.hier.PropertyKey)125 DashHierarchy (net.sourceforge.processdash.hier.DashHierarchy)40 Prop (net.sourceforge.processdash.hier.Prop)16 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)10 SimpleData (net.sourceforge.processdash.data.SimpleData)7 ArrayList (java.util.ArrayList)6 Enumeration (java.util.Enumeration)6 IOException (java.io.IOException)5 Iterator (java.util.Iterator)5 StringTokenizer (java.util.StringTokenizer)5 TreePath (javax.swing.tree.TreePath)5 ListData (net.sourceforge.processdash.data.ListData)5 DefectLog (net.sourceforge.processdash.log.defects.DefectLog)5 List (java.util.List)4 ProcessDashboard (net.sourceforge.processdash.ProcessDashboard)4 HierarchyAlterer (net.sourceforge.processdash.hier.HierarchyAlterer)4 HierarchyAlterationException (net.sourceforge.processdash.hier.HierarchyAlterer.HierarchyAlterationException)4 DefectLogID (net.sourceforge.processdash.log.defects.DefectLogID)4 TinyCGIException (net.sourceforge.processdash.net.http.TinyCGIException)4 Point (java.awt.Point)3