Search in sources :

Example 91 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.

the class DropinsPluginDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
    setTitle(Messages.DropinsPluginDialog_1);
    setMessage(Messages.DropinsPluginDialog_2);
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    container.setLayout(new GridLayout(1, false));
    Composite tableComp = new Composite(container, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    tableComp.setLayout(layout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    tableComp.setLayoutData(gd);
    viewer = new TableViewer(tableComp, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    // Mac Silicon Item height
    UIUtils.fixMacSiliconItemHeight(viewer.getTable());
    viewer.getTable().setHeaderVisible(true);
    TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(10, false));
    column.getColumn().setText(Messages.DropinsPluginDialog_3);
    column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(8, false));
    column.getColumn().setText(Messages.DropinsPluginDialog_4);
    column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(10, false));
    column.getColumn().setText(Messages.DropinsPluginDialog_5);
    column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(10, false));
    column.getColumn().setText(Messages.DropinsPluginDialog_6);
    column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(10, false));
    column.getColumn().setText(Messages.DropinsPluginDialog_14);
    DropinsPluginHandler handler = new DropinsPluginHandler();
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            try {
                return handler.getInstalledPlugins().toArray();
            } catch (IOException ex) {
                // $NON-NLS-1$
                Logger.logError("Error getting installed plug-in", ex);
            }
            return new Object[0];
        }
    });
    class LabelCellProvider extends LabelProvider implements ITableLabelProvider {

        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }

        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (element instanceof Bundle) {
                Bundle bundle = (Bundle) element;
                switch(columnIndex) {
                    case 0:
                        // $NON-NLS-1$
                        return bundle.getHeaders().get("Bundle-Name");
                    case 1:
                        return bundle.getVersion().toString();
                    case 2:
                        return bundle.getSymbolicName();
                    case 3:
                        // $NON-NLS-1$
                        return bundle.getHeaders().get("Bundle-Vendor");
                    case 4:
                        try {
                            File file = handler.getDropinsBundleFile(bundle);
                            return file == null ? Messages.DropinsPluginDialog_13 : file.getParentFile().getPath();
                        } catch (IOException ex) {
                            return Messages.DropinsPluginDialog_13;
                        }
                    default:
                        break;
                }
            }
            return element.toString();
        }
    }
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            Bundle b1 = (Bundle) e1;
            Bundle b2 = (Bundle) e2;
            // $NON-NLS-1$ //$NON-NLS-2$
            return b1.getHeaders().get("Bundle-Name").compareToIgnoreCase(b2.getHeaders().get("Bundle-Name"));
        }
    });
    viewer.setLabelProvider(new LabelCellProvider());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            getButton(UNINSTALL).setEnabled(!event.getSelection().isEmpty());
        }
    });
    // anything will do //$NON-NLS-1$
    viewer.setInput("");
    return area;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) Bundle(org.osgi.framework.Bundle) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IOException(java.io.IOException) GridLayout(org.eclipse.swt.layout.GridLayout) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) File(java.io.File) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 92 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.

the class AppearancePreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
    Composite client = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = layout.marginHeight = 0;
    client.setLayout(layout);
    // Enable Theming
    fUseThemes = new Button(client, SWT.CHECK);
    fUseThemes.setText(Messages.AppearancePreferencePage_4);
    fUseThemes.setLayoutData(createHorizontalGridData(2));
    // Themes, if enabled
    if (themeEngine != null) {
        Label label = new Label(client, SWT.NULL);
        label.setText(Messages.AppearancePreferencePage_1);
        fThemeComboViewer = new ComboViewer(client, SWT.READ_ONLY);
        fThemeComboViewer.getCombo().setLayoutData(createHorizontalGridData(1));
        fThemeComboViewer.setContentProvider(new IStructuredContentProvider() {

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

            @Override
            public void dispose() {
            }

            @Override
            public Object[] getElements(Object inputElement) {
                return (Object[]) inputElement;
            }
        });
        fThemeComboViewer.setLabelProvider(new LabelProvider() {

            @Override
            public String getText(Object element) {
                return ((ITheme) element).getLabel();
            }
        });
        fThemeComboViewer.setComparator(new ViewerComparator());
    }
    // Use Round Tabs
    fUseRoundTabsButton = new Button(client, SWT.CHECK);
    fUseRoundTabsButton.setText(Messages.AppearancePreferencePage_3);
    fUseRoundTabsButton.setLayoutData(createHorizontalGridData(2));
    // Show Status Line
    fShowStatusLineButton = new Button(client, SWT.CHECK);
    fShowStatusLineButton.setText(Messages.AppearancePreferencePage_2);
    fShowStatusLineButton.setLayoutData(createHorizontalGridData(2));
    setValues();
    if (themeEngine != null) {
        fThemeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                ITheme theme = (ITheme) ((IStructuredSelection) fThemeComboViewer.getSelection()).getFirstElement();
                setTheme(theme, false);
            }
        });
    }
    return client;
}
Also used : ITheme(org.eclipse.e4.ui.css.swt.theme.ITheme) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 93 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.

