use of org.eclipse.swt.widgets.TreeColumn in project eclipse.platform.swt by eclipse.
the class TreeTab method initializeSortState.
/**
* Sets the initial sort indicator state and adds a listener
* to cycle through sort states and columns.
*/
void initializeSortState(final Tree tree) {
/* Reset to known state: 'down' on column 0. */
tree.setSortDirection(SWT.DOWN);
TreeColumn[] columns = tree.getColumns();
for (int i = 0; i < columns.length; i++) {
TreeColumn column = columns[i];
if (i == 0)
tree.setSortColumn(column);
SelectionListener listener = widgetSelectedAdapter(e -> {
int sortDirection = SWT.DOWN;
if (e.widget == tree.getSortColumn()) {
/* If the sort column hasn't changed, cycle down -> up -> none. */
switch(tree.getSortDirection()) {
case SWT.DOWN:
sortDirection = SWT.UP;
break;
case SWT.UP:
sortDirection = SWT.NONE;
break;
}
} else {
tree.setSortColumn((TreeColumn) e.widget);
}
tree.setSortDirection(sortDirection);
});
column.addSelectionListener(listener);
// $NON-NLS-1$
column.setData("SortListener", listener);
}
}
use of org.eclipse.swt.widgets.TreeColumn in project eclipse.platform.swt by eclipse.
the class Bug529126_TreeMouseDown method main.
// Static =================================================================
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Custom gradient selection for Tree");
shell.setLayout(new FillLayout());
final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
final int columnCount = 4;
for (int i = 0; i < columnCount; i++) {
final TreeColumn column = new TreeColumn(tree, SWT.NONE);
column.setText("Column " + i);
}
final int itemCount = 5;
for (int i = 0; i < itemCount; i++) {
final TreeItem item1 = new TreeItem(tree, SWT.NONE);
for (int j = 0; j < i; j++) {
final TreeItem item2 = new TreeItem(item1, SWT.NONE);
for (int k = 0; k < j; k++) {
new TreeItem(item2, SWT.NONE);
}
}
}
tree.addListener(SWT.SetData, event -> {
final TreeItem item = (TreeItem) event.item;
final TreeItem parentItem = item.getParentItem();
final String text;
if (parentItem != null) {
final String parentText = (String) parentItem.getData();
text = parentText + event.index + "/";
} else {
text = "/";
}
item.setData(text);
});
tree.addListener(SWT.PaintItem, event -> {
final TreeItem item = (TreeItem) event.item;
final String text = (String) item.getData();
event.gc.drawText(text + " [" + event.index + "]", event.x, event.y, true);
});
/*
* NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly.
* Therefore, it is critical for performance that these methods be
* as efficient as possible.
*/
tree.addListener(SWT.EraseItem, event -> {
event.detail &= ~SWT.HOT;
if ((event.detail & SWT.SELECTED) != 0) {
final GC gc = event.gc;
final Rectangle area = tree.getClientArea();
/*
* If you wish to paint the selection beyond the end of
* last column, you must change the clipping region.
*/
final int columnCount1 = tree.getColumnCount();
if (event.index == columnCount1 - 1 || columnCount1 == 0) {
final int width = area.x + area.width - event.x;
if (width > 0) {
final Region region = new Region();
gc.getClipping(region);
region.add(event.x, event.y, width, event.height);
gc.setClipping(region);
region.dispose();
}
}
gc.setAdvanced(true);
if (gc.getAdvanced()) {
gc.setAlpha(127);
}
final Rectangle rect = event.getBounds();
final Color foreground = gc.getForeground();
final Color background = gc.getBackground();
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
gc.fillGradientRectangle(0, rect.y, 500, rect.height, false);
// restore colors for subsequent drawing
gc.setForeground(foreground);
gc.setBackground(background);
event.detail &= ~SWT.SELECTED;
}
});
tree.getColumn(0).setWidth(200);
for (int i = 1; i < columnCount; i++) {
tree.getColumn(i).pack();
}
tree.setSelection(tree.getItem(0));
tree.addListener(SWT.MouseDown, event -> System.out.println("event = " + event));
shell.setSize(500, 500);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
use of org.eclipse.swt.widgets.TreeColumn in project eclipse.platform.swt by eclipse.
the class MJ_Tree method bug73812_treeColumn_getWidth_0.
@Test
public void bug73812_treeColumn_getWidth_0() {
Shell shell = mkShell("Verify that all columns are of same width. (100).");
shell.setSize(SWIDTH, SHEIGHT);
shell.setLayout(new FillLayout());
final Tree tt = new Tree(shell, SWT.FULL_SELECTION | SWT.MULTI | SWT.VIRTUAL);
tt.setLinesVisible(true);
tt.setHeaderVisible(true);
for (int i = 0; i < 10; i++) {
TreeColumn tc = new TreeColumn(tt, SWT.NONE);
tc.setWidth(100);
System.out.println(tc.getWidth());
tc.setWidth(tc.getWidth());
tc.setText("Column " + i);
}
for (int i = 0; i < 100; i++) {
new TreeItem(tt, SWT.NONE);
}
shell.open();
mainLoop(shell);
}
use of org.eclipse.swt.widgets.TreeColumn in project dbeaver by dbeaver.
the class ExasolBaseTableToolDialog method getScriptListener.
@Override
protected SQLScriptProgressListener<ExasolTableBase> getScriptListener() {
final int nbExtraColumns = getNumberExtraResultingColumns();
return new SQLScriptStatusDialog<ExasolTableBase>(getTitle() + " " + ExasolMessages.dialog_table_tools_progress, null) {
@Override
protected void createStatusColumns(Tree objectTree) {
TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
msgColumn.setText(ExasolMessages.dialog_table_tools_result);
for (int i = 0; i < nbExtraColumns; i++) {
new TreeColumn(objectTree, SWT.NONE);
}
}
@Override
public void endObjectProcessing(@NotNull ExasolTableBase exasolTable, Exception exception) {
TreeItem treeItem = getTreeItem(exasolTable);
if (exception == null) {
treeItem.setText(1, ExasolMessages.dialog_table_tools_success_title);
} else {
treeItem.setText(1, exception.getMessage());
}
UIUtils.packColumns(treeItem.getParent(), false, null);
}
// DF: This method is for tools that return resultsets
@Override
public void processObjectResults(@NotNull ExasolTableBase exasolTable, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
if (resultSet == null) {
return;
}
// Retrieve column names
DBCResultSetMetaData rsMetaData = resultSet.getMeta();
try {
TreeItem treeItem = getTreeItem(exasolTable);
Font f = UIUtils.makeBoldFont(treeItem.getFont());
if (treeItem != null) {
// Display the column names
TreeItem subItem = null;
subItem = new TreeItem(treeItem, SWT.NONE);
subItem.setFont(f);
for (DBCAttributeMetaData column : rsMetaData.getAttributes()) {
subItem.setText(column.getOrdinalPosition(), column.getName());
subItem.setGrayed(true);
}
// Display the data for each row
while (resultSet.nextRow()) {
subItem = new TreeItem(treeItem, SWT.NONE);
for (int i = 0; i < rsMetaData.getAttributes().size(); i++) {
subItem.setText(i, CommonUtils.toString(resultSet.getAttributeValue(i)));
i++;
}
}
treeItem.setExpanded(true);
}
} catch (Exception e) {
throw new DBCException(e.getMessage());
}
}
};
}
use of org.eclipse.swt.widgets.TreeColumn in project dbeaver by dbeaver.
the class TableToolDialog method getScriptListener.
@Override
protected SQLScriptProgressListener<PostgreObject> getScriptListener() {
return new SQLScriptStatusDialog<PostgreObject>(getTitle() + " progress", null) {
@Override
protected void createStatusColumns(Tree objectTree) {
TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
msgColumn.setText("Message");
}
@Override
public void processObjectResults(@NotNull PostgreObject object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
if (statement == null) {
return;
}
TreeItem treeItem = getTreeItem(object);
if (treeItem != null) {
try {
int warnNum = 0;
SQLWarning warning = ((JDBCStatement) statement).getWarnings();
while (warning != null) {
if (warnNum == 0) {
treeItem.setText(1, warning.getMessage());
} else {
TreeItem warnItem = new TreeItem(treeItem, SWT.NONE);
warnItem.setText(0, "");
warnItem.setText(1, warning.getMessage());
}
warnNum++;
warning = warning.getNextWarning();
}
if (warnNum == 0) {
treeItem.setText(1, "Done");
}
} catch (SQLException e) {
// ignore
}
treeItem.setExpanded(true);
}
}
@Override
public void endObjectProcessing(@NotNull PostgreObject object, Exception error) {
super.endObjectProcessing(object, error);
if (error != null) {
TreeItem treeItem = getTreeItem(object);
if (treeItem != null) {
treeItem.setText(1, error.getMessage());
}
}
}
};
}
Aggregations