Search in sources :

Example 1 with ProfilesManagerDialog

use of com.archimatetool.editor.tools.ProfilesManagerDialog 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 2 with ProfilesManagerDialog

use of com.archimatetool.editor.tools.ProfilesManagerDialog in project archi by archimatetool.

the class ShowProfilesManagerHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart part = HandlerUtil.getActivePart(event);
    IArchimateModel model = part != null ? part.getAdapter(IArchimateModel.class) : null;
    if (model != null) {
        ProfilesManagerDialog dialog = new ProfilesManagerDialog(HandlerUtil.getActiveShell(event), model);
        dialog.open();
    }
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ProfilesManagerDialog(com.archimatetool.editor.tools.ProfilesManagerDialog) IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

ProfilesManagerDialog (com.archimatetool.editor.tools.ProfilesManagerDialog)2 SetProfileCommand (com.archimatetool.editor.model.commands.SetProfileCommand)1 IArchimateConcept (com.archimatetool.model.IArchimateConcept)1 IArchimateModel (com.archimatetool.model.IArchimateModel)1 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)1 IProfile (com.archimatetool.model.IProfile)1 Comparator (java.util.Comparator)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 Command (org.eclipse.gef.commands.Command)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1