Search in sources :

Example 21 with ITreeContentProvider

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

the class XmlPreviewer method createControls.

public void createControls(Composite parent, final Object data) throws ExplorerException {
    Element rootElem = getXml(data);
    if (rootElem == null)
        return;
    final Object[] root = new Object[] { rootElem };
    TreeViewer tree = new TreeViewer(parent, SWT.SINGLE);
    tree.setContentProvider(new ITreeContentProvider() {

        public void dispose() {
        }

        /**
         * Called to get the top level items
         */
        public Object[] getChildren(Object parentElement) {
            return root;
        }

        /**
         * Called to get the item's children
         */
        public Object[] getElements(Object inputElement) {
            Element elem = (Element) inputElement;
            return elem.elements().toArray();
        }

        public boolean hasChildren(Object element) {
            Element elem = (Element) element;
            List<Element> list = elem.elements();
            return list != null && list.size() > 0;
        }

        public Object getParent(Object element) {
            Element elem = (Element) element;
            return elem.getParent();
        }

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

        public String getText(Object obj) {
            Element elem = (Element) obj;
            StringBuffer result = new StringBuffer();
            result.append('<');
            result.append(elem.getName());
            for (Attribute attr : elem.attributes()) {
                result.append(' ').append(attr.getName()).append('=').append('\"').append(attr.getValue()).append('\"');
            }
            if (!elem.hasContent())
                result.append('/');
            result.append('>');
            return result.toString();
        }
    });
    tree.expandToLevel(1);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Attribute(org.dom4j.Attribute) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Element(org.dom4j.Element) List(java.util.List) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 22 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project whole by wholeplatform.

the class MergeResourcesAction method performWorkspaceResourceSelection.

protected IEntity performWorkspaceResourceSelection(Shell shell, IEntity entity) {
    IResource input;
    if (Matcher.matchImpl(ArtifactsEntityDescriptorEnum.Workspace, entity.wGetParent()))
        input = ResourcesPlugin.getWorkspace().getRoot();
    else {
        IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
        ArtifactsWorkspaceUtils.bindPath(entity.wGetParent(), bm, false);
        input = (IResource) (bm.wIsSet("folder") ? bm.wGetValue("folder") : bm.wGetValue("project"));
    }
    IJavaElement javaInput = JavaCore.create(input);
    LabelProvider labelProvider = javaInput != null ? new JavaElementLabelProvider() : new WorkbenchLabelProvider();
    ITreeContentProvider contentProvider = javaInput != null ? new StandardJavaElementContentProvider() : new WorkbenchContentProvider();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, labelProvider, contentProvider);
    dialog.setInput(javaInput != null ? javaInput : input);
    dialog.setTitle(SELECT_RESOURCE_MSG);
    dialog.setMessage("Choose a resource");
    if (javaInput != null)
        dialog.addFilter(new ViewerFilter() {

            public boolean select(Viewer viewer, Object parentElement, Object element) {
                try {
                    return !(element instanceof IPackageFragmentRoot) || ((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_SOURCE;
                } catch (Exception e) {
                    return false;
                }
            }
        });
    if (dialog.open() != IDialogConstants.OK_ID)
        return NullEntity.instance;
    IEntity result = null;
    for (Object resource : dialog.getResult()) {
        IEntity artifactsPath;
        if (resource instanceof IJavaElement) {
            IJavaElement toJavaElement = (IJavaElement) resource;
            artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(javaInput, toJavaElement);
        } else {
            IResource toResource = (IResource) resource;
            IJavaElement parentJavaElement = JavaCore.create(toResource.getParent());
            if (javaInput == null || parentJavaElement == null)
                artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(input, toResource);
            else
                artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(javaInput, toResource);
        }
        result = result == null ? artifactsPath : EntityUtils.merge(result, artifactsPath, createEntityComparator(), false);
    }
    int index = Matcher.match(ArtifactsEntityDescriptorEnum.Workspace, result) ? result.wIndexOf(ArtifactsFeatureDescriptorEnum.projects) : result.wIndexOf(ArtifactsFeatureDescriptorEnum.artifacts);
    IEntity tree = result.wGet(index);
    result.wRemove(index);
    return tree;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IEntity(org.whole.lang.model.IEntity) Viewer(org.eclipse.jface.viewers.Viewer) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) JavaElementLabelProvider(org.eclipse.jdt.ui.JavaElementLabelProvider) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) StandardJavaElementContentProvider(org.eclipse.jdt.ui.StandardJavaElementContentProvider) IBindingManager(org.whole.lang.bindings.IBindingManager) JavaElementLabelProvider(org.eclipse.jdt.ui.JavaElementLabelProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IResource(org.eclipse.core.resources.IResource)

Example 23 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project portfolio by buchen.

the class TreeViewerCSVExporter method writeToFile.

@Override
protected void writeToFile(File file) throws IOException {
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
        CSVPrinter printer = new CSVPrinter(writer);
        printer.setStrategy(STRATEGY);
        ITreeContentProvider provider = (ITreeContentProvider) viewer.getContentProvider();
        int depth = depth(provider);
        int columnCount = viewer.getTree().getColumnCount();
        ILabelProvider[] labels = new ILabelProvider[columnCount];
        extractLabelProvider(labels);
        // write header
        String label = viewer.getTree().getColumn(0).getText();
        for (int ii = 0; ii < depth; ii++) // $NON-NLS-1$
        printer.print(label + " " + (ii + 1));
        for (int ii = 1; ii < columnCount; ii++) printer.print(viewer.getTree().getColumn(ii).getText());
        printer.println();
        // write body
        LinkedList<String> path = new LinkedList<>();
        for (Object element : provider.getElements(null)) {
            writeLine(printer, provider, labels, depth, path, element);
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) LinkedList(java.util.LinkedList)

Example 24 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.

the class LinkRequirementsCheckStateListener method checkAndGrayAllParents.

/**
 * Checks and grays all the parents in {@code checkboxTreeViewer} of
 * {@code element}.
 *
 * @param checkboxTreeViewer
 * @param element
 */
private static void checkAndGrayAllParents(CheckboxTreeViewer checkboxTreeViewer, Object element) {
    ITreeContentProvider contentProvider = getTreeContentProvider(checkboxTreeViewer);
    Object parent = contentProvider.getParent(element);
    do {
        checkboxTreeViewer.setGrayChecked(parent, true);
        parent = contentProvider.getParent(parent);
    } while (parent != null);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider)

Example 25 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.

the class LinkRequirementsCheckStateListener method unCheckAndUnGrayAllAppropriateParents.

/**
 * Unchecks and ungrays all parents which have no more children that's
 * checked.
 *
 * @param checkboxTreeViewer
 * @param element
 */
private static void unCheckAndUnGrayAllAppropriateParents(CheckboxTreeViewer checkboxTreeViewer, Object element) {
    ITreeContentProvider contentProvider = getTreeContentProvider(checkboxTreeViewer);
    Object parent = contentProvider.getParent(element);
    while (parent != null && !anyCheckedInViewer(Arrays.asList(contentProvider.getChildren(parent)), checkboxTreeViewer)) {
        checkboxTreeViewer.setGrayChecked(parent, false);
        parent = contentProvider.getParent(parent);
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider)

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