use of de.jaret.util.ui.table.model.ITableNode in project translationstudio8 by heartsome.
the class TableHierarchicalExample method createControls.
/**
* Create the controls that compose the console test.
*
*/
protected void createControls(IHierarchicalJaretTableModel hierarchicalModel) {
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_shell.setLayout(gl);
GridData gd = new GridData(GridData.FILL_BOTH);
_jt = new JaretTable(_shell, SWT.V_SCROLL | SWT.H_SCROLL);
_jt.setLayoutData(gd);
IHierarchicalJaretTableModel hmodel = hierarchicalModel;
if (hierarchicalModel == null) {
ITableNode root = new DummyTableNode("tn1", "tn1", "Root", "This the root node");
ITableNode r1 = new DummyTableNode("tn11", "tn12", "1", "Child 1 of the root");
ITableNode r2 = new DummyTableNode("tn12", "tn12", "2", "Child 2 of the root");
ITableNode r3 = new DummyTableNode("tn13", "tn13", "3", "Child 3 of the root");
root.addNode(r1);
root.addNode(r2);
root.addNode(r3);
r1.addNode(new DummyTableNode("tn111", "tn111", "1", "A second level child"));
r1.addNode(new DummyTableNode("tn112", "tn112", "2", "Another second level child"));
ITableNode n1 = new DummyTableNode("tn131", "tn131", "1", "A second level child");
r3.addNode(n1);
ITableNode n2 = new DummyTableNode("tn132", "tn132", "2", "Another second level child");
r3.addNode(n2);
n1.addNode(new DummyTableNode("tn1311", "tn1311", "1", "A third level child"));
n1.addNode(new DummyTableNode("tn1312", "tn1312", "2", "Another third level child"));
DefaultHierarchicalTableModel dhmodel = new DefaultHierarchicalTableModel(root);
hmodel = dhmodel;
if (SUPPORT_DND) {
// init the simple drag and drop handling
initDND(_jt, _shell);
}
}
_jt.setTableModel(hmodel);
StdHierarchicalTableModel model = (StdHierarchicalTableModel) _jt.getTableModel();
IColumn hcol = new HierarchyColumn();
// create and setup hierarchy renderer
final TableHierarchyRenderer hierarchyRenderer = new TableHierarchyRenderer();
hierarchyRenderer.setLabelProvider(new LabelProvider());
hierarchyRenderer.setDrawIcons(true);
hierarchyRenderer.setDrawLabels(true);
_jt.registerCellRenderer(hcol, hierarchyRenderer);
model.addColumn(hcol);
model.addColumn(new PropCol("b1", "column 1", "B1"));
model.addColumn(new PropCol("t1", "column 2", "T1"));
model.addColumn(new PropCol("t2", "column 3", "T2"));
model.addColumn(new PropCol("t3", "column 4", "T3"));
JaretTableActionFactory af = new JaretTableActionFactory();
MenuManager mm = new MenuManager();
mm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_CONFIGURECOLUMNS));
_jt.setHeaderContextMenu(mm.createContextMenu(_jt));
MenuManager rm = new MenuManager();
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTROWHEIGHT));
rm.add(af.createStdAction(_jt, JaretTableActionFactory.ACTION_OPTALLROWHEIGHTS));
_jt.setRowContextMenu(rm.createContextMenu(_jt));
TableControlPanel ctrlPanel = new TableControlPanel(_shell, SWT.NULL, _jt);
Label l = new Label(_shell, SWT.NONE);
l.setText("Level width:");
final Scale levelWidthScale = new Scale(_shell, SWT.HORIZONTAL);
levelWidthScale.setMaximum(40);
levelWidthScale.setMinimum(0);
levelWidthScale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent ev) {
int val = levelWidthScale.getSelection();
hierarchyRenderer.setLevelWidth(val);
_jt.redraw();
}
});
}
use of de.jaret.util.ui.table.model.ITableNode in project translationstudio8 by heartsome.
the class TableHierarchicalExample method initDND.
/**
* Init a simple drag and drop operation for moving rows in the table.
*
* @param table
* @param parent
*/
private void initDND(final JaretTable table, Composite parent) {
// support move only
int operations = DND.DROP_MOVE;
final DragSource source = new DragSource(table, operations);
// Provide data in Text format
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
source.setTransfer(types);
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
// check whether drag occured on the hierarchy column
IColumn column = table.colForX(event.x);
if (column != null && table.isHierarchyColumn(column)) {
// TODO check whether a resize may have
// higher priority
// possible row drag
IRow row = table.rowForY(event.y);
if (row != null) {
// row hit, start row drag
_draggedRow = row;
// capture the data for internal use
// row drag: use row at starting position
_parentTableNode = getParent(table.getHierarchicalModel().getRootNode(), (ITableNode) row);
} else {
event.doit = false;
}
}
}
public void dragSetData(DragSourceEvent event) {
// Provide the data of the requested type.
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
if (_draggedRow != null) {
event.data = "row: " + _draggedRow.getId();
}
}
}
public void dragFinished(DragSourceEvent event) {
// for this simple case we do all the manipulations in the drop
// target
// this is more of a hack ...
_draggedRow = null;
}
});
// ////////////////////
// Drop target
// moved to the drop target
operations = DND.DROP_MOVE;
final DropTarget target = new DropTarget(table, operations);
// Receive data in Text
final TextTransfer textTransfer = TextTransfer.getInstance();
types = new Transfer[] { textTransfer };
target.setTransfer(types);
target.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
if (_draggedRow != null) {
// no drag over effect right now
}
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dropAccept(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
// this is kind of a hack ...
if (textTransfer.isSupportedType(event.currentDataType)) {
String text = (String) event.data;
System.out.println("DROP: " + text);
if (_draggedRow != null) {
int destY = Display.getCurrent().map(null, table, event.x, event.y).y;
int destX = Display.getCurrent().map(null, table, event.x, event.y).x;
IRow overRow = table.rowForY(destY);
if (overRow != null) {
System.out.println("over row " + overRow.getId());
// this is an action from the drag source listener
// ...
// this has to be done right here because otherwise
// the node would be at two places
// at the same time causing some redraw trouble ...
_parentTableNode.remNode((ITableNode) _draggedRow);
ITableNode node = (ITableNode) overRow;
node.addNode((ITableNode) _draggedRow);
}
}
}
}
});
// Dispose listener on parent of timebar viewer to dispose the
// dragsource and dragtarget BEFORE the timebar
// viewer
// this prevents an exception beeing thrown by SWT
parent.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
source.dispose();
target.dispose();
}
});
}
use of de.jaret.util.ui.table.model.ITableNode in project translationstudio8 by heartsome.
the class TableHierarchyRenderer method draw.
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) {
int offx;
offx = scaleX(_levelWidth);
ITableNode node = (ITableNode) row;
int level = node.getLevel();
boolean leaf = node.getChildren().size() == 0;
boolean expanded = ((IHierarchicalTableViewState) jaretTable.getTableViewState()).isExpanded(node);
int x = drawingArea.x + offx * level + SIZE / 2;
int y = drawingArea.y + (drawingArea.height - SIZE) / 2;
if (leaf && !_drawIcons) {
drawLeaf(gc, SIZE, x, y);
} else if (expanded && !leaf) {
if (_nodeMarkType == 1) {
drawMinus(gc, SIZE, x, y);
} else if (_nodeMarkType == 2) {
drawTriangleDown(gc, SIZE, x, y);
}
} else if (!leaf) {
if (_nodeMarkType == 1) {
drawPlus(gc, SIZE, x, y);
} else if (_nodeMarkType == 2) {
drawTriangleRight(gc, SIZE, x, y);
}
}
if (_nodeMarkType != 0) {
x += SIZE + 4;
}
// default for drawing selection
Rectangle labelrect = drawingArea;
if (_labelProvider != null && (_drawIcons || _drawLabels)) {
int labelx = x;
labelrect = new Rectangle(x, y, 0, 0);
if (_drawIcons) {
Image img = _labelProvider.getImage(row);
if (img != null) {
if (!printing) {
gc.drawImage(img, x, y);
labelx += img.getBounds().width;
labelrect.width += img.getBounds().width;
labelrect.height = img.getBounds().height;
} else {
gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width), scaleY(img.getBounds().height));
labelx += scaleX(img.getBounds().width);
labelrect.width += scaleX(img.getBounds().width);
labelrect.height = scaleY(img.getBounds().height);
}
}
}
if (_drawLabels) {
String label = _labelProvider.getText(row);
if (label != null) {
gc.drawString(label, labelx, y);
Point extent = gc.stringExtent(label);
labelrect.width += extent.x;
labelrect.height = Math.max(labelrect.height, extent.y);
}
}
}
// draw tree connections
if (_drawTree) {
// TimeBarNode node = (TimeBarNode) row;
if (printing) {
gc.setLineWidth(3);
}
gc.setLineStyle(SWT.LINE_DOT);
int midy = drawingArea.y + ((drawingArea.height - SIZE) / 2) + SIZE / 2;
int icoy = drawingArea.y + ((drawingArea.height - SIZE) / 2) + SIZE;
int icox = drawingArea.x + offx * (level) + SIZE - SIZE / 2;
int midx = drawingArea.x + +offx * (level) + SIZE;
int beginx = drawingArea.x + offx * (level - 1) + SIZE;
int endx = drawingArea.x + offx * (level + 1) + SIZE;
// connection
gc.drawLine(beginx, midy, icox, midy);
// uplink
gc.drawLine(beginx, drawingArea.y, beginx, midy);
// downlink
if ((!leaf && expanded)) {
gc.drawLine(midx, icoy, midx, drawingArea.y + drawingArea.height);
}
boolean hasMoreSiblings = true;
if (jaretTable.getTableModel() instanceof StdHierarchicalTableModel) {
StdHierarchicalTableModel model = (StdHierarchicalTableModel) jaretTable.getTableModel();
hasMoreSiblings = model.moreSiblings(node, node.getLevel());
}
// level lines
if (jaretTable.getTableModel() instanceof StdHierarchicalTableModel) {
StdHierarchicalTableModel model = (StdHierarchicalTableModel) jaretTable.getTableModel();
for (int i = 0; i < level; i++) {
if (model.moreSiblings(node, i)) {
x = drawingArea.x + offx * i + SIZE;
gc.drawLine(x, drawingArea.y, x, drawingArea.y + drawingArea.height);
}
}
}
gc.setLineStyle(SWT.LINE_SOLID);
gc.setLineWidth(1);
}
if (drawFocus) {
drawFocus(gc, labelrect);
}
drawSelection(gc, labelrect, cellStyle, selected, printing);
}
use of de.jaret.util.ui.table.model.ITableNode in project translationstudio8 by heartsome.
the class TableHierarchyRenderer method isInActiveArea.
/**
* {@inheritDoc}
*/
public boolean isInActiveArea(IRow row, Rectangle drawingArea, int xx, int yy) {
int offx = scaleX(_levelWidth);
ITableNode node = (ITableNode) row;
int level = node.getLevel();
boolean leaf = node.getChildren().size() == 0;
// leaves can not be toggled
if (leaf) {
return false;
}
int x = drawingArea.x + offx * level + SIZE / 2;
int y = drawingArea.y + (drawingArea.height - SIZE) / 2;
return x <= xx && xx <= x + SIZE && y <= yy && yy <= y + SIZE;
}
Aggregations