Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode getUserObject.

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

From source file:lcmc.gui.resources.ServiceInfo.java

/** Removes the service without confirmation dialog. */
protected void removeMyselfNoConfirm(final Host dcHost, final boolean testOnly) {
    if (!testOnly) {
        if (!getService().isNew()) {
            setUpdated(true);/*from  w w w  . j a va  2  s  .c  om*/
        }
        getService().setRemoved(true);
        cleanup();
    }
    final CloneInfo ci = getCloneInfo();
    if (ci != null) {
        ci.removeMyselfNoConfirm(dcHost, testOnly);
        setCloneInfo(null);
    }
    final GroupInfo gi = groupInfo;
    if (getService().isNew() && gi == null) {
        if (!testOnly) {
            getService().setNew(false);
            getBrowser().getCRMGraph().killRemovedVertices();
        }
    } else {
        final ClusterStatus cs = getBrowser().getClusterStatus();
        if (gi == null) {
            removeConstraints(dcHost, testOnly);
        }
        if (!getResourceAgent().isGroup() && !getResourceAgent().isClone()) {
            String groupId = null; /* for pacemaker */
            if (gi != null) {
                /* get group id only if there is only one resource in a
                 * group.
                 */
                if (getService().isNew()) {
                    if (!testOnly) {
                        super.removeMyself(false);
                    }
                } else {
                    final String group = gi.getHeartbeatId(testOnly);
                    final DefaultMutableTreeNode giNode = gi.getNode();
                    if (giNode != null) {
                        @SuppressWarnings("unchecked")
                        final Enumeration<DefaultMutableTreeNode> e = giNode.children();
                        while (e.hasMoreElements()) {
                            final DefaultMutableTreeNode n = e.nextElement();
                            final ServiceInfo child = (ServiceInfo) n.getUserObject();
                            child.getService().setModified(true);
                            child.getService().doneModifying();
                        }
                    }
                    if (cs.getGroupResources(group, testOnly).size() == 1) {
                        if (!testOnly) {
                            gi.getService().setRemoved(true);
                        }
                        gi.removeMyselfNoConfirmFromChild(dcHost, testOnly);
                        groupId = group;
                        gi.getService().doneRemoving();
                    }
                }
                gi.resetPopup();
            }
            if (!getService().isNew()) {
                String cloneId = null;
                boolean master = false;
                if (ci != null) {
                    cloneId = ci.getHeartbeatId(testOnly);
                    master = ci.getService().isMaster();
                }
                final boolean ret = CRM.removeResource(dcHost, getHeartbeatId(testOnly), groupId, cloneId,
                        master, testOnly);
                cleanupResource(dcHost, testOnly);
                setUpdated(false); /* must be here, is not a clone anymore*/
                if (!testOnly && !ret) {
                    Tools.progressIndicatorFailed(dcHost.getName(), "removing failed");
                }
            }
        }
    }
    if (!testOnly) {
        getBrowser().removeFromServiceInfoHash(this);
        infoPanel = null;
        getService().doneRemoving();
    }
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Get the chosen Wrapper from the tree node that was clicked on.
 * //from  w w w .j av a 2  s.  com
 * @param event
 *          The mouse click event
 * 
 * @return The Wrapper instance or null if the node is not a Wrapper
 */
private Wrapper getSelectedWrapperInTree(MouseEvent event) {
    Wrapper chosenWrapper = null;

    LOGGER.debug("Tree mouse event: " + event.paramString());
    final TreePath path = ontModelTree.getPathForLocation(event.getX(), event.getY());
    if (path != null) {
        LOGGER.debug("Tree right-mouse event on: " + path.getLastPathComponent() + " of class "
                + path.getLastPathComponent().getClass());
        if (path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
            final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
            final Object selectedObject = selectedNode.getUserObject();
            LOGGER.debug("Class of object in the selected tree node: " + selectedObject.getClass().getName());
            if (selectedObject instanceof Wrapper) {
                chosenWrapper = (Wrapper) selectedObject;
                LOGGER.debug("Wrapper found: " + selectedObject);
            }
        }
    }

    return chosenWrapper;
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Find a matching individual in the tree.
 * /*from  w  w w  . j a  v  a2s  .  c  o  m*/
 * @param wrapper
 *          The individual to be matched
 * @param forward
 *          True to search forward, false to search backward
 */
private void findMatchingIndividual(Wrapper wrapper, boolean forward) {
    final DefaultTreeModel treeModel = (DefaultTreeModel) ontModelTree.getModel();
    final DefaultMutableTreeNode finalMatchAt;
    DefaultMutableTreeNode latestMatchAt = null;
    DefaultMutableTreeNode firstMatchAt = null;
    boolean foundClickedNode = false;
    boolean wrappedAroundBackward = false;

    if (wrapper != null && wrapper instanceof WrapperInstance) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeModel.getRoot();
        @SuppressWarnings("unchecked")
        final Enumeration<DefaultMutableTreeNode> nodeEnumeration = node.preorderEnumeration();
        while (nodeEnumeration.hasMoreElements()) {
            final DefaultMutableTreeNode nextNode = nodeEnumeration.nextElement();
            if (nextNode.getUserObject() instanceof Wrapper) {
                final Wrapper nodeWrapper = (Wrapper) nextNode.getUserObject();
                if (wrapper.getUuid().equals(nodeWrapper.getUuid())) {
                    foundClickedNode = true;
                    if (forward) {
                        // If there is one past this location then
                        // use it, otherwise wrap back to top
                        latestMatchAt = null;
                    } else {
                        if (firstMatchAt != null || latestMatchAt != null) {
                            // Searching backward and have found a previous one
                            break;
                        }
                        wrappedAroundBackward = true;
                    }
                } else if (!wrapper.getUuid().equals(nodeWrapper.getUuid())
                        && wrapper.getClass().equals(wrapper.getClass())
                        && wrapper.getLocalName().equals(nodeWrapper.getLocalName())
                        && wrapper.getUri().equals(nodeWrapper.getUri())) {
                    if (firstMatchAt == null && !foundClickedNode) {
                        // First one found, keep it in case we wrap around
                        firstMatchAt = nextNode;
                        LOGGER.debug("Found first matching node: search UUID: " + wrapper.getUuid()
                                + " found UUID: " + nodeWrapper.getUuid());
                    } else {
                        // Keep track of latest one found
                        latestMatchAt = nextNode;
                        LOGGER.debug("Found a following matching node: search UUID: " + wrapper.getUuid()
                                + " found UUID: " + nodeWrapper.getUuid());
                        // If going forward then this is the next match
                        if (forward && foundClickedNode) {
                            break;
                        }
                    }
                }
            }
        }

        if ((!forward || foundClickedNode) && latestMatchAt != null) {
            finalMatchAt = latestMatchAt;
            if (forward) {
                setStatus("Next " + wrapper.getLocalName() + " found");
            } else {
                if (wrappedAroundBackward) {
                    setStatus("Wrapped to bottom of tree and found a " + wrapper.getLocalName());
                } else {
                    setStatus("Previous " + wrapper.getLocalName() + " found");
                }
            }
        } else if (firstMatchAt != null) {
            finalMatchAt = firstMatchAt;
            if (forward) {
                setStatus("Wrapped to top of tree and found a " + wrapper.getLocalName());
            } else {
                setStatus("Previous " + wrapper.getLocalName() + " found");
            }
        } else {
            finalMatchAt = null;
            setStatus(wrapper.getLocalName() + " could not be found elsewhere in the tree");
        }

        if (finalMatchAt != null) {
            ontModelTree.setExpandsSelectedPaths(true);

            // Scroll to the selected node
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    ontModelTree.setSelectionPath(new TreePath(treeModel.getPathToRoot(finalMatchAt)));
                    ontModelTree.scrollPathToVisible(new TreePath(treeModel.getPathToRoot(finalMatchAt)));
                    final Rectangle visible = ontModelTree.getVisibleRect();
                    visible.x = 0;
                    ontModelTree.scrollRectToVisible(visible);
                }
            });
        }
    }
}

