Search in sources :

Example 86 with IStructuredContentProvider

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

the class DiagramFiguresPreferencePage method createTable.

private void createTable(Composite parent) {
    fTableViewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);
    TableColumnLayout layout = (TableColumnLayout) parent.getLayout();
    TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
    // Fix row height
    // This is definitely needed on some Linux versions where the row height is stuck at 17 for some reason
    fTableViewer.getTable().addListener(SWT.MeasureItem, new Listener() {

        @Override
        public void handleEvent(Event event) {
            event.height = itemHeight;
        }
    });
    fTableViewer.getTable().addListener(SWT.PaintItem, new Listener() {

        int alpha = 100;

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            if (item == null) {
                return;
            }
            event.gc.setAntialias(SWT.ON);
            int row = fTableViewer.getTable().indexOf(item);
            ImageChoice ic = fChoices.get(row);
            Image image1 = ic.getImage(0);
            int x = (itemWidth / 2) - (image1.getBounds().width / 2);
            event.gc.setAlpha(ic.chosenType == 0 ? 255 : alpha);
            event.gc.drawImage(image1, event.x + x, event.y + (itemHeight - image1.getBounds().height) / 2);
            Image image2 = ic.getImage(1);
            x = itemWidth + ((itemWidth / 2) - (image2.getBounds().width / 2));
            event.gc.setAlpha(ic.chosenType == 1 ? 255 : alpha);
            event.gc.drawImage(image2, event.x + x, event.y + (itemHeight - image2.getBounds().height) / 2);
            // Highlight rectangle
            int highlight_x = ic.chosenType == 0 ? 20 : itemWidth + 20;
            event.gc.setForeground(hiliteColor);
            event.gc.setAlpha(255);
            event.gc.setLineWidth(2);
            event.gc.drawRoundRectangle(event.x + highlight_x, event.y + 2, event.x + itemWidth - 39, itemHeight - 3, 15, 15);
        }
    });
    fTableViewer.getTable().addListener(SWT.EraseItem, new Listener() {

        @Override
        public void handleEvent(Event event) {
            // No selection highlighting
            event.detail &= ~SWT.SELECTED;
            event.detail &= ~SWT.HOT;
        }
    });
    fTableViewer.getTable().addListener(SWT.MouseDown, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = fTableViewer.getTable().getItem(new Point(event.x, event.y));
            if (item == null) {
                return;
            }
            int row = fTableViewer.getTable().indexOf(item);
            ImageChoice ic = fChoices.get(row);
            if (event.x < itemWidth) {
                ic.chosenType = 0;
            } else {
                ic.chosenType = 1;
            }
            fTableViewer.refresh(ic);
        }
    });
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        }

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

        @Override
        public Object[] getElements(Object inputElement) {
            return ((List<?>) inputElement).toArray();
        }
    });
    fTableViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return null;
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Listener(org.eclipse.swt.widgets.Listener) TableItem(org.eclipse.swt.widgets.TableItem) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Event(org.eclipse.swt.widgets.Event) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 87 with IStructuredContentProvider

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

