Search in sources :

Example 46 with IStructuredContentProvider

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

the class SpecializationSection method createControls.

@Override
protected void createControls(Composite parent) {
    NONE_PROFILE = IArchimateFactory.eINSTANCE.createProfile();
    NONE_PROFILE.setName(Messages.SpecializationSection_0);
    createLabel(parent, Messages.SpecializationSection_1, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
    Composite comp = createComposite(parent, 2);
    comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fComboViewer = new ComboViewer(new Combo(comp, 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(event -> {
        if (fIsRefreshing) {
            // A Viewer will get a selectionChanged event when setting it
            return;
        }
        IProfile profile = (IProfile) ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (profile != null) {
            // None Profile is null
            if (profile == NONE_PROFILE) {
                profile = null;
            }
            CompoundCommand result = new CompoundCommand();
            for (EObject object : getEObjects()) {
                if (isAlive(object)) {
                    Command cmd = new SetProfileCommand((IArchimateConcept) object, profile);
                    if (cmd.canExecute()) {
                        result.add(cmd);
                    }
                }
            }
            executeCommand(result.unwrap());
        }
    });
    fComboViewer.setContentProvider(new IStructuredContentProvider() {

        /**
         * Return a list of suitable Profiles in the model given the concept type of the first selected object
         */
        @Override
        public Object[] getElements(Object inputElement) {
            IArchimateConcept firstSelected = (IArchimateConcept) getFirstSelectedObject();
            if (firstSelected == null) {
                return new Object[0];
            }
            List<IProfile> list = ArchimateModelUtils.findProfilesForConceptType(firstSelected.getArchimateModel(), firstSelected.eClass());
            // Sort the Profiles by name
            Collections.sort(list, new Comparator<IProfile>() {

                @Override
                public int compare(IProfile p1, IProfile p2) {
                    return p1.getName().compareToIgnoreCase(p2.getName());
                }
            });
            // Add the "none" Profile at the top
            list.add(0, NONE_PROFILE);
            return list.toArray();
        }
    });
    fComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((IProfile) element).getName();
        }
    });
    // $NON-NLS-1$
    fComboViewer.setInput("");
    // Open Profiles Manager Dialog button
    Button button = getWidgetFactory().createButton(comp, null, SWT.PUSH);
    // $NON-NLS-1$
    button.setText(" ... ");
    button.setToolTipText(Messages.SpecializationSection_2);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IArchimateModelObject selected = getFirstSelectedObject();
            if (selected != null && selected.getArchimateModel() != null) {
                ProfilesManagerDialog dialog = new ProfilesManagerDialog(getPart().getSite().getShell(), selected.getArchimateModel());
                dialog.setDefaultClass(selected.eClass());
                dialog.open();
            }
        }
    });
    // Help ID
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SetProfileCommand(com.archimatetool.editor.model.commands.SetProfileCommand) Combo(org.eclipse.swt.widgets.Combo) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Comparator(java.util.Comparator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) SetProfileCommand(com.archimatetool.editor.model.commands.SetProfileCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) Button(org.eclipse.swt.widgets.Button) EObject(org.eclipse.emf.ecore.EObject) ProfilesManagerDialog(com.archimatetool.editor.tools.ProfilesManagerDialog) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) IProfile(com.archimatetool.model.IProfile) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 47 with IStructuredContentProvider

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

