List of usage examples for javax.swing.tree DefaultMutableTreeNode add
public void add(MutableTreeNode newChild)
newChild
from its parent and makes it a child of this node by adding it to the end of this node's child array. From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
@SuppressWarnings("unchecked") private List<ParameterInfo> createAndDisplayAParameterPanel( final List<ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?>> batchParameters, final String title, final SubmodelInfo parent, final boolean submodelSelectionWithoutNotify, final IModelHandler currentModelHandler) { final List<ParameterMetaData> metadata = new LinkedList<ParameterMetaData>(), unknownFields = new ArrayList<ParameterMetaData>(); for (final ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?> record : batchParameters) { final String parameterName = record.getName(), fieldName = StringUtils.uncapitalize(parameterName); Class<?> modelComponentType = parent == null ? currentModelHandler.getModelClass() : parent.getActualType(); while (true) { try { final Field field = modelComponentType.getDeclaredField(fieldName); final ParameterMetaData datum = new ParameterMetaData(); for (final Annotation element : field.getAnnotations()) { if (element.annotationType().getName() != Layout.class.getName()) // Proxies continue; final Class<? extends Annotation> type = element.annotationType(); datum.verboseDescription = (String) type.getMethod("VerboseDescription").invoke(element); datum.banner = (String) type.getMethod("Title").invoke(element); datum.fieldName = (String) " " + type.getMethod("FieldName").invoke(element); datum.imageFileName = (String) type.getMethod("Image").invoke(element); datum.layoutOrder = (Double) type.getMethod("Order").invoke(element); }//from w ww .j a va 2 s . c o m datum.parameter = record; if (datum.fieldName.trim().isEmpty()) datum.fieldName = parameterName.replaceAll("([A-Z])", " $1"); metadata.add(datum); break; } catch (final SecurityException e) { } catch (final NoSuchFieldException e) { } catch (final IllegalArgumentException e) { } catch (final IllegalAccessException e) { } catch (final InvocationTargetException e) { } catch (final NoSuchMethodException e) { } modelComponentType = modelComponentType.getSuperclass(); if (modelComponentType == null) { ParameterMetaData.createAndRegisterUnknown(fieldName, record, unknownFields); break; } } } Collections.sort(metadata); for (int i = unknownFields.size() - 1; i >= 0; --i) metadata.add(0, unknownFields.get(i)); // initialize single run form final DefaultFormBuilder formBuilder = FormsUtils.build("p ~ p:g", ""); appendMinimumWidthHintToPresentation(formBuilder, 550); if (parent == null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { numberOfTurnsField.grabFocus(); } }); appendBannerToPresentation(formBuilder, "General Parameters"); appendTextToPresentation(formBuilder, "Global parameters affecting the entire simulation"); formBuilder.append(NUMBER_OF_TURNS_LABEL_TEXT, numberOfTurnsField); formBuilder.append(NUMBER_OF_TIMESTEPS_TO_IGNORE_LABEL_TEXT, numberTimestepsIgnored); appendCheckBoxFieldToPresentation(formBuilder, UPDATE_CHARTS_LABEL_TEXT, onLineChartsCheckBox); appendCheckBoxFieldToPresentation(formBuilder, DISPLAY_ADVANCED_CHARTS_LABEL_TEXT, advancedChartsCheckBox); } appendBannerToPresentation(formBuilder, title); final DefaultMutableTreeNode parentNode = (parent == null) ? parameterValueComponentTree : findParameterInfoNode(parent, false); final List<ParameterInfo> info = new ArrayList<ParameterInfo>(); // Search for a @ConfigurationComponent annotation { String headerText = "", imagePath = ""; final Class<?> parentType = parent == null ? currentModelHandler.getModelClass() : parent.getActualType(); for (final Annotation element : parentType.getAnnotations()) { // Proxies if (element.annotationType().getName() != ConfigurationComponent.class.getName()) continue; boolean doBreak = false; try { try { headerText = (String) element.annotationType().getMethod("Description").invoke(element); if (headerText.startsWith("#")) { headerText = (String) parent.getActualType().getMethod(headerText.substring(1)) .invoke(parent.getInstance()); } doBreak = true; } catch (IllegalArgumentException e) { } catch (SecurityException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } } catch (final Exception e) { } try { imagePath = (String) element.annotationType().getMethod("ImagePath").invoke(element); doBreak = true; } catch (IllegalArgumentException e) { } catch (SecurityException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } if (doBreak) break; } if (!headerText.isEmpty()) appendHeaderTextToPresentation(formBuilder, headerText); if (!imagePath.isEmpty()) appendImageToPresentation(formBuilder, imagePath); } if (metadata.isEmpty()) { // No fields to display. appendTextToPresentation(formBuilder, "No configuration is required for this module."); } else { for (final ParameterMetaData record : metadata) { final ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?> batchParameterInfo = record.parameter; if (!record.banner.isEmpty()) appendBannerToPresentation(formBuilder, record.banner); if (!record.imageFileName.isEmpty()) appendImageToPresentation(formBuilder, record.imageFileName); appendTextToPresentation(formBuilder, record.verboseDescription); final ParameterInfo parameterInfo = InfoConverter.parameterInfo2ParameterInfo(batchParameterInfo); if (parent != null && parameterInfo instanceof ISubmodelGUIInfo) { // sgi.setParentValue(parent.getActualType()); } final JComponent field; final DefaultMutableTreeNode oldNode = findParameterInfoNode(parameterInfo, true); Pair<ParameterInfo, JComponent> userData = null; JComponent oldField = null; if (oldNode != null) { userData = (Pair<ParameterInfo, JComponent>) oldNode.getUserObject(); oldField = userData.getSecond(); } if (parameterInfo.isBoolean()) { field = new JCheckBox(); boolean value = oldField != null ? ((JCheckBox) oldField).isSelected() : ((Boolean) batchParameterInfo.getDefaultValue()).booleanValue(); ((JCheckBox) field).setSelected(value); } else if (parameterInfo.isEnum() || parameterInfo instanceof MasonChooserParameterInfo) { Object[] elements = null; if (parameterInfo.isEnum()) { final Class<Enum<?>> type = (Class<Enum<?>>) parameterInfo.getJavaType(); elements = type.getEnumConstants(); } else { final MasonChooserParameterInfo chooserInfo = (MasonChooserParameterInfo) parameterInfo; elements = chooserInfo.getValidStrings(); } final JComboBox list = new JComboBox(elements); if (parameterInfo.isEnum()) { final Object value = oldField != null ? ((JComboBox) oldField).getSelectedItem() : parameterInfo.getValue(); list.setSelectedItem(value); } else { final int value = oldField != null ? ((JComboBox) oldField).getSelectedIndex() : (Integer) parameterInfo.getValue(); list.setSelectedIndex(value); } field = list; } else if (parameterInfo instanceof SubmodelInfo) { final SubmodelInfo submodelInfo = (SubmodelInfo) parameterInfo; final Object[] elements = new Object[] { "Loading class information..." }; final JComboBox list = new JComboBox(elements); // field = list; final Object value = oldField != null ? ((JComboBox) ((JPanel) oldField).getComponent(0)).getSelectedItem() : new ClassElement(submodelInfo.getActualType(), null); new ClassCollector(this, list, submodelInfo, value, submodelSelectionWithoutNotify).execute(); final JButton rightButton = new JButton(); rightButton.setOpaque(false); rightButton.setRolloverEnabled(true); rightButton.setIcon(SHOW_SUBMODEL_ICON); rightButton.setRolloverIcon(SHOW_SUBMODEL_ICON_RO); rightButton.setDisabledIcon(SHOW_SUBMODEL_ICON_DIS); rightButton.setBorder(null); rightButton.setToolTipText("Display submodel parameters"); rightButton.setActionCommand(ACTIONCOMMAND_SHOW_SUBMODEL); rightButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (parameterInfo instanceof SubmodelInfo) { SubmodelInfo submodelInfo = (SubmodelInfo) parameterInfo; int level = 0; showHideSubparameters(list, submodelInfo); List<String> components = new ArrayList<String>(); components.add(submodelInfo.getName()); while (submodelInfo.getParent() != null) { submodelInfo = submodelInfo.getParent(); components.add(submodelInfo.getName()); level++; } Collections.reverse(components); final String[] breadcrumbText = components.toArray(new String[components.size()]); for (int i = 0; i < breadcrumbText.length; ++i) breadcrumbText[i] = breadcrumbText[i].replaceAll("([A-Z])", " $1"); breadcrumb.setPath( currentModelHandler.getModelClassSimpleName().replaceAll("([A-Z])", " $1"), breadcrumbText); Style.apply(breadcrumb, dashboard.getCssStyle()); // reset all buttons that are nested deeper than this to default color for (int i = submodelButtons.size() - 1; i >= level; i--) { JButton button = submodelButtons.get(i); button.setIcon(SHOW_SUBMODEL_ICON); submodelButtons.remove(i); } rightButton.setIcon(SHOW_SUBMODEL_ICON_RO); submodelButtons.add(rightButton); } } }); field = new JPanel(new BorderLayout()); field.add(list, BorderLayout.CENTER); field.add(rightButton, BorderLayout.EAST); } else if (File.class.isAssignableFrom(parameterInfo.getJavaType())) { field = new JPanel(new BorderLayout()); String oldName = ""; String oldPath = ""; if (oldField != null) { final JTextField oldTextField = (JTextField) oldField.getComponent(0); oldName = oldTextField.getText(); oldPath = oldTextField.getToolTipText(); } else if (parameterInfo.getValue() != null) { final File file = (File) parameterInfo.getValue(); oldName = file.getName(); oldPath = file.getAbsolutePath(); } final JTextField textField = new JTextField(oldName); textField.setToolTipText(oldPath); textField.setInputVerifier(new InputVerifier() { @Override public boolean verify(final JComponent input) { final JTextField inputField = (JTextField) input; if (inputField.getText() == null || inputField.getText().isEmpty()) { final File file = new File(""); inputField.setToolTipText(file.getAbsolutePath()); hideError(); return true; } final File oldFile = new File(inputField.getToolTipText()); if (oldFile.exists() && oldFile.getName().equals(inputField.getText().trim())) { hideError(); return true; } inputField.setToolTipText(""); final File file = new File(inputField.getText().trim()); if (file.exists()) { inputField.setToolTipText(file.getAbsolutePath()); inputField.setText(file.getName()); hideError(); return true; } else { final PopupFactory popupFactory = PopupFactory.getSharedInstance(); final Point locationOnScreen = inputField.getLocationOnScreen(); final JLabel message = new JLabel("Please specify an existing file!"); message.setBorder(new LineBorder(Color.RED, 2, true)); if (errorPopup != null) errorPopup.hide(); errorPopup = popupFactory.getPopup(inputField, message, locationOnScreen.x - 10, locationOnScreen.y - 30); errorPopup.show(); return false; } } }); final JButton browseButton = new JButton(BROWSE_BUTTON_TEXT); browseButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JFileChooser fileDialog = new JFileChooser( !"".equals(textField.getToolTipText()) ? textField.getToolTipText() : currentDirectory); if (!"".equals(textField.getToolTipText())) fileDialog.setSelectedFile(new File(textField.getToolTipText())); int dialogResult = fileDialog.showOpenDialog(dashboard); if (dialogResult == JFileChooser.APPROVE_OPTION) { final File selectedFile = fileDialog.getSelectedFile(); if (selectedFile != null) { currentDirectory = selectedFile.getAbsoluteFile().getParent(); textField.setText(selectedFile.getName()); textField.setToolTipText(selectedFile.getAbsolutePath()); } } } }); field.add(textField, BorderLayout.CENTER); field.add(browseButton, BorderLayout.EAST); } else if (parameterInfo instanceof MasonIntervalParameterInfo) { final MasonIntervalParameterInfo intervalInfo = (MasonIntervalParameterInfo) parameterInfo; field = new JPanel(new BorderLayout()); String oldValueStr = String.valueOf(parameterInfo.getValue()); if (oldField != null) { final JTextField oldTextField = (JTextField) oldField.getComponent(0); oldValueStr = oldTextField.getText(); } final JTextField textField = new JTextField(oldValueStr); PercentJSlider tempSlider = null; if (intervalInfo.isDoubleInterval()) tempSlider = new PercentJSlider(intervalInfo.getIntervalMin().doubleValue(), intervalInfo.getIntervalMax().doubleValue(), Double.parseDouble(oldValueStr)); else tempSlider = new PercentJSlider(intervalInfo.getIntervalMin().longValue(), intervalInfo.getIntervalMax().longValue(), Long.parseLong(oldValueStr)); final PercentJSlider slider = tempSlider; slider.setMajorTickSpacing(100); slider.setMinorTickSpacing(10); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.addChangeListener(new ChangeListener() { public void stateChanged(final ChangeEvent _) { if (slider.hasFocus()) { final String value = intervalInfo.isDoubleInterval() ? String.valueOf(slider.getDoubleValue()) : String.valueOf(slider.getLongValue()); textField.setText(value); slider.setToolTipText(value); } } }); textField.setInputVerifier(new InputVerifier() { public boolean verify(JComponent input) { final JTextField inputField = (JTextField) input; try { hideError(); final String valueStr = inputField.getText().trim(); if (intervalInfo.isDoubleInterval()) { final double value = Double.parseDouble(valueStr); if (intervalInfo.isValidValue(valueStr)) { slider.setValue(value); return true; } else showError( "Please specify a value between " + intervalInfo.getIntervalMin() + " and " + intervalInfo.getIntervalMax() + ".", inputField); return false; } else { final long value = Long.parseLong(valueStr); if (intervalInfo.isValidValue(valueStr)) { slider.setValue(value); return true; } else { showError("Please specify an integer value between " + intervalInfo.getIntervalMin() + " and " + intervalInfo.getIntervalMax() + ".", inputField); return false; } } } catch (final NumberFormatException _) { final String message = "The specified value is not a" + (intervalInfo.isDoubleInterval() ? "" : "n integer") + " number."; showError(message, inputField); return false; } } }); textField.getDocument().addDocumentListener(new DocumentListener() { // private Popup errorPopup; public void removeUpdate(final DocumentEvent _) { textFieldChanged(); } public void insertUpdate(final DocumentEvent _) { textFieldChanged(); } public void changedUpdate(final DocumentEvent _) { textFieldChanged(); } private void textFieldChanged() { if (!textField.hasFocus()) { hideError(); return; } try { hideError(); final String valueStr = textField.getText().trim(); if (intervalInfo.isDoubleInterval()) { final double value = Double.parseDouble(valueStr); if (intervalInfo.isValidValue(valueStr)) slider.setValue(value); else showError("Please specify a value between " + intervalInfo.getIntervalMin() + " and " + intervalInfo.getIntervalMax() + ".", textField); } else { final long value = Long.parseLong(valueStr); if (intervalInfo.isValidValue(valueStr)) slider.setValue(value); else showError("Please specify an integer value between " + intervalInfo.getIntervalMin() + " and " + intervalInfo.getIntervalMax() + ".", textField); } } catch (final NumberFormatException _) { final String message = "The specified value is not a" + (intervalInfo.isDoubleInterval() ? "" : "n integer") + " number."; showError(message, textField); } } }); field.add(textField, BorderLayout.CENTER); field.add(slider, BorderLayout.SOUTH); } else { final Object value = oldField != null ? ((JTextField) oldField).getText() : parameterInfo.getValue(); field = new JTextField(value.toString()); ((JTextField) field).addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { wizard.clickDefaultButton(); } }); } final JLabel parameterLabel = new JLabel(record.fieldName); final String description = parameterInfo.getDescription(); if (description != null && !description.isEmpty()) { parameterLabel.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(final MouseEvent e) { final DescriptionPopupFactory popupFactory = DescriptionPopupFactory.getInstance(); final Popup parameterDescriptionPopup = popupFactory.getPopup(parameterLabel, description, dashboard.getCssStyle()); parameterDescriptionPopup.show(); } }); } if (oldNode != null) userData.setSecond(field); else { final Pair<ParameterInfo, JComponent> pair = new Pair<ParameterInfo, JComponent>(parameterInfo, field); final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(pair); parentNode.add(newNode); } if (field instanceof JCheckBox) { parameterLabel .setText("<html><div style=\"margin-bottom: 4pt; margin-top: 6pt; margin-left: 4pt\">" + parameterLabel.getText() + "</div></html>"); formBuilder.append(parameterLabel, field); // appendCheckBoxFieldToPresentation( // formBuilder, parameterLabel.getText(), (JCheckBox) field); } else { formBuilder.append(parameterLabel, field); final CellConstraints constraints = formBuilder.getLayout().getConstraints(parameterLabel); constraints.vAlign = CellConstraints.TOP; constraints.insets = new Insets(5, 0, 0, 0); formBuilder.getLayout().setConstraints(parameterLabel, constraints); } // prepare the parameterInfo for the param sweeps parameterInfo.setRuns(0); parameterInfo.setDefinitionType(ParameterInfo.CONST_DEF); parameterInfo.setValue(batchParameterInfo.getDefaultValue()); info.add(parameterInfo); } } appendVerticalSpaceToPresentation(formBuilder); final JPanel panel = formBuilder.getPanel(); singleRunParametersPanel.add(panel); if (singleRunParametersPanel.getComponentCount() > 1) { panel.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, Color.GRAY), BorderFactory.createEmptyBorder(0, 5, 0, 5))); } else { panel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); } Style.apply(panel, dashboard.getCssStyle()); return info; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenterTest.java
@Test public final void testGetFileSystemMenu() { // Includes a test for setting the root entity DefaultMutableTreeNode node = new DefaultMutableTreeNode("Nothing"); JPopupMenu menu = depositPresenter.getFileSystemMenu(node); // menu should be null if the user object isn't a FileSystemObject assertTrue(menu == null);//from ww w. j a va2s . c om File theFile = new File(RESOURCES_INPUT_SOUND); String description = "ManualDeposit"; FileSystemObject root = new FileSystemObject(description, theFile, null); node = new DefaultMutableTreeNode(root); AppProperties props = depositPresenter.getAppProperties(); UserGroupData userGroupData = null; try { userGroupData = props.getUserData().getUser(props.getLoggedOnUser()).getUserGroupData(); } catch (Exception ex) { fail(); } userGroupData.setIncludeMultiEntityMenuItem(false); menu = depositPresenter.getFileSystemMenu(node); assertTrue(menu != null); int menuCount = menu.getComponentCount(); assertTrue(menuCount >= 1); try { depositPresenter.setupScreen(); } catch (Exception ex) { fail(); } userGroupData.setIncludeMultiEntityMenuItem(true); menu = depositPresenter.getFileSystemMenu(node); assertTrue(menu != null && menu.getComponentCount() == menuCount + 2); try { depositPresenter.setupScreen(); } catch (Exception ex) { fail(); } theFile = new File(RESOURCES_INPUT_SOUND + "/Preservation Copy/OHC-0000_s_1.wav"); description = "OHC-0000_s_1.wav"; FileSystemObject newRoot = new FileSystemObject(description, theFile, null); DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(newRoot); node.add(childNode); userGroupData.setIncludeMultiEntityMenuItem(false); menu = depositPresenter.getFileSystemMenu(childNode); assertTrue(menu != null); menuCount = menu.getComponentCount(); assertTrue(menuCount >= 1); try { depositPresenter.setupScreen(); } catch (Exception ex) { fail(); } userGroupData.setIncludeMultiEntityMenuItem(true); menu = depositPresenter.getFileSystemMenu(childNode); assertTrue(menu != null && menu.getComponentCount() == menuCount); root = setRoot(); // assertTrue(_presenter _theFrame._rootNode.equals(root)); assertFalse(theFrame.cursorIsWaiting); // node = new DefaultMutableTreeNode(root); // menu = _presenter.getFileSystemMenu(node); // menu should have at least one item // When the menu is fixed, implement this check // assertTrue(menu != null && menu.getComponentCount() >= 1); assertFalse(theFrame.cursorIsWaiting); }
From source file:op.tools.SYSTools.java
public static void addAllNodes(DefaultMutableTreeNode root, java.util.List children) { if (children.size() > 0) { Iterator it = children.iterator(); while (it.hasNext()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) it.next(); root.add(node); }/* w ww . j a v a 2 s . com*/ } }
From source file:org.alfresco.repo.jive.impl.MockJiveService.java
private final TreeModel buildMockData1() { TreeModel result = null;/*from w w w . ja va2 s . c om*/ /* * Build up a tree that looks like this: * * root * Child 1 * Child 1.1 * Child 1.1.1 * Child 1.1.2 * Child 1.1.3 * Child 1.1.3.1 * Child 1.1.3.1.1 * Child 1.1.3.1.1.1 * Child 1.1.3.1.1.1.1 * Child 1.1.3.1.1.1.1.1 * Child 1.2 * Child 1.2.1 * Child 1.2.2 * Child 1.3 * Child 2 * Child 2.1 * Child 2.2 * Child 2.3 * Child 2.4 * ... 45 other children omitted for brevity ... * Child 2.50 * Child 3 * Child 4 which has some punctuation characters: '";/?\[]{} * Child 5 which has an extremely long name that is intended to test out how it'll appear in the Share UI * Child 6 which has some Unicode characters: ? */ // First up we create all the nodes DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JiveCommunity(0, "root")); DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(new JiveCommunity(1, "Child 1")); DefaultMutableTreeNode child11 = new DefaultMutableTreeNode(new JiveCommunity(11, "Child 1.1")); DefaultMutableTreeNode child111 = new DefaultMutableTreeNode(new JiveCommunity(111, "Child 1.1.1")); DefaultMutableTreeNode child112 = new DefaultMutableTreeNode(new JiveCommunity(112, "Child 1.1.2")); DefaultMutableTreeNode child113 = new DefaultMutableTreeNode(new JiveCommunity(113, "Child 1.1.3")); DefaultMutableTreeNode child1131 = new DefaultMutableTreeNode(new JiveCommunity(1131, "Child 1.1.3.1")); DefaultMutableTreeNode child11311 = new DefaultMutableTreeNode(new JiveCommunity(11311, "Child 1.1.3.1.1")); DefaultMutableTreeNode child113111 = new DefaultMutableTreeNode( new JiveCommunity(113111, "Child 1.1.3.1.1.1")); DefaultMutableTreeNode child1131111 = new DefaultMutableTreeNode( new JiveCommunity(1131111, "Child 1.1.3.1.1.1.1")); DefaultMutableTreeNode child11311111 = new DefaultMutableTreeNode( new JiveCommunity(11311111, "Child 1.1.3.1.1.1.1.1")); DefaultMutableTreeNode child12 = new DefaultMutableTreeNode(new JiveCommunity(12, "Child 1.2")); DefaultMutableTreeNode child121 = new DefaultMutableTreeNode(new JiveCommunity(121, "Child 1.2.1")); DefaultMutableTreeNode child122 = new DefaultMutableTreeNode(new JiveCommunity(122, "Child 1.2.2")); DefaultMutableTreeNode child13 = new DefaultMutableTreeNode(new JiveCommunity(13, "Child 1.3")); DefaultMutableTreeNode child2 = new DefaultMutableTreeNode(new JiveCommunity(2, "Child 2")); DefaultMutableTreeNode child21 = new DefaultMutableTreeNode(new JiveCommunity(21, "Child 2.1")); DefaultMutableTreeNode child22 = new DefaultMutableTreeNode(new JiveCommunity(22, "Child 2.2")); DefaultMutableTreeNode child23 = new DefaultMutableTreeNode(new JiveCommunity(23, "Child 2.3")); DefaultMutableTreeNode child24 = new DefaultMutableTreeNode(new JiveCommunity(24, "Child 2.4")); DefaultMutableTreeNode child25 = new DefaultMutableTreeNode(new JiveCommunity(25, "Child 2.5")); DefaultMutableTreeNode child26 = new DefaultMutableTreeNode(new JiveCommunity(26, "Child 2.6")); DefaultMutableTreeNode child27 = new DefaultMutableTreeNode(new JiveCommunity(27, "Child 2.7")); DefaultMutableTreeNode child28 = new DefaultMutableTreeNode(new JiveCommunity(28, "Child 2.8")); DefaultMutableTreeNode child29 = new DefaultMutableTreeNode(new JiveCommunity(29, "Child 2.9")); DefaultMutableTreeNode child210 = new DefaultMutableTreeNode(new JiveCommunity(210, "Child 2.10")); DefaultMutableTreeNode child211 = new DefaultMutableTreeNode(new JiveCommunity(211, "Child 2.11")); DefaultMutableTreeNode child212 = new DefaultMutableTreeNode(new JiveCommunity(212, "Child 2.12")); DefaultMutableTreeNode child213 = new DefaultMutableTreeNode(new JiveCommunity(213, "Child 2.13")); DefaultMutableTreeNode child214 = new DefaultMutableTreeNode(new JiveCommunity(214, "Child 2.14")); DefaultMutableTreeNode child215 = new DefaultMutableTreeNode(new JiveCommunity(215, "Child 2.15")); DefaultMutableTreeNode child216 = new DefaultMutableTreeNode(new JiveCommunity(216, "Child 2.16")); DefaultMutableTreeNode child217 = new DefaultMutableTreeNode(new JiveCommunity(217, "Child 2.17")); DefaultMutableTreeNode child218 = new DefaultMutableTreeNode(new JiveCommunity(218, "Child 2.18")); DefaultMutableTreeNode child219 = new DefaultMutableTreeNode(new JiveCommunity(219, "Child 2.19")); DefaultMutableTreeNode child220 = new DefaultMutableTreeNode(new JiveCommunity(220, "Child 2.20")); DefaultMutableTreeNode child221 = new DefaultMutableTreeNode(new JiveCommunity(221, "Child 2.21")); DefaultMutableTreeNode child222 = new DefaultMutableTreeNode(new JiveCommunity(222, "Child 2.22")); DefaultMutableTreeNode child223 = new DefaultMutableTreeNode(new JiveCommunity(223, "Child 2.23")); DefaultMutableTreeNode child224 = new DefaultMutableTreeNode(new JiveCommunity(224, "Child 2.24")); DefaultMutableTreeNode child225 = new DefaultMutableTreeNode(new JiveCommunity(225, "Child 2.25")); DefaultMutableTreeNode child226 = new DefaultMutableTreeNode(new JiveCommunity(226, "Child 2.26")); DefaultMutableTreeNode child227 = new DefaultMutableTreeNode(new JiveCommunity(227, "Child 2.27")); DefaultMutableTreeNode child228 = new DefaultMutableTreeNode(new JiveCommunity(228, "Child 2.28")); DefaultMutableTreeNode child229 = new DefaultMutableTreeNode(new JiveCommunity(229, "Child 2.29")); DefaultMutableTreeNode child230 = new DefaultMutableTreeNode(new JiveCommunity(230, "Child 2.30")); DefaultMutableTreeNode child231 = new DefaultMutableTreeNode(new JiveCommunity(231, "Child 2.31")); DefaultMutableTreeNode child232 = new DefaultMutableTreeNode(new JiveCommunity(232, "Child 2.32")); DefaultMutableTreeNode child233 = new DefaultMutableTreeNode(new JiveCommunity(233, "Child 2.33")); DefaultMutableTreeNode child234 = new DefaultMutableTreeNode(new JiveCommunity(234, "Child 2.34")); DefaultMutableTreeNode child235 = new DefaultMutableTreeNode(new JiveCommunity(235, "Child 2.35")); DefaultMutableTreeNode child236 = new DefaultMutableTreeNode(new JiveCommunity(236, "Child 2.36")); DefaultMutableTreeNode child237 = new DefaultMutableTreeNode(new JiveCommunity(237, "Child 2.37")); DefaultMutableTreeNode child238 = new DefaultMutableTreeNode(new JiveCommunity(238, "Child 2.38")); DefaultMutableTreeNode child239 = new DefaultMutableTreeNode(new JiveCommunity(239, "Child 2.39")); DefaultMutableTreeNode child240 = new DefaultMutableTreeNode(new JiveCommunity(240, "Child 2.40")); DefaultMutableTreeNode child241 = new DefaultMutableTreeNode(new JiveCommunity(241, "Child 2.41")); DefaultMutableTreeNode child242 = new DefaultMutableTreeNode(new JiveCommunity(242, "Child 2.42")); DefaultMutableTreeNode child243 = new DefaultMutableTreeNode(new JiveCommunity(243, "Child 2.43")); DefaultMutableTreeNode child244 = new DefaultMutableTreeNode(new JiveCommunity(244, "Child 2.44")); DefaultMutableTreeNode child245 = new DefaultMutableTreeNode(new JiveCommunity(245, "Child 2.45")); DefaultMutableTreeNode child246 = new DefaultMutableTreeNode(new JiveCommunity(246, "Child 2.46")); DefaultMutableTreeNode child247 = new DefaultMutableTreeNode(new JiveCommunity(247, "Child 2.47")); DefaultMutableTreeNode child248 = new DefaultMutableTreeNode(new JiveCommunity(248, "Child 2.48")); DefaultMutableTreeNode child249 = new DefaultMutableTreeNode(new JiveCommunity(249, "Child 2.49")); DefaultMutableTreeNode child250 = new DefaultMutableTreeNode(new JiveCommunity(250, "Child 2.50")); DefaultMutableTreeNode child3 = new DefaultMutableTreeNode(new JiveCommunity(3, "Child 3")); DefaultMutableTreeNode child4 = new DefaultMutableTreeNode( new JiveCommunity(4, "Child 4 which has some punctuation characters: '\";/?\\[]{}")); DefaultMutableTreeNode child5 = new DefaultMutableTreeNode(new JiveCommunity(5, "Child 5 which has an extremely long name that is intended to test out how it'll appear in the Share UI")); DefaultMutableTreeNode child6 = new DefaultMutableTreeNode(new JiveCommunity(6, "Child 6 which has some Unicode characters: ?")); // Now link all of the nodes together to create the tree structure root.add(child1); root.add(child2); root.add(child3); root.add(child4); root.add(child5); root.add(child6); child1.add(child11); child1.add(child12); child1.add(child13); child11.add(child111); child11.add(child112); child11.add(child113); child113.add(child1131); child1131.add(child11311); child11311.add(child113111); child113111.add(child1131111); child1131111.add(child11311111); child12.add(child121); child12.add(child122); child2.add(child21); child2.add(child22); child2.add(child23); child2.add(child24); child2.add(child25); child2.add(child26); child2.add(child27); child2.add(child28); child2.add(child29); child2.add(child210); child2.add(child211); child2.add(child212); child2.add(child213); child2.add(child214); child2.add(child215); child2.add(child216); child2.add(child217); child2.add(child218); child2.add(child219); child2.add(child220); child2.add(child221); child2.add(child222); child2.add(child223); child2.add(child224); child2.add(child225); child2.add(child226); child2.add(child227); child2.add(child228); child2.add(child229); child2.add(child230); child2.add(child231); child2.add(child232); child2.add(child233); child2.add(child234); child2.add(child235); child2.add(child236); child2.add(child237); child2.add(child238); child2.add(child239); child2.add(child240); child2.add(child241); child2.add(child242); child2.add(child243); child2.add(child244); child2.add(child245); child2.add(child246); child2.add(child247); child2.add(child248); child2.add(child249); child2.add(child250); result = new DefaultTreeModel(root); return (result); }
From source file:org.alfresco.repo.jive.impl.MockJiveService.java
/** * Alternative mock data that returns a tree of communities matched to the mocked up screen shots. * @return//from ww w . ja v a 2 s . c om */ private final TreeModel buildMockData2() { TreeModel result = null; DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JiveCommunity(0, "Alfresco Green Energy")); DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(new JiveCommunity(1, "Engineering")); DefaultMutableTreeNode child2 = new DefaultMutableTreeNode(new JiveCommunity(2, "Finance")); DefaultMutableTreeNode child3 = new DefaultMutableTreeNode(new JiveCommunity(3, "Human Resources")); DefaultMutableTreeNode child31 = new DefaultMutableTreeNode(new JiveCommunity(31, "Archived Policies")); DefaultMutableTreeNode child32 = new DefaultMutableTreeNode(new JiveCommunity(32, "Company Policies")); DefaultMutableTreeNode child33 = new DefaultMutableTreeNode( new JiveCommunity(33, "Performance Appraisals")); DefaultMutableTreeNode child4 = new DefaultMutableTreeNode(new JiveCommunity(4, "Marketing")); // Now link all of the nodes together to create the tree structure root.add(child1); root.add(child2); root.add(child3); root.add(child4); child3.add(child31); child3.add(child32); child3.add(child33); result = new DefaultTreeModel(root); return (result); }
From source file:org.apache.jetspeed.portlets.site.PortalSiteManager.java
private DefaultMutableTreeNode retrieveFolders(String folderPath, DefaultMutableTreeNode rootNode, boolean cleanBeforeRetrieve) { try {//from www. j av a2 s . c o m Link link; Folder folder; DefaultMutableTreeNode tmpNode; Page page; Folder rootfolder = getServiceLocator().getPageManager().getFolder(folderPath); if (rootNode == null) { rootNode = new DefaultMutableTreeNode(new SiteTreeNode(rootfolder, true)); } if (cleanBeforeRetrieve) { rootNode.removeAllChildren(); } Iterator folders = rootfolder.getFolders().iterator(); while (folders.hasNext()) { folder = (Folder) folders.next(); if (rootfolder.getPath().equals("/_user")) { if (folder.getName().startsWith("template")) { rootNode.add(new DefaultMutableTreeNode(new SiteTreeNode(folder))); } } else { rootNode.add(new DefaultMutableTreeNode(new SiteTreeNode(folder))); } } Iterator pages = rootfolder.getPages().iterator(); while (pages.hasNext()) { page = (Page) pages.next(); tmpNode = new DefaultMutableTreeNode(new SiteTreeNode(page)); tmpNode.setAllowsChildren(false); rootNode.add(tmpNode); } Iterator links = rootfolder.getLinks().iterator(); while (links.hasNext()) { link = (Link) links.next(); tmpNode = new DefaultMutableTreeNode(new SiteTreeNode(link)); tmpNode.setAllowsChildren(false); rootNode.add(tmpNode); } } catch (Exception e) { log.error("Failed to retrieve folders ", e); } return rootNode; }
From source file:org.apache.jetspeed.portlets.site.PortalSiteManager.java
private DefaultMutableTreeNode retrieveCopyFolders(String folderPath, DefaultMutableTreeNode rootNode) { try {/* w w w. ja va 2s . c o m*/ Folder folder; Folder rootfolder = getServiceLocator().getPageManager().getFolder(folderPath); if (rootNode == null) { rootNode = new DefaultMutableTreeNode(new SiteTreeNode(rootfolder, true)); } Iterator folders = rootfolder.getFolders().iterator(); while (folders.hasNext()) { folder = (Folder) folders.next(); if (rootfolder.getPath().equals("/_user")) { if (folder.getName().startsWith("template")) { rootNode.add(new DefaultMutableTreeNode(new SiteTreeNode(folder))); } } else { rootNode.add(new DefaultMutableTreeNode(new SiteTreeNode(folder))); } } } catch (Exception e) { log.error("Failed to retrieve folders ", e); } return rootNode; }
From source file:org.apache.jetspeed.portlets.site.PortalSiteManager.java
private void getMenus(JetspeedDocument document, DefaultMutableTreeNode menuNode) { MenuDefinition definitaion = null;//from w w w . ja v a 2s.com DefaultMutableTreeNode menu = null; List menuDefinitions = null; if (getUserSelectedNode().getDocType() == FileType.Folder) { menuDefinitions = getJetspeedFolder(document.getPath()).getMenuDefinitions(); } else { menuDefinitions = getJetspeedPage(document.getPath()).getMenuDefinitions(); } if (menuDefinitions == null || menuDefinitions.size() == 0) { return; } Iterator menuItreator = menuDefinitions.iterator(); while (menuItreator.hasNext()) { definitaion = (MenuDefinition) menuItreator.next(); menu = new DefaultMutableTreeNode(new MenuTreeNode(definitaion.getName(), document.getPath(), document.getType(), getServiceLocator())); menuNode.add(menu); } }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java
@Override public void refreshView(final ViewState state) { Rectangle visibleRect = null; if (this.tree != null) { visibleRect = this.tree.getVisibleRect(); }//from ww w .j av a2s. c o m this.removeAll(); this.actionsMenu = this.createPopupMenu(state); DefaultMutableTreeNode root = new DefaultMutableTreeNode("WORKFLOWS"); for (ModelGraph graph : state.getGraphs()) { root.add(this.buildTree(graph, state)); } tree = new JTree(root); tree.setShowsRootHandles(true); tree.setRootVisible(false); tree.add(this.actionsMenu); if (state.getSelected() != null) { // System.out.println("SELECTED: " + state.getSelected()); TreePath treePath = this.getTreePath(root, state.getSelected()); if (state.getCurrentMetGroup() != null) { treePath = this.getTreePath(treePath, state); } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_STATIC_METADATA))) { DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject() .equals("static-metadata")) { treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath()); break; } } } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS))) { if (treePath == null) { treePath = this.getTreePath(root, state.getSelected().getPreConditions()); } DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject() .equals("pre-conditions")) { treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath()); break; } } } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_POSTCONDITIONS))) { if (treePath == null) { treePath = this.getTreePath(root, state.getSelected().getPostConditions()); } DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); for (int i = 0; i < baseNode.getChildCount(); i++) { if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject() .equals("post-conditions")) { treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath()); break; } } } this.tree.expandPath(treePath); this.tree.setSelectionPath(treePath); } tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { if (e.getPath().getLastPathComponent() instanceof DefaultMutableTreeNode) { DefaultTreeView.this.resetProperties(state); DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); if (node.getUserObject() instanceof ModelGraph) { state.setSelected((ModelGraph) node.getUserObject()); state.setCurrentMetGroup(null); DefaultTreeView.this.notifyListeners(); } else if (node.getUserObject().equals("static-metadata") || node.getUserObject().equals("pre-conditions") || node.getUserObject().equals("post-conditions")) { state.setSelected((ModelGraph) ((DefaultMutableTreeNode) node.getParent()).getUserObject()); state.setCurrentMetGroup(null); state.setProperty(EXPAND_STATIC_METADATA, Boolean.toString(node.getUserObject().equals("static-metadata"))); state.setProperty(EXPAND_PRECONDITIONS, Boolean.toString(node.getUserObject().equals("pre-conditions"))); state.setProperty(EXPAND_POSTCONDITIONS, Boolean.toString(node.getUserObject().equals("post-conditions"))); DefaultTreeView.this.notifyListeners(); } else if (node.getUserObject() instanceof ConcurrentHashMap) { DefaultMutableTreeNode metNode = null; String group = null; Object[] path = e.getPath().getPath(); for (int i = path.length - 1; i >= 0; i--) { if (((DefaultMutableTreeNode) path[i]).getUserObject() instanceof ModelGraph) { metNode = (DefaultMutableTreeNode) path[i]; break; } else if (((DefaultMutableTreeNode) path[i]) .getUserObject() instanceof ConcurrentHashMap) { if (group == null) { group = (String) ((ConcurrentHashMap<String, String>) ((DefaultMutableTreeNode) path[i]) .getUserObject()).keySet().iterator().next(); } else { group = (String) ((ConcurrentHashMap<String, String>) ((DefaultMutableTreeNode) path[i]) .getUserObject()).keySet().iterator().next() + "/" + group; } } } ModelGraph graph = (ModelGraph) metNode.getUserObject(); state.setSelected(graph); state.setCurrentMetGroup(group); DefaultTreeView.this.notifyListeners(); } else { state.setSelected(null); DefaultTreeView.this.notifyListeners(); } } } }); tree.setCellRenderer(new TreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; if (node.getUserObject() instanceof String) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel label = new JLabel((String) node.getUserObject()); label.setForeground(Color.blue); panel.add(label, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof ModelGraph) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel iconLabel = new JLabel( ((ModelGraph) node.getUserObject()).getModel().getExecutionType() + ": "); iconLabel.setForeground(((ModelGraph) node.getUserObject()).getModel().getColor()); iconLabel.setBackground(Color.white); JLabel idLabel = new JLabel(((ModelGraph) node.getUserObject()).getModel().getModelName()); idLabel.setBackground(Color.white); panel.add(iconLabel, BorderLayout.WEST); panel.add(idLabel, BorderLayout.CENTER); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else if (node.getUserObject() instanceof ConcurrentHashMap) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); String group = (String) ((ConcurrentHashMap<String, String>) node.getUserObject()).keySet() .iterator().next(); JLabel nameLabel = new JLabel(group + " : "); nameLabel.setForeground(Color.blue); nameLabel.setBackground(Color.white); JLabel valueLabel = new JLabel( ((ConcurrentHashMap<String, String>) node.getUserObject()).get(group)); valueLabel.setForeground(Color.darkGray); valueLabel.setBackground(Color.white); panel.add(nameLabel, BorderLayout.WEST); panel.add(valueLabel, BorderLayout.EAST); panel.setBackground(selected ? Color.lightGray : Color.white); return panel; } else { return new JLabel(); } } }); tree.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3 && DefaultTreeView.this.tree.getSelectionPath() != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) DefaultTreeView.this.tree .getSelectionPath().getLastPathComponent(); if (node.getUserObject() instanceof String && !(node.getUserObject().equals("pre-conditions") || node.getUserObject().equals("post-conditions"))) { return; } orderSubMenu.setEnabled(node.getUserObject() instanceof ModelGraph && !((ModelGraph) node.getUserObject()).isCondition() && ((ModelGraph) node.getUserObject()).getParent() != null); DefaultTreeView.this.actionsMenu.show(DefaultTreeView.this.tree, e.getX(), e.getY()); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); this.scrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); this.add(this.scrollPane, BorderLayout.CENTER); if (visibleRect != null) { this.tree.scrollRectToVisible(visibleRect); } this.revalidate(); }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java
private DefaultMutableTreeNode buildTree(ModelGraph graph, ViewState state) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(graph); DefaultMutableTreeNode metadataNode = new DefaultMutableTreeNode("static-metadata"); Metadata staticMetadata = new Metadata(); if (graph.getInheritedStaticMetadata(state) != null) { staticMetadata.replaceMetadata(graph.getInheritedStaticMetadata(state)); }/* w ww. j a v a 2s.co m*/ if (graph.getModel().getStaticMetadata() != null) { staticMetadata.replaceMetadata(graph.getModel().getStaticMetadata()); } this.addMetadataNodes(metadataNode, staticMetadata); if (!metadataNode.isLeaf()) { node.add(metadataNode); } if (graph.getPreConditions() != null) { DefaultMutableTreeNode preConditions = new DefaultMutableTreeNode("pre-conditions"); List<ModelGraph> leafNodes = graph.getPreConditions().getLeafNodes(); for (ModelGraph cond : leafNodes) { DefaultMutableTreeNode condNode = new DefaultMutableTreeNode(cond); preConditions.add(condNode); } node.add(preConditions); } if (graph.getPostConditions() != null) { DefaultMutableTreeNode postConditions = new DefaultMutableTreeNode("post-conditions"); List<ModelGraph> leafNodes = graph.getPostConditions().getLeafNodes(); for (ModelGraph cond : leafNodes) { DefaultMutableTreeNode condNode = new DefaultMutableTreeNode(cond); postConditions.add(condNode); } node.add(postConditions); } for (ModelGraph child : graph.getChildren()) { if (!GuiUtils.isDummyNode(child.getModel())) { node.add(this.buildTree(child, state)); } } return node; }