List of usage examples for javax.swing.tree DefaultMutableTreeNode getParent
public TreeNode getParent()
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
/** {@inheritDoc} *///from www. ja va2 s .c om @Override public boolean onButtonPress(final Button button) { if (Button.NEXT.equals(button)) { ParameterTree parameterTree = null; if (tabbedPane.getSelectedIndex() == SINGLE_RUN_GUI_TABINDEX) { currentModelHandler.setIntelliMethodPlugin(null); parameterTree = new ParameterTree(); final Set<ParameterInfo> invalids = new HashSet<ParameterInfo>(); @SuppressWarnings("rawtypes") final Enumeration treeValues = parameterValueComponentTree.breadthFirstEnumeration(); treeValues.nextElement(); // root element while (treeValues.hasMoreElements()) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeValues.nextElement(); @SuppressWarnings("unchecked") final Pair<ParameterInfo, JComponent> userData = (Pair<ParameterInfo, JComponent>) node .getUserObject(); final ParameterInfo parameterInfo = userData.getFirst(); final JComponent valueContainer = userData.getSecond(); if (parameterInfo instanceof ISubmodelGUIInfo) { final ISubmodelGUIInfo sgi = (ISubmodelGUIInfo) parameterInfo; if (sgi.getParent() != null) { final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); @SuppressWarnings("unchecked") final Pair<ParameterInfo, JComponent> parentUserData = (Pair<ParameterInfo, JComponent>) parentNode .getUserObject(); final SubmodelInfo parentParameterInfo = (SubmodelInfo) parentUserData.getFirst(); if (invalids.contains(parentParameterInfo) || !classEquals(parentParameterInfo.getActualType(), sgi.getParentValue())) { invalids.add(parameterInfo); continue; } } } if (parameterInfo.isBoolean()) { final JCheckBox checkBox = (JCheckBox) valueContainer; parameterInfo.setValue(checkBox.isSelected()); } else if (parameterInfo.isEnum()) { final JComboBox comboBox = (JComboBox) valueContainer; parameterInfo.setValue(comboBox.getSelectedItem()); } else if (parameterInfo instanceof MasonChooserParameterInfo) { final JComboBox comboBox = (JComboBox) valueContainer; parameterInfo.setValue(comboBox.getSelectedIndex()); } else if (parameterInfo instanceof SubmodelInfo) { // we don't need the SubmodelInfo parameters anymore (all descendant parameters are in the tree too) // but we need to check that an actual type is provided final SubmodelInfo smi = (SubmodelInfo) parameterInfo; final JComboBox comboBox = (JComboBox) ((JPanel) valueContainer).getComponent(0); final ClassElement selected = (ClassElement) comboBox.getSelectedItem(); smi.setActualType(selected.clazz, selected.instance); if (smi.getActualType() == null) { final String errorMsg = "Please select a type from the dropdown list of " + smi.getName().replaceAll("([A-Z])", " $1"); JOptionPane.showMessageDialog(wizard, new JLabel(errorMsg), "Error", JOptionPane.ERROR_MESSAGE); return false; } //continue; } else if (parameterInfo.isFile()) { final JTextField textField = (JTextField) valueContainer.getComponent(0); if (textField.getText().trim().isEmpty()) log.warn("Empty string was specified as file parameter " + parameterInfo.getName().replaceAll("([A-Z])", " $1")); final File file = new File(textField.getToolTipText()); if (!file.exists()) { final String errorMsg = "Please specify an existing file parameter " + parameterInfo.getName().replaceAll("([A-Z])", " $1"); JOptionPane.showMessageDialog(wizard, new JLabel(errorMsg), "Error", JOptionPane.ERROR_MESSAGE); return false; } parameterInfo.setValue( ParameterInfo.getValue(textField.getToolTipText(), parameterInfo.getType())); } else if (parameterInfo instanceof MasonIntervalParameterInfo) { final JTextField textField = (JTextField) valueContainer.getComponent(0); parameterInfo.setValue( ParameterInfo.getValue(textField.getText().trim(), parameterInfo.getType())); } else { final JTextField textField = (JTextField) valueContainer; parameterInfo .setValue(ParameterInfo.getValue(textField.getText(), parameterInfo.getType())); if ("String".equals(parameterInfo.getType()) && parameterInfo.getValue() == null) parameterInfo.setValue(textField.getText().trim()); } final AbstractParameterInfo<?> batchParameterInfo = InfoConverter .parameterInfo2ParameterInfo(parameterInfo); parameterTree.addNode(batchParameterInfo); } dashboard.setOnLineCharts(onLineChartsCheckBox.isSelected()); dashboard.setDisplayAdvancedCharts(advancedChartsCheckBox.isSelected()); } if (tabbedPane.getSelectedIndex() == PARAMSWEEP_GUI_TABINDEX) { currentModelHandler.setIntelliMethodPlugin(null); boolean success = true; if (editedNode != null) success = modify(); if (success) { String invalidInfoName = checkInfos(true); if (invalidInfoName != null) { Utilities.userAlert(sweepPanel, "Please select a type from the dropdown list of " + invalidInfoName); return false; } invalidInfoName = checkInfos(false); if (invalidInfoName != null) { Utilities.userAlert(sweepPanel, "Please specify a file for parameter " + invalidInfoName); return false; } if (needWarning()) { final int result = Utilities.askUser(sweepPanel, false, "Warning", "There are two or more combination boxes that contains non-constant parameters." + " Parameters are unsynchronized:", "simulation may exit before all parameter values are assigned.", " ", "To explore all possible combinations you must use only one combination box.", " ", "Do you want to run simulation with these parameter settings?"); if (result == 0) { return false; } } try { parameterTree = createParameterTreeFromParamSweepGUI(); final ParameterNode rootNode = parameterTree.getRoot(); dumpParameterTree(rootNode); // dashboard.setOnLineCharts(onLineChartsCheckBoxPSW.isSelected()); } catch (final ModelInformationException e) { JOptionPane.showMessageDialog(wizard, new JLabel(e.getMessage()), "Error while creating runs", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); return false; } } else return false; } if (tabbedPane.getSelectedIndex() == GASEARCH_GUI_TABINDEX) { final IIntelliDynamicMethodPlugin gaPlugin = (IIntelliDynamicMethodPlugin) gaSearchHandler; currentModelHandler.setIntelliMethodPlugin(gaPlugin); boolean success = gaSearchPanel.closeActiveModification(); if (success) { String invalidInfoName = checkInfosInGeneTree(); if (invalidInfoName != null) { Utilities.userAlert(sweepPanel, "Please select a type from the dropdown list of " + invalidInfoName); return false; } final String[] errors = gaSearchHandler.checkGAModel(); if (errors != null) { Utilities.userAlert(sweepPanel, (Object[]) errors); return false; } final DefaultMutableTreeNode parameterTreeRootNode = new DefaultMutableTreeNode(); final IIntelliContext ctx = new DashboardIntelliContext(parameterTreeRootNode, gaSearchHandler.getChromosomeTree()); gaPlugin.alterParameterTree(ctx); parameterTree = InfoConverter.node2ParameterTree(parameterTreeRootNode); dashboard.setOptimizationDirection(gaSearchHandler.getFitnessFunctionDirection()); } else return false; } currentModelHandler.setParameters(parameterTree); } return true; }
From source file:edu.ku.brc.specify.tasks.subpane.security.SecurityAdminPane.java
/** * //from www . j av a 2 s. co m */ private void createNavigationTree() { TreeSelectionListener tsl = new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent tse) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null || !(node.getUserObject() instanceof DataModelObjBaseWrapper)) { // Nothing is selected or object type isn't relevant clearPanels(); return; } // ask if user he wants to discard changes if that's the case if (!aboutToShutdown()) { clearPanels(); return; } DataModelObjBaseWrapper dataWrp = (DataModelObjBaseWrapper) (node.getUserObject()); // get parent if it is a user /*DataModelObjBaseWrapper userObjWrp = null; DataModelObjBaseWrapper groupObjWrp = null; DataModelObjBaseWrapper collectionWrp = null; Object dataObj = dataWrp.getDataObj(); if (dataObj instanceof SpecifyUser) { // XXX Also might need to check to see if anyone is logged into the Group // when editing a Group SpecifyUser currentUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class); SpecifyUser spUser = (SpecifyUser)dataObj; if (!spUser.getIsLoggedIn() || currentUser.getId().equals(spUser.getId())) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); userObjWrp = (DataModelObjBaseWrapper) node.getUserObject(); groupObjWrp = (DataModelObjBaseWrapper) parent.getUserObject(); collectionWrp = (DataModelObjBaseWrapper) ((DefaultMutableTreeNode)parent.getParent()).getUserObject(); } else { UIRegistry.showLocalizedError("SecuirytAdminPane.USR_IS_ON", spUser.getName()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { tree.clearSelection(); } }); return; } } nodesDiscipline = navTreeMgr.getParentOfClass(node, Discipline.class); nodesDivision = nodesDiscipline != null ? nodesDiscipline.getDivision() : null; showInfoPanel(dataWrp, userObjWrp, groupObjWrp, collectionWrp, node.toString()); updateUIEnabled(dataWrp);*/ // get parent if it is a user DataModelObjBaseWrapper secondObjWrp = null; DataModelObjBaseWrapper collectionWrp = null; Object dataObj = dataWrp.getDataObj(); if (dataObj instanceof SpecifyUser) { // XXX Also might need to check to see if anyone is logged into the Group // when editing a Group SpecifyUser currentUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class); SpecifyUser spUser = (SpecifyUser) dataObj; if (!spUser.getIsLoggedIn() || currentUser.getId().equals(spUser.getId())) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); secondObjWrp = (DataModelObjBaseWrapper) parent.getUserObject(); collectionWrp = (DataModelObjBaseWrapper) ((DefaultMutableTreeNode) parent.getParent()) .getUserObject(); } else { UIRegistry.showLocalizedError("SecuirytAdminPane.USR_IS_ON", spUser.getName()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { tree.clearSelection(); } }); return; } } nodesDiscipline = navTreeMgr.getParentOfClass(node, Discipline.class); nodesDivision = nodesDiscipline != null ? nodesDiscipline.getDivision() : null; showInfoPanel(dataWrp, secondObjWrp, collectionWrp, node.toString()); updateUIEnabled(dataWrp); } }; DefaultTreeModel model = createNavigationTreeModel(); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setRootVisible(false); tree.setCellRenderer(new MyTreeCellRenderer()); tree.addTreeSelectionListener(tsl); // Expand the tree for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i); } for (int i = tree.getRowCount() - 1; i >= 1; i--) { if (tree.getPathForRow(i).getPathCount() > 3) { tree.collapseRow(i); } } navTreeMgr = new NavigationTreeMgr(tree, spUsers); // create object that will control the creation of popups // constructor will take care of hooking up right listeners to the tree. navTreeContextMgr = new NavigationTreeContextMenuMgr(navTreeMgr); IconManager.IconSize iconSize = IconManager.IconSize.Std20; ImageIcon sysIcon = IconManager.getIcon("SystemSetup", iconSize); JLabel label = createLabel("XXXX"); label.setIcon(sysIcon); label.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0)); tree.setRowHeight(label.getPreferredSize().height); // Why doesn't this work? SwingUtilities.invokeLater(new Runnable() { @Override public void run() { tree.expandRow(1); } }); //expandAll(tree, true); }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
private JPanel createAParameterBox(final boolean first) { final JLabel runLabel = new JLabel("<html><b>Number of runs:</b> 0</html>"); final JLabel warningLabel = new JLabel(); final JButton closeButton = new JButton(); closeButton.setOpaque(false);/*from w ww. jav a 2 s .c o m*/ closeButton.setBorder(null); closeButton.setFocusable(false); if (!first) { closeButton.setRolloverIcon(PARAMETER_BOX_REMOVE); closeButton.setRolloverEnabled(true); closeButton.setIcon(RGBGrayFilter.getDisabledIcon(closeButton, PARAMETER_BOX_REMOVE)); closeButton.setActionCommand(ACTIONCOMMAND_REMOVE_BOX); } final JScrollPane treeScrPane = new JScrollPane(); final DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(); final JTree tree = new JTree(treeRoot); ToolTipManager.sharedInstance().registerComponent(tree); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setCellRenderer(new ParameterBoxTreeRenderer()); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(final TreeSelectionEvent e) { final TreePath selectionPath = tree.getSelectionPath(); boolean success = true; if (editedNode != null && (selectionPath == null || !editedNode.equals(selectionPath.getLastPathComponent()))) success = modify(); if (success) { if (selectionPath != null) { cancelAllSelectionBut(tree); final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); if (!node.equals(editedNode)) { ParameterInATree userObj = null; final DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); if (!node.isRoot() && selectionPath.getPathCount() == model.getPathToRoot(node).length) { userObj = (ParameterInATree) node.getUserObject(); final ParameterInfo info = userObj.info; editedNode = node; editedTree = tree; edit(info); } else { tree.setSelectionPath(null); if (cancelButton.isEnabled()) cancelButton.doClick(); resetSettings(); enableDisableSettings(false); editedNode = null; editedTree = null; } updateDescriptionField(userObj); } else updateDescriptionField(); } else updateDescriptionField(); enableDisableParameterCombinationButtons(); } else { final DefaultTreeModel model = (DefaultTreeModel) editedTree.getModel(); final DefaultMutableTreeNode storedEditedNode = editedNode; editedNode = null; tree.setSelectionPath(null); editedNode = storedEditedNode; editedTree.setSelectionPath(new TreePath(model.getPathToRoot(editedNode))); } } }); treeScrPane.setViewportView(tree); treeScrPane.setBorder(null); treeScrPane.setViewportBorder(null); treeScrPane.setPreferredSize(new Dimension(450, 250)); final JButton upButton = new JButton(); upButton.setOpaque(false); upButton.setRolloverEnabled(true); upButton.setIcon(PARAMETER_UP_ICON); upButton.setRolloverIcon(PARAMETER_UP_ICON_RO); upButton.setDisabledIcon(PARAMETER_UP_ICON_DIS); upButton.setBorder(null); upButton.setToolTipText("Move up the selected parameter"); upButton.setActionCommand(ACTIONCOMMAND_MOVE_UP); final JButton downButton = new JButton(); downButton.setOpaque(false); downButton.setRolloverEnabled(true); downButton.setIcon(PARAMETER_DOWN_ICON); downButton.setRolloverIcon(PARAMETER_DOWN_ICON_RO); downButton.setDisabledIcon(PARAMETER_DOWN_ICON_DIS); downButton.setBorder(null); downButton.setToolTipText("Move down the selected parameter"); downButton.setActionCommand(ACTIONCOMMAND_MOVE_DOWN); final JPanel mainPanel = FormsUtils.build("~ f:p:g ~ p ~ r:p", "012||" + "333||" + "44_||" + "445||" + "446||" + "44_ f:p:g", runLabel, first ? "" : warningLabel, first ? warningLabel : closeButton, new FormsUtils.Separator(""), treeScrPane, upButton, downButton) .getPanel(); mainPanel.setBorder(BorderFactory.createTitledBorder("")); final JButton addButton = new JButton(); addButton.setOpaque(false); addButton.setRolloverEnabled(true); addButton.setIcon(PARAMETER_ADD_ICON); addButton.setRolloverIcon(PARAMETER_ADD_ICON_RO); addButton.setDisabledIcon(PARAMETER_ADD_ICON_DIS); addButton.setBorder(null); addButton.setToolTipText("Add selected parameter"); addButton.setActionCommand(ACTIONCOMMAND_ADD_PARAM); final JButton removeButton = new JButton(); removeButton.setOpaque(false); removeButton.setRolloverEnabled(true); removeButton.setIcon(PARAMETER_REMOVE_ICON); removeButton.setRolloverIcon(PARAMETER_REMOVE_ICON_RO); removeButton.setDisabledIcon(PARAMETER_REMOVE_ICON_DIS); removeButton.setBorder(null); removeButton.setToolTipText("Remove selected parameter"); removeButton.setActionCommand(ACTIONCOMMAND_REMOVE_PARAM); final JPanel result = FormsUtils.build("p ~ f:p:g", "_0 f:p:g||" + "10 p ||" + "20 p||" + "_0 f:p:g", mainPanel, addButton, removeButton).getPanel(); Style.registerCssClasses(result, Dashboard.CSS_CLASS_COMMON_PANEL); final ParameterCombinationGUI pcGUI = new ParameterCombinationGUI(tree, treeRoot, runLabel, warningLabel, addButton, removeButton, upButton, downButton); parameterTreeBranches.add(pcGUI); final ActionListener boxActionListener = new ActionListener() { //==================================================================================================== // methods //---------------------------------------------------------------------------------------------------- public void actionPerformed(final ActionEvent e) { final String cmd = e.getActionCommand(); if (ACTIONCOMMAND_ADD_PARAM.equals(cmd)) handleAddParameter(pcGUI); else if (ACTIONCOMMAND_REMOVE_PARAM.equals(cmd)) handleRemoveParameter(tree); else if (ACTIONCOMMAND_REMOVE_BOX.equals(cmd)) handleRemoveBox(tree); else if (ACTIONCOMMAND_MOVE_UP.equals(cmd)) handleMoveUp(); else if (ACTIONCOMMAND_MOVE_DOWN.equals(cmd)) handleMoveDown(); } //---------------------------------------------------------------------------------------------------- private void handleAddParameter(final ParameterCombinationGUI pcGUI) { final Object[] selectedValues = parameterList.getSelectedValues(); if (selectedValues != null && selectedValues.length > 0) { final AvailableParameter[] params = new AvailableParameter[selectedValues.length]; System.arraycopy(selectedValues, 0, params, 0, selectedValues.length); addParameterToTree(params, pcGUI); enableDisableParameterCombinationButtons(); } } //---------------------------------------------------------------------------------------------------- private void handleRemoveParameter(final JTree tree) { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { cancelButton.doClick(); final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); if (!node.isRoot()) { final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); if (parentNode.isRoot()) { removeParameter(tree, node, parentNode); enableDisableParameterCombinationButtons(); } } } } //---------------------------------------------------------------------------------------------------- private void handleRemoveBox(final JTree tree) { final int answer = Utilities.askUser(dashboard, false, "Comfirmation", "This operation deletes the combination.", "All related parameter returns back to the list on the left side.", "Are you sure?"); if (answer == 1) { final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); if (tree.getSelectionCount() > 0) { editedNode = null; tree.setSelectionPath(null); if (cancelButton.isEnabled()) cancelButton.doClick(); } final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot(); for (int i = 0; i < root.getChildCount(); ++i) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i); removeParameter(tree, node, root); } enableDisableParameterCombinationButtons(); parameterTreeBranches.remove(pcGUI); combinationsPanel.remove(result); combinationsPanel.revalidate(); updateNumberOfRuns(); } } //---------------------------------------------------------------------------------------------------- private void removeParameter(final JTree tree, final DefaultMutableTreeNode node, final DefaultMutableTreeNode parentNode) { final ParameterInATree userObj = (ParameterInATree) node.getUserObject(); final ParameterInfo originalInfo = findOriginalInfo(userObj.info); if (originalInfo != null) { final DefaultListModel model = (DefaultListModel) parameterList.getModel(); model.addElement(new AvailableParameter(originalInfo, currentModelHandler.getModelClass())); final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); treeModel.removeNodeFromParent(node); updateNumberOfRuns(); tree.expandPath(new TreePath(treeModel.getPathToRoot(parentNode))); } else throw new IllegalStateException( "Parameter " + userObj.info.getName() + " is not found in the model."); } //---------------------------------------------------------------------------------------------------- private void handleMoveUp() { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { boolean success = true; if (editedNode != null) success = modify(); if (success) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent == null || parent.getFirstChild().equals(node)) { tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel tree.setSelectionPath(new TreePath(node.getPath())); return; } final int index = parent.getIndex(node); final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel(); treemodel.removeNodeFromParent(node); treemodel.insertNodeInto(node, parent, index - 1); tree.setSelectionPath(new TreePath(node.getPath())); } } } //---------------------------------------------------------------------------------------------------- private void handleMoveDown() { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { boolean success = true; if (editedNode != null) success = modify(); if (success) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent == null || parent.getLastChild().equals(node)) { tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel tree.setSelectionPath(new TreePath(node.getPath())); return; } final int index = parent.getIndex(node); final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel(); treemodel.removeNodeFromParent(node); treemodel.insertNodeInto(node, parent, index + 1); tree.setSelectionPath(new TreePath(node.getPath())); } } } }; GUIUtils.addActionListener(boxActionListener, closeButton, upButton, downButton, addButton, removeButton); result.setPreferredSize(new Dimension(500, 250)); enableDisableParameterCombinationButtons(); Style.apply(result, dashboard.getCssStyle()); return result; }
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 w ww . ja va 2 s. c o m // 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 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 w ww .ja v a 2s .c o m*/ } }
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 av a2 s . c o m*/ .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;/*from w ww. j a v a 2s. c o 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
public void setEntityRoot(DefaultMutableTreeNode node) { if (node.getUserObject() instanceof FileSystemObject) { FileSystemObject fsoRoot = (FileSystemObject) node.getUserObject(); FileSystemObject fsoRootFile = null; if (fsoRoot.getIsFile()) { DefaultMutableTreeNode nodeParent = (DefaultMutableTreeNode) node.getParent(); fsoRootFile = fsoRoot;/*w w w .j a v a 2s.c o m*/ fsoRoot = (FileSystemObject) nodeParent.getUserObject(); } setEntityRoot(fsoRoot, fsoRootFile); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void deleteEntityNode(DefaultMutableTreeNode node) { DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); DepositTreeModel model = (DepositTreeModel) theEntityTree.getModel(); if (parentNode != null) { if (parentNode.getUserObject() instanceof FileSystemObject) { FileSystemObject parent = (FileSystemObject) parentNode.getUserObject(); if (node.getUserObject() instanceof FileSystemObject) { // Can't // be // anything // else parent.getChildren().remove((FileSystemObject) node.getUserObject()); }/*from w w w. ja v a2 s .c o m*/ } else if (parentNode.getUserObject() instanceof FileGroup) { FileGroup parent = (FileGroup) parentNode.getUserObject(); if (node.getUserObject() instanceof FileSystemObject) { // Can't // be // anything // else parent.getChildren().remove((FileSystemObject) node.getUserObject()); } } else if (parentNode.getUserObject() instanceof FileGroupCollection) { FileGroupCollection parent = (FileGroupCollection) parentNode.getUserObject(); if (node.getUserObject() instanceof FileGroup) { // Can't be // anything // else parent.getFileGroupList().remove((FileGroup) node.getUserObject()); } } model.removeNodeFromParent(node); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void deleteStructMapNode(DefaultMutableTreeNode node) { DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); if (parentNode != null) { if (parentNode.getUserObject() instanceof StructMap) { // Can't be // anything // else StructMap parent = (StructMap) parentNode.getUserObject(); if (node.getUserObject() instanceof FileSystemObject) { parent.getFiles().remove((FileSystemObject) node.getUserObject()); } else if (node.getUserObject() instanceof StructMap) { parent.getChildren().remove((StructMap) node.getUserObject()); }//w ww. j a v a 2 s . co m } } DepositTreeModel model = (DepositTreeModel) theStructMapTree.getModel(); model.removeNodeFromParent(node); }