From source file:com.pironet.tda.SunJDKParser.java

/**
 * parse the next thread dump from the stream passed with the constructor.
 *
 * @return null if no more thread dumps were found.
 *//*from   w w  w .  j a  v a  2 s .com*/
public MutableTreeNode parseNext() {
    if (nextDump != null) {
        MutableTreeNode tmpDump = nextDump;
        nextDump = null;
        return (tmpDump);
    }
    boolean retry = false;
    String line = null;

    do {

        try {
            Map<String, String> threads = new HashMap<>();
            ThreadDumpInfo overallTDI = new ThreadDumpInfo("Dump No. " + counter++, 0);
            if (withCurrentTimeStamp) {
                overallTDI.setStartTime((new Date(System.currentTimeMillis())).toString());
            }
            DefaultMutableTreeNode threadDump = new DefaultMutableTreeNode(overallTDI);

            DefaultMutableTreeNode catThreads = new DefaultMutableTreeNode(
                    new TableCategory("Threads", IconFactory.THREADS));
            threadDump.add(catThreads);

            DefaultMutableTreeNode catWaiting = new DefaultMutableTreeNode(
                    new TableCategory("Threads waiting for Monitors", IconFactory.THREADS_WAITING));

            DefaultMutableTreeNode catSleeping = new DefaultMutableTreeNode(
                    new TableCategory("Threads sleeping on Monitors", IconFactory.THREADS_SLEEPING));

            DefaultMutableTreeNode catLocking = new DefaultMutableTreeNode(
                    new TableCategory("Threads locking Monitors", IconFactory.THREADS_LOCKING));

            // create category for monitors with disabled filtering.
            // NOTE:  These strings are "magic" in that the methods
            // TDA#displayCategory and TreeCategory#getCatComponent both
            // checks these literal strings and the behavior differs.
            DefaultMutableTreeNode catMonitors = new DefaultMutableTreeNode(
                    new TreeCategory("Monitors", IconFactory.MONITORS, false));
            DefaultMutableTreeNode catMonitorsLocks = new DefaultMutableTreeNode(
                    new TreeCategory("Monitors without locking thread", IconFactory.MONITORS_NO_LOCKS, false));
            DefaultMutableTreeNode catBlockingMonitors = new DefaultMutableTreeNode(
                    new TreeCategory("Threads blocked by Monitors", IconFactory.THREADS_LOCKING, false));

            String title = null;
            String dumpKey = null;
            StringBuffer content = null;
            boolean inLocking = false;
            boolean inSleeping = false;
            boolean inWaiting = false;
            int threadCount = 0;
            int waiting = 0;
            int locking = 0;
            int sleeping = 0;
            boolean locked = true;
            boolean finished = false;
            final MonitorMap mmap = new MonitorMap();
            final Stack<String> monitorStack = new Stack<>();
            long startTime = 0;
            int singleLineCounter = 0;
            boolean concurrentSyncsFlag = false;
            Matcher matched = getDm().getLastMatch();

            while (getBis().ready() && !finished) {
                line = getNextLine();
                lineCounter++;
                singleLineCounter++;
                if (locked) {
                    if (line.contains("Full thread dump")) {
                        locked = false;
                        if (!withCurrentTimeStamp) {
                            overallTDI.setLogLine(lineCounter);

                            if (startTime != 0) {
                                startTime = 0;
                            } else if (matched != null && matched.matches()) {

                                String parsedStartTime = matched.group(1);
                                if (!getDm().isDefaultMatches() && isMillisTimeStamp()) {
                                    try {
                                        // the factor is a hack for a bug in oc4j timestamp printing (pattern timeStamp=2342342340)
                                        if (parsedStartTime.length() < 13) {
                                            startTime = Long.parseLong(parsedStartTime)
                                                    * (long) Math.pow(10, 13 - parsedStartTime.length());
                                        } else {
                                            startTime = Long.parseLong(parsedStartTime);
                                        }
                                    } catch (NumberFormatException nfe) {
                                        startTime = 0;
                                    }
                                    if (startTime > 0) {
                                        overallTDI.setStartTime((new Date(startTime)).toString());
                                    }
                                } else {
                                    overallTDI.setStartTime(parsedStartTime);
                                }
                                matched = null;
                                getDm().resetLastMatch();
                            }
                        }
                        dumpKey = overallTDI.getName();
                    } else if (!getDm().isPatternError() && (getDm().getRegexPattern() != null)) {
                        Matcher m = getDm().checkForDateMatch(line);
                        if (m != null) {
                            matched = m;
                        }
                    }
                } else {
                    if (line.startsWith("\"")) {
                        // We are starting a group of lines for a different thread
                        // First, flush state for the previous thread (if any)
                        concurrentSyncsFlag = false;
                        String stringContent = content != null ? content.toString() : null;
                        if (title != null) {
                            threads.put(title, content.toString());
                            content.append("</pre></pre>");
                            addToCategory(catThreads, title, null, stringContent, singleLineCounter, true);
                            threadCount++;
                        }
                        if (inWaiting) {
                            addToCategory(catWaiting, title, null, stringContent, singleLineCounter, true);
                            inWaiting = false;
                            waiting++;
                        }
                        if (inSleeping) {
                            addToCategory(catSleeping, title, null, stringContent, singleLineCounter, true);
                            inSleeping = false;
                            sleeping++;
                        }
                        if (inLocking) {
                            addToCategory(catLocking, title, null, stringContent, singleLineCounter, true);
                            inLocking = false;
                            locking++;
                        }
                        singleLineCounter = 0;
                        while (!monitorStack.empty()) {
                            mmap.parseAndAddThread(monitorStack.pop(), title, content.toString());
                        }

                        // Second, initialize state for this new thread
                        title = line;
                        content = new StringBuffer("<body bgcolor=\"ffffff\"><pre><font size="
                                + TDA.getFontSizeModifier(-1) + '>');
                        content.append(line);
                        content.append('\n');
                    } else if (line.contains("at ")) {
                        content.append(line);
                        content.append('\n');
                    } else if (line.contains("java.lang.Thread.State")) {
                        content.append(line);
                        content.append('\n');
                        if (title.indexOf("t@") > 0) {
                            // in this case the title line is missing state informations
                            String state = line.substring(line.indexOf(':') + 1).trim();
                            if (state.indexOf(' ') > 0) {
                                title += " state=" + state.substring(0, state.indexOf(' '));
                            } else {
                                title += " state=" + state;
                            }
                        }
                    } else if (line.contains("Locked ownable synchronizers:")) {
                        concurrentSyncsFlag = true;
                        content.append(line);
                        content.append('\n');
                    } else if (line.contains("- waiting on")) {
                        content.append(linkifyMonitor(line));
                        monitorStack.push(line);
                        inSleeping = true;
                        content.append('\n');
                    } else if (line.contains("- parking to wait")) {
                        content.append(linkifyMonitor(line));
                        monitorStack.push(line);
                        inSleeping = true;
                        content.append('\n');
                    } else if (line.contains("- waiting to")) {
                        content.append(linkifyMonitor(line));
                        monitorStack.push(line);
                        inWaiting = true;
                        content.append('\n');
                    } else if (line.contains("- locked")) {
                        content.append(linkifyMonitor(line));
                        inLocking = true;
                        monitorStack.push(line);
                        content.append('\n');
                    } else if (line.contains("- ")) {
                        if (concurrentSyncsFlag) {
                            content.append(linkifyMonitor(line));
                            monitorStack.push(line);
                        } else {
                            content.append(line);
                        }
                        content.append('\n');
                    }

                    // last thread reached?
                    if ((line.contains("\"Suspend Checker Thread\""))
                            || (line.contains("\"VM Periodic Task Thread\""))
                            || (line.contains("<EndOfDump>"))) {
                        finished = true;
                        getBis().mark(getMarkSize());
                        if ((checkForDeadlocks(threadDump)) == 0) {
                            // no deadlocks found, set back original position.
                            getBis().reset();
                        }

                        if (!checkThreadDumpStatData(overallTDI)) {
                            // no statistical data found, set back original position.
                            getBis().reset();
                        }

                        getBis().mark(getMarkSize());
                        if (!(foundClassHistograms = checkForClassHistogram(threadDump))) {
                            getBis().reset();
                        }
                    }
                }
            }
            // last thread
            String stringContent = content != null ? content.toString() : null;
            if (title != null) {
                threads.put(title, content.toString());
                content.append("</pre></pre>");
                addToCategory(catThreads, title, null, stringContent, singleLineCounter, true);
                threadCount++;
            }
            if (inWaiting) {
                addToCategory(catWaiting, title, null, stringContent, singleLineCounter, true);
                waiting++;
            }
            if (inSleeping) {
                addToCategory(catSleeping, title, null, stringContent, singleLineCounter, true);
                sleeping++;
            }
            if (inLocking) {
                addToCategory(catLocking, title, null, stringContent, singleLineCounter, true);
                locking++;
            }
            while (!monitorStack.empty()) {
                mmap.parseAndAddThread(monitorStack.pop(), title, content.toString());
            }

            int monitorCount = mmap.size();

            int monitorsWithoutLocksCount = 0;
            int contendedMonitors = 0;
            int blockedThreads = 0;
            // dump monitors 
            if (mmap.size() > 0) {
                int[] result = dumpMonitors(catMonitors, catMonitorsLocks, mmap);
                monitorsWithoutLocksCount = result[0];
                overallTDI.setOverallThreadsWaitingWithoutLocksCount(result[1]);

                result = dumpBlockingMonitors(catBlockingMonitors, mmap);
                contendedMonitors = result[0];
                blockedThreads = result[1];
            }

            // display nodes with stuff to display
            if (waiting > 0) {
                overallTDI.setWaitingThreads((Category) catWaiting.getUserObject());
                threadDump.add(catWaiting);
            }

            if (sleeping > 0) {
                overallTDI.setSleepingThreads((Category) catSleeping.getUserObject());
                threadDump.add(catSleeping);
            }

            if (locking > 0) {
                overallTDI.setLockingThreads((Category) catLocking.getUserObject());
                threadDump.add(catLocking);
            }

            if (monitorCount > 0) {
                overallTDI.setMonitors((Category) catMonitors.getUserObject());
                threadDump.add(catMonitors);
            }

            if (contendedMonitors > 0) {
                overallTDI.setBlockingMonitors((Category) catBlockingMonitors.getUserObject());
                threadDump.add(catBlockingMonitors);
            }

            if (monitorsWithoutLocksCount > 0) {
                overallTDI.setMonitorsWithoutLocks((Category) catMonitorsLocks.getUserObject());
                threadDump.add(catMonitorsLocks);
            }
            overallTDI.setThreads((Category) catThreads.getUserObject());

            ((Category) catThreads.getUserObject())
                    .setName(catThreads.getUserObject() + " (" + threadCount + " Threads overall)");
            ((Category) catWaiting.getUserObject())
                    .setName(catWaiting.getUserObject() + " (" + waiting + " Threads waiting)");
            ((Category) catSleeping.getUserObject())
                    .setName(catSleeping.getUserObject() + " (" + sleeping + " Threads sleeping)");
            ((Category) catLocking.getUserObject())
                    .setName(catLocking.getUserObject() + " (" + locking + " Threads locking)");
            ((Category) catMonitors.getUserObject())
                    .setName(catMonitors.getUserObject() + " (" + monitorCount + " Monitors)");
            ((Category) catBlockingMonitors.getUserObject()).setName(catBlockingMonitors.getUserObject() + " ("
                    + blockedThreads + " Threads blocked by " + contendedMonitors + " Monitors)");
            ((Category) catMonitorsLocks.getUserObject()).setName(
                    catMonitorsLocks.getUserObject() + " (" + monitorsWithoutLocksCount + " Monitors)");
            // add thread dump to passed dump store.
            if ((threadCount > 0) && (dumpKey != null)) {
                threadStore.put(dumpKey.trim(), threads);
            }

            // check custom categories
            addCustomCategories(threadDump);

            return (threadCount > 0 ? threadDump : null);
        } catch (StringIndexOutOfBoundsException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null,
                    "Error during parsing of a found thread dump, skipping to next one!\n"
                            + "Check for possible broken dumps, sometimes, stream flushing mixes the logged data.\n"
                            + "Error Message is \"" + e.getLocalizedMessage() + "\". \n"
                            + (line != null ? "Last line read was \"" + line + "\". \n" : ""),
                    "Error during Parsing Thread Dump", JOptionPane.ERROR_MESSAGE);
            retry = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
    } while (retry);

    return (null);
}

