Search in sources :

Example 1 with HierarchyAlterer

use of net.sourceforge.processdash.hier.HierarchyAlterer 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 2 with HierarchyAlterer

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

the class TeamProjectBrowser method maybeRenameSelectedProject.

private void maybeRenameSelectedProject() {
    // determine which team project is selected. If none, abort.
    PropertyKey projectNode = getSelectedTreeNode();
    String projectPath = projectNode.path();
    String templateID = ctx.getHierarchy().getID(projectNode);
    if (!StringUtils.hasValue(templateID))
        return;
    // Create objects we will use in a dialog
    String title = resources.getString("Rename.Title");
    JTextField newPathField = new JTextField(projectPath);
    Object message = resources.formatStrings("Rename.Message_Header_FMT", projectPath);
    message = new Object[] { message, " ", newPathField, new JOptionPaneTweaker.GrabFocus(newPathField) };
    while (true) {
        // Show the user a dialog asking for the new path and name.
        int userChoice = JOptionPane.showConfirmDialog(this, message, title, JOptionPane.OK_CANCEL_OPTION);
        // if the user didn't press the OK button, abort.
        if (userChoice != JOptionPane.OK_OPTION)
            return;
        // get the new path in canonical form. If it was not absolute,
        // interpret it relative to the current parent of the project.
        String newPath = newPathField.getText().trim();
        if (newPath.indexOf('/') == -1)
            newPath = projectNode.getParent().path() + "/" + newPath;
        newPath = DashHierarchy.scrubPath(newPath);
        newPathField.setText(newPath);
        // if the user didn't change the name, abort.
        if (newPath.length() < 2 || newPath.equals(projectPath))
            return;
        // check for various error conditions.
        if (projectAlreadyExists(newPath)) {
            showInvalidRenameMessage("Rename.Duplicate_Name");
        } else if (projectParentIsInvalid(newPath)) {
            showInvalidRenameMessage("Rename.Invalid_Parent");
        } else {
            try {
                // try performing the renaming operation.
                HierarchyAlterer hierarchyAlterer = DashController.getHierarchyAlterer();
                hierarchyAlterer.renameNode(projectPath, newPath);
                // if this caused the old parent of the project to become
                // childless, delete that parent (and grandparent, etc)
                PropertyKey oldParent = projectNode.getParent();
                while (ctx.getHierarchy().getNumChildren(oldParent) == 0) {
                    hierarchyAlterer.deleteNode(oldParent.path());
                    oldParent = oldParent.getParent();
                }
                // point the "active task" at the renamed project.
                PropertyKey newNode = ctx.getHierarchy().findExistingKey(newPath);
                if (newNode != null)
                    taskModel.setNode(newNode);
            } catch (HierarchyAlterationException e) {
                e.printStackTrace();
            }
            return;
        }
    }
}
Also used : JOptionPaneTweaker(net.sourceforge.processdash.ui.lib.JOptionPaneTweaker) HierarchyAlterationException(net.sourceforge.processdash.hier.HierarchyAlterer.HierarchyAlterationException) HierarchyAlterer(net.sourceforge.processdash.hier.HierarchyAlterer) JTextField(javax.swing.JTextField) PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Example 3 with HierarchyAlterer

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

the class MigrationToolTeam method convertHierarchy.

private void convertHierarchy() throws HierarchyAlterationException {
    ProcessDashboard dash = (ProcessDashboard) ctx;
    HierarchyAlterer alt = new HierarchyAlterer(dash);
    DashHierarchy hier = ctx.getHierarchy();
    PropertyKey key = hier.findExistingKey(projectPath);
    // delete the children of the team project root node.
    for (int i = hier.getNumChildren(key); i-- > 0; ) {
        PropertyKey child = hier.getChildKey(key, i);
        alt.deleteNode(child.path());
    }
    // change the template ID of the root node.
    alt.setTemplateId(projectPath, newRootTemplateID);
}
Also used : HierarchyAlterer(net.sourceforge.processdash.hier.HierarchyAlterer) DashHierarchy(net.sourceforge.processdash.hier.DashHierarchy) ProcessDashboard(net.sourceforge.processdash.ProcessDashboard) PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Example 4 with HierarchyAlterer

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

the class DashController method alterTemplateID.

public static boolean alterTemplateID(String prefix, String oldID, String newID) {
    if (Settings.isReadOnly())
        return false;
    PropertyKey key = dash.props.findExistingKey(prefix);
    String actualID = dash.props.getID(key);
    if (// handles "null == null" case
    oldID == actualID || (oldID != null && oldID.equals(actualID)))
        try {
            HierarchyAlterer a = new HierarchyAlterer(dash);
            a.addTemplate(prefix, newID);
            return true;
        } catch (Exception e) {
        }
    return false;
}
Also used : HierarchyAlterer(net.sourceforge.processdash.hier.HierarchyAlterer) PropertyKey(net.sourceforge.processdash.hier.PropertyKey) IOException(java.io.IOException)

Aggregations

HierarchyAlterer (net.sourceforge.processdash.hier.HierarchyAlterer)4 PropertyKey (net.sourceforge.processdash.hier.PropertyKey)4 DashHierarchy (net.sourceforge.processdash.hier.DashHierarchy)2 HierarchyAlterationException (net.sourceforge.processdash.hier.HierarchyAlterer.HierarchyAlterationException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JTextField (javax.swing.JTextField)1 ProcessDashboard (net.sourceforge.processdash.ProcessDashboard)1 JOptionPaneTweaker (net.sourceforge.processdash.ui.lib.JOptionPaneTweaker)1