Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-10-15 16:26:07 +0000
committercletavernie2012-10-15 16:26:07 +0000
commit0deece6c1f05e15594d8b111ad8d5ac12e1004ad (patch)
tree60a983e11a4284632422dede675b183846173e03 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse
parent3da13f092b20cf10f445dad148945c879057a7f5 (diff)
downloadorg.eclipse.papyrus-0deece6c1f05e15594d8b111ad8d5ac12e1004ad.tar.gz
org.eclipse.papyrus-0deece6c1f05e15594d8b111ad8d5ac12e1004ad.tar.xz
org.eclipse.papyrus-0deece6c1f05e15594d8b111ad8d5ac12e1004ad.zip
391945: [Refactoring] Part 2: Refactoring on Kepler (0.10)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=391945
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/CreateProfileModelCommand.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java36
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/helper/ExtensionHelper.java40
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java86
4 files changed, 76 insertions, 88 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/CreateProfileModelCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/CreateProfileModelCommand.java
index c4e457f0a03..6d6eea0ee04 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/CreateProfileModelCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/CreateProfileModelCommand.java
@@ -14,7 +14,7 @@
package org.eclipse.papyrus.uml.diagram.profile;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.core.extension.commands.ModelCreationCommandBase;
+import org.eclipse.papyrus.uml.diagram.common.commands.ModelCreationCommandBase;
import org.eclipse.uml2.uml.UMLFactory;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java
index 670132d7e58..259c2332439 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java
@@ -11,8 +11,6 @@
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
-
-
package org.eclipse.papyrus.uml.diagram.profile.custom.commands;
import java.util.Collections;
@@ -24,12 +22,8 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.profile.definition.PapyrusDefinitionAnnotation;
import org.eclipse.papyrus.uml.profile.definition.ProfileRedefinition;
import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
@@ -42,15 +36,8 @@ import org.eclipse.uml2.uml.Profile;
* @author VL222926
*
*/
-
public class DefineProfileCommand extends AbstractTransactionalCommand {
-
- /**
- * the {@link EditPartViewer}
- */
- private EditPartViewer viewer;
-
/**
* the {@link PapyrusDefinitionAnnotation}
*/
@@ -70,16 +57,12 @@ public class DefineProfileCommand extends AbstractTransactionalCommand {
* @param rootProfile
* @param viewer
*/
- public DefineProfileCommand(TransactionalEditingDomain domain, PapyrusDefinitionAnnotation papyrusAnnotation, Profile rootProfile, EditPartViewer viewer) {
+ public DefineProfileCommand(TransactionalEditingDomain domain, PapyrusDefinitionAnnotation papyrusAnnotation, Profile rootProfile) {
super(domain, "DefineProfileCommand", null); //$NON-NLS-1$
- this.viewer = viewer;
this.rootProfile = rootProfile;
this.papyrusAnnotation = papyrusAnnotation;
-
}
-
-
/**
*
*
@@ -101,7 +84,6 @@ public class DefineProfileCommand extends AbstractTransactionalCommand {
e.printStackTrace();
}
-
setResult(CommandResult.newOKCommandResult());
return CommandResult.newOKCommandResult();
}
@@ -113,18 +95,8 @@ public class DefineProfileCommand extends AbstractTransactionalCommand {
* @return
*/
@Override
- public List getAffectedFiles() {
- if(viewer != null) {
- EditPart editpart = viewer.getRootEditPart().getContents();
- if(editpart instanceof IGraphicalEditPart) {
- View view = (View)((IGraphicalEditPart)editpart).getModel();
- if(view != null) {
- IFile f = WorkspaceSynchronizer.getFile(view.eResource());
- return f != null ? Collections.singletonList(f) : Collections.EMPTY_LIST;
- }
- }
- }
- return super.getAffectedFiles();
-
+ public List<IFile> getAffectedFiles() {
+ IFile f = WorkspaceSynchronizer.getFile(rootProfile.eResource());
+ return f != null ? Collections.<IFile> singletonList(f) : Collections.<IFile> emptyList();
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/helper/ExtensionHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/helper/ExtensionHelper.java
index e6a63deb0c2..0666c5881f4 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/helper/ExtensionHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/helper/ExtensionHelper.java
@@ -24,6 +24,7 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
@@ -31,8 +32,14 @@ import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper;
-import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.IModel;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.helper.ElementHelper;
import org.eclipse.papyrus.uml.diagram.common.helper.NamedElementHelper;
import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
@@ -40,6 +47,7 @@ import org.eclipse.papyrus.uml.diagram.common.util.MDTUtil;
import org.eclipse.papyrus.uml.diagram.common.util.Util;
import org.eclipse.papyrus.uml.diagram.profile.custom.policies.ExtensionCustomNameEditPolicy;
import org.eclipse.papyrus.uml.diagram.profile.edit.parts.ExtensionEditPart;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.AggregationKind;
@@ -86,9 +94,29 @@ public class ExtensionHelper extends ElementHelper {
/* get all the profile and sub-profile for the diagram */
- CoreMultiDiagramEditor editor = (CoreMultiDiagramEditor)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- DiagramEditPart rootProfileEP = editor.getDiagramEditPart();
- Profile rootProfile = (Profile)((View)rootProfileEP.getModel()).getElement();
+ IMultiDiagramEditor editor = (IMultiDiagramEditor)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ ServicesRegistry registry = editor.getServicesRegistry();
+
+ Profile rootProfile = null;
+ try {
+ ModelSet modelSet = ServiceUtils.getInstance().getModelSet(registry);
+
+
+
+ if(modelSet != null) {
+ IModel umlModel = modelSet.getModel(UmlModel.MODEL_ID);
+ if(umlModel != null) {
+ rootProfile = (Profile)((UmlModel)umlModel).lookupRoot();
+ }
+ }
+ } catch (NotFoundException ex) {
+ Activator.log.error(ex);
+ return UnexecutableCommand.INSTANCE;
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ return UnexecutableCommand.INSTANCE;
+ }
+
List<?> profileList = Util.getInstancesFilteredByType(rootProfile, rootProfile.getClass(), null);
/*
@@ -154,7 +182,7 @@ public class ExtensionHelper extends ElementHelper {
List<?> view = DiagramEditPartsUtil.getEObjectViews(link);
if(!view.isEmpty()) {
IEditorPart editor = MDTUtil.getActiveEditor();
- DiagramEditPart diagram = ((PapyrusMultiDiagramEditor)editor).getDiagramEditPart();
+ DiagramEditPart diagram = (DiagramEditPart)((IMultiDiagramEditor)editor).getAdapter(DiagramEditPart.class);
EditPart extensionEP = DiagramEditPartsUtil.getEditPartFromView((View)view.get(0), diagram);
if(extensionEP instanceof ExtensionEditPart) {
policy = extensionEP.getEditPolicy(ExtensionCustomNameEditPolicy.SPECIFIC_EXTENSION_NAME_POLICY);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java
index 67a05be04bc..740e31dd573 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java
@@ -13,11 +13,8 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.profile.service;
-import java.util.Collection;
-import java.util.Iterator;
import java.util.Map;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.notify.AdapterFactory;
@@ -32,22 +29,20 @@ import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.core.lifecycleevents.DoSaveEvent;
import org.eclipse.papyrus.infra.core.lifecycleevents.ISaveEventListener;
+import org.eclipse.papyrus.infra.core.resource.IModel;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
import org.eclipse.papyrus.infra.services.validation.ValidationTool;
-import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
import org.eclipse.papyrus.uml.diagram.profile.custom.commands.DefineProfileCommand;
import org.eclipse.papyrus.uml.profile.definition.PapyrusDefinitionAnnotation;
import org.eclipse.papyrus.uml.profile.ui.dialogs.ProfileDefinitionDialog;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Profile;
@@ -66,70 +61,63 @@ public class PreSaveProfileListener implements ISaveEventListener {
* This function is called before the user make a "save" action
*/
public void doSave(DoSaveEvent event) {
- Diagram diag = null;
try {
//System.out.println("preSave Event received"); //$NON-NLS-1$
/**
* if the root is a profile, we must define it. If it's another thing, we
* do nothing
*/
- IMultiDiagramEditor multidiag = event.getMultiDiagramEditor();
- if(multidiag instanceof PapyrusMultiDiagramEditor) {
- diag = ((PapyrusMultiDiagramEditor)multidiag).getDiagram();
- if(diag == null || diag.getElement() == null || (!(diag.getElement() instanceof Profile))) {
- return;
- }
+
+ Profile rootProfile = null;
+ /**
+ * Obtain the root profile
+ */
+ ServicesRegistry registry = event.getServiceRegistry();
+
+ ModelSet modelSet = ServiceUtils.getInstance().getModelSet(registry);
+
+ IModel umlModel = modelSet.getModel(UmlModel.MODEL_ID);
+
+ EObject profileEObject = null;
+ if(umlModel != null) {
+ profileEObject = ((UmlModel)umlModel).lookupRoot();
}
+
+ if(profileEObject instanceof Profile) {
+ rootProfile = (Profile)profileEObject;
+ }
+
+ if(rootProfile == null) {
+ return; //We're not saving a profile model
+ }
+
/**
* Does the user want define the profile?
*/
- String DEFINE_MSG = "In order to apply this profile, it had to be defined.\nWould you like to define it?"; //$NON-NLS-1$
+ String DEFINE_MSG = "In order to apply this profile, it had to be defined.\nWould you like to define it?";
String PAPYRUS_QUESTION = "Papyrus question"; //$NON-NLS-1$
boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), PAPYRUS_QUESTION, DEFINE_MSG);
if(!result) {
return;
}
- Collection<EditPart> editPartSet = null;
- DiagramEditPart diagramEditPart = null;
- Profile rootProfile = null;
- /**
- * Obtain the root profile
- */
- IMultiDiagramEditor diag1 = event.getMultiDiagramEditor();
- Object diagramView = diag1.getAdapter(IDiagramGraphicalViewer.class);
- if(diagramView instanceof DiagramGraphicalViewer) {
- editPartSet = ((DiagramGraphicalViewer)diagramView).getEditPartRegistry().values();
- }
- Iterator<EditPart> editPartIterator = editPartSet.iterator();
- while(editPartIterator.hasNext()) {
- diagramEditPart = DiagramEditPartsUtil.getDiagramEditPart(editPartIterator.next());
- if(diagramEditPart != null) {
- break;
- }
- }
- EObject profileEObject = ((Diagram)diagramEditPart.getModel()).getElement();
- if(profileEObject instanceof Profile) {
- rootProfile = (Profile)profileEObject;
- }
- Assert.isNotNull(rootProfile);
- diagramEditPart.getEditingDomain();
+
ProfileDefinitionDialog dialog = new ProfileDefinitionDialog(new Shell(), rootProfile);
dialog.open();
- if(dialog.getReturnCode() == dialog.OK) {
+ if(dialog.getReturnCode() == Window.OK) {
PapyrusDefinitionAnnotation papyrusAnnotation = dialog.getPapyrusDefinitionAnnotation();
- TransactionalEditingDomain domain = diagramEditPart.getEditingDomain();
+ TransactionalEditingDomain domain = ServiceUtils.getInstance().getTransactionalEditingDomain(registry);
//evaluate contraint of profiles
AdapterFactory adapterFactory = domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null;
Diagnostician diagnostician = createDiagnostician(adapterFactory, new NullProgressMonitor());
BasicDiagnostic diagnostic = diagnostician.createDefaultDiagnostic(rootProfile);
diagnostic.getSeverity();
Map<Object, Object> context = diagnostician.createDefaultContext();
- boolean isValid = diagnostician.validate(rootProfile, diagnostic, context);
+ diagnostician.validate(rootProfile, diagnostic, context);
int severity = diagnostic.getSeverity();
if(severity != Diagnostic.ERROR) {
- DefineProfileCommand cmd = new DefineProfileCommand(domain, papyrusAnnotation, rootProfile, diagramEditPart.getViewer());
+ DefineProfileCommand cmd = new DefineProfileCommand(domain, papyrusAnnotation, rootProfile);
try {
- diagramEditPart.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(cmd));
+ domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
} catch (Exception e) {
e.printStackTrace();
}

Back to the top