Search in sources :

Example 76 with SelectionChangedEvent

use of org.eclipse.jface.viewers.SelectionChangedEvent in project knime-core by knime.

the class WorkflowSelectionDialog method createDialogArea.

/**
 * {@inheritDoc}
 */
@Override
protected Control createDialogArea(final Composite parent) {
    // a tree viewer to select a workflow group or workflow
    Group overall = new Group(parent, SWT.SHADOW_ETCHED_IN);
    overall.setText("Export selection:");
    overall.setLayout(new GridLayout(1, false));
    GridData shellLayout = new GridData(GridData.FILL_BOTH);
    shellLayout.widthHint = 300;
    shellLayout.heightHint = 350;
    overall.setLayoutData(shellLayout);
    GridData fillBoth = new GridData(GridData.FILL_BOTH);
    m_viewer = new TreeViewer(overall, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    m_viewer.getTree().setLayoutData(fillBoth);
    m_viewer.setLabelProvider(new KnimeResourceLabelProviderWithRoot());
    m_viewer.setContentProvider(new KnimeResourceContentProviderWithRoot());
    m_viewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
            if (element instanceof IWorkspaceRoot) {
                return true;
            }
            IResource resource = null;
            if (element instanceof NodeContainer) {
                ProjectWorkflowMap.findProjectFor(((NodeContainer) element).getID());
            } else if (element instanceof IResource) {
                resource = (IResource) element;
            }
            if (KnimeResourceUtil.isWorkflow(resource)) {
                return true;
            }
            if (KnimeResourceUtil.isWorkflowGroup(resource)) {
                return true;
            }
            return false;
        }
    });
    m_viewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
    m_viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            m_selectedObjs = (IStructuredSelection) m_viewer.getSelection();
        }
    });
    if (m_initialSelection != null) {
        m_viewer.setSelection(m_initialSelection);
    }
    m_viewer.expandAll();
    return overall;
}
Also used : Group(org.eclipse.swt.widgets.Group) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) KnimeResourceLabelProviderWithRoot(org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceLabelProviderWithRoot) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) NodeContainer(org.knime.core.node.workflow.NodeContainer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) KnimeResourceContentProviderWithRoot(org.knime.workbench.ui.wizards.workflowgroup.KnimeResourceContentProviderWithRoot) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) GridData(org.eclipse.swt.layout.GridData) IResource(org.eclipse.core.resources.IResource)

Example 77 with SelectionChangedEvent

use of org.eclipse.jface.viewers.SelectionChangedEvent in project bndtools by bndtools.

the class PluginPathPart method createClient.

/**
     * Fill the section.
     */
private void createClient(Section section, FormToolkit toolkit) {
    section.setText("Plugin Path");
    createToolBar(section);
    Table table = new Table(section, SWT.BORDER | SWT.FULL_SELECTION);
    toolkit.adapt(table);
    toolkit.paintBordersFor(table);
    section.setClient(table);
    viewer = new TableViewer(table);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new PluginPathLabelProvider());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            boolean enable = !viewer.getSelection().isEmpty();
            removeItem.setEnabled(enable);
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemove();
            } else if (e.character == '+') {
                doAdd();
            }
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Table(org.eclipse.swt.widgets.Table) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 78 with SelectionChangedEvent

use of org.eclipse.jface.viewers.SelectionChangedEvent in project bndtools by bndtools.

the class JpmDependencyWizardPage method createControl.

@Override
@SuppressWarnings("unused")
public void createControl(Composite parent) {
    // CREATE CONTROLS
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    Label lblDirect = new Label(container, SWT.NONE);
    lblDirect.setFont(JFaceResources.getBannerFont());
    lblDirect.setText("Direct Dependencies:");
    Table tblDirect = new Table(container, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL);
    viewerDirect = new TableViewer(tblDirect);
    viewerDirect.setContentProvider(ArrayContentProvider.getInstance());
    viewerDirect.setLabelProvider(new ResourceDescriptorLabelProvider());
    createHelpLabel(container, "The above dependencies will be added to the project and, if necessary, to the JPM4J local index.");
    Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label lblIndirect = new Label(container, SWT.NONE);
    lblIndirect.setFont(JFaceResources.getBannerFont());
    lblIndirect.setText("Transitive Dependencies:");
    Composite cmpIndirect = new Composite(container, SWT.NONE);
    Table tblIndirect = new Table(cmpIndirect, SWT.CHECK | SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL);
    viewerIndirect = new CheckboxTableViewer(tblIndirect);
    viewerIndirect.setContentProvider(ArrayContentProvider.getInstance());
    viewerIndirect.setLabelProvider(new ResourceDescriptorLabelProvider());
    Button btnSelectAll = new Button(cmpIndirect, SWT.PUSH);
    btnSelectAll.setText("All");
    Button btnSelectNone = new Button(cmpIndirect, SWT.PUSH);
    btnSelectNone.setText("None");
    new Label(cmpIndirect, SWT.NONE);
    createHelpLabel(container, "The above dependencies will be added to the JPM4J local index. Checked dependencies will also be added directly to the project.");
    // LISTENERS
    // Query JPM and show results *after* dialog is shown. This ensures progress is visible in the dialog's
    // progress bar
    getContainer().getShell().addShellListener(new ShellAdapter() {

        @Override
        public void shellActivated(ShellEvent e) {
            runQuery();
        }
    });
    viewerIndirect.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent ev) {
            if (selectedIndirectResources == null)
                selectedIndirectResources = new HashSet<ResourceDescriptor>();
            ResourceDescriptor resource = (ResourceDescriptor) ev.getElement();
            if (ev.getChecked())
                selectedIndirectResources.add(resource);
            else
                selectedIndirectResources.remove(resource);
        }
    });
    btnSelectAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedIndirectResources.addAll(indirectResources);
            updateSelectedCheckboxes();
        }
    });
    btnSelectNone.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedIndirectResources.clear();
            updateSelectedCheckboxes();
        }
    });
    viewerDirect.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection sel = event.getSelection();
            if (sel.isEmpty())
                selection = (ResourceDescriptor) ((IStructuredSelection) viewerIndirect.getSelection()).getFirstElement();
            else
                selection = (ResourceDescriptor) ((IStructuredSelection) sel).getFirstElement();
            getContainer().updateMessage();
        }
    });
    viewerIndirect.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection sel = event.getSelection();
            if (sel.isEmpty())
                selection = (ResourceDescriptor) ((IStructuredSelection) viewerDirect.getSelection()).getFirstElement();
            else
                selection = (ResourceDescriptor) ((IStructuredSelection) sel).getFirstElement();
            getContainer().updateMessage();
        }
    });
    // LAYOUT
    GridLayout layout;
    GridData gd;
    layout = new GridLayout(1, true);
    container.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    gd.heightHint = 30;
    tblDirect.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    separator.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    cmpIndirect.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = 2;
    layout.verticalSpacing = 2;
    cmpIndirect.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3);
    gd.heightHint = 100;
    tblIndirect.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    btnSelectAll.setLayoutData(gd);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    btnSelectNone.setLayoutData(gd);
}
Also used : ShellAdapter(org.eclipse.swt.events.ShellAdapter) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 79 with SelectionChangedEvent

