org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode Java Examples
The following examples show how to use
org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisTreeTableModel.java From gameserver with Apache License 2.0 | 6 votes |
@Override public Object getValueAt(Object node, int column) { Object value = null; if ( node instanceof DefaultMutableTreeTableNode ) { DefaultMutableTreeTableNode mutableNode = (DefaultMutableTreeTableNode)node; Object o = mutableNode.getUserObject(); if ( o != null && o instanceof String[] ) { String[] array = (String[])o; if ( column >= array.length ) { return ""; } else { value = array[column]; } } } return value; }
Example #2
Source File: ResourceTreeTable.java From ganttproject with GNU General Public License v3.0 | 6 votes |
/** Move the selected resource down */ public void downResource() { final DefaultMutableTreeTableNode[] selectedNodes = getSelectedNodes(); if (selectedNodes.length == 0) { return; } DefaultMutableTreeTableNode selectedNode = selectedNodes[0]; TreeNode nextSibling = TreeUtil.getNextSibling(selectedNode); if (nextSibling == null) { return; } if (selectedNode instanceof ResourceNode) { HumanResource people = (HumanResource) selectedNode.getUserObject(); myResourceTreeModel.moveDown(people); getTreeSelectionModel().setSelectionPath(TreeUtil.createPath(selectedNode)); } else if (selectedNode instanceof AssignmentNode) { swapAssignents((AssignmentNode) selectedNode, (AssignmentNode) nextSibling); } }
Example #3
Source File: TaskContainmentHierarchyFacadeImpl.java From ganttproject with GNU General Public License v3.0 | 6 votes |
@Override public Task[] getNestedTasks(Task container) { Task[] result = null; MutableTreeTableNode treeNode = myTask2treeNode.get(container); if (treeNode != null) { ArrayList<Task> list = new ArrayList<Task>(); for (Enumeration children = treeNode.children(); children.hasMoreElements();) { DefaultMutableTreeTableNode next = (DefaultMutableTreeTableNode) children.nextElement(); if (next instanceof TaskNode) { list.add((Task) next.getUserObject()); } } result = list.toArray(new Task[0]); } return result == null ? new Task[0] : result; }
Example #4
Source File: GanttTree2.java From ganttproject with GNU General Public License v3.0 | 6 votes |
@Override protected void handlePopupTrigger(MouseEvent e) { if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON3) { TreePath selPath = getTreeTable().getTreeTable().getPathForLocation(e.getX(), e.getY()); if (selPath != null) { DefaultMutableTreeTableNode treeNode = (DefaultMutableTreeTableNode) selPath.getLastPathComponent(); Task task = (Task) treeNode.getUserObject(); if (!getTaskSelectionManager().isTaskSelected(task)) { getTaskSelectionManager().clear(); getTaskSelectionManager().addTask(task); } } createPopupMenu(e.getX(), e.getY()); e.consume(); } }
Example #5
Source File: ResourceTreeTable.java From ganttproject with GNU General Public License v3.0 | 6 votes |
/** Move selected resource up */ public void upResource() { final DefaultMutableTreeTableNode[] selectedNodes = getSelectedNodes(); if (selectedNodes.length != 1) { return; } DefaultMutableTreeTableNode selectedNode = selectedNodes[0]; TreeNode previousSibling = TreeUtil.getPrevSibling(selectedNode); if (previousSibling == null) { return; } if (selectedNode instanceof ResourceNode) { HumanResource people = (HumanResource) selectedNode.getUserObject(); myResourceTreeModel.moveUp(people); getTreeSelectionModel().setSelectionPath(TreeUtil.createPath(selectedNode)); } else if (selectedNode instanceof AssignmentNode) { swapAssignents((AssignmentNode) selectedNode, (AssignmentNode) previousSibling); } }
Example #6
Source File: GanttResourcePanel.java From ganttproject with GNU General Public License v3.0 | 6 votes |
@Override protected void onSelectionChanged(List<DefaultMutableTreeTableNode> selection) { super.onSelectionChanged(selection); getPropertiesAction().setEnabled(!selection.isEmpty()); updateContextActions(); List<Task> selectedTasks = Lists.newArrayList(); for (DefaultMutableTreeTableNode node : selection) { if (node instanceof AssignmentNode) { selectedTasks.add(((AssignmentNode) node).getTask()); } } if (selectedTasks.isEmpty()) { myUIFacade.getTaskSelectionManager().clear(); } else { myUIFacade.getTaskSelectionManager().setSelectedTasks(selectedTasks); } }
Example #7
Source File: GanttResourcePanel.java From ganttproject with GNU General Public License v3.0 | 6 votes |
private void saveSelectionToClipboard(ClipboardContents clipboardContents, boolean cut) { DefaultMutableTreeTableNode selectedNodes[] = getSelectedNodes(); if (selectedNodes == null) { return; } for (DefaultMutableTreeTableNode node : selectedNodes) { if (node instanceof ResourceNode) { HumanResource res = (HumanResource) node.getUserObject(); if (cut) { this.appli.getHumanResourceManager().remove(res, this.appli.getUndoManager()); } clipboardContents.addResource(res); } } }
Example #8
Source File: GanttResourcePanel.java From ganttproject with GNU General Public License v3.0 | 6 votes |
@Override public ResourceAssignment[] getResourceAssignments() { ResourceAssignment[] res = null; DefaultMutableTreeTableNode[] tNodes = getSelectedNodes(); if (tNodes != null) { int nbAssign = 0; for (int i = 0; i < tNodes.length; i++) { if (tNodes[i] instanceof AssignmentNode) { nbAssign++; } } res = new ResourceAssignment[nbAssign]; for (int i = 0; i < nbAssign; i++) { if (tNodes[i] instanceof AssignmentNode) { res[i] = (ResourceAssignment) ((AssignmentNode) tNodes[i]).getUserObject(); } } } return res; }
Example #9
Source File: GanttResourcePanel.java From ganttproject with GNU General Public License v3.0 | 6 votes |
@Override protected void handlePopupTrigger(MouseEvent e) { if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON3) { DefaultMutableTreeTableNode[] selectedNodes = getSelectedNodes(); // TODO Allow to have multiple assignments selected as well! if (selectedNodes.length == 1 && selectedNodes[0] instanceof AssignmentNode) { // Clicked on an assignment node (ie a task assigned to a resource) AssignmentNode assignmentNode = (AssignmentNode) selectedNodes[0]; getTaskSelectionManager().clear(); getTaskSelectionManager().addTask(assignmentNode.getTask()); Point popupPoint = getPopupMenuPoint(e); getUIFacade().showPopupMenu(this, new Action[]{myTaskPropertiesAction, myResourceActionSet.getAssignmentDelete()}, popupPoint.x, popupPoint.y); } else { createPopupMenu(e); } } }
Example #10
Source File: GanttResourcePanel.java From ganttproject with GNU General Public License v3.0 | 6 votes |
@Override public HumanResource[] getResources() { // ProjectResource[] res; // List allRes = model.getAllResouces(); // res = new ProjectResource[allRes.size()]; // model.getAllResouces().toArray(res); // return res; DefaultMutableTreeTableNode[] tNodes = getSelectedNodes(); if (tNodes == null) { return new HumanResource[0]; } int nbHumanResource = 0; for (int i = 0; i < tNodes.length; i++) { if (tNodes[i] instanceof ResourceNode) { nbHumanResource++; } } HumanResource[] res = new HumanResource[nbHumanResource]; for (int i = 0; i < nbHumanResource; i++) { if (tNodes[i] instanceof ResourceNode) { res[i] = (HumanResource) ((ResourceNode) tNodes[i]).getUserObject(); } } return res; }
Example #11
Source File: GPTreeTransferHandler.java From ganttproject with GNU General Public License v3.0 | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } try { Transferable t = support.getTransferable(); final ClipboardContents clipboard = (ClipboardContents) t.getTransferData(GPTransferable.INTERNAL_DATA_FLAVOR); JXTreeTable.DropLocation dl = (JXTreeTable.DropLocation) support.getDropLocation(); int dropRow = myTreeTable.rowAtPoint(dl.getDropPoint()); TreePath dropPath = myTreeTable.getPathForRow(dropRow); if (dropPath == null) { return false; } DefaultMutableTreeTableNode dropNode = (DefaultMutableTreeTableNode) dropPath.getLastPathComponent(); final Task dropTask = (Task) dropNode.getUserObject(); final ClipboardTaskProcessor processor = new ClipboardTaskProcessor(myTaskManager); if (processor.canMove(dropTask, clipboard)) { myUndoManager.undoableEdit(GanttLanguage.getInstance().getText("dragndrop.undo.label"), new Runnable() { @Override public void run() { clipboard.cut(); processor.pasteAsChild(dropTask, clipboard); } }); return true; } } catch (UnsupportedFlavorException | IOException | RuntimeException e) { GPLogger.logToLogger(e); } return false; }
Example #12
Source File: GanttChartSelection.java From ganttproject with GNU General Public License v3.0 | 5 votes |
public ClipboardContents buildClipboardContents() { DefaultMutableTreeTableNode[] selectedNodes = myTree.getSelectedNodes(); GPLogger.getLogger("Clipboard").fine(String.format("Selected nodes: %s", Arrays.asList(selectedNodes))); List<DefaultMutableTreeTableNode> selectedRoots = Lists.newArrayList(); myRetainRootsAlgorithm.run(selectedNodes, getParentNode, selectedRoots); GPLogger.getLogger("Clipboard").fine(String.format("Roots: %s", selectedRoots)); ClipboardContents result = new ClipboardContents(myTaskManager); result.addTasks(Lists.transform(selectedRoots, getTaskFromNode)); return result; }
Example #13
Source File: ResourceTreeTableModel.java From ganttproject with GNU General Public License v3.0 | 5 votes |
private DefaultMutableTreeTableNode buildTree() { DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode(); List<HumanResource> listResources = myResourceManager.getResources(); Iterator<HumanResource> itRes = listResources.iterator(); while (itRes.hasNext()) { HumanResource hr = itRes.next(); ResourceNode rnRes = new ResourceNode(hr); // the first for the resource root.add(rnRes); } return root; }
Example #14
Source File: ResourceTreeTableModel.java From ganttproject with GNU General Public License v3.0 | 5 votes |
SelectionKeeper(TreeSelectionModel selectionModel, DefaultMutableTreeTableNode changingSubtreeRoot) { mySelectionModel = selectionModel; myChangingSubtreeRoot = changingSubtreeRoot; TreePath selectionPath = mySelectionModel.getSelectionPath(); if (selectionPath != null && TreeUtil.createPath(myChangingSubtreeRoot).isDescendant(selectionPath)) { hasWork = true; DefaultMutableTreeTableNode lastNode = (DefaultMutableTreeTableNode) selectionPath.getLastPathComponent(); myModelObject = lastNode.getUserObject(); } }
Example #15
Source File: GanttResourcePanel.java From ganttproject with GNU General Public License v3.0 | 5 votes |
/** * Create a new Human */ public void newHuman(HumanResource people) { if (people != null) { try { DefaultMutableTreeTableNode result = getTreeModel().addResource(people); getTreeTable().getTree().scrollPathToVisible(TreeUtil.createPath(result)); } catch (Exception e) { System.err.println("when adding this guy: " + people); e.printStackTrace(); } } }
Example #16
Source File: TreeTableContainer.java From ganttproject with GNU General Public License v3.0 | 5 votes |
public DefaultMutableTreeTableNode[] getSelectedNodes() { TreePath[] currentSelection = getTree().getTreeSelectionModel().getSelectionPaths(); if (currentSelection == null || currentSelection.length == 0) { return new DefaultMutableTreeTableNode[0]; } DefaultMutableTreeTableNode[] result = new DefaultMutableTreeTableNode[currentSelection.length]; for (int i = 0; i < currentSelection.length; i++) { result[i] = (DefaultMutableTreeTableNode) currentSelection[i].getLastPathComponent(); } return result; }
Example #17
Source File: CheckTreeSelectionModel.java From GsonFormat with Apache License 2.0 | 5 votes |
public void addPathsByNodes(List selectedNodes) { int num = selectedNodes.size(); TreePath[] tps = new TreePath[num]; for (int i = 0; i < num; i++) { DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) selectedNodes.get(i); tps[i] = new TreePath(getPathToRoot(node)); } this.addSelectionPaths(tps); }
Example #18
Source File: CheckTreeCellProvider.java From GsonFormat with Apache License 2.0 | 5 votes |
@Override protected void format(CellContext arg0) { // 从CellContext获取tree中的文字和图标 JTree tree = (JTree) arg0.getComponent(); DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) arg0.getValue(); Object obj = node.getUserObject(); if(obj instanceof FieldEntity){ _label.setText(((FieldEntity) obj).getKey()); _checkBox.setSelector((FieldEntity) obj); }else if(obj instanceof ClassEntity){ _label.setText(((ClassEntity) obj).getClassName()); _checkBox.setSelector((ClassEntity) obj); } // _label.setIcon(arg0.getIcon()); // 根据selectionModel中的状态来绘制TristateCheckBox的外观 TreePath path = tree.getPathForRow(arg0.getRow()); if (path != null) { if (selectionModel.isPathSelected(path, true)) { _checkBox.setState(Boolean.TRUE); } else if (selectionModel.isPartiallySelected(path)) { _checkBox.setState(null); // 注意“部分选中”状态的API } else { _checkBox.setState(Boolean.FALSE); } } // 使用BorderLayout布局,依次放置TristateCheckBox和JLabel rendererComponent.setLayout(new BorderLayout()); rendererComponent.add(_checkBox); rendererComponent.add(_label, BorderLayout.LINE_END); }
Example #19
Source File: FiledTreeTableModel.java From GsonFormat with Apache License 2.0 | 5 votes |
/** * 返回在单元格中显示的Object */ @Override public Object getValueAt(Object node, int column) { Object value = ""; if (node instanceof DefaultMutableTreeTableNode) { DefaultMutableTreeTableNode mutableNode = (DefaultMutableTreeTableNode) node; Object o = mutableNode.getUserObject(); if (o != null && o instanceof CellProvider) { CellProvider cellProvider = (CellProvider) o; value = cellProvider.getCellTitle(column); } } return value; }
Example #20
Source File: FiledTreeTableModel.java From GsonFormat with Apache License 2.0 | 5 votes |
@Override public void setValueAt(Object value, Object node, int column) { super.setValueAt(value, node, column); if (node instanceof DefaultMutableTreeTableNode) { DefaultMutableTreeTableNode mutableNode = (DefaultMutableTreeTableNode) node; Object o = mutableNode.getUserObject(); if (o != null && o instanceof CellProvider) { CellProvider cellProvider = (CellProvider) o; cellProvider.setValueAt(column,value.toString()); } } }
Example #21
Source File: RedisCleanService.java From gameserver with Apache License 2.0 | 5 votes |
@Override protected Void doInBackground() throws Exception { publish(); Thread.sleep(100); stage = Stage.DELETE; try { Set<byte[]> keys = jedis.keys("*".getBytes()); if ( keys != null ) { DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode(); ArrayList<byte[]> keyList = new ArrayList<byte[]>(); for ( byte[] key : keys ) { keyList.add(key); } progressBar.setMaximum(keyList.size()); int i = 0; for ( byte[] keyStr : keyList ) { jedis.del(keyStr); publish(i++); } } else { JOptionPane.showMessageDialog(null, "无法链接到Redis服务器"); } } catch (Exception e) { e.printStackTrace(); } return null; }
Example #22
Source File: GanttChartController.java From ganttproject with GNU General Public License v3.0 | 5 votes |
@Override public void paste(ChartSelection selection) { DefaultMutableTreeTableNode[] selectedNodes = myTree.getSelectedNodes(); if (selectedNodes.length > 1) { return; } DefaultMutableTreeTableNode pasteRoot = selectedNodes.length == 0 ? myTree.getRoot() : selectedNodes[0]; for (Task t : mySelection.paste((Task)pasteRoot.getUserObject())) { mySelectionManager.addTask(t); } }
Example #23
Source File: ResourceTreeTable.java From ganttproject with GNU General Public License v3.0 | 5 votes |
public boolean canMoveSelectionDown() { final DefaultMutableTreeTableNode[] selectedNodes = getSelectedNodes(); if (selectedNodes.length != 1) { return false; } DefaultMutableTreeTableNode selectedNode = selectedNodes[0]; TreeNode nextSibling = TreeUtil.getNextSibling(selectedNode); if (nextSibling == null) { return false; } return true; }
Example #24
Source File: FileSystemPanel.java From aion-germany with GNU General Public License v3.0 | 5 votes |
@Override public Object getValueAt(Object node, int column) { if (node instanceof LogFileNode) { LogFileNode logNode = ((LogFileNode)node); switch(column) { case 0: return logNode.getLogFile().getName(); case 1: long size = logNode.getLogFile().getSize(); if (size > 0 && size < 1024) { return "< 1 KB"; } return (size/1024)+" KB"; case 2: return logNode.getLogFile().getRemoteUploader(); default: return ""; } } DefaultMutableTreeTableNode defNode = (DefaultMutableTreeTableNode) node; switch(column) { case 0: return defNode.toString(); default: return null; } }
Example #25
Source File: ResourceTreeTable.java From ganttproject with GNU General Public License v3.0 | 5 votes |
public boolean canMoveSelectionUp() { final DefaultMutableTreeTableNode[] selectedNodes = getSelectedNodes(); if (selectedNodes.length != 1) { return false; } DefaultMutableTreeTableNode selectedNode = selectedNodes[0]; TreeNode previousSibling = TreeUtil.getPrevSibling(selectedNode); if (previousSibling == null) { return false; } return true; }
Example #26
Source File: ResourceTreeTable.java From ganttproject with GNU General Public License v3.0 | 5 votes |
/** @return the list of the selected nodes. */ @Deprecated public DefaultMutableTreeTableNode[] getSelectedNodes() { TreePath[] currentSelection = getTreeSelectionModel().getSelectionPaths(); if (currentSelection == null || currentSelection.length == 0) { return new DefaultMutableTreeTableNode[0]; } DefaultMutableTreeTableNode[] dmtnselected = new DefaultMutableTreeTableNode[currentSelection.length]; for (int i = 0; i < currentSelection.length; i++) { dmtnselected[i] = (DefaultMutableTreeTableNode) currentSelection[i].getLastPathComponent(); } return dmtnselected; }
Example #27
Source File: GanttTree2.java From ganttproject with GNU General Public License v3.0 | 5 votes |
@Override protected void onSelectionChanged(List<DefaultMutableTreeTableNode> selection) { if (isOnTaskSelectionEventProcessing) { return; } List<Task> selectedTasks = Lists.newArrayList(); for (DefaultMutableTreeTableNode node : selection) { if (node instanceof TaskNode) { selectedTasks.add((Task) node.getUserObject()); } } mySelectionManager.setSelectedTasks(selectedTasks); }
Example #28
Source File: GanttTree2.java From ganttproject with GNU General Public License v3.0 | 5 votes |
/** add an object with the expand information */ DefaultMutableTreeTableNode addObjectWithExpand(Object child, MutableTreeTableNode parent) { DefaultMutableTreeTableNode childNode = new TaskNode((Task) child); if (parent == null) { parent = getRootNode(); } getTreeModel().insertNodeInto(childNode, parent, parent.getChildCount()); myProject.refreshProjectInformation(); return childNode; }
Example #29
Source File: GanttTree2.java From ganttproject with GNU General Public License v3.0 | 5 votes |
@Override public void treeCollapsed(TreeExpansionEvent e) { if (area != null) { area.repaint(); } DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) (e.getPath().getLastPathComponent()); Task task = (Task) node.getUserObject(); task.setExpand(false); myProject.setAskForSave(true); }
Example #30
Source File: GanttTree2.java From ganttproject with GNU General Public License v3.0 | 5 votes |
@Override public void treeExpanded(TreeExpansionEvent e) { if (area != null) { area.repaint(); } DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) (e.getPath().getLastPathComponent()); Task task = (Task) node.getUserObject(); task.setExpand(true); myProject.setAskForSave(true); }