use of org.eclipse.emf.common.notify.AdapterFactory 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;
}
Aggregations