Search in sources :

Example 1 with ITreeViewerListener

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

the class StatLogsAndImplicitcontextTreeViewPage method createStatTree.

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

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
            RepositoryNode node = (RepositoryNode) event.getElement();
            if (node.getType().equals(ENodeType.SIMPLE_FOLDER)) {
                TreeItem item = getObject(statViewer.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(statViewer.getTree(), event.getElement());
                if (item != null) {
                    item.setImage(ImageProvider.getImage(ECoreImage.FOLDER_OPEN_ICON));
                }
            }
        }
    });
    statViewer.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()) {
                statAddedObjects.addAll(objects);
                statRemovedObjects.removeAll(objects);
                statCheckedObjects.addAll(objects);
            } else {
                statAddedObjects.removeAll(objects);
                statRemovedObjects.addAll(objects);
                statCheckedObjects.removeAll(objects);
            }
            // set checked
            statViewer.setCheckedElements(statCheckedObjects.toArray());
        // viewer.refresh();
        }
    });
    RepositoryNode[] nodes = statContentProvider.getContents();
    List<RepositoryNode> objects = new ArrayList<RepositoryNode>();
    if (nodes != null) {
        for (RepositoryNode n : nodes) {
            processItems(objects, n);
            for (RepositoryNode node : objects) {
                if (isStatUseProjectSetting(node)) {
                    if (!statCheckedObjects.contains(node)) {
                        statCheckedObjects.add(node);
                    }
                }
            }
        }
    }
    statViewer.setCheckedElements(statCheckedObjects.toArray());
    if (nodes != null) {
        statViewer.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 2 with ITreeViewerListener

use of org.eclipse.jface.viewers.ITreeViewerListener in project cubrid-manager by CUBRID.

the class CubridHostNavigatorView method createNavigator.

/**
	 * Create the navigator
	 */
protected void createNavigator() {
    tv.setSorter(new CMNavigatorViewSorter());
    tv.setContentProvider(new DeferredContentProvider());
    tv.setLabelProvider(new DecoratingLabelProvider(new NavigatorTreeLabelProvider()));
    tv.addDoubleClickListener(LayoutManager.getInstance());
    tv.addTreeListener(new ITreeViewerListener() {

        public void treeCollapsed(TreeExpansionEvent event) {
            CommonUITool.clearExpandedElements(tv);
        }

        public void treeExpanded(TreeExpansionEvent event) {
            CommonUITool.clearExpandedElements(tv);
        }
    });
    CubridActionBuilder.init();
    hookRetragetActions();
    addHostListener();
}
Also used : DeferredContentProvider(com.cubrid.common.ui.common.navigator.DeferredContentProvider) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) DecoratingLabelProvider(com.cubrid.common.ui.common.navigator.DecoratingLabelProvider) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent)

Example 3 with ITreeViewerListener

use of org.eclipse.jface.viewers.ITreeViewerListener in project eclipse.platform.text by eclipse.

the class FileSearchPage method configureTreeViewer.

@Override
protected void configureTreeViewer(TreeViewer viewer) {
    viewer.setUseHashlookup(true);
    FileLabelProvider innerLabelProvider = new FileLabelProvider(this, FileLabelProvider.SHOW_LABEL);
    viewer.setLabelProvider(new DecoratingFileSearchLabelProvider(innerLabelProvider));
    viewer.setContentProvider(new FileTreeContentProvider(this, viewer));
    viewer.setComparator(new DecoratorIgnoringViewerSorter(innerLabelProvider));
    fContentProvider = (IFileSearchContentProvider) viewer.getContentProvider();
    addDragAdapters(viewer);
    viewer.addTreeListener(new ITreeViewerListener() {

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            autoExpand(viewer, event.getElement());
        }
    });
}
Also used : ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent)

Example 4 with ITreeViewerListener

use of org.eclipse.jface.viewers.ITreeViewerListener in project dsl-devkit by dsldevkit.

the class ValidPreferenceCheckedTreeViewer method initViewer.

/**
 * Initialize the tree viewer.
 */
private void initViewer() {
    setUseHashlookup(true);
    addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            doCheckStateChanged(event.getElement());
        }
    });
    addTreeListener(new ITreeViewerListener() {

        @Override
        public void treeCollapsed(final TreeExpansionEvent event) {
        // nothing to do here
        }

        @Override
        public void treeExpanded(final TreeExpansionEvent event) {
            final Widget item = findItem(event.getElement());
            if (item instanceof TreeItem) {
                initializeItem((TreeItem) item);
            }
        }
    });
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) Widget(org.eclipse.swt.widgets.Widget) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent)