the class UserPropertiesManagerDialog method createTableControl.

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.MULTI | SWT.FULL_SELECTION);
    fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    // Mac Silicon Item height
    UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
    // Edit cell on double-click and add 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);
    fTableViewer.getTable().setHeaderVisible(true);
    fTableViewer.getTable().setLinesVisible(true);
    fTableViewer.setComparator(new ViewerComparator());
    // Columns
    TableViewerColumn columnOldKey = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    columnOldKey.getColumn().setText(Messages.UserPropertiesManagerDialog_6);
    tableLayout.setColumnData(columnOldKey.getColumn(), new ColumnWeightData(40, true));
    TableViewerColumn columnNewKey = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    columnNewKey.getColumn().setText(Messages.UserPropertiesManagerDialog_7);
    tableLayout.setColumnData(columnNewKey.getColumn(), new ColumnWeightData(40, true));
    columnNewKey.setEditingSupport(new KeyEditingSupport(fTableViewer));
    TableViewerColumn columnUsedNumber = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
    // $NON-NLS-1$
    columnUsedNumber.getColumn().setText("# " + Messages.UserPropertiesManagerDialog_8);
    tableLayout.setColumnData(columnUsedNumber.getColumn(), new ColumnWeightData(20, true));
    // 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 fKeysTable.entrySet().toArray();
        }
    });
    // Label Provider
    fTableViewer.setLabelProvider(new LabelCellProvider());
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            fActionDelete.setEnabled(!event.getSelection().isEmpty());
            fButtonDelete.setEnabled(!event.getSelection().isEmpty());
            fActionRename.setEnabled(!event.getSelection().isEmpty());
            fButtonRename.setEnabled(!event.getSelection().isEmpty());
        }
    });
    // anything will do //$NON-NLS-1$
    fTableViewer.setInput("");
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) 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)

Example 48 with IStructuredContentProvider

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

