Search in sources :

Example 1 with StateMachine

use of org.obeonetwork.dsl.statemachine.StateMachine in project InformationSystem by ObeoNetwork.

the class StateMachineStateMachinePropertiesEditionComponent method updateSemanticModel.

/**
 * {@inheritDoc}
 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 */
public void updateSemanticModel(final IPropertiesEditionEvent event) {
    StateMachine stateMachine = (StateMachine) semanticObject;
    if (StatemachineViewsRepository.StateMachine_.Properties.description == event.getAffectedEditor()) {
        stateMachine.setDescription((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
    if (StatemachineViewsRepository.StateMachine_.Properties.keywords == event.getAffectedEditor()) {
        if (event.getKind() == PropertiesEditionEvent.SET) {
            stateMachine.getKeywords().clear();
            stateMachine.getKeywords().addAll(((EList) event.getNewValue()));
        }
    }
    if (StatemachineViewsRepository.StateMachine_.Properties.name == event.getAffectedEditor()) {
        stateMachine.setName((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
    if (StatemachineViewsRepository.StateMachine_.Properties.regions == event.getAffectedEditor()) {
        if (event.getKind() == PropertiesEditionEvent.ADD) {
            EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, regionsSettings, editingContext.getAdapterFactory());
            PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt(semanticObject, PropertiesEditingProvider.class);
            if (provider != null) {
                PropertiesEditingPolicy policy = provider.getPolicy(context);
                if (policy instanceof CreateEditingPolicy) {
                    policy.execute();
                }
            }
        } else if (event.getKind() == PropertiesEditionEvent.EDIT) {
            EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, (EObject) event.getNewValue(), editingContext.getAdapterFactory());
            PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt((EObject) event.getNewValue(), PropertiesEditingProvider.class);
            if (provider != null) {
                PropertiesEditingPolicy editionPolicy = provider.getPolicy(context);
                if (editionPolicy != null) {
                    editionPolicy.execute();
                }
            }
        } else if (event.getKind() == PropertiesEditionEvent.REMOVE) {
            regionsSettings.removeFromReference((EObject) event.getNewValue());
        } else if (event.getKind() == PropertiesEditionEvent.MOVE) {
            regionsSettings.move(event.getNewIndex(), (Region) event.getNewValue());
        }
    }
}
Also used : EObjectPropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) PropertiesEditingProvider(org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider) StateMachine(org.obeonetwork.dsl.statemachine.StateMachine) EObject(org.eclipse.emf.ecore.EObject) Region(org.obeonetwork.dsl.statemachine.Region) PropertiesEditingPolicy(org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy) CreateEditingPolicy(org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy) EReferencePropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)

Example 2 with StateMachine

use of org.obeonetwork.dsl.statemachine.StateMachine 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)

Example 3 with StateMachine

use of org.obeonetwork.dsl.statemachine.StateMachine in project InformationSystem by ObeoNetwork.

the class StateMachineServices method evaluateLabel.

public String evaluateLabel(EObject context) {
    // ['State_' + container.oclAsType(statemachine::StateMachine).states->filter(statemachine::State)->size()/]
    String label = "State_";
    List<AbstractState> abstractStates = null;
    if (context.eContainer() instanceof StateMachine) {
        abstractStates = ((StateMachine) context.eContainer()).getStates();
    } else if (context.eContainer() instanceof Region) {
        abstractStates = ((Region) context.eContainer()).getStates();
    }
    List<State> states = new ArrayList<State>();
    for (AbstractState absState : abstractStates) {
        if (absState instanceof State) {
            states.add((State) absState);
        }
    }
    return label + states.size();
}
Also used : StateMachine(org.obeonetwork.dsl.statemachine.StateMachine) State(org.obeonetwork.dsl.statemachine.State) AbstractState(org.obeonetwork.dsl.statemachine.AbstractState) AbstractState(org.obeonetwork.dsl.statemachine.AbstractState) ArrayList(java.util.ArrayList) Region(org.obeonetwork.dsl.statemachine.Region)

Example 4 with StateMachine

use of org.obeonetwork.dsl.statemachine.StateMachine in project InformationSystem by ObeoNetwork.

the class CreateStateMachineDiagramAction method run.

@Override
public void run() {
    if (context == null) {
        return;
    }
    final Shell shell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
    // TransactionalEditingDomain editingDomain = EditingDomainService.getInstance().getEditingDomainProvider().getEditingDomain();
    Session session = SessionManager.INSTANCE.getSession(context);
    if (session == null) {
        return;
    }
    TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
    if (editingDomain == null) {
        return;
    }
    RecordingCommand cmd = new RecordingCommand(editingDomain, "Create Sequence diagram") {

        protected void doExecute() {
            // Get Session
            Session session = SessionManager.INSTANCE.getSession(context);
            if (session != null) {
                // Ask the user to provide a name for the diagram
                InputDialog dialog = new InputDialog(shell, "New representation", "New representation name", "new State machine diagram", null);
                int buttonPressed = dialog.open();
                if (buttonPressed == InputDialog.OK) {
                    String diagramName = dialog.getValue();
                    // Create a new state machine instance
                    StateMachine statemachine = StateMachineFactory.eINSTANCE.createStateMachine();
                    statemachine.setName(diagramName);
                    context.getBehaviours().add(statemachine);
                    Collection<RepresentationDescription> descs = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), statemachine);
                    for (RepresentationDescription desc : descs) {
                        Viewpoint viewpoint = (Viewpoint) desc.eContainer();
                        if (StateMachineAnalysisContextMenuActionProvider.isStateMachineViewpoint(viewpoint) && "State Machine Diagram".equals(desc.getName())) {
                            // Create the new diagram
                            if (DialectManager.INSTANCE.canCreate(statemachine, desc)) {
                                DRepresentation stateMachineDiagram = DialectManager.INSTANCE.createRepresentation(diagramName, statemachine, desc, session, new NullProgressMonitor());
                                if (stateMachineDiagram != null) {
                                    DialectUIManager.INSTANCE.openEditor(session, stateMachineDiagram, new NullProgressMonitor());
                                }
                            }
                        }
                    }
                }
            }
        }
    };
    editingDomain.getCommandStack().execute(cmd);
}
Also used : RepresentationDescription(org.eclipse.sirius.viewpoint.description.RepresentationDescription) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) InputDialog(org.eclipse.jface.dialogs.InputDialog) StateMachine(org.obeonetwork.dsl.statemachine.StateMachine) Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) Shell(org.eclipse.swt.widgets.Shell) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) DRepresentation(org.eclipse.sirius.viewpoint.DRepresentation) Session(org.eclipse.sirius.business.api.session.Session)

