Search in sources :

Example 41 with TreeColumn

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

the class Test_org_eclipse_swt_widgets_TreeItem method test_setBackgroundILorg_eclipse_swt_graphics_Color.

@Test
public void test_setBackgroundILorg_eclipse_swt_graphics_Color() {
    Display display = treeItem.getDisplay();
    Color red = display.getSystemColor(SWT.COLOR_RED);
    Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    // no columns
    assertEquals(tree.getBackground(), treeItem.getBackground(0));
    assertEquals(treeItem.getBackground(), treeItem.getBackground(0));
    treeItem.setBackground(0, red);
    assertEquals(red, treeItem.getBackground(0));
    // index beyond range - no error
    treeItem.setBackground(10, red);
    assertEquals(treeItem.getBackground(), treeItem.getBackground(10));
    // with columns
    new TreeColumn(tree, SWT.LEFT);
    new TreeColumn(tree, SWT.LEFT);
    // index beyond range - no error
    treeItem.setBackground(10, red);
    assertEquals(treeItem.getBackground(), treeItem.getBackground(10));
    treeItem.setBackground(0, red);
    assertEquals(red, treeItem.getBackground(0));
    treeItem.setBackground(0, null);
    assertEquals(tree.getBackground(), treeItem.getBackground(0));
    treeItem.setBackground(0, blue);
    treeItem.setBackground(red);
    assertEquals(blue, treeItem.getBackground(0));
    treeItem.setBackground(0, null);
    assertEquals(red, treeItem.getBackground(0));
    treeItem.setBackground(null);
    assertEquals(tree.getBackground(), treeItem.getBackground(0));
    try {
        Color color = new Color(display, 255, 0, 0);
        color.dispose();
        treeItem.setBackground(color);
        fail("No exception thrown for color disposed");
    } catch (IllegalArgumentException e) {
    }
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) Color(org.eclipse.swt.graphics.Color) Display(org.eclipse.swt.widgets.Display) Test(org.junit.Test)

Example 42 with TreeColumn

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

the class Test_org_eclipse_swt_widgets_TreeItem method test_setFontILorg_eclipse_swt_graphics_Font.

@Test
public void test_setFontILorg_eclipse_swt_graphics_Font() {
    Display display = treeItem.getDisplay();
    Font font = new Font(display, SwtTestUtil.testFontName, 10, SWT.NORMAL);
    // no columns
    assertTrue(tree.getFont().equals(treeItem.getFont(0)));
    assertTrue(treeItem.getFont().equals(treeItem.getFont(0)));
    treeItem.setFont(0, font);
    assertTrue(font.equals(treeItem.getFont(0)));
    // index beyond range - no error
    treeItem.setFont(10, font);
    assertTrue(treeItem.getFont().equals(treeItem.getFont(10)));
    // with columns
    new TreeColumn(tree, SWT.LEFT);
    new TreeColumn(tree, SWT.LEFT);
    // index beyond range - no error
    treeItem.setFont(10, font);
    assertTrue(treeItem.getFont().equals(treeItem.getFont(10)));
    treeItem.setFont(0, font);
    assertTrue(font.equals(treeItem.getFont(0)));
    treeItem.setFont(0, null);
    assertTrue(tree.getFont().equals(treeItem.getFont(0)));
    Font font2 = new Font(display, SwtTestUtil.testFontName, 20, SWT.NORMAL);
    treeItem.setFont(0, font);
    treeItem.setFont(font2);
    assertTrue(font.equals(treeItem.getFont(0)));
    treeItem.setFont(0, null);
    assertTrue(font2.equals(treeItem.getFont(0)));
    treeItem.setFont(null);
    assertTrue(tree.getFont().equals(treeItem.getFont(0)));
    font.dispose();
    font2.dispose();
    try {
        treeItem.setFont(0, font);
        treeItem.setFont(0, null);
        fail("No exception thrown for disposed font");
    } catch (IllegalArgumentException e) {
    }
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) Font(org.eclipse.swt.graphics.Font) Display(org.eclipse.swt.widgets.Display) Test(org.junit.Test)

