Search in sources :

Example 6 with ITreeContentProvider

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

the class FileSearchPage method autoExpand.

/**
 * Performs an auto-expansion starting at the given element in the viewer.
 * As long as the object only has one unexpanded child, auto-expand will
 * expand that child. It stops expanding children once there is actually a
 * choice for the user to make.
 *
 * @param viewer
 *            the viewer to perform auto-expansion on
 * @param toExpand
 *            the viewer entry at which expansion should start
 */
private void autoExpand(TreeViewer viewer, Object toExpand) {
    final ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
    Display.getCurrent().asyncExec(() -> {
        if (viewer.getControl().isDisposed()) {
            return;
        }
        Object current = toExpand;
        while (current != null) {
            Object childToExpand = null;
            Object[] children = contentProvider.getChildren(current);
            if (children != null && children.length == 1) {
                childToExpand = children[0];
            }
            if (childToExpand != null) {
                if (!viewer.getExpandedState(childToExpand)) {
                    viewer.setExpandedState(childToExpand, true);
                }
            }
            current = childToExpand;
        }
    });
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider)

Example 7 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project linuxtools by eclipse.

the class STDataViewersCSVExporter method export.

public void export(IProgressMonitor monitor) {
    // monitoring
    this.monitor = monitor;
    monitor.beginTask("Exporting to CSV (file: " + getFilePath() + ")", IProgressMonitor.UNKNOWN);
    // save this configuration
    saveState();
    // init the printStream
    initPrintStream(filePath);
    // get the viewer's parameters
    monitor.subTask("collecting viewer's parameters...");
    collectViewerParameters();
    // start dumping to csv file
    dumpColumnHeaders();
    if (input != null) {
        if (contentProvider instanceof ITreeContentProvider) {
            ITreeContentProvider treeContentProvider = (ITreeContentProvider) contentProvider;
            Object[] topElements = treeContentProvider.getElements(input);
            if (topElements != null) {
                // monitoring
                int work = topElements.length;
                for (Object element : topElements) {
                    if (treeContentProvider.hasChildren(element)) {
                        work += treeContentProvider.getChildren(element).length;
                    }
                }
                monitor.beginTask("Exporting to CSV (file: " + getFilePath() + ")", work);
                monitor.subTask("exporting tree data...");
                // monitoring stuff
                int tempWork = 0;
                int workFloor = topElements.length / 100;
                if (workFloor == 0) {
                    workFloor = 1;
                }
                // exporting tree
                Arrays.sort(topElements, comparator);
                for (int i = 0; i < topElements.length; i++) {
                    dumpTreeData(treeContentProvider, topElements[i], "", i == topElements.length - 1, true);
                    // monitoring
                    tempWork++;
                    if (tempWork >= workFloor) {
                        if (monitor.isCanceled()) {
                            ps.close();
                            return;
                        }
                        monitor.worked(tempWork);
                        tempWork = 0;
                    }
                }
                // monitoring
                monitor.worked(tempWork);
            }
        } else if (contentProvider instanceof IStructuredContentProvider) {
            IStructuredContentProvider structContentProvider = (IStructuredContentProvider) contentProvider;
            Object[] topElements = structContentProvider.getElements(input);
            if (topElements != null) {
                // monitoring
                monitor.beginTask("Exporting to CSV (file: " + getFilePath() + ")", topElements.length);
                monitor.subTask("exporting table data...");
                // monitoring stuff
                int tempWork = 0;
                int workFloor = topElements.length / 100;
                if (workFloor == 0) {
                    workFloor = 1;
                }
                // exporting table
                Arrays.sort(topElements, comparator);
                for (int n = 0; n < topElements.length; n++) {
                    if (n < topElements.length - 1) {
                        dumpNodeData(topElements[n], csvChildMarker);
                    } else {
                        dumpNodeData(topElements[n], csvLastChildMarker);
                    }
                    // monitoring
                    tempWork++;
                    if (tempWork >= workFloor) {
                        if (monitor.isCanceled()) {
                            ps.close();
                            return;
                        }
                        monitor.worked(tempWork);
                        tempWork = 0;
                    }
                }
                // monitoring
                monitor.worked(tempWork);
            }
        }
    }
    // close the stream
    ps.close();
    // end monitoring
    monitor.done();
    IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(getFilePath()));
    if (c != null) {
        try {
            c.refreshLocal(1, new NullProgressMonitor());
        } catch (CoreException e) {
            STDataViewersActivator.getDefault().getLog().log(e.getStatus());
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider)

Example 8 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project linuxtools by eclipse.

the class TreeColumnViewerFilter method select.

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    ITreeContentProvider provider = (ITreeContentProvider) treeViewer.getContentProvider();
    String s = field.getValue(element);
    if (s.contains(matchingText)) {
        return true;
    }
    if (provider.hasChildren(element)) {
        for (Object o : provider.getChildren(element)) {
            if (select(viewer, element, o)) {
                return true;
            }
        }
    }
    if (keepAllChildIfParentMatch) {
        while (parentElement != null) {
            String ps = field.getValue(parentElement);
            if (ps.contains(matchingText)) {
                return true;
            }
            parentElement = provider.getParent(parentElement);
        }
    }
    return false;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider)

