Search in sources :

Example 71 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project liferay-ide by liferay.

the class AbstractCheckboxCustomPart method createPresentation.

@Override
public FormComponentPresentation createPresentation(SwtPresentation parent, Composite composite) {
    return new FormComponentPresentation(this, parent, composite) {

        @Override
        public void render() {
            final Composite parent = SWTUtil.createComposite(composite(), 2, 2, GridData.FILL_BOTH);
            checkBoxViewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
            checkBoxViewer.addCheckStateListener(new ICheckStateListener() {

                @Override
                public void checkStateChanged(CheckStateChangedEvent event) {
                    handleCheckStateChangedEvent(event);
                }
            });
            checkBoxViewer.setContentProvider(new CheckboxContentProvider());
            checkBoxViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(getLableProvider()));
            final Table table = checkBoxViewer.getTable();
            final GridData tableData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 4);
            tableData.heightHint = 225;
            tableData.widthHint = 400;
            table.setLayoutData(tableData);
            final Button selectAllButton = new Button(parent, SWT.NONE);
            selectAllButton.setText("Select All");
            selectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
            selectAllButton.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    handleSelectAllEvent();
                }
            });
            final Button deselectAllButton = new Button(parent, SWT.NONE);
            deselectAllButton.setText("Deselect All");
            deselectAllButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
            deselectAllButton.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    handleDeSelectAllEvent();
                }
            });
            final Button refreshButton = new Button(parent, SWT.NONE);
            refreshButton.setText("Refresh");
            refreshButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
            refreshButton.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    checkAndUpdateCheckboxElement();
                }
            });
            _startCheckThread();
        }

        private void _startCheckThread() {
            final Thread t = new Thread() {

                @Override
                public void run() {
                    checkAndUpdateCheckboxElement();
                }
            };
            t.start();
        }
    };
}
Also used : Table(org.eclipse.swt.widgets.Table) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) FormComponentPresentation(org.eclipse.sapphire.ui.forms.swt.FormComponentPresentation) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 72 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project arduino-eclipse-plugin by Sloeber.