Example 43 with TreeColumn

use of org.eclipse.swt.widgets.TreeColumn in project yamcs-studio by yamcs.

the class FunctionsView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    TreeColumnLayout tcl_composite = new TreeColumnLayout();
    composite.setLayout(tcl_composite);
    treeViewer = new TreeViewer(composite, SWT.BORDER);
    Tree tree = treeViewer.getTree();
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
    treeViewerColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return null;
        }

        @Override
        public String getText(Object element) {
            if (element instanceof FormulaFunctionSet) {
                return ((FormulaFunctionSet) element).getName();
            } else if (element instanceof FormulaFunction) {
                return FormulaFunctions.formatSignature((FormulaFunction) element);
            }
            return "";
        }
    });
    TreeColumn trclmnNewColumn = treeViewerColumn.getColumn();
    tcl_composite.setColumnData(trclmnNewColumn, new ColumnWeightData(10, ColumnWeightData.MINIMUM_WIDTH, true));
    trclmnNewColumn.setText("Name");
    TreeViewerColumn treeViewerColumn_1 = new TreeViewerColumn(treeViewer, SWT.NONE);
    treeViewerColumn_1.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return null;
        }

        @Override
        public String getText(Object element) {
            if (element instanceof FormulaFunction) {
                return ((FormulaFunction) element).getDescription();
            } else if (element instanceof FormulaFunctionSet) {
                return ((FormulaFunctionSet) element).getDescription();
            }
            return "";
        }
    });
    TreeColumn trclmnNewColumn_1 = treeViewerColumn_1.getColumn();
    tcl_composite.setColumnData(trclmnNewColumn_1, new ColumnWeightData(7, ColumnWeightData.MINIMUM_WIDTH, true));
    trclmnNewColumn_1.setText("Description");
    treeViewer.setContentProvider(new FunctionTreeContentProvider());
    List<String> functionSetNames = new ArrayList<>(FormulaRegistry.getDefault().listFunctionSets());
    Collections.sort(functionSetNames);
    List<FormulaFunctionSet> functionSets = new ArrayList<>();
    for (String functionSetName : functionSetNames) {
        functionSets.add(FormulaRegistry.getDefault().findFunctionSet(functionSetName));
    }
    treeViewer.setInput(functionSets);
}
Also used : FormulaFunctionSet(org.diirt.datasource.formula.FormulaFunctionSet) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) FormulaFunction(org.diirt.datasource.formula.FormulaFunction) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree)

Example 44 with TreeColumn

use of org.eclipse.swt.widgets.TreeColumn in project yamcs-studio by yamcs.