the class UsedInRelationshipsSection method createTableControl.

private void createTableControl(Composite parent) {
    createLabel(parent, Messages.UsedInRelationshipsSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
    // Table
    Composite tableComp = createTableComposite(parent, SWT.NONE);
    TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
    fTableViewer = new TableViewer(tableComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    // Font
    UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.ANALYSIS_TABLE_FONT, true);
    // Mac Silicon Item height
    UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
    // Column
    TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
    // On Mac shows alternate table row colours
    fTableViewer.getTable().setLinesVisible(true);
    // Help ID
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return ArchimateModelUtils.getAllRelationshipsForConcept((IArchimateConcept) inputElement).toArray();
        }
    });
    fTableViewer.setLabelProvider(new UsedInRelationshipsTableLabelProvider());
    fTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (isAlive(fArchimateConcept)) {
                Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
                if (o instanceof IArchimateRelationship) {
                    IArchimateRelationship relation = (IArchimateRelationship) o;
                    ITreeModelView view = (ITreeModelView) ViewManager.findViewPart(ITreeModelView.ID);
                    if (view != null) {
                        view.getViewer().setSelection(new StructuredSelection(relation), true);
                    }
                }
            }
        }
    });
    fTableViewer.setComparator(new ViewerComparator());
    // DND
    fTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceListener() {

        @Override
        public void dragStart(DragSourceEvent event) {
            // Drag started from the Table
            LocalSelectionTransfer.getTransfer().setSelection(fTableViewer.getSelection());
            event.doit = true;
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            // For consistency set the data to the selection even though
            // the selection is provided by the LocalSelectionTransfer
            // to the drop target adapter.
            event.data = LocalSelectionTransfer.getTransfer().getSelection();
        }

        @Override
        public void dragFinished(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(null);
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ITreeModelView(com.archimatetool.editor.views.tree.ITreeModelView) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 94 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.

the class UsedInViewsSection method createTableControl.

private void createTableControl(Composite parent) {
    createLabel(parent, Messages.UsedInViewsSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
    // Table
    Composite tableComp = createTableComposite(parent, SWT.NONE);
    TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
    fTableViewer = new TableViewer(tableComp, SWT.BORDER | SWT.FULL_SELECTION);
    // Font
    UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.ANALYSIS_TABLE_FONT, true);
    // Mac Silicon Item height
    UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
    // Column
    TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
    // On Mac shows alternate table row colours
    fTableViewer.getTable().setLinesVisible(true);
    // Help ID
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return DiagramModelUtils.findReferencedDiagramsForArchimateConcept((IArchimateConcept) inputElement).toArray();
        }
    });
    fTableViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            IDiagramModel dm = (IDiagramModel) element;
            // Display label according to ancestor folder's label expression, if present and preference is set
            if (ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.USE_LABEL_EXPRESSIONS_IN_ANALYSIS_TABLE)) {
                String expression = TextRenderer.getDefault().getFormatExpressionFromAncestorFolder(dm);
                if (expression != null) {
                    String text = StringUtils.normaliseNewLineCharacters(TextRenderer.getDefault().renderWithExpression(dm, expression));
                    if (text != null) {
                        return text;
                    }
                }
            }
            return dm.getName();
        }

        @Override
        public Image getImage(Object element) {
            return IArchiImages.ImageFactory.getImage(IArchiImages.ICON_DIAGRAM);
        }
    });
    fTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (!isAlive(fArchimateConcept)) {
                return;
            }
            IDiagramModel diagramModel = (IDiagramModel) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (diagramModel != null) {
                IDiagramModelEditor editor = EditorManager.openDiagramEditor(diagramModel, false);
                if (editor != null) {
                    // Needs to be asyncExec to allow EditorPart to open if it is currently closed
                    getPart().getSite().getShell().getDisplay().asyncExec(() -> {
                        editor.selectObjects(new Object[] { fArchimateConcept });
                    });
                }
            }
        }
    });
    fTableViewer.setComparator(new ViewerComparator());
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) IDiagramModelEditor(com.archimatetool.editor.diagram.IDiagramModelEditor) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IDiagramModel(com.archimatetool.model.IDiagramModel) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 95 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project archi-modelrepository-plugin by archi-contribs.

