Search in sources :

Example 31 with TreeColumn

use of org.eclipse.swt.widgets.TreeColumn in project eclipse.platform.swt by eclipse.

the class TreeTab method setColumnsMoveable.

/**
 * Sets the moveable columns state of the "Example" widgets.
 */
void setColumnsMoveable() {
    boolean selection = moveableColumns.getSelection();
    TreeColumn[] columns1 = tree1.getColumns();
    for (TreeColumn column : columns1) {
        column.setMoveable(selection);
    }
    TreeColumn[] columns2 = tree2.getColumns();
    for (TreeColumn column : columns2) {
        column.setMoveable(selection);
    }
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn)

Example 32 with TreeColumn

use of org.eclipse.swt.widgets.TreeColumn in project eclipse.platform.swt by eclipse.

the class TreeTab method createExampleWidgets.

/**
 * Creates the "Example" widgets.
 */
@Override
void createExampleWidgets() {
    /* Compute the widget style */
    int style = getDefaultStyle();
    if (singleButton.getSelection())
        style |= SWT.SINGLE;
    if (multiButton.getSelection())
        style |= SWT.MULTI;
    if (horizontalButton.getSelection())
        style |= SWT.H_SCROLL;
    if (verticalButton.getSelection())
        style |= SWT.V_SCROLL;
    if (noScrollButton.getSelection())
        style |= SWT.NO_SCROLL;
    if (checkButton.getSelection())
        style |= SWT.CHECK;
    if (fullSelectionButton.getSelection())
        style |= SWT.FULL_SELECTION;
    if (borderButton.getSelection())
        style |= SWT.BORDER;
    /* Create the text tree */
    tree1 = new Tree(treeGroup, style);
    boolean multiColumn = multipleColumns.getSelection();
    if (multiColumn) {
        for (String columnTitle : columnTitles) {
            TreeColumn treeColumn = new TreeColumn(tree1, SWT.NONE);
            treeColumn.setText(columnTitle);
            treeColumn.setToolTipText(ControlExample.getResourceString("Tooltip", columnTitle));
        }
        tree1.setSortColumn(tree1.getColumn(0));
    }
    for (int i = 0; i < 4; i++) {
        TreeItem item = new TreeItem(tree1, SWT.NONE);
        setItemText(item, i, ControlExample.getResourceString("Node_" + (i + 1)));
        if (i < 3) {
            TreeItem subitem = new TreeItem(item, SWT.NONE);
            setItemText(subitem, i, ControlExample.getResourceString("Node_" + (i + 1) + "_1"));
        }
    }
    TreeItem[] treeRoots = tree1.getItems();
    TreeItem item = new TreeItem(treeRoots[1], SWT.NONE);
    setItemText(item, 1, ControlExample.getResourceString("Node_2_2"));
    item = new TreeItem(item, SWT.NONE);
    setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1"));
    textNode1 = treeRoots[0];
    packColumns(tree1);
    try {
        TreeColumn column = tree1.getColumn(0);
        resizableColumns.setSelection(column.getResizable());
    } catch (IllegalArgumentException ex) {
    }
    /* Create the image tree */
    tree2 = new Tree(imageTreeGroup, style);
    Image image = instance.images[ControlExample.ciClosedFolder];
    if (multiColumn) {
        for (int i = 0; i < columnTitles.length; i++) {
            TreeColumn treeColumn = new TreeColumn(tree2, SWT.NONE);
            treeColumn.setText(columnTitles[i]);
            treeColumn.setToolTipText(ControlExample.getResourceString("Tooltip", columnTitles[i]));
            if (headerImagesButton.getSelection())
                treeColumn.setImage(instance.images[i % 3]);
        }
    }
    for (int i = 0; i < 4; i++) {
        item = new TreeItem(tree2, SWT.NONE);
        setItemText(item, i, ControlExample.getResourceString("Node_" + (i + 1)));
        if (multiColumn && subImagesButton.getSelection()) {
            for (int j = 0; j < columnTitles.length; j++) {
                item.setImage(j, image);
            }
        } else {
            item.setImage(image);
        }
        if (i < 3) {
            TreeItem subitem = new TreeItem(item, SWT.NONE);
            setItemText(subitem, i, ControlExample.getResourceString("Node_" + (i + 1) + "_1"));
            if (multiColumn && subImagesButton.getSelection()) {
                for (int j = 0; j < columnTitles.length; j++) {
                    subitem.setImage(j, image);
                }
            } else {
                subitem.setImage(image);
            }
        }
    }
    treeRoots = tree2.getItems();
    item = new TreeItem(treeRoots[1], SWT.NONE);
    setItemText(item, 1, ControlExample.getResourceString("Node_2_2"));
    if (multiColumn && subImagesButton.getSelection()) {
        for (int j = 0; j < columnTitles.length; j++) {
            item.setImage(j, image);
        }
    } else {
        item.setImage(image);
    }
    item = new TreeItem(item, SWT.NONE);
    setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1"));
    if (multiColumn && subImagesButton.getSelection()) {
        for (int j = 0; j < columnTitles.length; j++) {
            item.setImage(j, image);
        }
    } else {
        item.setImage(image);
    }
    imageNode1 = treeRoots[0];
    packColumns(tree2);
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 33 with TreeColumn

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);
    }
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) Point(org.eclipse.swt.graphics.Point) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 34 with TreeColumn

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();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Tree(org.eclipse.swt.widgets.Tree) Region(org.eclipse.swt.graphics.Region) FillLayout(org.eclipse.swt.layout.FillLayout) GC(org.eclipse.swt.graphics.GC) Display(org.eclipse.swt.widgets.Display)

Example 35 with TreeColumn

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);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Aggregations

TreeColumn (org.eclipse.swt.widgets.TreeColumn)95 Tree (org.eclipse.swt.widgets.Tree)43 TreeItem (org.eclipse.swt.widgets.TreeItem)31 Point (org.eclipse.swt.graphics.Point)26 TreeViewer (org.eclipse.jface.viewers.TreeViewer)23 Composite (org.eclipse.swt.widgets.Composite)23 GridData (org.eclipse.swt.layout.GridData)22 Test (org.junit.Test)16 FillLayout (org.eclipse.swt.layout.FillLayout)15 GridLayout (org.eclipse.swt.layout.GridLayout)15 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 Shell (org.eclipse.swt.widgets.Shell)10 Image (org.eclipse.swt.graphics.Image)8 Rectangle (org.eclipse.swt.graphics.Rectangle)8 Button (org.eclipse.swt.widgets.Button)8 ArrayList (java.util.ArrayList)7 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)7 CellEditor (org.eclipse.jface.viewers.CellEditor)6 Listener (org.eclipse.swt.widgets.Listener)6 ICellModifier (org.eclipse.jface.viewers.ICellModifier)5