Search in sources :

Example 86 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project yamcs-studio by yamcs.

the class LinkTableViewer method addFixedColumns.

private void addFixedColumns(TableColumnLayout tcl) {
    var nameColumn = new TableViewerColumn(this, SWT.LEFT);
    nameColumn.getColumn().setText(COL_NAME);
    tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(18));
    var typeColumn = new TableViewerColumn(this, SWT.LEFT);
    typeColumn.getColumn().setText(COL_TYPE);
    tcl.setColumnData(typeColumn.getColumn(), new ColumnWeightData(18));
    var statusColumn = new TableViewerColumn(this, SWT.CENTER);
    statusColumn.getColumn().setText(COL_STATUS);
    tcl.setColumnData(statusColumn.getColumn(), new ColumnWeightData(18));
    var inColumn = new TableViewerColumn(this, SWT.RIGHT);
    inColumn.getColumn().setText(COL_IN);
    tcl.setColumnData(inColumn.getColumn(), new ColumnWeightData(10));
    var outColumn = new TableViewerColumn(this, SWT.RIGHT);
    outColumn.getColumn().setText(COL_OUT);
    tcl.setColumnData(outColumn.getColumn(), new ColumnWeightData(10));
    // Common properties to all columns
    List<TableViewerColumn> columns = new ArrayList<>();
    columns.add(nameColumn);
    columns.add(typeColumn);
    columns.add(statusColumn);
    columns.add(inColumn);
    columns.add(outColumn);
    for (var column : columns) {
        // prevent resize to 0
        column.getColumn().addControlListener(new ControlListener() {

            @Override
            public void controlMoved(ControlEvent e) {
            }

            @Override
            public void controlResized(ControlEvent e) {
                if (column.getColumn().getWidth() < 5) {
                    column.getColumn().setWidth(5);
                }
            }
        });
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ArrayList(java.util.ArrayList) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 87 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project Malai by arnobl.

the class WidgetEditor method createPages.

/**
 * This is the method used by the framework to install your own controls.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void createPages() {
    // Creates the model from the editor input
    // 
    createModel();
    // 
    if (!getEditingDomain().getResourceSet().getResources().isEmpty()) {
        // Create a page for the selection tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            selectionViewer = (TreeViewer) viewerPane.getViewer();
            selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            selectionViewer.setInput(editingDomain.getResourceSet());
            selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
            viewerPane.setTitle(editingDomain.getResourceSet());
            new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
            createContextMenuFor(selectionViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_SelectionPage_label"));
        }
        // Create a page for the parent tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            parentViewer = (TreeViewer) viewerPane.getViewer();
            parentViewer.setAutoExpandLevel(30);
            parentViewer.setContentProvider(new ReverseAdapterFactoryContentProvider(adapterFactory));
            parentViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(parentViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ParentPage_label"));
        }
        // This is the page for the list viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new ListViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            listViewer = (ListViewer) viewerPane.getViewer();
            listViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            listViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(listViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ListPage_label"));
        }
        // This is the page for the tree viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewer = (TreeViewer) viewerPane.getViewer();
            treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            new AdapterFactoryTreeEditor(treeViewer.getTree(), adapterFactory);
            createContextMenuFor(treeViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreePage_label"));
        }
        // This is the page for the table viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TableViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            tableViewer = (TableViewer) viewerPane.getViewer();
            Table table = tableViewer.getTable();
            TableLayout layout = new TableLayout();
            table.setLayout(layout);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            TableColumn objectColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(3, 100, true));
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            TableColumn selfColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(2, 100, true));
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            tableViewer.setColumnProperties(new String[] { "a", "b" });
            tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            tableViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(tableViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TablePage_label"));
        }
        // This is the page for the table tree viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewerWithColumns = (TreeViewer) viewerPane.getViewer();
            Tree tree = treeViewerWithColumns.getTree();
            tree.setLayoutData(new FillLayout());
            tree.setHeaderVisible(true);
            tree.setLinesVisible(true);
            TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            objectColumn.setWidth(250);
            TreeColumn selfColumn = new TreeColumn(tree, SWT.NONE);
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            selfColumn.setWidth(200);
            treeViewerWithColumns.setColumnProperties(new String[] { "a", "b" });
            treeViewerWithColumns.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewerWithColumns.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(treeViewerWithColumns);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreeWithColumnsPage_label"));
        }
        getSite().getShell().getDisplay().asyncExec(new Runnable() {

            public void run() {
                setActivePage(0);
            }
        });
    }
    // Ensures that this editor will only display the page's tab
    // area if there are more than one page
    // 
    getContainer().addControlListener(new ControlAdapter() {

        boolean guard = false;

        @Override
        public void controlResized(ControlEvent event) {
            if (!guard) {
                guard = true;
                hideTabs();
                guard = false;
            }
        }
    });
    getSite().getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            updateProblemIndication();
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ListViewer(org.eclipse.jface.viewers.ListViewer) AdapterFactoryTreeEditor(org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ViewerPane(org.eclipse.emf.common.ui.ViewerPane) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 88 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project Malai by arnobl.

the class ActionEditor method createPages.

/**
 * This is the method used by the framework to install your own controls.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void createPages() {
    // Creates the model from the editor input
    // 
    createModel();
    // 
    if (!getEditingDomain().getResourceSet().getResources().isEmpty()) {
        // Create a page for the selection tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            selectionViewer = (TreeViewer) viewerPane.getViewer();
            selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            selectionViewer.setInput(editingDomain.getResourceSet());
            selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
            viewerPane.setTitle(editingDomain.getResourceSet());
            new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
            createContextMenuFor(selectionViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_SelectionPage_label"));
        }
        // Create a page for the parent tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            parentViewer = (TreeViewer) viewerPane.getViewer();
            parentViewer.setAutoExpandLevel(30);
            parentViewer.setContentProvider(new ReverseAdapterFactoryContentProvider(adapterFactory));
            parentViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(parentViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ParentPage_label"));
        }
        // This is the page for the list viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new ListViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            listViewer = (ListViewer) viewerPane.getViewer();
            listViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            listViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(listViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ListPage_label"));
        }
        // This is the page for the tree viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewer = (TreeViewer) viewerPane.getViewer();
            treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            new AdapterFactoryTreeEditor(treeViewer.getTree(), adapterFactory);
            createContextMenuFor(treeViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreePage_label"));
        }
        // This is the page for the table viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TableViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            tableViewer = (TableViewer) viewerPane.getViewer();
            Table table = tableViewer.getTable();
            TableLayout layout = new TableLayout();
            table.setLayout(layout);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            TableColumn objectColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(3, 100, true));
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            TableColumn selfColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(2, 100, true));
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            tableViewer.setColumnProperties(new String[] { "a", "b" });
            tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            tableViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(tableViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TablePage_label"));
        }
        // This is the page for the table tree viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewerWithColumns = (TreeViewer) viewerPane.getViewer();
            Tree tree = treeViewerWithColumns.getTree();
            tree.setLayoutData(new FillLayout());
            tree.setHeaderVisible(true);
            tree.setLinesVisible(true);
            TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            objectColumn.setWidth(250);
            TreeColumn selfColumn = new TreeColumn(tree, SWT.NONE);
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            selfColumn.setWidth(200);
            treeViewerWithColumns.setColumnProperties(new String[] { "a", "b" });
            treeViewerWithColumns.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewerWithColumns.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(treeViewerWithColumns);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreeWithColumnsPage_label"));
        }
        getSite().getShell().getDisplay().asyncExec(new Runnable() {

            public void run() {
                setActivePage(0);
            }
        });
    }
    // Ensures that this editor will only display the page's tab
    // area if there are more than one page
    // 
    getContainer().addControlListener(new ControlAdapter() {

        boolean guard = false;

        @Override
        public void controlResized(ControlEvent event) {
            if (!guard) {
                guard = true;
                hideTabs();
                guard = false;
            }
        }
    });
    getSite().getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            updateProblemIndication();
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ListViewer(org.eclipse.jface.viewers.ListViewer) AdapterFactoryTreeEditor(org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ViewerPane(org.eclipse.emf.common.ui.ViewerPane) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 89 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project Malai by arnobl.

the class EventEditor method createPages.

/**
 * This is the method used by the framework to install your own controls.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void createPages() {
    // Creates the model from the editor input
    // 
    createModel();
    // 
    if (!getEditingDomain().getResourceSet().getResources().isEmpty()) {
        // Create a page for the selection tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), EventEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            selectionViewer = (TreeViewer) viewerPane.getViewer();
            selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            selectionViewer.setInput(editingDomain.getResourceSet());
            selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
            viewerPane.setTitle(editingDomain.getResourceSet());
            new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
            createContextMenuFor(selectionViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_SelectionPage_label"));
        }
        // Create a page for the parent tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), EventEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            parentViewer = (TreeViewer) viewerPane.getViewer();
            parentViewer.setAutoExpandLevel(30);
            parentViewer.setContentProvider(new ReverseAdapterFactoryContentProvider(adapterFactory));
            parentViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(parentViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ParentPage_label"));
        }
        // This is the page for the list viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), EventEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new ListViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            listViewer = (ListViewer) viewerPane.getViewer();
            listViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            listViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(listViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ListPage_label"));
        }
        // This is the page for the tree viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), EventEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewer = (TreeViewer) viewerPane.getViewer();
            treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            new AdapterFactoryTreeEditor(treeViewer.getTree(), adapterFactory);
            createContextMenuFor(treeViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreePage_label"));
        }
        // This is the page for the table viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), EventEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TableViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            tableViewer = (TableViewer) viewerPane.getViewer();
            Table table = tableViewer.getTable();
            TableLayout layout = new TableLayout();
            table.setLayout(layout);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            TableColumn objectColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(3, 100, true));
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            TableColumn selfColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(2, 100, true));
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            tableViewer.setColumnProperties(new String[] { "a", "b" });
            tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            tableViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(tableViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TablePage_label"));
        }
        // This is the page for the table tree viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), EventEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewerWithColumns = (TreeViewer) viewerPane.getViewer();
            Tree tree = treeViewerWithColumns.getTree();
            tree.setLayoutData(new FillLayout());
            tree.setHeaderVisible(true);
            tree.setLinesVisible(true);
            TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            objectColumn.setWidth(250);
            TreeColumn selfColumn = new TreeColumn(tree, SWT.NONE);
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            selfColumn.setWidth(200);
            treeViewerWithColumns.setColumnProperties(new String[] { "a", "b" });
            treeViewerWithColumns.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewerWithColumns.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(treeViewerWithColumns);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreeWithColumnsPage_label"));
        }
        getSite().getShell().getDisplay().asyncExec(new Runnable() {

            public void run() {
                setActivePage(0);
            }
        });
    }
    // Ensures that this editor will only display the page's tab
    // area if there are more than one page
    // 
    getContainer().addControlListener(new ControlAdapter() {

        boolean guard = false;

        @Override
        public void controlResized(ControlEvent event) {
            if (!guard) {
                guard = true;
                hideTabs();
                guard = false;
            }
        }
    });
    getSite().getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            updateProblemIndication();
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ListViewer(org.eclipse.jface.viewers.ListViewer) AdapterFactoryTreeEditor(org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ViewerPane(org.eclipse.emf.common.ui.ViewerPane) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 90 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project dbeaver by dbeaver.

the class EditBootstrapQueriesDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(CoreMessages.dialog_connection_edit_wizard_general_bootstrap_query_title);
    Composite composite = (Composite) super.createDialogArea(parent);
    Group group = UIUtils.createControlGroup(composite, CoreMessages.dialog_connection_edit_wizard_general_bootstrap_query_sql_label, 2, GridData.FILL_BOTH, 0);
    queriesTable = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    final GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 300;
    gd.heightHint = 100;
    queriesTable.setLayoutData(gd);
    queriesTable.setLinesVisible(true);
    final TableColumn valueColumn = UIUtils.createTableColumn(queriesTable, SWT.LEFT, "SQL");
    valueColumn.setWidth(300);
    for (String value : queries) {
        new TableItem(queriesTable, SWT.LEFT).setText(value);
    }
    final CustomTableEditor tableEditor = new CustomTableEditor(queriesTable) {

        @Override
        protected Control createEditor(Table table, int index, TableItem item) {
            Text editor = new Text(table, SWT.BORDER);
            editor.setText(item.getText());
            return editor;
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            item.setText(((Text) control).getText());
        }
    };
    Composite buttonsGroup = UIUtils.createPlaceholder(group, 1, 5);
    buttonsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    final Button addButton = new Button(buttonsGroup, SWT.PUSH);
    addButton.setText(UIMessages.button_add);
    addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tableEditor.closeEditor();
            String sql = EditTextDialog.editText(getShell(), CoreMessages.dialog_connection_edit_wizard_general_bootstrap_query_sql_title, "");
            if (sql != null) {
                TableItem newItem = new TableItem(queriesTable, SWT.LEFT);
                newItem.setText(sql);
                queriesTable.setSelection(newItem);
                UIUtils.packColumns(queriesTable, true);
            }
        }
    });
    final Button removeButton = new Button(buttonsGroup, SWT.PUSH);
    removeButton.setText(UIMessages.button_remove);
    removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = queriesTable.getSelectionIndex();
            if (selectionIndex >= 0) {
                tableEditor.closeEditor();
                queriesTable.remove(selectionIndex);
                removeButton.setEnabled(queriesTable.getSelectionIndex() >= 0);
            }
        }
    });
    removeButton.setEnabled(false);
    queriesTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = queriesTable.getSelectionIndex();
            removeButton.setEnabled(selectionIndex >= 0);
        }
    });
    queriesTable.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            int sbWidth = 0;
            if (queriesTable.getVerticalBar() != null) {
                sbWidth = queriesTable.getVerticalBar().getSize().x;
            }
            queriesTable.getColumn(0).setWidth(queriesTable.getSize().x - queriesTable.getBorderWidth() * 2 - sbWidth);
        }
    });
    ignoreErrorButton = UIUtils.createCheckbox(composite, CoreMessages.dialog_connection_edit_wizard_general_bootstrap_query_ignore_error_lable, ignoreErrors);
    VariablesHintLabel variablesHintLabel = new VariablesHintLabel(composite, CoreMessages.dialog_connection_edit_wizard_shell_cmd_variables_hint_label, CoreMessages.dialog_connection_edit_wizard_shell_cmd_variables_hint_title, DataSourceDescriptor.CONNECT_VARIABLES);
    if (dataSourceDescriptor != null) {
        variablesHintLabel.setResolver(new DataSourceVariableResolver(dataSourceDescriptor, dataSourceDescriptor.getConnectionConfiguration()));
    }
    UIUtils.asyncExec(() -> UIUtils.packColumns(queriesTable, true));
    return composite;
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) VariablesHintLabel(org.jkiss.dbeaver.ui.controls.VariablesHintLabel) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver)

Aggregations

ControlEvent (org.eclipse.swt.events.ControlEvent)187 ControlAdapter (org.eclipse.swt.events.ControlAdapter)135 Composite (org.eclipse.swt.widgets.Composite)76 GridData (org.eclipse.swt.layout.GridData)67 ControlListener (org.eclipse.swt.events.ControlListener)54 GridLayout (org.eclipse.swt.layout.GridLayout)50 SelectionEvent (org.eclipse.swt.events.SelectionEvent)49 TableColumn (org.eclipse.swt.widgets.TableColumn)42 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)41 Point (org.eclipse.swt.graphics.Point)38 Table (org.eclipse.swt.widgets.Table)37 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)36 FillLayout (org.eclipse.swt.layout.FillLayout)35 Tree (org.eclipse.swt.widgets.Tree)35 TreeViewer (org.eclipse.jface.viewers.TreeViewer)33 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)32 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)31 AdapterFactoryTreeEditor (org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor)30 AdapterFactoryContentProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider)30 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)30