Search in sources :

Example 31 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project webtools.sourceediting by eclipse.

the class TaglibIndexDeltaTraceView method showSelectionDetail.

void showSelectionDetail(final Composite composite) {
    IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
    if (!selection.isEmpty()) {
        final TaglibIndexDelta selectedDelta = (TaglibIndexDelta) selection.getFirstElement();
        final ITableLabelProvider tableLabelProvider = ((ITableLabelProvider) fViewer.getLabelProvider());
        String columnText = tableLabelProvider.getColumnText(selectedDelta, 1);
        columnText = columnText + ":" + tableLabelProvider.getColumnText(selectedDelta, 2);
        new Dialog(composite.getShell()) {

            public void create() {
                setShellStyle(getShellStyle() | SWT.RESIZE);
                super.create();
            }

            protected Control createDialogArea(final Composite parent) {
                final Composite inner = new Composite(parent, SWT.NONE);
                inner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                final Sash sash = new Sash(inner, SWT.HORIZONTAL);
                final TreeViewer treeViewer = new TreeViewer(inner);
                treeViewer.setContentProvider(new ITreeContentProvider() {

                    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
                    }

                    public void dispose() {
                    }

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

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

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

                    public Object[] getChildren(Object parentElement) {
                        if (parentElement instanceof TaglibIndexDelta) {
                            TaglibIndexDelta taglibIndexDelta = ((TaglibIndexDelta) parentElement);
                            if (taglibIndexDelta.getTrigger() != null) {
                                List combined = new ArrayList();
                                combined.add(taglibIndexDelta.getTrigger());
                                combined.addAll(Arrays.asList(taglibIndexDelta.getAffectedChildren()));
                                return combined.toArray();
                            }
                            return taglibIndexDelta.getAffectedChildren();
                        }
                        return new Object[0];
                    }
                });
                treeViewer.setLabelProvider(new LabelProvider() {

                    public String getText(Object element) {
                        if (element instanceof ITaglibIndexDelta) {
                            ITaglibIndexDelta taglibIndexDelta = ((ITaglibIndexDelta) element);
                            if (taglibIndexDelta.getTaglibRecord() != null)
                                return taglibIndexDelta.toString();
                            String text = tableLabelProvider.getColumnText(selectedDelta, 1);
                            text = text + ":" + tableLabelProvider.getColumnText(selectedDelta, 2);
                            return text;
                        }
                        return StringUtils.firstLineOf(super.getText(element));
                    }
                });
                treeViewer.setInput(selectedDelta);
                final Text text = new Text(inner, SWT.MULTI);
                treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

                    public void selectionChanged(SelectionChangedEvent event) {
                        IStructuredSelection selection2 = (IStructuredSelection) treeViewer.getSelection();
                        if (!selection2.isEmpty())
                            text.setText("" + (selection2).getFirstElement());
                        else
                            text.setText("");
                    }
                });
                final FormLayout form = new FormLayout();
                inner.setLayout(form);
                FormData firstData = new FormData();
                firstData.top = new FormAttachment(0, 0);
                firstData.bottom = new FormAttachment(sash, 2);
                firstData.left = new FormAttachment(0, 0);
                firstData.right = new FormAttachment(100, 0);
                treeViewer.getControl().setLayoutData(firstData);
                FormData secondData = new FormData();
                secondData.top = new FormAttachment(sash, 2);
                secondData.left = new FormAttachment(0, 0);
                secondData.right = new FormAttachment(100, 0);
                secondData.bottom = new FormAttachment(100, 0);
                text.setLayoutData(secondData);
                final FormData sashData = new FormData();
                sashData.top = new FormAttachment(60, 0);
                sashData.left = new FormAttachment(0, 0);
                sashData.right = new FormAttachment(100, 0);
                sash.setLayoutData(sashData);
                sash.addListener(SWT.Selection, new org.eclipse.swt.widgets.Listener() {

                    public void handleEvent(Event e) {
                        sashData.top = new FormAttachment(0, e.y);
                        inner.layout();
                    }
                });
                return sash;
            }
        }.open();
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) ITaglibIndexListener(org.eclipse.jst.jsp.core.taglib.ITaglibIndexListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) ITaglibIndexDelta(org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) Control(org.eclipse.swt.widgets.Control) Dialog(org.eclipse.jface.dialogs.Dialog) ArrayList(java.util.ArrayList) List(java.util.List) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) Sash(org.eclipse.swt.widgets.Sash) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) TaglibIndexDelta(org.eclipse.jst.jsp.core.taglib.TaglibIndexDelta) ITaglibIndexDelta(org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta) GridData(org.eclipse.swt.layout.GridData) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 32 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project webtools.sourceediting by eclipse.

the class JSONSyntaxColoringPage method createStylesViewer.

