Search in sources :

Example 1 with LockStatus

use of org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus in project InformationSystem by ObeoNetwork.

the class InteractionServices method changeParentForInteraction.

/**
 * Change the parent of an interaction with a selected one
 * @param interaction
 * @return
 */
public Interaction changeParentForInteraction(final Interaction interaction) {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    InteractionParentSelectionLabelProvider labelProvider = new InteractionParentSelectionLabelProvider(adapterFactory);
    InteractionParentSelectionContentProvider contentProvider = new InteractionParentSelectionContentProvider(adapterFactory);
    ElementTreeSelectionDialog dlg = new ElementTreeSelectionDialog(shell, labelProvider, contentProvider);
    dlg.setHelpAvailable(false);
    dlg.setValidator(new ISelectionStatusValidator() {

        public IStatus validate(Object[] selection) {
            Object selectedObject = selection[0];
            if (selectedObject instanceof EObject) {
                IPermissionAuthority authority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority((EObject) selectedObject);
                if (authority != null) {
                    LockStatus lockStatus = authority.getLockStatus((EObject) selectedObject);
                    if (LockStatus.LOCKED_BY_OTHER.equals(lockStatus)) {
                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "This element is locked by another user");
                    }
                }
            }
            return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
        }
    });
    dlg.setTitle("Change interaction's parent");
    dlg.setMessage("Select the new parent for the interaction");
    Session session = SessionManager.INSTANCE.getSession(interaction);
    if (session == null) {
        return interaction;
    }
    dlg.setInput(session.getSemanticResources().toArray());
    dlg.setInitialSelection(interaction.eContainer());
    int btn = dlg.open();
    if (btn == Dialog.OK) {
        Object selectedElement = dlg.getFirstResult();
        if (selectedElement instanceof ObeoDSMObject && selectedElement != interaction.eContainer()) {
            // Change the parent
            ((ObeoDSMObject) selectedElement).getBehaviours().add(interaction);
        }
    }
    return interaction;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) LockStatus(org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus) IPermissionAuthority(org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority) IStatus(org.eclipse.core.runtime.IStatus) LockStatus(org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) InteractionParentSelectionLabelProvider(org.obeonetwork.dsl.interaction.design.ui.extension.providers.InteractionParentSelectionLabelProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) Shell(org.eclipse.swt.widgets.Shell) InteractionParentSelectionContentProvider(org.obeonetwork.dsl.interaction.design.ui.extension.providers.InteractionParentSelectionContentProvider) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) EObject(org.eclipse.emf.ecore.EObject) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) EObject(org.eclipse.emf.ecore.EObject) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) Session(org.eclipse.sirius.business.api.session.Session)

Example 2 with LockStatus

use of org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus in project InformationSystem by ObeoNetwork.

the class StateMachineServices method changeParentForStateMachine.

/**
 * Change the parent of an interaction with the
 * @param stateMachine
 * @return
 */
public StateMachine changeParentForStateMachine(EObject context) {
    StateMachine stateMachine = null;
    if (context instanceof StateMachine) {
        stateMachine = (StateMachine) context;
    } else {
        EObject container = context.eContainer();
        while (!(container instanceof StateMachine) && container.eContainer() != null) {
            container = container.eContainer();
        }
        stateMachine = (StateMachine) container;
    }
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    StateMachineParentSelectionLabelProvider labelProvider = new StateMachineParentSelectionLabelProvider(adapterFactory);
    StateMachineParentSelectionContentProvider contentProvider = new StateMachineParentSelectionContentProvider(adapterFactory);
    ElementTreeSelectionDialog dlg = new ElementTreeSelectionDialog(shell, labelProvider, contentProvider);
    dlg.setHelpAvailable(false);
    dlg.setValidator(new ISelectionStatusValidator() {

        public IStatus validate(Object[] selection) {
            if (selection.length > 0) {
                Object selectedObject = selection[0];
                if (selectedObject instanceof EObject) {
                    IPermissionAuthority authority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority((EObject) selectedObject);
                    if (authority != null) {
                        LockStatus lockStatus = authority.getLockStatus((EObject) selectedObject);
                        if (LockStatus.LOCKED_BY_OTHER.equals(lockStatus)) {
                            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "This element is locked by another user");
                        }
                    }
                }
            }
            return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
        }
    });
    dlg.setTitle("Change statemachine's parent");
    dlg.setMessage("Select the new parent for the statemachine");
    Session session = SessionManager.INSTANCE.getSession(stateMachine);
    if (session == null) {
        return stateMachine;
    }
    dlg.setInput(session.getSemanticResources().toArray());
    dlg.setInitialSelection(stateMachine.eContainer());
    int btn = dlg.open();
    if (btn == Dialog.OK) {
        Object selectedElement = dlg.getFirstResult();
        if (selectedElement instanceof ObeoDSMObject && selectedElement != stateMachine.eContainer()) {
            // Change the parent
            ((ObeoDSMObject) selectedElement).getBehaviours().add(stateMachine);
        }
    }
    return stateMachine;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) LockStatus(org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus) IPermissionAuthority(org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority) IStatus(org.eclipse.core.runtime.IStatus) StateMachineParentSelectionLabelProvider(org.obeonetwork.dsl.statemachine.design.ui.extension.providers.StateMachineParentSelectionLabelProvider) StateMachine(org.obeonetwork.dsl.statemachine.StateMachine) LockStatus(org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) Shell(org.eclipse.swt.widgets.Shell) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) EObject(org.eclipse.emf.ecore.EObject) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) EObject(org.eclipse.emf.ecore.EObject) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) StateMachineParentSelectionContentProvider(org.obeonetwork.dsl.statemachine.design.ui.extension.providers.StateMachineParentSelectionContentProvider) Session(org.eclipse.sirius.business.api.session.Session)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 AdapterFactory (org.eclipse.emf.common.notify.AdapterFactory)2 EObject (org.eclipse.emf.ecore.EObject)2 ComposedAdapterFactory (org.eclipse.emf.edit.provider.ComposedAdapterFactory)2 Session (org.eclipse.sirius.business.api.session.Session)2 IPermissionAuthority (org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority)2 LockStatus (org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus)2 Shell (org.eclipse.swt.widgets.Shell)2 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)2 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)2 ObeoDSMObject (org.obeonetwork.dsl.environment.ObeoDSMObject)2 InteractionParentSelectionContentProvider (org.obeonetwork.dsl.interaction.design.ui.extension.providers.InteractionParentSelectionContentProvider)1 InteractionParentSelectionLabelProvider (org.obeonetwork.dsl.interaction.design.ui.extension.providers.InteractionParentSelectionLabelProvider)1 StateMachine (org.obeonetwork.dsl.statemachine.StateMachine)1 StateMachineParentSelectionContentProvider (org.obeonetwork.dsl.statemachine.design.ui.extension.providers.StateMachineParentSelectionContentProvider)1 StateMachineParentSelectionLabelProvider (org.obeonetwork.dsl.statemachine.design.ui.extension.providers.StateMachineParentSelectionLabelProvider)1