Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptessier2012-07-31 17:29:18 +0000
committerptessier2012-07-31 17:29:18 +0000
commit377b26af0450ad1bbbf67f5bb6ad600e76d6116c (patch)
tree6266dfb84a9de0413a22cb0b5a5af90f97420fb7 /plugins/uml
parentde598d06b564755b2ea5ac88dc4e418f5d24e2f9 (diff)
downloadorg.eclipse.papyrus-377b26af0450ad1bbbf67f5bb6ad600e76d6116c.tar.gz
org.eclipse.papyrus-377b26af0450ad1bbbf67f5bb6ad600e76d6116c.tar.xz
org.eclipse.papyrus-377b26af0450ad1bbbf67f5bb6ad600e76d6116c.zip
330349: [All diagrams]Applying a profile with a Property of an undefined Type corrupts the model and makes save action crash
https://bugs.eclipse.org/bugs/show_bug.cgi?id=330349
Diffstat (limited to 'plugins/uml')
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileTreeSelectionDialog.java92
1 files changed, 92 insertions, 0 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileTreeSelectionDialog.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileTreeSelectionDialog.java
index 6961f4192f8..6afe81e05ac 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileTreeSelectionDialog.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileTreeSelectionDialog.java
@@ -17,7 +17,22 @@ package org.eclipse.papyrus.uml.profile.ui.dialogs;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.DiagnosticChain;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
@@ -43,6 +58,9 @@ public class ProfileTreeSelectionDialog extends ElementImportTreeSelectionDialog
*/
public ProfileTreeSelectionDialog(Shell parent, Package model) {
super(parent, model);
+ if( !isAValidProfile(model)){
+ this.model=null;
+ }
subSelection = true;
subProfilesList = new ArrayList<String>();
}
@@ -57,6 +75,8 @@ public class ProfileTreeSelectionDialog extends ElementImportTreeSelectionDialog
*/
public ProfileTreeSelectionDialog(Shell parent, List<Package> model) {
this(parent, model, new ArrayList<String>());
+
+
subSelection = true;
}
@@ -67,6 +87,37 @@ public class ProfileTreeSelectionDialog extends ElementImportTreeSelectionDialog
* of the profile
* @param parent
* the shell
+ * @param testValidity true to test if profile to apply are valids
+ */
+ public ProfileTreeSelectionDialog(Shell parent, List<Package> model, boolean testValidity) {
+ this(parent, model, new ArrayList<String>());
+ if(testValidity){
+ List<Package> modelToRemoveList= new ArrayList<Package>();
+ for(Iterator<Package> iterator = model.iterator(); iterator.hasNext();) {
+ Package currentPackage = (Package)iterator.next();
+ if( !isAValidProfile(currentPackage)){
+ modelToRemoveList.add(currentPackage);
+ }
+
+ }
+ for(Iterator<Package> iterator = modelToRemoveList.iterator(); iterator.hasNext();) {
+ Package currentPackage = (Package)iterator.next();
+ this.models.remove(currentPackage);
+ }
+ if( this.models.size()==0){
+ MessageDialog.openError(new Shell(), "Profiles not Valid", "Selected profiles cannot be applied because their definition are not valid");
+ getShell().dispose();
+ }
+ }
+ subSelection = true;
+ }
+ /**
+ * constructor
+ *
+ * @param model
+ * of the profile
+ * @param parent
+ * the shell
* @param
*/
public ProfileTreeSelectionDialog(Shell parent, List<Package> model, List<String> subprofiles) {
@@ -93,6 +144,47 @@ public class ProfileTreeSelectionDialog extends ElementImportTreeSelectionDialog
return profileList;
}
+ private boolean isAValidProfile(Package profile){
+
+ EditingDomain domain=TransactionUtil.getEditingDomain(profile);;
+ AdapterFactory adapterFactory = domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null;
+ Diagnostician diagnostician = createDiagnostician(adapterFactory, new NullProgressMonitor());
+ BasicDiagnostic diagnostic = diagnostician.createDefaultDiagnostic(profile);
+ Map<Object, Object> context = diagnostician.createDefaultContext();
+ boolean isValid = diagnostician.validate(profile, diagnostic, context);
+ int severity=diagnostic.getSeverity();
+ if(severity==Diagnostic.ERROR) {return false;}
+ return true;
+ }
+
+ /**
+ * create a diagnostician to evaluate a profil
+ * @param adapterFactory
+ * @param progressMonitor
+ * @return
+ */
+ protected Diagnostician createDiagnostician(final AdapterFactory adapterFactory, final IProgressMonitor progressMonitor) {
+ return new Diagnostician() {
+
+ @Override
+ public String getObjectLabel(EObject eObject) {
+ if(adapterFactory != null && !eObject.eIsProxy()) {
+ IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(eObject, IItemLabelProvider.class);
+ if(itemLabelProvider != null) {
+ return itemLabelProvider.getText(eObject);
+ }
+ }
+ return super.getObjectLabel(eObject);
+ }
+
+ @Override
+ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ progressMonitor.worked(1);
+ return super.validate(eClass, eObject, diagnostics, context);
+ }
+ };
+ }
+
/*
* (non-Javadoc)
*

Back to the top