Search in sources :

Example 1 with HierarchyAlterationException

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

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

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

the class HierarchyAltererMessageHandler method handle.

public void handle(MessageEvent message) {
    try {
        logger.info("Handling hierarchy alteration message " + message.getMessageId());
        HierarchyAlterer alterer = DashController.getHierarchyAlterer();
        Element xml = message.getMessageXml();
        for (Element instr : XMLUtils.getChildElements(xml)) handleInstr(alterer, instr);
        logger.info("Done handling hierarchy alteration message");
    } catch (HierarchyAlterationException hae) {
        // HierarchyAlterationExceptions typically indicate transient
        // problems, so mark the message as unhandled and try again later.
        MessageDispatcher.getInstance().setMessageHandled(message, false);
        logError(hae, message.getMessageXml());
    } catch (IllegalArgumentException iae) {
        // Print a warning about the invalid XML message we received.
        logError(iae, message.getMessageXml());
    }
}
Also used : HierarchyAlterationException(net.sourceforge.processdash.hier.HierarchyAlterer.HierarchyAlterationException) Element(org.w3c.dom.Element)

Example 4 with HierarchyAlterationException

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

the class TeamProjectBrowser method maybeDeleteSelectedProject.

private void maybeDeleteSelectedProject() {
    PropertyKey selectedNode = getSelectedTreeNode();
    String projectPath = selectedNode.path();
    String templateID = ctx.getHierarchy().getID(selectedNode);
    if (okToDeleteProject(projectPath, templateID)) {
        try {
            DashController.getHierarchyAlterer().deleteNode(projectPath);
        } catch (HierarchyAlterationException e) {
            e.printStackTrace();
        }
    }
}
Also used : HierarchyAlterationException(net.sourceforge.processdash.hier.HierarchyAlterer.HierarchyAlterationException) PropertyKey(net.sourceforge.processdash.hier.PropertyKey)

Aggregations

HierarchyAlterationException (net.sourceforge.processdash.hier.HierarchyAlterer.HierarchyAlterationException)4 PropertyKey (net.sourceforge.processdash.hier.PropertyKey)3 HierarchyAlterer (net.sourceforge.processdash.hier.HierarchyAlterer)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JTextField (javax.swing.JTextField)1 DashHierarchy (net.sourceforge.processdash.hier.DashHierarchy)1 JOptionPaneTweaker (net.sourceforge.processdash.ui.lib.JOptionPaneTweaker)1 Element (org.w3c.dom.Element)1