Search in sources :

Example 96 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout 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 97 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout 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 98 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout 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 99 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project archi by archimatetool.

the class TemplatesTableViewer method setColumns.

/**
 * Set up the columns
 */
private void setColumns() {
    Table table = getTable();
    table.setHeaderVisible(false);
    // Use layout from parent container
    TableColumnLayout layout = (TableColumnLayout) getControl().getParent().getLayout();
    TableViewerColumn column = new TableViewerColumn(this, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 100 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project archi by archimatetool.

the class NewModelFromTemplateWizardPage method createGroupsTableViewer.

/**
 * Create a table
 */
protected TemplateGroupsTableViewer createGroupsTableViewer(Composite parent, String labelText, GridData gd) {
    CLabel label = new CLabel(parent, SWT.NULL);
    label.setText(labelText);
    label.setImage(fTemplateManager.getMainImage());
    Composite tableComp = new Composite(parent, SWT.NULL);
    tableComp.setLayout(new TableColumnLayout());
    tableComp.setLayoutData(gd);
    final TemplateGroupsTableViewer tableViewer = new TemplateGroupsTableViewer(tableComp, SWT.NULL);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            handleTableItemSelected(o);
            deFocusTable(tableViewer);
        }
    });
    return tableViewer;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Aggregations

TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)105 Composite (org.eclipse.swt.widgets.Composite)94 TableViewer (org.eclipse.jface.viewers.TableViewer)78 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)62 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)51 GridData (org.eclipse.swt.layout.GridData)46 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)44 Table (org.eclipse.swt.widgets.Table)38 GridLayout (org.eclipse.swt.layout.GridLayout)34 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)31 Image (org.eclipse.swt.graphics.Image)28 Label (org.eclipse.swt.widgets.Label)27 Viewer (org.eclipse.jface.viewers.Viewer)25 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)23 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 Button (org.eclipse.swt.widgets.Button)21 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)18 TableColumn (org.eclipse.swt.widgets.TableColumn)18 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)17