use of org.eclipse.jface.viewers.SelectionChangedEvent in project yamcs-studio by yamcs.

the class ScriptsInputDialog method createScriptsTableViewer.

/**
 * Creates and configures a {@link TableViewer}.
 *
 * @param parent
 *            The parent for the table
 * @return The {@link TableViewer}
 */
private TableViewer createScriptsTableViewer(final Composite parent) {
    TableViewer viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.SINGLE);
    viewer.setContentProvider(new BaseWorkbenchContentProvider() {

        @SuppressWarnings("unchecked")
        @Override
        public Object[] getElements(final Object element) {
            return (((List<ScriptData>) element).toArray());
        }
    });
    viewer.setLabelProvider(new WorkbenchLabelProvider());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            refreshGUIOnSelection();
        }
    });
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    return viewer;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) BaseWorkbenchContentProvider(org.eclipse.ui.model.BaseWorkbenchContentProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) GridData(org.eclipse.swt.layout.GridData) ArrayList(java.util.ArrayList) List(java.util.List) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 80 with SelectionChangedEvent

use of org.eclipse.jface.viewers.SelectionChangedEvent in project yamcs-studio by yamcs.

the class ResourceSelectionGroup method createTreeViewer.

/**
 * Returns a new drill down viewer for this dialog.
 *
 * @param filters
 * @param heightHint
 *            height hint for the drill down composite
 */
protected void createTreeViewer(final String[] filters, final int heightHint) {
    // Create drill down.
    DrillDownComposite drillDown = new DrillDownComposite(this, SWT.BORDER);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.widthHint = SIZING_SELECTION_PANE_WIDTH;
    gridData.heightHint = heightHint;
    drillDown.setLayoutData(gridData);
    // Create tree viewer inside drill down.
    _treeViewer = new TreeViewer(drillDown, SWT.NONE);
    drillDown.setChildTree(_treeViewer);
    WorkspaceResourceContentProvider contentProvider = new WorkspaceResourceContentProvider(filters);
    contentProvider.showClosedProjects(_showClosedProjects);
    _treeViewer.setContentProvider(contentProvider);
    _treeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
    _treeViewer.setSorter(new ViewerSorter());
    _treeViewer.setUseHashlookup(true);
    _treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection == null) {
                containerSelectionChanged(null);
            } else {
                containerSelectionChanged((IResource) selection.getFirstElement());
            }
            if (_newFolderAction != null) {
                _newFolderAction.setEnabled(selection != null);
            }
        }
    });
    _treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(final DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                Object item = ((IStructuredSelection) selection).getFirstElement();
                if (item == null) {
                    return;
                }
                if (_treeViewer.getExpandedState(item)) {
                    _treeViewer.collapseToLevel(item, 1);
                } else {
                    _treeViewer.expandToLevel(item, 1);
                }
            }
        }
    });
    // This has to be done after the viewer has been laid out
    _treeViewer.setInput(ResourcesPlugin.getWorkspace());
    this.addNewContainerActions(drillDown.getToolBarManager());
    this.addPopupMenu(_treeViewer);
    this.setDefaultSelection(_treeViewer);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) IResource(org.eclipse.core.resources.IResource)

Aggregations

SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)168 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)161 GridData (org.eclipse.swt.layout.GridData)95 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)82 Composite (org.eclipse.swt.widgets.Composite)74 GridLayout (org.eclipse.swt.layout.GridLayout)65 TableViewer (org.eclipse.jface.viewers.TableViewer)60 SelectionEvent (org.eclipse.swt.events.SelectionEvent)55 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)46 Label (org.eclipse.swt.widgets.Label)42 ISelection (org.eclipse.jface.viewers.ISelection)41 Table (org.eclipse.swt.widgets.Table)41 TreeViewer (org.eclipse.jface.viewers.TreeViewer)36 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)31 Button (org.eclipse.swt.widgets.Button)31 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)25 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)25 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)18 ArrayList (java.util.ArrayList)17 ComboViewer (org.eclipse.jface.viewers.ComboViewer)17