the class ConflictsDialog method createTableControl.

// ===========================================================
// Top Table Control
// ===========================================================
private void createTableControl(Composite parent) {
    Composite tableComp = new Composite(parent, SWT.BORDER);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableComp.setLayout(tableLayout);
    tableComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    fTableViewer = new TableViewer(tableComp, SWT.FULL_SELECTION | SWT.MULTI);
    fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    fTableViewer.getTable().setHeaderVisible(true);
    fTableViewer.getTable().setLinesVisible(true);
    fTableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object object1, Object object2) {
            EObject eObject1 = ((MergeObjectInfo) object1).getDefaultEObject();
            EObject eObject2 = ((MergeObjectInfo) object2).getDefaultEObject();
            String s1 = ArchiLabelProvider.INSTANCE.getDefaultName(eObject1.eClass());
            String s2 = ArchiLabelProvider.INSTANCE.getDefaultName(eObject2.eClass());
            return s1.compareToIgnoreCase(s2);
        }
    });
    // Columns
    TableViewerColumn column1 = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    column1.getColumn().setText(Messages.ConflictsDialog_24);
    tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(30, true));
    TableViewerColumn column2 = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    column2.getColumn().setText(Messages.ConflictsDialog_25);
    tableLayout.setColumnData(column2.getColumn(), new ColumnWeightData(40, true));
    TableViewerColumn column3 = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
    column3.getColumn().setText(Messages.ConflictsDialog_26);
    tableLayout.setColumnData(column3.getColumn(), new ColumnWeightData(15, true));
    TableViewerColumn column4 = new TableViewerColumn(fTableViewer, SWT.NONE, 3);
    column4.getColumn().setText(Messages.ConflictsDialog_27);
    tableLayout.setColumnData(column4.getColumn(), new ColumnWeightData(15, true));
    column4.setEditingSupport(new ComboChoiceEditingSupport(fTableViewer));
    // Content Provider
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fHandler.getMergeObjectInfos().toArray();
        }
    });
    // Table Selection Listener
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            MergeObjectInfo info = (MergeObjectInfo) ((StructuredSelection) event.getSelection()).getFirstElement();
            updateTabs(info);
        }
    });
    // Table Label Provider
    fTableViewer.setLabelProvider(new TableLabelProvider());
    // Start the table
    // anything will do //$NON-NLS-1$
    fTableViewer.setInput("");
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) EObject(org.eclipse.emf.ecore.EObject) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) EObject(org.eclipse.emf.ecore.EObject) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)110 Viewer (org.eclipse.jface.viewers.Viewer)64 Composite (org.eclipse.swt.widgets.Composite)59 TableViewer (org.eclipse.jface.viewers.TableViewer)50 GridData (org.eclipse.swt.layout.GridData)50 GridLayout (org.eclipse.swt.layout.GridLayout)34 Label (org.eclipse.swt.widgets.Label)29 LabelProvider (org.eclipse.jface.viewers.LabelProvider)23 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)18 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)17 Button (org.eclipse.swt.widgets.Button)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)15 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)15