Example 9 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project erlide_eclipse by erlang.

the class DirectorySelectUtil method chooseLocation.

public static IContainer chooseLocation(final String dialogTitle, final String labelText, final IProject project2, final String outputLocation, final Shell shell) {
    final IWorkspaceRoot root = project2.getWorkspace().getRoot();
    final Class<?>[] acceptedClasses = new Class[] { IProject.class, IFolder.class };
    final IProject[] allProjects = root.getProjects();
    final List<IProject> rejectedElements = new ArrayList<>(allProjects.length);
    for (IProject allProject : allProjects) {
        if (!allProject.equals(project2)) {
            rejectedElements.add(allProject);
        }
    }
    final ViewerFilter filter = new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());
    final ILabelProvider lp = new WorkbenchLabelProvider();
    final ITreeContentProvider cp = new WorkbenchContentProvider();
    IResource initSelection = null;
    if (outputLocation != null) {
        initSelection = root.findMember(outputLocation);
    }
    final FolderSelectionDialog dialog = new FolderSelectionDialog(shell, lp, cp);
    dialog.setTitle(dialogTitle);
    final ISelectionStatusValidator validator = new ISelectionStatusValidator() {

        ISelectionStatusValidator myValidator = new TypedElementSelectionValidator(acceptedClasses, false);

        @Override
        public IStatus validate(final Object[] selection) {
            final IStatus typedStatus = myValidator.validate(selection);
            if (!typedStatus.isOK()) {
                return typedStatus;
            }
            if (selection[0] instanceof IFolder) {
                // }
                return new StatusInfo();
            }
            return new StatusInfo(IStatus.ERROR, "");
        }
    };
    dialog.setValidator(validator);
    dialog.setMessage(labelText);
    dialog.addFilter(filter);
    dialog.setInput(root);
    dialog.setInitialSelection(initSelection);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (dialog.open() == Window.OK) {
        return (IContainer) dialog.getFirstResult();
    }
    return null;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TypedViewerFilter(org.erlide.ui.util.TypedViewerFilter) ArrayList(java.util.ArrayList) FolderSelectionDialog(org.erlide.ui.util.FolderSelectionDialog) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TypedElementSelectionValidator(org.erlide.ui.util.TypedElementSelectionValidator) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) StatusInfo(org.erlide.ui.util.StatusInfo) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) TypedViewerFilter(org.erlide.ui.util.TypedViewerFilter)

Example 10 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project tmdm-studio-se by Talend.

the class MenuMainPage method createCharacteristicsContent.