the class PlatformSelectionPage method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite control = new Composite(parent, SWT.NONE);
    control.setLayout(new GridLayout());
    Button btnCheckButton = new Button(control, SWT.CHECK);
    // $NON-NLS-1$
    btnCheckButton.setText("Hide 3th party json files");
    btnCheckButton.setSelection(this.myHideJson);
    btnCheckButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            PlatformSelectionPage.this.myHideJson = btnCheckButton.getSelection();
            MyPreferences.setHideJson(PlatformSelectionPage.this.myHideJson);
            PlatformSelectionPage.this.viewer.setInput(EMPTY_STRING);
        }
    });
    Text desc = new Text(control, SWT.READ_ONLY);
    desc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    desc.setBackground(parent.getBackground());
    desc.setText(Messages.platformSelectionTip);
    PatternFilter filter = new PatternFilter() {

        @Override
        protected boolean isLeafMatch(final Viewer viewer1, final Object element) {
            boolean isMatch = false;
            if (element instanceof InstallableVersion) {
                InstallableVersion ver = (InstallableVersion) element;
                isMatch |= wordMatches(ver.getVersion().toString());
                isMatch |= myWordMatches(ver.getPlatform());
            }
            if (element instanceof IndexFile) {
                IndexFile indexFile = (IndexFile) element;
                isMatch |= myWordMatches(indexFile);
            }
            if (element instanceof Package) {
                Package pac = (Package) element;
                isMatch |= myWordMatches(pac);
            }
            if (element instanceof Platform) {
                Platform platform = (Platform) element;
                isMatch |= myWordMatches(platform);
            }
            return isMatch;
        }

        private boolean myWordMatches(Platform platform) {
            boolean ret = wordMatches(platform.getName());
            ret |= wordMatches(platform.getArchitecture());
            ret |= wordMatches(platform.getBoards());
            ret |= myWordMatches(platform.getPackage());
            return ret;
        }

        private boolean myWordMatches(Package pac) {
            boolean ret = wordMatches(pac.getEmail());
            ret |= wordMatches(pac.getMaintainer());
            ret |= wordMatches(pac.getName());
            ret |= wordMatches(pac.getWebsiteURL().toString());
            ret |= wordMatches(pac.getIndexFile().toString());
            return ret;
        }

        private boolean myWordMatches(IndexFile indexFile) {
            return wordMatches(indexFile.getFullName());
        }
    };
    this.myGuiplatformTree = new FilteredTree(control, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true) {

        @Override
        protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
            CheckboxTreeViewer viewer1 = new CheckboxTreeViewer(composite);
            viewer1.setCheckStateProvider(new ICheckStateProvider() {

                @Override
                public boolean isChecked(Object element) {
                    if (element instanceof InstallableVersion) {
                        return ((InstallableVersion) element).isInstalled();
                    }
                    if (element instanceof IndexFile) {
                        return ((IndexFile) element).isInstalled();
                    }
                    if (element instanceof Package) {
                        return ((Package) element).isInstalled();
                    }
                    if (element instanceof Platform) {
                        return ((Platform) element).isInstalled();
                    }
                    return false;
                }

                @Override
                public boolean isGrayed(Object element) {
                    if (element instanceof InstallableVersion) {
                        return false;
                    }
                    if (element instanceof IndexFile) {
                        return ((IndexFile) element).isInstalled();
                    }
                    if (element instanceof Package) {
                        return ((Package) element).isInstalled();
                    }
                    if (element instanceof Platform) {
                        return ((Platform) element).isInstalled();
                    }
                    return false;
                }
            });
            viewer1.addCheckStateListener(new ICheckStateListener() {

                @Override
                public void checkStateChanged(CheckStateChangedEvent event) {
                    Object element = event.getElement();
                    if (element instanceof InstallableVersion) {
                        InstallableVersion cur = (InstallableVersion) element;
                        cur.setInstalled(event.getChecked());
                    }
                    PlatformSelectionPage.this.viewer.refresh();
                }
            });
            viewer1.setContentProvider(new ITreeContentProvider() {

                @Override
                public Object[] getElements(Object inputElement) {
                    if (PlatformSelectionPage.this.myHideJson) {
                        Set<Package> packages = PlatformSelectionPage.this.myPlatformTree.getAllPackages();
                        return packages.toArray(new Object[packages.size()]);
                    }
                    Collection<IndexFile> indexFiles = PlatformSelectionPage.this.myPlatformTree.getAllIndexFiles();
                    return indexFiles.toArray(new Object[indexFiles.size()]);
                }

                @Override
                public void dispose() {
                // nothing to do
                }

                @Override
                public void inputChanged(Viewer viewer11, Object oldInput, Object newInput) {
                // nothing to do
                }

                @Override
                public Object[] getChildren(Object parentElement) {
                    if (parentElement instanceof IndexFile) {
                        Collection<Package> packages = ((IndexFile) parentElement).getAllPackages();
                        return packages.toArray(new Object[packages.size()]);
                    }
                    if (parentElement instanceof Package) {
                        Collection<Platform> platforms = ((Package) parentElement).getPlatforms();
                        return platforms.toArray(new Object[platforms.size()]);
                    }
                    if (parentElement instanceof Platform) {
                        Collection<InstallableVersion> versions = ((Platform) parentElement).getVersions();
                        return versions.toArray(new Object[versions.size()]);
                    }
                    return null;
                }

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

                @Override
                public boolean hasChildren(Object element) {
                    return !(element instanceof InstallableVersion);
                }
            });
            viewer1.setLabelProvider(new CellLabelProvider() {

                @Override
                public String getToolTipText(Object element) {
                    if (element instanceof IndexFile) {
                        return ((IndexFile) element).getFullName();
                    }
                    if (element instanceof Package) {
                        Package pkg = (Package) element;
                        return // $NON-NLS-1$
                        Messages.packageTooltip.replaceAll("\\$\\{MAINTAINER}", pkg.getMaintainer()).replaceAll("\\$\\{EMAIL}", // $NON-NLS-1$
                        pkg.getEmail()).replaceAll("\\$\\{URL}", // $NON-NLS-1$
                        pkg.getWebsiteURL().toString());
                    }
                    if (element instanceof Platform) {
                        return ((Platform) element).getBoards();
                    }
                    if (element instanceof InstallableVersion) {
                        return null;
                    }
                    return null;
                }

                @Override
                public org.eclipse.swt.graphics.Point getToolTipShift(Object object) {
                    return new org.eclipse.swt.graphics.Point(5, 5);
                }

                @Override
                public int getToolTipDisplayDelayTime(Object object) {
                    return 1000;
                }

                @Override
                public int getToolTipTimeDisplayed(Object object) {
                    return 5000;
                }

                @Override
                public void update(ViewerCell cell) {
                    if (cell.getElement() instanceof IndexFile) {
                        cell.setText(((IndexFile) cell.getElement()).getNiceName());
                    }
                    if (cell.getElement() instanceof Package) {
                        cell.setText(((Package) cell.getElement()).getName());
                    }
                    if (cell.getElement() instanceof Platform) {
                        cell.setText(((Platform) cell.getElement()).getName());
                    }
                    if (cell.getElement() instanceof InstallableVersion) {
                        cell.setText(((InstallableVersion) cell.getElement()).getVersion().toString());
                    }
                }
            });
            return viewer1;
        }
    };
    this.viewer = this.myGuiplatformTree.getViewer();
    ColumnViewerToolTipSupport.enableFor(this.viewer);
    this.myGuiplatformTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    this.viewer.setInput(EMPTY_STRING);
    return control;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Listener(org.eclipse.swt.widgets.Listener) Platform(io.sloeber.core.api.PackageManager.PlatformTree.Platform) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) IndexFile(io.sloeber.core.api.PackageManager.PlatformTree.IndexFile) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) Text(org.eclipse.swt.widgets.Text) ViewerCell(org.eclipse.jface.viewers.ViewerCell) InstallableVersion(io.sloeber.core.api.PackageManager.PlatformTree.InstallableVersion) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Package(io.sloeber.core.api.PackageManager.PlatformTree.Package) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 73 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project mdw-designer by CenturyLinkCloud.