the class AddToStackWizardPage1 method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    setControl(composite);
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    composite.setLayout(gl);
    // add filter box
    Text searchbox = new Text(composite, SWT.SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
    searchbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // build tree table
    ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), composite);
    level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level1s.png"));
    level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level2s.png"));
    level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level3s.png"));
    level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level4s.png"));
    level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level5s.png"));
    Composite tableWrapper = new Composite(composite, SWT.NONE);
    tcl = new TreeColumnLayout();
    tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper.setLayout(tcl);
    commandsTreeTable = new TreeViewer(tableWrapper, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    commandsTreeTable.getTree().setHeaderVisible(true);
    commandsTreeTable.getTree().setLinesVisible(false);
    // column xtce path
    TreeViewerColumn pathColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    pathColumn.getColumn().setText(COL_PATH);
    pathColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            CommandInfo cmd = (CommandInfo) element;
            return cmd.getName();
        }
    });
    tcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    // column significance
    TreeViewerColumn significanceColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    significanceColumn.getColumn().setText(COL_SIGN);
    significanceColumn.getColumn().setToolTipText("Significance Level");
    significanceColumn.getColumn().setAlignment(SWT.CENTER);
    significanceColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            CommandInfo cmd = (CommandInfo) element;
            if (cmd.getSignificance() == null)
                return null;
            switch(cmd.getSignificance().getConsequenceLevel()) {
                case WATCH:
                    return level1Image;
                case WARNING:
                    return level2Image;
                case DISTRESS:
                    return level3Image;
                case CRITICAL:
                    return level4Image;
                case SEVERE:
                    return level5Image;
                default:
                    return null;
            }
        }
    });
    tcl.setColumnData(significanceColumn.getColumn(), new ColumnPixelData(40));
    // column qualified name
    TreeViewerColumn nameColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    nameColumn.getColumn().setText(COL_QNAME);
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            CommandInfo cmd = (CommandInfo) element;
            if (cmd.getAbstract()) {
                // show a blank line if the command is abstract
                return "";
            }
            return cmd.getQualifiedName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    // on item selection update significance message and page completion status
    commandsTreeTable.addSelectionChangedListener(evt -> {
        IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            setMessage(null);
            return;
        }
        CommandInfo cmd = (CommandInfo) sel.getFirstElement();
        setMessage(getMessage(cmd));
        command.setMetaCommand(cmd);
        command.setSelectedAliase(cmd.getQualifiedName());
        setPageComplete(!cmd.getAbstract());
    });
    CommandTreeContentProvider commandTreeContentProvider = new CommandTreeContentProvider();
    commandsTreeTable.setContentProvider(commandTreeContentProvider);
    // load command list
    Collection<CommandInfo> commandInfos = new ArrayList<>();
    CommandingCatalogue.getInstance().getMetaCommands().forEach(cmd -> {
        // add aliases columns
        for (NamedObjectId alias : cmd.getAliasList()) {
            String namespace = alias.getNamespace();
            if (!namespaces.contains(namespace) && !namespace.startsWith("/")) {
                namespaces.add(namespace);
                addAliasColumn(namespace);
            }
        }
        commandInfos.add(cmd);
    });
    commandsTreeTable.setInput(commandInfos);
    commandsTreeTable.expandAll();
    // with a small hack to display full data on the first column
    for (TreeColumn tc : commandsTreeTable.getTree().getColumns()) tc.pack();
    pathColumn.getColumn().setWidth(pathColumn.getColumn().getWidth() + 11 * commandTreeContentProvider.nbLevels);
    for (TreeColumn tc : commandsTreeTable.getTree().getColumns()) {
        if (tc.getWidth() > COLUMN_MAX_WIDTH)
            tc.setWidth(COLUMN_MAX_WIDTH);
    }
    // filter
    CommandInfoTreeViewerFilter filter = new CommandInfoTreeViewerFilter(commandTreeContentProvider);
    commandsTreeTable.addFilter(filter);
    searchbox.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent ke) {
            filter.setSearchTerm(searchbox.getText());
            commandsTreeTable.refresh();
            commandsTreeTable.expandAll();
        }
    });
    commandsTreeTable.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            CommandInfo c1 = (CommandInfo) o1;
            CommandInfo c2 = (CommandInfo) o2;
            return c1.getQualifiedName().compareTo(c2.getQualifiedName());
        }
    });
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ArrayList(java.util.ArrayList) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) KeyEvent(org.eclipse.swt.events.KeyEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Text(org.eclipse.swt.widgets.Text) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) CenteredImageLabelProvider(org.yamcs.studio.core.ui.utils.CenteredImageLabelProvider) CommandInfo(org.yamcs.protobuf.Mdb.CommandInfo) GridData(org.eclipse.swt.layout.GridData) NamedObjectId(org.yamcs.protobuf.Yamcs.NamedObjectId)

Example 45 with TreeColumn

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

the class SWTTreeProjectSelectionState method deselectColumns.

protected void deselectColumns() {
    Iterator<TreeColumn> selCols = selectedColumns.iterator();
    while (selCols.hasNext()) {
        TreeColumn column = selCols.next();
        selCols.remove();
        deselectColumn(column);
    }
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn)

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