/**
 * Creates the List viewer where we see the various syntax element display
 * names--would it ever be a Tree like JDT's?
 *
 * @param parent
 * @return
 */
private StructuredViewer createStylesViewer(Composite parent) {
    StructuredViewer stylesViewer = new ListViewer(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    stylesViewer.setComparator(new ViewerComparator(Collator.getInstance()));
    stylesViewer.setLabelProvider(new LabelProvider() {

        public String getText(Object element) {
            Object description = fStyleToDescriptionMap.get(element);
            if (description != null)
                return description.toString();
            return super.getText(element);
        }
    });
    stylesViewer.setContentProvider(new ITreeContentProvider() {

        public void dispose() {
        }

        public Object[] getChildren(Object parentElement) {
            return getStylePreferenceKeys().toArray();
        }

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

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

        public boolean hasChildren(Object element) {
            return false;
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    return stylesViewer;
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 33 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project webtools.sourceediting by eclipse.

the class JSPSyntaxColoringPage method createStylesViewer.

/**
 * Creates the List viewer where we see the various syntax element display
 * names--would it ever be a Tree like JDT's?
 *
 * @param parent
 * @return
 */
private StructuredViewer createStylesViewer(Composite parent) {
    StructuredViewer stylesViewer = new ListViewer(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    stylesViewer.setComparator(new ViewerComparator(Collator.getInstance()));
    stylesViewer.setLabelProvider(new LabelProvider() {

        public String getText(Object element) {
            Object description = fStyleToDescriptionMap.get(element);
            if (description != null)
                return description.toString();
            return super.getText(element);
        }
    });
    stylesViewer.setContentProvider(new ITreeContentProvider() {

        public void dispose() {
        }

        public Object[] getChildren(Object parentElement) {
            return getStylePreferenceKeys().toArray();
        }

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

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

        public boolean hasChildren(Object element) {
            return false;
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    return stylesViewer;
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 34 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project webtools.sourceediting by eclipse.

the class XSLSyntaxColoringPage method createStylesViewer.

/**
 * Creates the List viewer where we see the various syntax element display
 * names--would it ever be a Tree like JDT's?
 *
 * @param parent
 * @return
 */
private StructuredViewer createStylesViewer(Composite parent) {
    StructuredViewer stylesViewer = new ListViewer(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    stylesViewer.setComparator(new ViewerComparator(Collator.getInstance()));
    stylesViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            Object description = styleToDescriptionMap.get(element);
            if (description != null)
                return description.toString();
            return super.getText(element);
        }
    });
    stylesViewer.setContentProvider(new ITreeContentProvider() {

        public void dispose() {
        }

        public Object[] getChildren(Object parentElement) {
            return getStylePreferenceKeys().toArray();
        }

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

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

        public boolean hasChildren(Object element) {
            return false;
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    return stylesViewer;
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ListViewer(org.eclipse.jface.viewers.ListViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 35 with ITreeContentProvider

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

the class ResolutionFailurePanel method copyUnresolvedToClipboard.

// private void switchFailureViewMode() {
// Object input = unresolvedViewer.getInput();
// unresolvedViewer.setInput(null);
// setFailureViewMode();
// unresolvedViewer.setInput(input);
// unresolvedViewer.expandToLevel(2);
// }
private void copyUnresolvedToClipboard() {
    StringBuilder builder = new StringBuilder();
    Object input = unresolvedViewer.getInput();
    if (input == null)
        return;
    ITreeContentProvider contentProvider = (ITreeContentProvider) unresolvedViewer.getContentProvider();
    Object[] roots = contentProvider.getElements(input);
    ViewerSorter sorter = unresolvedViewer.getSorter();
    if (sorter != null)
        Arrays.sort(roots, new SorterComparatorAdapter(unresolvedViewer, sorter));
    for (Object root : roots) {
        appendLabels(root, contentProvider, builder, 0);
    }
    /*
         * TODO if (result != null) { StringBuilder buffer = new StringBuilder(); List<Reason> unresolved =
         * result.getUnresolved(); if (unresolved != null) for (Iterator<Reason> iter = unresolved.iterator();
         * iter.hasNext(); ) { Reason reason = iter.next();
         * buffer.append(unresolvedLabelProvider.getLabel(reason.getRequirement ()).getString()); buffer.append('\t');
         * buffer.append(unresolvedLabelProvider .getLabel(reason.getResource())); if (iter.hasNext())
         * buffer.append('\n'); } }
         */
    Clipboard clipboard = new Clipboard(composite.getDisplay());
    TextTransfer transfer = TextTransfer.getInstance();
    clipboard.setContents(new Object[] { builder.toString() }, new Transfer[] { transfer });
    clipboard.dispose();
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Clipboard(org.eclipse.swt.dnd.Clipboard) SorterComparatorAdapter(bndtools.model.obr.SorterComparatorAdapter) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

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