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());
}
}
}
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;
}
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();
}
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);
}
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;
}
Aggregations