Search in sources :

Example 51 with ICheckStateListener

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

the class ImportItemWizardPage method createTreeViewer.

private TreeViewer createTreeViewer(Composite listComposite) {
    filteredCheckboxTree = new FilteredCheckboxTree(listComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    CheckboxTreeViewer viewer = filteredCheckboxTree.getViewer();
    viewer.setContentProvider(new ITreeContentProvider() {

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof IContainerNode) {
                return ((IContainerNode) parentElement).getChildren().toArray();
            }
            return null;
        }

        @Override
        public Object[] getElements(Object inputElement) {
            // return getValidItems();
            return repositoryUtil.getTreeViewInput().toArray();
        }

        @Override
        public boolean hasChildren(Object element) {
            if (element instanceof IContainerNode) {
                return ((IContainerNode) element).hasChildren();
            }
            return false;
        }

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

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IContainerNode) {
                if (element instanceof ProjectNode) {
                    Project project = ((ProjectNode) element).getProject();
                    return ProjectManager.getProjectDisplayLabel(project);
                }
                return ((IContainerNode) element).getLabel();
            } else if (element instanceof ItemRecord) {
                return ((ItemRecord) element).getLabel();
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof IContainerNode) {
                return ((IContainerNode) element).getImage();
            } else if (element instanceof ItemRecord) {
                return ((ItemRecord) element).getImage();
            }
            return super.getImage(element);
        }
    });
    viewer.setSorter(TreeBuilder.createSorter());
    viewer.setInput(this);
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            filteredCheckboxTree.calculateCheckedLeafNodes();
            updateFinishStatus();
        }
    });
    filteredCheckboxTree.getViewer().addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return selectRepositoryNode(viewer, element);
        }
    });
    return viewer;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) FilteredCheckboxTree(org.talend.core.ui.advanced.composite.FilteredCheckboxTree) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TableViewer(org.eclipse.jface.viewers.TableViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Image(org.eclipse.swt.graphics.Image) IContainerNode(org.talend.repository.imports.TreeBuilder.IContainerNode) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Project(org.talend.core.model.properties.Project) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) ProjectNode(org.talend.repository.imports.TreeBuilder.ProjectNode) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 52 with ICheckStateListener

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

the class StatLogsAndImplicitcontextTreeViewPage method createImplicitcontextTree.

private void createImplicitcontextTree(Composite composite) {
    //$NON-NLS-1$
    Group g = widgetFactory.createGroup(composite, Messages.getString("ExtraComposite.ImplicitContextSettings"));
    GridData gd = new GridData(GridData.FILL_BOTH);
    g.setLayoutData(gd);
    g.setLayout(new FillLayout());
    viewer = new CheckboxRepositoryTreeViewer(g, SWT.MULTI | SWT.V_SCROLL);
    contentProvider = new AllJobContentProvider(repositoryView);
    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(new RepositoryLabelProvider(repositoryView));
    viewer.setSorter(repositoryView.getViewer().getSorter());
    IViewSite viewSite = repositoryView.getViewSite();
    viewer.setInput(viewSite);
    // This only tree listener aim is to change open/close icons on folders :
    viewer.addTreeListener(new ITreeViewerListener() {

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
            RepositoryNode node = (RepositoryNode) event.getElement();
            if (node.getType().equals(ENodeType.SIMPLE_FOLDER)) {
                TreeItem item = getObject(viewer.getTree(), event.getElement());
                if (item != null) {
                    item.setImage(ImageProvider.getImage(ECoreImage.FOLDER_CLOSE_ICON));
                }
            }
        }

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            RepositoryNode node = (RepositoryNode) event.getElement();
            if (node.getType().equals(ENodeType.SIMPLE_FOLDER)) {
                TreeItem item = getObject(viewer.getTree(), event.getElement());
                if (item != null) {
                    item.setImage(ImageProvider.getImage(ECoreImage.FOLDER_OPEN_ICON));
                }
            }
        }
    });
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            RepositoryNode node = (RepositoryNode) event.getElement();
            List<RepositoryNode> objects = new ArrayList<RepositoryNode>();
            processItems(objects, node);
            if (event.getChecked()) {
                addedObjects.addAll(objects);
                removedObjects.removeAll(objects);
                checkedObjects.addAll(addedObjects);
            } else {
                addedObjects.removeAll(objects);
                removedObjects.addAll(objects);
                checkedObjects.removeAll(objects);
            }
            // set checked
            viewer.setCheckedElements(checkedObjects.toArray());
        // viewer.refresh();
        }
    });
    RepositoryNode[] nodes = contentProvider.getContents();
    List<RepositoryNode> objects = new ArrayList<RepositoryNode>();
    if (nodes != null) {
        for (RepositoryNode n : nodes) {
            processItems(objects, n);
            for (RepositoryNode node : objects) {
                if (isUseProjectSetting(node)) {
                    if (!checkedObjects.contains(node)) {
                        checkedObjects.add(node);
                    }
                }
            }
        }
    }
    viewer.setCheckedElements(checkedObjects.toArray());
    if (nodes != null) {
        viewer.setExpandedElements(nodes);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) TreeItem(org.eclipse.swt.widgets.TreeItem) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) ArrayList(java.util.ArrayList) FillLayout(org.eclipse.swt.layout.FillLayout) RepositoryLabelProvider(org.talend.core.repository.ui.view.RepositoryLabelProvider) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IViewSite(org.eclipse.ui.IViewSite) CheckboxRepositoryTreeViewer(org.talend.repository.viewer.ui.viewer.CheckboxRepositoryTreeViewer) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ArrayList(java.util.ArrayList) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent)

