List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:org.openengsb.ui.admin.testClient.TestClient.java
@SuppressWarnings("serial") private Form<MethodCall> createMethodCallForm() { Form<MethodCall> form = new Form<MethodCall>("methodCallForm"); form.setModel(new Model<MethodCall>(call)); form.setOutputMarkupId(true);//from w ww. j a va 2 s. c o m editButton = initializeEditButton(form); editButton.setEnabled(false); editButton.setOutputMarkupId(true); deleteButton = initializeDeleteButton(form); deleteButton.setEnabled(false); deleteButton.setOutputMarkupId(true); methodList = new DropDownChoice<MethodId>("methodList"); methodList.setModel(new PropertyModel<MethodId>(call, "method")); methodList.setChoiceRenderer(new ChoiceRenderer<MethodId>()); methodList.setOutputMarkupId(true); methodList.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { LOGGER.info("method selected: " + call.getMethod()); populateArgumentList(); target.add(argumentListContainer); } }); form.add(methodList); argumentListContainer = new WebMarkupContainer("argumentListContainer"); argumentListContainer.setOutputMarkupId(true); argumentList = new RepeatingView("argumentList"); argumentList.setOutputMarkupId(true); argumentListContainer.add(argumentList); form.add(argumentListContainer); submitButton = initializeSubmitButton(form); jsonButton = initializeJsonButton(form); serviceList = new LinkTree("serviceList", createModel()) { @Override protected void onNodeLinkClicked(Object node, BaseTree tree, AjaxRequestTarget target) { DefaultMutableTreeNode mnode = (DefaultMutableTreeNode) node; try { argumentList.removeAll(); target.add(argumentListContainer); ServiceId service = (ServiceId) mnode.getUserObject(); LOGGER.info("clicked on node {} of type {}", node, node.getClass()); call.setService(service); populateMethodList(); updateModifyButtons(service); jsonButton.setEnabled(true); } catch (ClassCastException ex) { LOGGER.info("clicked on not ServiceId node"); methodList.setChoices(new ArrayList<MethodId>()); editButton.setEnabled(false); deleteButton.setEnabled(false); submitButton.setEnabled(false); jsonButton.setEnabled(false); } target.add(methodList); target.add(editButton); target.add(deleteButton); target.add(submitButton); target.add(jsonButton); target.add(feedbackPanel); } }; serviceList.setOutputMarkupId(true); form.add(serviceList); serviceList.getTreeState().expandAll(); submitButton.setOutputMarkupId(true); submitButton.setEnabled(false); jsonButton.setOutputMarkupId(true); jsonButton.setEnabled(false); form.add(submitButton); form.add(editButton); form.add(deleteButton); form.add(jsonButton); return form; }
From source file:org.openengsb.ui.admin.testClient.TestClient.java
private DefaultMutableTreeNode findService(DefaultMutableTreeNode node, ServiceId jumpToService) { if (node.isLeaf()) { Object userObject = node.getUserObject(); if (jumpToService.equals(userObject)) { return node; }/*from ww w.j a v a 2s .c o m*/ } else { for (int i = 0; i < node.getChildCount(); i++) { DefaultMutableTreeNode result = findService((DefaultMutableTreeNode) node.getChildAt(i), jumpToService); if (result != null) { return result; } } } return null; }
From source file:org.openengsb.ui.admin.testClient.TestClientTest.java
@Test public void testForEachDomainVisibleInCreatePartIsAnEntryInTree_shouldWork() throws Exception { setupAndStartTestClientPage();/* w w w .jav a2 s . c o m*/ tester.assertRenderedPage(TestClient.class); List<String> domains = new ArrayList<String>(); List<String> availableInTree = new ArrayList<String>(); List<DefaultMutableTreeNode> availableInTreeAsTreeNode = new ArrayList<DefaultMutableTreeNode>(); Component domainsComponent = tester.getComponentFromLastRenderedPage("serviceManagementContainer:domains"); int count = ((ArrayList<?>) domainsComponent.getDefaultModelObject()).size(); // get all domains for (int i = 0; i < count; i++) { Component label = tester .getComponentFromLastRenderedPage("serviceManagementContainer:domains:" + i + ":domain.name"); domains.add(label.getDefaultModelObjectAsString()); } // get all services from the tree DefaultTreeModel serviceListTree = (DefaultTreeModel) tester .getComponentFromLastRenderedPage("methodCallForm:serviceList").getDefaultModelObject(); count = serviceListTree.getChildCount(serviceListTree.getRoot()); for (int i = 0; i < count; i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) serviceListTree .getChild(serviceListTree.getRoot(), i); String userObject = (String) child.getUserObject(); availableInTreeAsTreeNode.add(child); availableInTree.add(userObject); } for (int i = 0; i < domains.size(); i++) { String domain = domains.get(i); assertThat(availableInTree.contains(domain), is(true)); assertThat(serviceListTree.getChildCount(availableInTreeAsTreeNode.get(i)), greaterThan(0)); } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Returns <code>true</code> if the first child of the passed node * is one of the added element.//from www . j a v a 2s. c o m * * @param parent The node to handle. * @return See above. */ boolean isFirstChildMessage(TreeImageDisplay parent) { int n = parent.getChildCount(); if (n == 0) return true; DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getChildAt(0); Object uo = node.getUserObject(); if (Browser.LOADING_MSG.equals(uo) || Browser.EMPTY_MSG.equals(uo)) return true; return false; }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Collapses the node when an on-going data loading is cancelled. * /* w ww . ja va 2s . co m*/ * @param node The node to collapse. */ void cancel(DefaultMutableTreeNode node) { if (node == null) return; if (node.getChildCount() <= 1) { if (node.getUserObject() instanceof String) { node.removeAllChildren(); buildEmptyNode(node); } } //in this order otherwise the node is not collapsed. ((DefaultTreeModel) treeDisplay.getModel()).reload(node); collapsePath(node); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Sets the number of items imported during a period of time. * /* w ww. j a v a 2s . co m*/ * @param expNode The node hosting the experimenter. * @param index The index of the time node. * @param value The value to set. */ void setCountValues(TreeImageDisplay expNode, int index, Object value) { DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); if (model.getBrowserType() != Browser.TAGS_EXPLORER) expNode.setChildrenLoaded(Boolean.valueOf(true)); int n = expNode.getChildCount(); TreeImageSet node; List l; Iterator i, k; TreeImageTimeSet child; //Test List<TreeImageSet> toRemove = new ArrayList<TreeImageSet>(); List<TreeImageSet> toKeep = new ArrayList<TreeImageSet>(); int number; int total; DefaultMutableTreeNode childNode; List<DefaultMutableTreeNode> remove = new ArrayList<DefaultMutableTreeNode>(); for (int j = 0; j < n; j++) { childNode = (DefaultMutableTreeNode) expNode.getChildAt(j); Object o = childNode.getUserObject(); if (o instanceof String) { String s = (String) o; if (Browser.EMPTY_MSG.equals(s)) { remove.add(childNode); } } if (childNode instanceof TreeImageTimeSet) { node = (TreeImageTimeSet) childNode; if (((TreeImageTimeSet) node).getType() == index) { if (value instanceof Integer) { //Check if the number is 0 int vv = ((Integer) value).intValue(); long v = node.getNumberItems(); node.setNumberItems(vv); if (v == 0 && vv > 0) { buildEmptyNode(node); node.setChildrenLoaded(Boolean.valueOf(false)); } } else if (value instanceof List) { l = (List) value; total = 0; i = node.getChildrenDisplay().iterator(); while (i.hasNext()) { child = (TreeImageTimeSet) i.next(); number = child.countTime(l); total += number; if (number > 0) { child.setNumberItems(number); toKeep.add(child); } else { toRemove.add(child); } } node.removeAllChildren(); node.removeChildrenDisplay(toRemove); node.setNumberItems(total); k = toKeep.iterator(); while (k.hasNext()) { dtm.insertNodeInto((TreeImageTimeSet) k.next(), node, node.getChildCount()); } } dtm.reload(node); } } else if (childNode instanceof TreeFileSet) { node = (TreeFileSet) childNode; if (((TreeFileSet) node).getType() == index) { if (value instanceof Long) node.setNumberItems((Long) value); } } } if (remove.size() > 0) { Iterator<DefaultMutableTreeNode> j = remove.iterator(); while (j.hasNext()) { expNode.remove(j.next()); dtm.reload(expNode); } } }
From source file:org.optaplanner.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.java
private CheckBoxTree createCheckBoxTree() { final CheckBoxTree resultCheckBoxTree = new CheckBoxTree(initBenchmarkHierarchy(true)); resultCheckBoxTree.addTreeSelectionListener(new TreeSelectionListener() { @Override/*from w ww .ja v a 2 s .c o m*/ public void valueChanged(TreeSelectionEvent e) { TreePath treeSelectionPath = e.getNewLeadSelectionPath(); if (treeSelectionPath != null) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treeSelectionPath .getLastPathComponent(); MixedCheckBox checkBox = (MixedCheckBox) treeNode.getUserObject(); detailTextArea.setText(checkBox.getDetail()); detailTextArea.setCaretPosition(0); renameNodeButton.setEnabled(checkBox.getBenchmarkResult() instanceof PlannerBenchmarkResult || checkBox.getBenchmarkResult() instanceof SolverBenchmarkResult); } } }); resultCheckBoxTree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { // Enable button if checked singleBenchmarkResults exist generateReportButton.setEnabled(!resultCheckBoxTree.getSelectedSingleBenchmarkNodes().isEmpty()); } }); checkBoxTree = resultCheckBoxTree; return resultCheckBoxTree; }
From source file:org.pentaho.reporting.designer.core.ReportDesignerFrame.java
private void insertReports(final TreeModel model, final Object currentLevel, final XulMenupopup popup) throws XulException { final int childCount = model.getChildCount(currentLevel); for (int i = 0; i < childCount; i += 1) { final ReportDesignerView frame = context.getView(); final Object child = model.getChild(currentLevel, i); if (model.isLeaf(child)) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) child; final File file = new File(String.valueOf(node.getUserObject())); final OpenSampleReportAction action = new OpenSampleReportAction(file, node.toString()); action.setReportDesignerContext(context); popup.addChild(frame.createMenuItem(action)); } else {//ww w.j av a2s. c o m final XulMenupopup childPopup = frame.createPopupMenu(String.valueOf(child), popup); insertReports(model, child, childPopup); } } }
From source file:org.photovault.swingui.volumetree.VolumeTreeController.java
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { DefaultMutableTreeNode expandingNode = (DefaultMutableTreeNode) event.getPath().getLastPathComponent(); Object o = expandingNode.getUserObject(); if (o instanceof VolumeTreeNode) { VolumeTreeNode node = (VolumeTreeNode) o; if (node.path.equals("") && node.state == NodeState.UNINITIALIZED) { node.state = NodeState.INITIALIZING; log.debug("expand volume " + node.volId); QuerySubfoldersTask fillTreeTask = new QuerySubfoldersTask( ((HibernateDAOFactory) getDAOFactory()).getSession(), this, expandingNode); fillTreeTask.execute();/*w w w . j a v a2 s. c o m*/ } } }
From source file:org.photovault.swingui.volumetree.VolumeTreeController.java
public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); VolumeTreeNode dir = (VolumeTreeNode) node.getUserObject(); // Test//from ww w . ja v a2 s . c om ExtDirPhotos photoQuery = new ExtDirPhotos(dir.volId, dir.path); fireEvent(new PhotoFolderTreeEvent(this, photoQuery)); List<PhotoInfo> photos = photoQuery.queryPhotos(getPersistenceContext()); log.debug("Directory " + dir.volId + ":" + dir.path + " selected. " + photos.size() + " photos."); }