Search in sources :

Example 1 with ITaglibIndexDelta

use of org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta in project webtools.sourceediting by eclipse.

the class TaglibIndexDeltaTraceView method createPartControl.

public void createPartControl(final Composite parent) {
    fViewer = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION);
    fViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            showSelectionDetail(parent);
        }
    });
    fViewer.setContentProvider(new ArrayContentProvider());
    fViewer.setLabelProvider(new ITableLabelProvider() {

        public void removeListener(ILabelProviderListener listener) {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void dispose() {
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public String getColumnText(Object element, int columnIndex) {
            switch(columnIndex) {
                case 0:
                    {
                        return Long.toString(((TaglibIndexDelta) element).getTime());
                    }
                case 1:
                    {
                        String kind = null;
                        switch(((ITaglibIndexDelta) element).getKind()) {
                            case ITaglibIndexDelta.ADDED:
                                kind = "added";
                                break;
                            case ITaglibIndexDelta.REMOVED:
                                kind = "removed";
                                break;
                            case ITaglibIndexDelta.CHANGED:
                                kind = "changed";
                                break;
                        }
                        return kind;
                    }
                case 2:
                    return ((ITaglibIndexDelta) element).getProject().getName();
                case 3:
                    return ((TaglibIndexDelta) element).getTrigger().toString();
            }
            return "";
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });
    String[] columnProperties = new String[] { "time", "Kind", "Project", "Trigger" };
    TableLayout tlayout = new TableLayout();
    CellEditor[] cellEditors = new CellEditor[columnProperties.length];
    int[] columnWidths = new int[] { Display.getCurrent().getBounds().width / 14, Display.getCurrent().getBounds().width / 7, Display.getCurrent().getBounds().width / 7, Display.getCurrent().getBounds().width / 14, Display.getCurrent().getBounds().width / 7 };
    for (int i = 0; i < columnProperties.length; i++) {
        tlayout.addColumnData(new ColumnWeightData(1));
        TableColumn tc = new TableColumn(fViewer.getTable(), SWT.NONE);
        tc.setText(columnProperties[i]);
        tc.setResizable(true);
        tc.setWidth(columnWidths[i]);
    }
    fViewer.setCellEditors(cellEditors);
    fViewer.setColumnProperties(columnProperties);
    fViewer.getTable().setHeaderVisible(true);
    fViewer.getTable().setLinesVisible(true);
    fViewer.setColumnProperties(columnProperties);
    MenuManager contextMenuManager = new MenuManager();
    contextMenuManager.setRemoveAllWhenShown(false);
    contextMenuManager.add(new Action() {

        public void run() {
            super.run();
            showSelectionDetail(parent);
        }

        public String getText() {
            return "Details...";
        }

        public boolean isEnabled() {
            return !fViewer.getSelection().isEmpty();
        }
    });
    Menu contextMenu = contextMenuManager.createContextMenu(fViewer.getControl());
    getControl().setMenu(contextMenu);
    fViewer.setInput(fInput);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) CellEditor(org.eclipse.jface.viewers.CellEditor) ITaglibIndexDelta(org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Image(org.eclipse.swt.graphics.Image) TableColumn(org.eclipse.swt.widgets.TableColumn) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) TaglibIndexDelta(org.eclipse.jst.jsp.core.taglib.TaglibIndexDelta) ITaglibIndexDelta(org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) MenuManager(org.eclipse.jface.action.MenuManager) Menu(org.eclipse.swt.widgets.Menu) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 2 with ITaglibIndexDelta

use of org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta 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)

Aggregations

DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)2 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 ITaglibIndexDelta (org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta)2 TaglibIndexDelta (org.eclipse.jst.jsp.core.taglib.TaglibIndexDelta)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Dialog (org.eclipse.jface.dialogs.Dialog)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1