Java Code Examples for org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode#getUserObject()

The following examples show how to use org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode#getUserObject() . 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: GanttTree2.java    From ganttproject with 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 2
Source File: ResourceTreeTable.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
/** 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 3
Source File: ResourceTreeTable.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
/** 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 4
Source File: GanttResourcePanel.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
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 5
Source File: RedisTreeTableModel.java    From gameserver with 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 6
Source File: GanttTree2.java    From ganttproject with 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 7
Source File: GanttTree2.java    From ganttproject with 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 8
Source File: GPTreeTransferHandler.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
@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 9
Source File: ResourceTreeTableModel.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
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 10
Source File: CheckTreeCellProvider.java    From GsonFormat with 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 11
Source File: FiledTreeTableModel.java    From GsonFormat with 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;
}
 
Example 12
Source File: FiledTreeTableModel.java    From GsonFormat with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: GanttChartSelection.java    From ganttproject with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Task apply(DefaultMutableTreeTableNode node) {
  return (Task) node.getUserObject();
}