the class ImportPackageSelectPage method createAssetTree.

private void createAssetTree(Composite parent) {
    treeViewer = new CheckboxTreeViewer(parent, SWT.CHECK | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    treeViewer.setContentProvider(new ViewContentProvider());
    treeViewer.setLabelProvider(new ViewLabelProvider());
    treeViewer.setCheckStateProvider(new ViewCheckStateProvider());
    GridData data = new GridData(GridData.FILL_BOTH);
    treeViewer.getTree().setLayoutData(data);
    treeViewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            boolean checked = event.getChecked();
            if (event.getElement() instanceof File) {
                File file = (File) event.getElement();
                if (checked && !selectedPackages.contains(file))
                    selectedPackages.add(file);
                else if (!checked && selectedPackages.contains(file))
                    selectedPackages.remove(file);
                treeViewer.refresh();
                handleFieldChanged();
            } else if (event.getElement() instanceof Folder) {
                FileCollector collector = new FileCollector((Folder) event.getElement());
                for (File file : collector.getDescendantFiles()) {
                    if (checked && !selectedPackages.contains(file))
                        selectedPackages.add(file);
                    else if (!checked && selectedPackages.contains(file))
                        selectedPackages.remove(file);
                }
                treeViewer.refresh();
                handleFieldChanged();
            }
        }
    });
    ColumnViewerToolTipSupport.enableFor(treeViewer);
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Folder(com.centurylink.mdw.plugin.designer.model.Folder) File(com.centurylink.mdw.plugin.designer.model.File)

Example 74 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project mdw-designer by CenturyLinkCloud.

the class ToolboxFilterDialog method createPackageTree.

private void createPackageTree(Composite parent) {
    treeViewer = new CheckboxTreeViewer(parent, SWT.CHECK | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    treeViewer.setContentProvider(new ViewContentProvider());
    treeViewer.setLabelProvider(new ViewLabelProvider());
    treeViewer.setCheckStateProvider(new ViewCheckStateProvider());
    treeViewer.setInput(workflowProject.getTopLevelUserVisiblePackages());
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = 400;
    treeViewer.getTree().setLayoutData(data);
    treeViewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            boolean checked = event.getChecked();
            if (event.getElement() instanceof WorkflowPackage) {
                WorkflowPackage pkg = (WorkflowPackage) event.getElement();
                for (ActivityImpl impl : pkg.getActivityImpls()) {
                    if (checked)
                        suppressedImplementors.remove(impl.getImplClassName());
                    else if (!suppressedImplementors.contains(impl.getImplClassName()))
                        suppressedImplementors.add(impl.getImplClassName());
                }
                treeViewer.refresh();
            } else if (event.getElement() instanceof ActivityImpl) {
                ActivityImpl impl = (ActivityImpl) event.getElement();
                if (checked)
                    suppressedImplementors.remove(impl.getImplClassName());
                else if (!suppressedImplementors.contains(impl.getImplClassName()))
                    suppressedImplementors.add(impl.getImplClassName());
                treeViewer.refresh();
            }
        }
    });
    ColumnViewerToolTipSupport.enableFor(treeViewer);
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) ActivityImpl(com.centurylink.mdw.plugin.designer.model.ActivityImpl) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 75 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project tdq-studio-se by Talend.

the class AbstractJarSelectDialog method createTreeViewer.

/**
 * Creates the tree viewer.
 *
 * @param parent the parent composite
 * @return the tree viewer
 */
protected CheckboxTreeViewer createTreeViewer(Composite parent) {
    if (fContainerMode) {
        fViewer = new ContainerCheckedTreeViewer(parent, SWT.BORDER);
    } else {
        fViewer = new CheckboxTreeViewer(parent, SWT.BORDER);
    }
    fViewer.setContentProvider(fContentProvider);
    fViewer.setLabelProvider(fLabelProvider);
    fViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            // ADD msjian 2011-8-9 TDQ-3199 fixed: Make it convenient to delete the jar which is used already.
            handleChecked();
            handleClassNameFromJarFile();
            // ADD end
            updateOKStatus();
        }
    });
    fViewer.setComparator(fComparator);
    if (fFilters != null) {
        for (int i = 0; i != fFilters.size(); i++) {
            fViewer.addFilter((ViewerFilter) fFilters.get(i));
        }
    }
    fViewer.setInput(fInput);
    return fViewer;
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Aggregations

ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)98 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)93 GridData (org.eclipse.swt.layout.GridData)61 Composite (org.eclipse.swt.widgets.Composite)48 GridLayout (org.eclipse.swt.layout.GridLayout)44 SelectionEvent (org.eclipse.swt.events.SelectionEvent)39 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)33 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)31 Button (org.eclipse.swt.widgets.Button)30 Label (org.eclipse.swt.widgets.Label)30 Viewer (org.eclipse.jface.viewers.Viewer)21 ArrayList (java.util.ArrayList)20 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)20 Table (org.eclipse.swt.widgets.Table)19 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)16 Event (org.eclipse.swt.widgets.Event)16 TableColumn (org.eclipse.swt.widgets.TableColumn)16 List (java.util.List)14 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)14 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)14