the class ExportToXMLPageMetadata method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout());
    setControl(container);
    Composite tableComp = new Composite(container, SWT.BORDER);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableComp.setLayout(tableLayout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    // stop overstretch
    gd.heightHint = 300;
    tableComp.setLayoutData(gd);
    fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
    fTableViewer.getTable().setHeaderVisible(true);
    fTableViewer.getTable().setLinesVisible(true);
    fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    // Edit cell on double-click and Tab key traversal
    TableViewerEditor.create(fTableViewer, new ColumnViewerEditorActivationStrategy(fTableViewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return super.isEditorActivationEvent(event) || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION);
        }
    }, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK | ColumnViewerEditor.KEYBOARD_ACTIVATION);
    // Help ID on table
    PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID);
    // 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 fNames.keySet().toArray();
        }
    });
    // Columns
    TableViewerColumn columnName = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    columnName.getColumn().setText(Messages.ExportToXMLPageMetadata_17);
    tableLayout.setColumnData(columnName.getColumn(), new ColumnWeightData(20, true));
    TableViewerColumn columnValue = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    columnValue.getColumn().setText(Messages.ExportToXMLPageMetadata_18);
    tableLayout.setColumnData(columnValue.getColumn(), new ColumnWeightData(80, true));
    columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
    fTableViewer.setLabelProvider(new LabelCellProvider());
    for (int i = 0; i < dcNames.length; i++) {
        IPreferenceStore store = XMLExchangePlugin.INSTANCE.getPreferenceStore();
        String lastValue = store.getString(PREFS_LAST_VALUE + dcNames[i]);
        fData.put(dcNames[i], lastValue);
    }
    fClearAllButton = new Button(container, SWT.PUSH);
    fClearAllButton.setText(Messages.ExportToXMLPageMetadata_19);
    fClearAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (Entry<String, String> entry : fData.entrySet()) {
                // $NON-NLS-1$
                entry.setValue("");
            }
            // $NON-NLS-1$
            fTableViewer.setInput("");
        }
    });
    // Table row bug on Yosemite https://bugs.eclipse.org/bugs/show_bug.cgi?id=446534
    if (PlatformUtils.isMac() && System.getProperty("os.version").startsWith("10.10")) {
        // $NON-NLS-1$ //$NON-NLS-2$
        Display.getCurrent().asyncExec(new Runnable() {

            @Override
            public void run() {
                // $NON-NLS-1$
                fTableViewer.setInput("");
            }
        });
    } else {
        // $NON-NLS-1$
        fTableViewer.setInput("");
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 88 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider 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 89 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider 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 90 with IStructuredContentProvider

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

the class ViewpointSection method createControls.

@Override
protected void createControls(Composite parent) {
    createLabel(parent, Messages.ViewpointSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
    fComboViewer = new ComboViewer(new Combo(parent, SWT.READ_ONLY | SWT.BORDER));
    fComboViewer.getCombo().setVisibleItemCount(12);
    fComboViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    getWidgetFactory().adapt(fComboViewer.getControl(), true, true);
    fComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (fIsRefreshing) {
                // A Viewer will get a selectionChanged event when setting it
                return;
            }
            IViewpoint viewPoint = (IViewpoint) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (viewPoint != null) {
                CompoundCommand result = new CompoundCommand();
                for (EObject diagramModel : getEObjects()) {
                    if (isAlive(diagramModel)) {
                        Command cmd = new EObjectFeatureCommand(Messages.ViewpointSection_1, diagramModel, IArchimatePackage.Literals.ARCHIMATE_DIAGRAM_MODEL__VIEWPOINT, viewPoint.getID());
                        if (cmd.canExecute()) {
                            result.add(cmd);
                        }
                    }
                }
                executeCommand(result.unwrap());
            }
        }
    });
    fComboViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return ViewpointManager.INSTANCE.getAllViewpoints().toArray();
        }
    });
    fComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((IViewpoint) element).getName();
        }
    });
    // $NON-NLS-1$
    fComboViewer.setInput("");
    // Help ID
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Viewer(org.eclipse.jface.viewers.Viewer) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IViewpoint(com.archimatetool.model.viewpoints.IViewpoint) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ComboViewer(org.eclipse.jface.viewers.ComboViewer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) EObject(org.eclipse.emf.ecore.EObject) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) EObject(org.eclipse.emf.ecore.EObject) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)99 Viewer (org.eclipse.jface.viewers.Viewer)77 Composite (org.eclipse.swt.widgets.Composite)58 GridData (org.eclipse.swt.layout.GridData)54 TableViewer (org.eclipse.jface.viewers.TableViewer)45 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)43 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)42 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)40 GridLayout (org.eclipse.swt.layout.GridLayout)40 LabelProvider (org.eclipse.jface.viewers.LabelProvider)32 Image (org.eclipse.swt.graphics.Image)29 Button (org.eclipse.swt.widgets.Button)28 Label (org.eclipse.swt.widgets.Label)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)26 Table (org.eclipse.swt.widgets.Table)24 ArrayList (java.util.ArrayList)23 ComboViewer (org.eclipse.jface.viewers.ComboViewer)19 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)18 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)18