Example 5 with ITreeViewerListener

use of org.eclipse.jface.viewers.ITreeViewerListener in project usbdm-eclipse-plugins by podonoghue.

the class DeviceSelectorPanel method createControl.

/**
 * Create control composite
 *
 * @param parent
 */
private void createControl(Composite parent) {
    setLayout(new GridLayout(3, false));
    Label label = new Label(this, SWT.NONE);
    label.setText("Search Filter: ");
    fDeviceText = new Text(this, SWT.BORDER);
    fDeviceText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    fDeviceText.setToolTipText("Filter/name of device");
    fDeviceText.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
        }

        @Override
        public void focusGained(FocusEvent e) {
            fDeviceText.selectAll();
        }
    });
    fDeviceText.setText(NO_DEVICE_STRING);
    fDeviceText.addVerifyListener(new VerifyListener() {

        public void verifyText(VerifyEvent e) {
            e.text = e.text.toUpperCase();
            if (!e.text.matches("[A-Z|0-9|_\\-]*")) {
                e.doit = false;
            }
        }
    });
    fDeviceText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            fMatchErrorMsg = null;
            try {
                filter = new NameFilter(fDeviceText.getText());
            } catch (PatternSyntaxException e) {
                fMatchErrorMsg = "Illegal filter";
                filter = Filter.NullNameFilter;
            }
            filterNodes();
        }
    });
    fButton = new Button(this, SWT.NONE);
    fButton.setText("X");
    fButton.setToolTipText("Clear filter");
    GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
    gd.widthHint = 40;
    fButton.setLayoutData(gd);
    fButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            fDeviceText.setText(NO_DEVICE_STRING);
            fDeviceText.setFocus();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    fViewer = new TreeViewer(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    fViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    fViewer.getTree().setToolTipText("Available devices");
    fViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // System.err.println("selectionChanged() "+event);
            if (!((TreeViewer) event.getSource()).getControl().isFocusControl()) {
                // Filter selection events due to re-population of tree i.e. when  tree doesn't have focus
                return;
            }
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
                Object domain = iterator.next();
                if (domain instanceof DeviceModel) {
                    DeviceModel deviceModel = (DeviceModel) domain;
                    fDeviceName = deviceModel.getName();
                    fDeviceText.setText(fDeviceName);
                }
            }
        }
    });
    fViewer.setContentProvider(new ViewContentProvider());
    fViewer.setInput(fModel);
    fViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parent, Object item) {
            if (item instanceof BaseModel) {
                boolean rv = ((BaseModel) item).isAvailable();
                return rv;
            }
            return true;
        }
    });
    fViewer.addTreeListener(new ITreeViewerListener() {

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            if (fMatchingNodesCount <= EXPAND_THRESHOLD) {
                return;
            }
            Object domain = event.getElement();
            if (domain instanceof CategoryModel) {
                CategoryModel deviceModel = (CategoryModel) domain;
                BaseModel parent = deviceModel.getParent();
                for (BaseModel sibling : parent.getChildren()) {
                    if (sibling == domain) {
                        continue;
                    }
                    fViewer.collapseToLevel(sibling, AbstractTreeViewer.ALL_LEVELS);
                }
            }
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent arg0) {
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) VerifyEvent(org.eclipse.swt.events.VerifyEvent) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) PatternSyntaxException(java.util.regex.PatternSyntaxException) VerifyListener(org.eclipse.swt.events.VerifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) Text(org.eclipse.swt.widgets.Text) GridData(org.eclipse.swt.layout.GridData) FocusListener(org.eclipse.swt.events.FocusListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ITreeViewerListener (org.eclipse.jface.viewers.ITreeViewerListener)17 TreeExpansionEvent (org.eclipse.jface.viewers.TreeExpansionEvent)17 GridData (org.eclipse.swt.layout.GridData)8 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)7 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)7 TreeItem (org.eclipse.swt.widgets.TreeItem)5 IRepositoryNode (org.talend.repository.model.IRepositoryNode)5 RepositoryNode (org.talend.repository.model.RepositoryNode)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)4 CheckboxRepositoryTreeViewer (org.talend.repository.viewer.ui.viewer.CheckboxRepositoryTreeViewer)4 DeferredContentProvider (com.cubrid.common.ui.common.navigator.DeferredContentProvider)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 Viewer (org.eclipse.jface.viewers.Viewer)3