@Override
protected void createCharacteristicsContent(FormToolkit toolkit, Composite mainComposite) {
    try {
        // description
        Label descriptionLabel = toolkit.createLabel(mainComposite, Messages.MenuMainPage_Description, SWT.NULL);
        descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
        // $NON-NLS-1$
        descriptionText = toolkit.createText(mainComposite, "", SWT.BORDER);
        descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        ((GridData) descriptionText.getLayoutData()).minimumHeight = 30;
        descriptionText.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                if (refreshing) {
                    return;
                }
                markDirtyWithoutCommit();
            }
        });
        // Util.createCompDropTarget(descriptionText);
        // make the Page window a DropTarget - we need to dispose it
        windowTarget = new DropTarget(this.getPartControl(), DND.DROP_MOVE);
        windowTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
        windowTarget.addDropListener(new DCDropTargetListener());
        Composite composite = toolkit.createComposite(mainComposite, SWT.BORDER);
        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        composite.setLayout(new GridLayout(1, false));
        menuTree = new TreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
        menuTree.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        ((GridData) menuTree.getControl().getLayoutData()).heightHint = 150;
        menuTree.setContentProvider(new ITreeContentProvider() {

            public void dispose() {
            }

            public Object[] getChildren(Object parentElement) {
                if (parentElement instanceof TreeEntry) {
                    WSMenuEntry wsEntry = ((TreeEntry) parentElement).getWSMenuEntry();
                    if (wsEntry.getSubMenus() != null) {
                        TreeEntry[] children = new TreeEntry[wsEntry.getSubMenus().size()];
                        for (int i = 0; i < wsEntry.getSubMenus().size(); i++) {
                            children[i] = new TreeEntry((TreeEntry) parentElement, wsEntry.getSubMenus().get(i));
                        }
                        return children;
                    }
                    return null;
                }
                if (parentElement instanceof WSMenu) {
                    // the root
                    java.util.List<WSMenuEntry> menuEntries = ((WSMenu) parentElement).getMenuEntries();
                    if (menuEntries != null) {
                        TreeEntry[] children = new TreeEntry[menuEntries.size()];
                        for (int i = 0; i < menuEntries.size(); i++) {
                            children[i] = new TreeEntry(null, menuEntries.get(i));
                        }
                        return children;
                    }
                    return null;
                }
                // ??!!?
                return null;
            }

            public Object[] getElements(Object inputElement) {
                return getChildren(inputElement);
            }

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

            public boolean hasChildren(Object element) {
                return ((getChildren(element) == null) || (getChildren(element).length > 0));
            }

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

            @Override
            public String getText(Object element) {
                WSMenuEntry wsMenuEntry = ((TreeEntry) element).getWSMenuEntry();
                // $NON-NLS-1$
                StringBuffer label = new StringBuffer(wsMenuEntry.getId() + " - ");
                for (WSMenuMenuEntriesDescriptions description : wsMenuEntry.getDescriptions()) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    label.append("[").append(description.getLanguage()).append(": ").append(description.getLabel()).append(// $NON-NLS-1$
                    "] ");
                }
                if (label.length() > 200) {
                    // $NON-NLS-1$
                    return label.substring(0, 197) + "...";
                }
                return label.toString();
            }

            @Override
            public Image getImage(Object element) {
                return ImageCache.getCreatedImage(EImage.MENU.getPath());
            }
        });
        menuTreeMgr = new MenuManager();
        menuTreeMgr.setRemoveAllWhenShown(true);
        menuTreeMgr.addMenuListener(new IMenuListener() {

            public void menuAboutToShow(IMenuManager manager) {
                IStructuredSelection selection = ((IStructuredSelection) menuTree.getSelection());
                if ((selection == null) || (selection.getFirstElement() == null)) {
                    manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
                    return;
                }
                // TreeEntry entry = (TreeEntry)selection.getFirstElement();
                menuTreeMgr.add(new TreeEntryEditAction(menuTree));
                menuTreeMgr.add(new TreeEntryAddAction(menuTree, LOCATION_BEFORE));
                menuTreeMgr.add(new TreeEntryAddAction(menuTree, LOCATION_AFTER));
                menuTreeMgr.add(new TreeEntryAddAction(menuTree, LOCATION_UNDER));
                menuTreeMgr.add(new TreeEntryDeleteAction(menuTree));
                menuTreeMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
            }
        });
        menuTree.addDoubleClickListener(new IDoubleClickListener() {

            public void doubleClick(DoubleClickEvent event) {
                (new TreeEntryEditAction(menuTree)).run();
            }
        });
        Menu menu = menuTreeMgr.createContextMenu(menuTree.getControl());
        menuTree.getControl().setMenu(menu);
        getSite().registerContextMenu(menuTreeMgr, menuTree);
        refreshData();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EImage(com.amalto.workbench.image.EImage) Image(org.eclipse.swt.graphics.Image) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) List(org.eclipse.swt.widgets.List) ArrayList(java.util.ArrayList) WSMenu(com.amalto.workbench.webservices.WSMenu) Menu(org.eclipse.swt.widgets.Menu) WSMenuEntry(com.amalto.workbench.webservices.WSMenuEntry) Composite(org.eclipse.swt.widgets.Composite) WSMenuMenuEntriesDescriptions(com.amalto.workbench.webservices.WSMenuMenuEntriesDescriptions) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) WSMenu(com.amalto.workbench.webservices.WSMenu) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) TreeObject(com.amalto.workbench.models.TreeObject) DropTarget(org.eclipse.swt.dnd.DropTarget) IMenuManager(org.eclipse.jface.action.IMenuManager) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Separator(org.eclipse.jface.action.Separator)

Aggregations

ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)68 Viewer (org.eclipse.jface.viewers.Viewer)32 LabelProvider (org.eclipse.jface.viewers.LabelProvider)19 GridData (org.eclipse.swt.layout.GridData)19 Composite (org.eclipse.swt.widgets.Composite)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 GridLayout (org.eclipse.swt.layout.GridLayout)15 Label (org.eclipse.swt.widgets.Label)13 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)12 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)11 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)11 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)11 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)11 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)11 ArrayList (java.util.ArrayList)10 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)9 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)9 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)8 SourceViewer (org.eclipse.jface.text.source.SourceViewer)7