From source file:nz.govt.natlib.ndha.manualdeposit.customui.IconRenderer.java

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    this.setToolTipText("");
    DepositTreeModel model = null;/*from   ww w .  j  ava  2 s  .  c om*/
    //      MD5Digest digest = null;
    ChecksumDigest digest = null;
    if (tree.getModel() instanceof DepositTreeModel) {
        model = (DepositTreeModel) tree.getModel();
        digest = model.getChecksumDigest();
    }
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    if ((node.getParent() != null) && (node.getUserObject() instanceof FileGroupCollection)
            && (model.getChecksumDigest() != null) && !(model.getChecksumDigest().isFixitySuccessful(node))) {
        setIcon(folderHomeIcon);
        this.setForeground(java.awt.Color.red);
    } else if (node.getUserObject() instanceof FileSystemObject) {
        FileSystemObject fso = (FileSystemObject) node.getUserObject();
        if (digest != null && fso.getOriginalChecksum() != null) {
            if (!fso.checksumMatches()) {
                this.setForeground(java.awt.Color.red);
                this.setToolTipText("Invalid Fixity value");
            } else {
                this.setForeground(new Color(0, 125, 0));
                this.setToolTipText("File has correct fixity value");
            }
        } else if (digest != null && fso.getIsDuplicate()) {
            this.setForeground(new Color(255, 127, 80));
            this.setToolTipText("Duplicate filename in checksum digest");
        } else if (digest != null && digest.getFileStatus(fso) == null && fso.getIsFile()) {
            this.setForeground(java.awt.Color.blue);
            this.setToolTipText("File is not listed in checksum Digest");
        }
        if (model != null && model.getTreeType() == ETreeType.FileSystemTree) {
            if (fso.getIsFile()) {
                setIcon(getMimeTypeIcon(fso));
            } else {
                setIcon(folderFileSystemIcon);
            }
        } else if (model != null && model.getTreeType() == ETreeType.EntityTree) {
            if (fso.getIsFile()) {
                setIcon(getMimeTypeIcon(fso));
            } else {
                setIcon(folderEntityIcon);
            }
        } else if (model != null && model.getTreeType() == ETreeType.StructMapTree) {
            if (fso.getIsFile()) {
                setIcon(getMimeTypeIcon(fso));
            } else {
                setIcon(folderFileSystemIcon);
            }
        }
    } else if (node.getUserObject() instanceof FileGroup) {
        FileGroup group = (FileGroup) node.getUserObject();
        if (group.getEntityType() == RepresentationTypes.DigitalOriginal) {
            setIcon(digitalOriginalIcon);
        } else if (group.getEntityType() == RepresentationTypes.PreservationMaster) {
            setIcon(preservationCopyIcon);
        } else if (group.getEntityType() == RepresentationTypes.ModifiedMaster) {
            setIcon(modifiedMasterIcon);
        } else if (group.getEntityType() == RepresentationTypes.AccessCopy
                || group.getEntityType() == RepresentationTypes.AccessCopy_High
                || group.getEntityType() == RepresentationTypes.AccessCopy_Medium
                || group.getEntityType() == RepresentationTypes.AccessCopy_Low
                || group.getEntityType() == RepresentationTypes.AccessCopy_Epub
                || group.getEntityType() == RepresentationTypes.AccessCopy_Pdf) {
            setIcon(accessCopyIcon);
        } else {
            setIcon(digitalOriginalIcon);
        }
    } else if (node.getUserObject() instanceof StructMap) {
        setIcon(structMapIcon);
    } else {
        setIcon(folderHomeIcon);

        // Build tooltip at SIP level, to inform user of all colour coded issues with this SIP.
        String toolTipText = "";
        if ((node.getParent() == null) && (node.getUserObject() != null) && (model != null)
                && (model.getChecksumDigest() != null)) {
            if (model.getChecksumDigest().getMissingFiles().size() > 0) {
                toolTipText = "Some files from checksum digest can't be located.";
            }
            if (model.getChecksumDigest().getFilesMissingFromDigest(node).size() > 0) {
                if (toolTipText.isEmpty())
                    toolTipText = "Some files not listed in the checksum digest. (BLUE)";
                else
                    toolTipText = toolTipText + "<br>" + "Some files not listed in the checksum digest. (BLUE)";
            }
            if (model.getChecksumDigest().hasDuplicateFiles(node)) {
                if (toolTipText.isEmpty())
                    toolTipText = "Duplicate files in checksum digest. (ORANGE)";
                else
                    toolTipText = toolTipText + "<br>" + "Duplicate files in checksum digest. (ORANGE)";
            }
            if (!(model.getChecksumDigest().isFixitySuccessful(node))) {
                if (toolTipText.isEmpty())
                    toolTipText = "Files with invalid fixity values. (RED)";
                else
                    toolTipText = toolTipText + "<br>" + "Files with invalid fixity values. (RED)";
            }
        }
        if (!toolTipText.isEmpty()) {
            this.setForeground(java.awt.Color.red);
            toolTipText = "<html>" + toolTipText + "</html>";
            this.setToolTipText(toolTipText);
        }

        // If an IE has customized Metadata then change colour of entity
        if (node.getUserObject() != null) {
            if (node.getUserObject() instanceof FileGroupCollection
                    && (!node.getUserObject().toString().equals("Preservation Master"))) {
                FileGroupCollection entity = (FileGroupCollection) node.getUserObject();
                if (entity.isCustomized()) {
                    this.setForeground(java.awt.Color.MAGENTA);
                    this.setToolTipText("IE has customized Metadata.");
                }
            }
        }
    }
    repaint();
    return this;
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