the class GenerateViewDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
    setTitle(Messages.GenerateViewDialog_1);
    // $NON-NLS-1$
    String message = "";
    for (Iterator<IArchimateElement> iter = fSelectedElements.iterator(); iter.hasNext(); ) {
        message += ArchiLabelProvider.INSTANCE.getLabel(iter.next());
        if (iter.hasNext()) {
            // $NON-NLS-1$
            message += ", ";
        } else {
            // $NON-NLS-1$
            message += ".";
        }
    }
    setMessage(message);
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite client = new Composite(composite, SWT.NULL);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 10;
    layout.marginHeight = 10;
    layout.verticalSpacing = 20;
    client.setLayout(layout);
    client.setLayoutData(new GridData(GridData.FILL_BOTH));
    Label label = new Label(client, SWT.NONE);
    label.setText(Messages.GenerateViewDialog_3);
    fComboViewer = new ComboViewer(new Combo(client, SWT.READ_ONLY | SWT.BORDER));
    fComboViewer.getCombo().setVisibleItemCount(12);
    fComboViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    for (IViewpoint viewpoint : ViewpointManager.INSTANCE.getAllViewpoints()) {
        boolean allowed = true;
        for (IArchimateElement element : fSelectedElements) {
            if (!viewpoint.isAllowedConcept(element.eClass())) {
                allowed = false;
                break;
            }
        }
        if (allowed && !fValidViewPoints.contains(viewpoint)) {
            fValidViewPoints.add(viewpoint);
        }
    }
    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 fValidViewPoints.toArray();
        }
    });
    fComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((IViewpoint) element).getName();
        }
    });
    // $NON-NLS-1$
    fComboViewer.setInput("");
    label = new Label(client, SWT.NONE);
    label.setText(Messages.GenerateViewDialog_2);
    fNameText = new Text(client, SWT.BORDER);
    fNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // $NON-NLS-1$
    fNameText.setText(Messages.GenerateViewDialog_6 + " " + ArchiLabelProvider.INSTANCE.getLabel(fSelectedElements.get(0)));
    Group groupOptions = new Group(client, SWT.NONE);
    groupOptions.setText(Messages.GenerateViewDialog_4);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    groupOptions.setLayoutData(gd);
    groupOptions.setLayout(new GridLayout(2, false));
    label = new Label(groupOptions, SWT.NONE);
    label.setText(Messages.GenerateViewDialog_5);
    fAddAllConnectionsButton = new Button(groupOptions, SWT.CHECK);
    loadPreferences();
    return composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) Text(org.eclipse.swt.widgets.Text) IViewpoint(com.archimatetool.model.viewpoints.IViewpoint) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IArchimateElement(com.archimatetool.model.IArchimateElement) ArchiLabelProvider(com.archimatetool.editor.ui.ArchiLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 49 with IStructuredContentProvider

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

the class ProfilesManagerDialog method createTableControl.

/**
 * Create the Table
 */
private void createTableControl(Composite parent) {
    Composite tableComp = new Composite(parent, SWT.BORDER);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableComp.setLayout(tableLayout);
    GridDataFactory.create(GridData.FILL_BOTH).applyTo(tableComp);
    fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.FULL_SELECTION);
    GridDataFactory.create(GridData.FILL_BOTH).applyTo(fTableViewer.getControl());
    // Mac Silicon Item height
    UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
    // Edit cell on single-click and add Tab key traversal
    TableViewerEditor.create(fTableViewer, new ColumnViewerEditorActivationStrategy(fTableViewer), ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK | ColumnViewerEditor.KEYBOARD_ACTIVATION);
    fTableViewer.getTable().setHeaderVisible(true);
    fTableViewer.getTable().setLinesVisible(true);
    fTableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((IProfile) e1).getName().compareToIgnoreCase(((IProfile) e2).getName());
        }
    });
    // Columns
    // Icon
    TableViewerColumn columnIcon = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    tableLayout.setColumnData(columnIcon.getColumn(), new ColumnWeightData(5, true));
    // Name
    TableViewerColumn columnName = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    columnName.getColumn().setText(Messages.ProfilesManagerDialog_7);
    tableLayout.setColumnData(columnName.getColumn(), new ColumnWeightData(50, true));
    columnName.setEditingSupport(new NameEditingSupport(fTableViewer));
    // Restricted to Concept Type
    TableViewerColumn columnConceptType = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
    columnConceptType.getColumn().setText(Messages.ProfilesManagerDialog_8);
    tableLayout.setColumnData(columnConceptType.getColumn(), new ColumnWeightData(35, true));
    columnConceptType.setEditingSupport(new ConceptTypeEditingSupport(fTableViewer));
    // Usage
    TableViewerColumn columnUsage = new TableViewerColumn(fTableViewer, SWT.NONE, 3);
    columnUsage.getColumn().setText(Messages.ProfilesManagerDialog_9);
    tableLayout.setColumnData(columnUsage.getColumn(), new ColumnWeightData(10, true));
    // 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 fProfilesTemp.values().toArray();
        }
    });
    // Label Provider
    fTableViewer.setLabelProvider(new LabelCellProvider());
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = event.getStructuredSelection();
            boolean enabled = !selection.isEmpty();
            // Disable/enable some actions
            fActionDelete.setEnabled(enabled);
            fButtonDelete.setEnabled(enabled);
            fActionChooseImage.setEnabled(enabled);
            fActionClearImage.setEnabled(false);
            // Image buttons/actions depend on some factors...
            for (Object o : selection) {
                IProfile profile = (IProfile) o;
                // If any selected Profile can't have an image then this is disabled
                if (!canHaveImage(profile)) {
                    fActionChooseImage.setEnabled(false);
                }
                // Enable clear image only if there is one image to clear in the selection
                if (profile.getImagePath() != null) {
                    fActionClearImage.setEnabled(true);
                }
            }
            fImageButton.setEnabled(fActionChooseImage.isEnabled() || fActionClearImage.isEnabled());
            // Update Image Preview
            updateImagePreview();
        }
    });
    /*
         * Table Double-click
         */
    fTableViewer.getTable().addListener(SWT.MouseDoubleClick, (e) -> {
        // Get Table item
        Point pt = new Point(e.x, e.y);
        TableItem item = fTableViewer.getTable().getItem(pt);
        // Double-click into empty table creates new Profile
        if (item == null) {
            createNewProfile();
        }
    });
    // anything will do //$NON-NLS-1$
    fTableViewer.setInput("");
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableItem(org.eclipse.swt.widgets.TableItem) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IProfile(com.archimatetool.model.IProfile) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 50 with IStructuredContentProvider

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

the class ExportAsImagePage method createFormatComboViewer.

/**
 * Create tghe Format Combo Viewer
 */
private ComboViewer createFormatComboViewer(Composite parent) {
    ComboViewer viewer = new ComboViewer(new Combo(parent, SWT.READ_ONLY | SWT.BORDER));
    viewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

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

        @Override
        public String getText(Object element) {
            return ((ImageExportProviderInfo) element).getLabel();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ImageExportProviderInfo provider = (ImageExportProviderInfo) ((IStructuredSelection) event.getSelection()).getFirstElement();
            providerChanged(provider);
        }
    });
    // $NON-NLS-1$
    viewer.setInput("");
    return viewer;
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Combo(org.eclipse.swt.widgets.Combo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ImageExportProviderInfo(com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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