Example 53 with ICheckStateListener

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

the class ExportItemWizardPage method addTreeCheckedSelection.

private void addTreeCheckedSelection() {
    final CheckboxTreeViewer exportItemsTreeViewer = getItemsTreeViewer();
    exportItemsTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
        // refreshExportDependNodes();
        }
    });
    exportItemsTreeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
                initcheckedNodes.add(event.getElement());
                // remove children and parent from uncheckednodes
                TreeItem treeItem = getTreeItem(exportItemsTreeViewer.getTree().getItems(), event.getElement());
                Set subItems = collectSubData(treeItem);
                Set parent = collectParentData(treeItem);
                uncheckedNodes.removeAll(subItems);
                uncheckedNodes.removeAll(parent);
            } else {
                uncheckedNodes.add(event.getElement());
                // remove children from initcheckedNodes
                TreeItem treeItem = getTreeItem(exportItemsTreeViewer.getTree().getItems(), event.getElement());
                Set subItems = collectSubData(treeItem);
                initcheckedNodes.removeAll(subItems);
            }
        }
    });
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Set(java.util.Set) HashSet(java.util.HashSet) TreeItem(org.eclipse.swt.widgets.TreeItem) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 54 with ICheckStateListener

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

the class StatusManagerSettingPage method addRepositoryTreeViewer.

/**
     * repository tree viewer.
     */
private void addRepositoryTreeViewer(Composite leftComposite) {
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.widthHint = 210;
    gridData.heightHint = 400;
    leftComposite.setLayoutData(gridData);
    RepoCommonViewerProvider provider = RepoCommonViewerProvider.CHECKBOX;
    treeViewer = (CheckboxRepositoryTreeViewer) provider.createViewer(leftComposite);
    // filter
    treeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            RepositoryNode node = (RepositoryNode) element;
            return filterRepositoryNode(node);
        }
    });
    // event
    treeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            RepositoryNode node = (RepositoryNode) event.getElement();
            List<RepositoryObject> objects = new ArrayList<RepositoryObject>();
            processItems(objects, node);
            if (!objects.isEmpty()) {
                if (event.getChecked()) {
                    checkedObjects.addAll(objects);
                } else {
                    checkedObjects.removeAll(objects);
                    removeItemElements(objects);
                }
                // researchMaxVersion();
                refreshTableItems();
            }
        }
    });
    treeViewer.addTreeListener(new ITreeViewerListener() {

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        //
        }

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
        // refreshCheckedTreeView();
        }
    });
    expandSomeNodes(provider.getProjectRepositoryNode());
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) RepositoryObject(org.talend.core.model.repository.RepositoryObject) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) CheckboxRepositoryTreeViewer(org.talend.repository.viewer.ui.viewer.CheckboxRepositoryTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepoCommonViewerProvider(org.talend.repository.viewer.ui.provider.RepoCommonViewerProvider) GridData(org.eclipse.swt.layout.GridData) RepositoryObject(org.talend.core.model.repository.RepositoryObject) List(java.util.List) ArrayList(java.util.ArrayList) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent)

Example 55 with ICheckStateListener

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

the class TalendWizardArchiveFileResourceExportPage1 method myCreateResourcesGroup.

protected void myCreateResourcesGroup(Composite parent) {
    // create the input element, which has the root resource
    // as its only child
    List<String> notExportProjects = Arrays.asList(GeneralParametersProvider.getStrings(GeneralParameters.PROJECTS_EXCLUDED_FROM_EXPORT));
    List input = new ArrayList();
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (int i = 0; i < projects.length; i++) {
        if (projects[i].isOpen() && !notExportProjects.contains(projects[i].getName())) {
            input.add(projects[i]);
        }
    }
    resourceGroup = new ResourceTreeAndListGroup(parent, input, getResourceProvider(IResource.FOLDER | IResource.PROJECT), WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(), getResourceProvider(IResource.FILE), WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(), SWT.NONE, inRegularFontMode(parent));
    ICheckStateListener listener = new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateWidgetEnablements();
        }
    };
    resourceGroup.addCheckStateListener(listener);
}
Also used : ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) IProject(org.eclipse.core.resources.IProject) ResourceTreeAndListGroup(org.eclipse.ui.ide.dialogs.ResourceTreeAndListGroup)

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