Search in sources :

Example 11 with IProfile

use of com.archimatetool.model.IProfile 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 12 with IProfile

use of com.archimatetool.model.IProfile in project archi by archimatetool.

the class ProfilesManagerDialog method createNewProfile.

/**
 * Create a new Profile and add it to the temp profiles list
 */
private void createNewProfile() {
    IProfile profile = IArchimateFactory.eINSTANCE.createProfile();
    profile.setConceptType(fDefaultClass.getName());
    profile.setName(generateNewProfileName(profile.getConceptType()));
    fProfilesTemp.put(profile.getId(), profile);
    // fTableViewer.applyEditorValue(); // complete any current editing
    fTableViewer.refresh();
    fTableViewer.editElement(profile, 1);
}
Also used : IProfile(com.archimatetool.model.IProfile)

Example 13 with IProfile

use of com.archimatetool.model.IProfile in project archi by archimatetool.

the class ProfilesManagerDialog method chooseImage.

/**
 * Choose an image from the dialog and apply to selected profiles
 */
private void chooseImage() {
    IStructuredSelection selection = fTableViewer.getStructuredSelection();
    if (!selection.isEmpty()) {
        IProfile firstSelected = (IProfile) selection.getFirstElement();
        ImageManagerDialog dialog = new ImageManagerDialog(getParentShell());
        dialog.setSelected(fArchimateModel, firstSelected.getImagePath());
        if (dialog.open() == Window.OK) {
            try {
                IArchiveManager archiveManager = (IArchiveManager) fArchimateModel.getAdapter(IArchiveManager.class);
                String path = null;
                // Image from file
                if (dialog.getUserSelectedFile() != null && dialog.getUserSelectedFile().exists()) {
                    path = archiveManager.addImageFromFile(dialog.getUserSelectedFile());
                } else // Existing image which could be in this model or a different model
                if (dialog.getUserSelectedImagePath() != null) {
                    if (dialog.getUserSelectedModel() != fArchimateModel) {
                        // Different model
                        IArchiveManager selectedArchiveManager = (IArchiveManager) dialog.getUserSelectedModel().getAdapter(IArchiveManager.class);
                        path = archiveManager.copyImageBytes(selectedArchiveManager, dialog.getUserSelectedImagePath());
                    } else {
                        // Same model
                        path = dialog.getUserSelectedImagePath();
                    }
                }
                if (path != null) {
                    // Apply the image path to Profiles that can have an image
                    for (Object o : selection.toList()) {
                        IProfile profile = (IProfile) o;
                        if (canHaveImage(profile)) {
                            profile.setImagePath(path);
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                // $NON-NLS-1$
                Logger.logError("Could not create image!", ex);
            }
            // Select to update image preview
            fTableViewer.setSelection(selection);
        }
    }
}
Also used : ImageManagerDialog(com.archimatetool.editor.propertysections.ImageManagerDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProfile(com.archimatetool.model.IProfile) IArchiveManager(com.archimatetool.editor.model.IArchiveManager)

Example 14 with IProfile

use of com.archimatetool.model.IProfile 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 15 with IProfile

use of com.archimatetool.model.IProfile in project archi by archimatetool.

the class CSVExporterTests method testCreateElementRow.

@Test
public void testCreateElementRow() {
    IArchimateElement element = IArchimateFactory.eINSTANCE.createBusinessActor();
    element.setId("a1234567");
    element.setName("The Main Man");
    element.setDocumentation("This is the Documentation");
    IProfile profile = IArchimateFactory.eINSTANCE.createProfile();
    profile.setName("Profile");
    element.getProfiles().add(profile);
    assertEquals("\"a1234567\",\"BusinessActor\",\"The Main Man\",\"This is the Documentation\",\"Profile\"", exporter.createElementRow(element));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IProfile(com.archimatetool.model.IProfile) Test(org.junit.Test)

Aggregations

IProfile (com.archimatetool.model.IProfile)34 Test (org.junit.Test)11 IArchimateModel (com.archimatetool.model.IArchimateModel)7 IArchimateConcept (com.archimatetool.model.IArchimateConcept)6 IArchimateElement (com.archimatetool.model.IArchimateElement)6 IDiagramModel (com.archimatetool.model.IDiagramModel)4 EObject (org.eclipse.emf.ecore.EObject)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)3 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)3 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)3 IProfiles (com.archimatetool.model.IProfiles)3 List (java.util.List)3 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)2 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)2 IFolder (com.archimatetool.model.IFolder)2 ArrayList (java.util.ArrayList)2 CommandStack (org.eclipse.gef.commands.CommandStack)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)2