Example 5 with StateMachine

use of org.obeonetwork.dsl.statemachine.StateMachine in project InformationSystem by ObeoNetwork.

the class DeleteStateMachineHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final StateMachine stateMachine = extractStateMachine(event);
    if (stateMachine == null) {
        return null;
    }
    boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Delete State Machine", "Delete the selected state machine ?");
    if (confirm) {
        final Session session = SessionManager.INSTANCE.getSession(stateMachine);
        final ModelAccessor modelAccessor = session.getModelAccessor();
        final ECrossReferenceAdapter semanticCrossReferencer = session.getSemanticCrossReferencer();
        TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain();
        transactionalEditingDomain.getCommandStack().execute(new RecordingCommand(transactionalEditingDomain) {

            @Override
            protected void doExecute() {
                // Retrieve associated representations
                Collection<DRepresentationDescriptor> representationDescriptors = DialectManager.INSTANCE.getRepresentationDescriptors(stateMachine, session);
                // Delete representations
                for (DRepresentationDescriptor representationDescriptor : representationDescriptors) {
                    closeEditor(session, representationDescriptor.getRepresentation());
                    DialectManager.INSTANCE.deleteRepresentation(representationDescriptor, session);
                }
                // Delete StateMachine
                modelAccessor.eDelete(stateMachine, semanticCrossReferencer);
            }
        });
    }
    return null;
}
Also used : ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) StateMachine(org.obeonetwork.dsl.statemachine.StateMachine) ModelAccessor(org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor) Collection(java.util.Collection) DRepresentationDescriptor(org.eclipse.sirius.viewpoint.DRepresentationDescriptor) Session(org.eclipse.sirius.business.api.session.Session) IEditingSession(org.eclipse.sirius.ui.business.api.session.IEditingSession)

Aggregations

StateMachine (org.obeonetwork.dsl.statemachine.StateMachine)6 EObject (org.eclipse.emf.ecore.EObject)3 Session (org.eclipse.sirius.business.api.session.Session)3 Region (org.obeonetwork.dsl.statemachine.Region)3 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)2 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)2 Shell (org.eclipse.swt.widgets.Shell)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 AdapterFactory (org.eclipse.emf.common.notify.AdapterFactory)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EList (org.eclipse.emf.common.util.EList)1 ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)1 ComposedAdapterFactory (org.eclipse.emf.edit.provider.ComposedAdapterFactory)1 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)1 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)1 PropertiesEditingPolicy (org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy)1