Java Code Examples for org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode

The following examples show how to use org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode. These examples are extracted from open source projects. 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
@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 2
Source Project: ganttproject   Source File: GanttTree2.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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 3
/** 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 4
/** 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 5
@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 6
@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 7
@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 8
@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
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 10
Source Project: gameserver   Source File: RedisTreeTableModel.java    License: Apache License 2.0 6 votes vote down vote up
@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 11
Source Project: aion-germany   Source File: FileSystemPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 12
Source Project: ganttproject   Source File: GanttTree2.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 13
Source Project: ganttproject   Source File: GanttTree2.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** 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 14
Source Project: ganttproject   Source File: GanttTree2.java    License: GNU General Public License v3.0 5 votes vote down vote up
static List<Task> convertNodesListToItemList(List<DefaultMutableTreeTableNode> nodesList) {
  List<Task> res = new ArrayList<Task>(nodesList.size());
  Iterator<DefaultMutableTreeTableNode> itNodes = nodesList.iterator();
  while (itNodes.hasNext()) {
    res.add((Task) itNodes.next().getUserObject());
  }
  return res;
}
 
Example 15
Source Project: ganttproject   Source File: GanttTree2.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** @return the mother task. */
public static DefaultMutableTreeTableNode getParentNode(DefaultMutableTreeTableNode node) {
  if (node == null) {
    return null;
  }
  return (DefaultMutableTreeTableNode) node.getParent();
}
 
Example 16
Source Project: ganttproject   Source File: GanttTree2.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 17
Source Project: ganttproject   Source File: GanttTree2.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 18
/** @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 19
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 20
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 21
@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 22
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 23
@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 24
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 25
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 26
/**
 * 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 27
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 28
Source Project: GsonFormat   Source File: CheckTreeSelectionModel.java    License: Apache License 2.0 5 votes vote down vote up
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 29
Source Project: GsonFormat   Source File: CheckTreeCellProvider.java    License: Apache License 2.0 5 votes vote down vote up
@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 30
Source Project: GsonFormat   Source File: FiledTreeTableModel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 返回在单元格中显示的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;
}