private void setSortBy() {
    DefaultTreeModel model = (DefaultTreeModel) treeFileSystem.getModel();
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) model.getRoot();
    if (node.getUserObject() instanceof FileSystemObject) {
        FileSystemObject fso = (FileSystemObject) node.getUserObject();
        fso.setSortBy(getCurrentSortBy());
        theAppProperties.getApplicationData().getPersonalSettings().setSortFilesBy(getCurrentSortBy());
        depositPresenter.addFileSystemRoot(fso, false, false, theCurrentDirectory);
    }/*from  w  ww.jav  a 2  s . co m*/
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

private void moveItem(boolean moveUp) {
    if ((moveUp && mnuHotKeysMoveFileUp.isEnabled()) || (!moveUp && mnuHotKeysMoveFileDown.isEnabled())) {
        if (theCurrentCursorPosition == ScreenPosition.intellectualEntity) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeEntities.getSelectionPath()
                    .getLastPathComponent();
            DefaultMutableTreeNode nodeParent = (DefaultMutableTreeNode) node.getParent();
            FileSystemObject file = (FileSystemObject) node.getUserObject();
            depositPresenter.moveIEFile(file, nodeParent.getUserObject(), moveUp);
        } else { // Must be in the Struct Map
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeStructMap.getSelectionPath()
                    .getLastPathComponent();
            DefaultMutableTreeNode nodeParent = (DefaultMutableTreeNode) node.getParent();
            depositPresenter.moveStructObject(node.getUserObject(), nodeParent.getUserObject(), moveUp);
        }/*from  ww w  .  j a  va 2s  .c om*/
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

private void setHotKeyVisibility() {
    boolean fileSystemEntityRootNotSet = ((theCurrentCursorPosition == ScreenPosition.fileSystem)
            && (!depositPresenter.getEntityRootSet()));
    mnuHotKeysMenu.setVisible(fileSystemEntityRootNotSet);
    mnuHotKeysSetIE.setVisible(fileSystemEntityRootNotSet);
    mnuHotKeysSetEachFileIE//from w  w w .j  a  v  a2  s  .  c om
            .setVisible(fileSystemEntityRootNotSet && depositPresenter.getIncludeMultiEntityMenuItem());
    boolean fileSystemEntityRootSet = ((theCurrentCursorPosition == ScreenPosition.fileSystem)
            && (depositPresenter.getEntityRootSet()));
    mnuHotKeysDigitalOriginal
            .setVisible(fileSystemEntityRootSet && depositPresenter.canAddRepresentationType('d'));
    mnuHotKeysAccessCopy.setVisible(fileSystemEntityRootSet && depositPresenter.canAddRepresentationType('a'));
    mnuHotKeysAccessCopyHigh
            .setVisible(fileSystemEntityRootSet && depositPresenter.canAddRepresentationType('h'));
    mnuHotKeysAccessCopyMedium
            .setVisible(fileSystemEntityRootSet && depositPresenter.canAddRepresentationType('i'));
    mnuHotKeysAccessCopyLow
            .setVisible(fileSystemEntityRootSet && depositPresenter.canAddRepresentationType('l'));
    mnuHotKeysAccessCopyEpub
            .setVisible(fileSystemEntityRootSet && depositPresenter.canAddRepresentationType('b'));
    mnuHotKeysAccessCopyPdf
            .setVisible(fileSystemEntityRootSet && depositPresenter.canAddRepresentationType('c'));
    mnuHotKeysModifiedMaster
            .setVisible(fileSystemEntityRootSet && depositPresenter.canAddRepresentationType('m'));
    mnuHotKeysPreservationCopy
            .setVisible(fileSystemEntityRootSet && depositPresenter.canAddRepresentationType('p'));
    mnuHotKeysMakeStruct.setVisible(false);
    mnuHotKeysSelectAllFiles.setVisible(false);
    if (theCurrentCursorPosition == ScreenPosition.fileSystem) {
        TreePath[] paths = treeFileSystem.getSelectionPaths();
        mnuHotKeysOpenFile.setVisible(true);
        mnuHotKeysStoreAsFavourite.setVisible(true);
        mnuHotKeysOpenFile.setEnabled(depositPresenter.canOpenFiles(paths));
        mnuHotKeysStoreAsFavourite.setEnabled(depositPresenter.canStoreFavourites(paths));
        mnuHotKeysSetIE.setEnabled(depositPresenter.canSetIE());
        mnuHotKeysUseFileForIE.setEnabled(depositPresenter.canSetFileAsIE());
    } else {
        mnuHotKeysOpenFile.setVisible(false);
        mnuHotKeysStoreAsFavourite.setVisible(false);
    }
    if (theCurrentCursorPosition == ScreenPosition.intellectualEntity) {
        mnuHotKeysMoveFileUp.setVisible(true);
        mnuHotKeysMoveFileDown.setVisible(true);
        mnuHotKeysMoveFileUp.setText("<Alt>Up - Move file up IE");
        mnuHotKeysMoveFileDown.setText("<Alt>Down - Move file down IE");
        mnuHotKeysDelete.setText("<Delete> - Delete file(s) or folder(s) from IE");
        mnuHotKeysDelete.setEnabled(depositPresenter.canDeleteEntityItem());
        mnuHotKeysMakeStruct.setVisible(true);
        mnuHotKeysSelectAllFiles.setVisible(true);
        mnuHotKeysMakeStruct.setEnabled(depositPresenter.canCreateAutoStructItem());
        mnuHotKeysSelectAllFiles.setEnabled(depositPresenter.canCreateAutoStructItem());
        if (treeEntities.getSelectionPath() == null) {
            mnuHotKeysMoveFileUp.setEnabled(false);
            mnuHotKeysMoveFileDown.setEnabled(false);
        } else {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeEntities.getSelectionPath()
                    .getLastPathComponent();
            DefaultMutableTreeNode nodeParent = (DefaultMutableTreeNode) node.getParent();
            if (nodeParent != null && (node.getUserObject() instanceof FileSystemObject)) {
                FileSystemObject file = (FileSystemObject) node.getUserObject();
                mnuHotKeysMoveFileUp
                        .setEnabled(depositPresenter.canMoveIEFile(file, nodeParent.getUserObject(), true));
                mnuHotKeysMoveFileDown
                        .setEnabled(depositPresenter.canMoveIEFile(file, nodeParent.getUserObject(), false));
            } else {
                mnuHotKeysMoveFileUp.setEnabled(false);
                mnuHotKeysMoveFileDown.setEnabled(false);
            }
        }
    } else if (theCurrentCursorPosition == ScreenPosition.structMap) {
        mnuHotKeysMoveFileUp.setVisible(true);
        mnuHotKeysMoveFileDown.setVisible(true);
        mnuHotKeysMoveFileUp.setText("<Alt>Up - Move file up Struct Map");
        mnuHotKeysMoveFileDown.setText("<Alt>Down - Move file down Struct Map");
        mnuHotKeysDelete.setText("<Delete> - Delete file or structure item(s) from structure map");
        mnuHotKeysDelete.setEnabled(depositPresenter.canDeleteStructItem());
        if (treeStructMap.getSelectionPath() == null) {
            mnuHotKeysMoveFileUp.setEnabled(false);
            mnuHotKeysMoveFileDown.setEnabled(false);
        } else {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeStructMap.getSelectionPath()
                    .getLastPathComponent();
            DefaultMutableTreeNode nodeParent = (DefaultMutableTreeNode) node.getParent();
            if (nodeParent != null && (node.getUserObject() instanceof FileSystemObject)
                    || (node.getUserObject() instanceof StructMap)) {
                mnuHotKeysMoveFileUp.setEnabled(depositPresenter.canMoveStructObject(node.getUserObject(),
                        nodeParent.getUserObject(), true));
                mnuHotKeysMoveFileDown.setEnabled(depositPresenter.canMoveStructObject(node.getUserObject(),
                        nodeParent.getUserObject(), false));
            } else {
                mnuHotKeysMoveFileUp.setEnabled(false);
                mnuHotKeysMoveFileDown.setEnabled(false);
            }
        }
    } else {
        mnuHotKeysDelete.setVisible(false);
        mnuHotKeysMoveFileUp.setVisible(false);
        mnuHotKeysMoveFileDown.setVisible(false);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public JPopupMenu getFileSystemMenu(final DefaultMutableTreeNode node) {
    JPopupMenu menu = null;/* ww w . ja va  2s .co  m*/
    fsoRootFileTemp = null;
    if (node.getUserObject() instanceof FileSystemObject) {
        boolean allowBulkUpload = false;
        final FileSystemObject fso = (FileSystemObject) node.getUserObject();
        menu = new JPopupMenu();
        if ((fso != null) && (fso.getFile() != null) && (fso.getFile().exists())) {
            if (!entityRootSet) {
                stopEditingMetaData();
                allowBulkUpload = applicationProperties.getUserData()
                        .getUser(applicationProperties.getLoggedOnUser()).isAllowBulkLoad();
                String addRootText;
                boolean canAddMultiRoot = false;
                setCustomizeMetaData(false);
                if (fso.getIsFile()) {
                    addRootText = "Use file to describe IE root";
                    final DefaultMutableTreeNode nodeParent = (DefaultMutableTreeNode) node.getParent();
                    if (nodeParent.getUserObject() instanceof FileSystemObject) {
                        fsoRootTemp = (FileSystemObject) nodeParent.getUserObject();
                        fsoRootFileTemp = fso;
                    } else {
                        fsoRootTemp = fso;
                    }
                } else {
                    addRootText = "Set as root of Intellectual Entity";
                    canAddMultiRoot = (userGroupData != null && userGroupData.isIncludeMultiEntityMenuItem());
                    fsoRootTemp = fso;
                }
                JMenuItem item = new JMenuItem(addRootText);
                item.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(final java.awt.event.ActionEvent evt) {
                        manualDepositFrame.setWaitCursor(true);
                        itmSetRootActionPerformed(evt);
                        manualDepositFrame.setWaitCursor(false);
                    }
                });
                menu.add(item);
                if (canAddMultiRoot) {
                    item = new JMenuItem("Set each file as an Intellectual Entity");
                    item.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(final java.awt.event.ActionEvent evt) {
                            itmSetMultipleRootActionPerformed(evt);
                        }
                    });
                    menu.add(item);

                    // Added 5/09/2013 by Ben
                    // New menu option for creating multiple complex IEs
                    item = new JMenuItem("Set each folder as an Intellectual Entity");
                    item.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(final java.awt.event.ActionEvent evt) {
                            itmSetMultipleRootFolderActionPerformed(evt);
                        }
                    });
                    menu.add(item);

                }
            }
            if (fso.getIsFile()) {
                if (menu.getComponentCount() > 0) {
                    menu.addSeparator();
                }
                if (isWindows()) {
                    JMenuItem item = new JMenuItem("Open File");
                    item.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(final java.awt.event.ActionEvent evt) {
                            itmOpenFile(evt);
                        }
                    });
                    menu.add(item);

                    item = new JMenuItem("Open File Location");
                    item.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(final java.awt.event.ActionEvent evt) {
                            itmOpenFileLocation(evt);
                        }
                    });
                    menu.add(item);
                }
            } else {
                if (menu.getComponentCount() > 0) {
                    menu.addSeparator();
                }
                JMenuItem item = new JMenuItem("Store this directory as a favourite");
                item.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(final java.awt.event.ActionEvent evt) {
                        itmStoreAsFavourite(evt);
                    }
                });
                menu.add(item);
                item = new JMenuItem("Refresh directory file list");
                item.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(final java.awt.event.ActionEvent evt) {
                        itmRefreshDirectory(evt);
                    }
                });
                menu.add(item);
                if (allowBulkUpload) {
                    item = new JMenuItem("Bulk load this directory");
                    item.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(final java.awt.event.ActionEvent evt) {
                            bulkLoadDirectory(evt);
                        }
                    });
                    if (!metaDataOkay(false)) {
                        item.setEnabled(false);
                        item.setToolTipText("Meta data incomplete");
                    }
                    menu.add(item);

                    item = new JMenuItem("Bulk load each file as an Intellectual Entity");
                    item.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(final java.awt.event.ActionEvent evt) {
                            bulkLoadDirectoryAsIEs(evt);
                        }
                    });
                    if (!metaDataOkay(false)) {
                        item.setEnabled(false);
                        item.setToolTipText("Meta data incomplete");
                    }
                    menu.add(item);
                }
            }
        }
    }
    if (menu == null || menu.getComponentCount() == 0) {
        return null;
    } else {
        return menu;
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

private DefaultMutableTreeNode findNode(DefaultMutableTreeNode node, Object userObject) {
    DefaultMutableTreeNode retVal = null;
    if (node.getUserObject().equals(userObject)) {
        retVal = node;//from  ww  w.  j av  a  2s  .  co m
    }
    if (retVal == null) {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode nodeChild = (DefaultMutableTreeNode) node.getChildAt(i);
            retVal = findNode(nodeChild, userObject);
            if (retVal != null) {
                break;
            }
        }
    }
    return retVal;
}