Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2013-03-28 14:53:13 +0000
committercletavernie2013-03-28 14:53:13 +0000
commit737639568f1d3036441fb5401e72a41dcf4edf47 (patch)
tree4b02b34d1ac407bfc630c22cf5b930cb1d8c0468
parent3e0cca22e7cb0efab8936374592bbfb77186b9ff (diff)
downloadorg.eclipse.papyrus-737639568f1d3036441fb5401e72a41dcf4edf47.tar.gz
org.eclipse.papyrus-737639568f1d3036441fb5401e72a41dcf4edf47.tar.xz
org.eclipse.papyrus-737639568f1d3036441fb5401e72a41dcf4edf47.zip
404564: [Resource] Papyrus shall support optional ecore models
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404564
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml8
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java3
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/anytype/AnyTypeEditorFactory.java103
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorFactoryProxy.java14
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java10
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelUtils.java21
6 files changed, 143 insertions, 16 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml b/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml
index 5a836ef215b..45363218623 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml
@@ -323,5 +323,11 @@
description="Generic outline for Papyrus"
priority="2">
</contentoutline>
- </extension>
+ </extension>
+ <extension
+ point="org.eclipse.papyrus.infra.core.papyrusDiagram">
+ <editorDiagram
+ factoryClass="org.eclipse.papyrus.infra.core.editorsfactory.anytype.AnyTypeEditorFactory">
+ </editorDiagram>
+ </extension>
</plugin>
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java
index 39c4ca6ddae..19b6717ab76 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/PageModelFactoryRegistry.java
@@ -71,8 +71,9 @@ public class PageModelFactoryRegistry implements IPageModelFactory {
*/
public void add(IEditorFactory editorFactory) {
// This should never happen
- if(editorFactory == null)
+ if(editorFactory == null) {
throw new RuntimeException("Parameter should not be null.");
+ }
editorFactories.add(editorFactory);
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/anytype/AnyTypeEditorFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/anytype/AnyTypeEditorFactory.java
new file mode 100644
index 00000000000..4c892a657f6
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editorsfactory/anytype/AnyTypeEditorFactory.java
@@ -0,0 +1,103 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.editorsfactory.anytype;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.xml.type.AnyType;
+import org.eclipse.papyrus.infra.core.extension.diagrameditor.AbstractEditorFactory;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IComponentModel;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * An EditorFactory for "AnyType", i.e. EObject deserialized from unknown Packages
+ *
+ * Allows recovery and manipulation of models containing optional EMF components
+ *
+ * @author Camille Letavernier
+ */
+public class AnyTypeEditorFactory extends AbstractEditorFactory {
+
+ public AnyTypeEditorFactory() {
+ super(null, "AnyTypeHandler");
+ }
+
+ public IPageModel createIPageModel(Object pageIdentifier) {
+
+ final AnyType anyTypeModel = (AnyType)pageIdentifier;
+
+ return new IComponentModel() {
+
+ private AnyType anyType = anyTypeModel;
+
+ public String getTabTitle() {
+ return "Missing component";
+ }
+
+ public Image getComponentIcon() {
+ return Display.getDefault().getSystemImage(SWT.ICON_WARNING);
+ }
+
+ public Image getTabIcon() {
+ return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
+ }
+
+ public Object getRawModel() {
+ return anyType;
+ }
+
+ public String getErrorText() {
+ EClass eClass = anyTypeModel.eClass();
+ String className = eClass == null ? "None" : eClass.getName();
+ EPackage ePackage = eClass == null ? null : eClass.getEPackage();
+ String ePackageName = ePackage == null ? "None" : ePackage.getNsURI();
+ String message = "A component is missing. The following Model cannot be loaded: " + className + " (from " + ePackageName + ")\n";
+ message += "";
+ return message;
+ }
+
+ public Composite createPartControl(Composite parent) {
+ Composite tabComposite = new Composite(parent, SWT.NONE);
+ tabComposite.setLayout(new GridLayout(2, false));
+
+ Image componentIcon = getComponentIcon();
+ if(componentIcon != null) {
+ Label errorImageLabel = new Label(tabComposite, SWT.NONE);
+ errorImageLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ errorImageLabel.setImage(componentIcon);
+ }
+
+ Label label = new Label(tabComposite, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ label.setText(getErrorText());
+
+ return tabComposite;
+ }
+ };
+ }
+
+ public boolean isPageModelFactoryFor(Object pageIdentifier) {
+ return pageIdentifier instanceof AnyType;
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorFactoryProxy.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorFactoryProxy.java
index 9c9c91cb6a2..3745fb605fc 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorFactoryProxy.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/extension/diagrameditor/EditorFactoryProxy.java
@@ -50,7 +50,12 @@ public class EditorFactoryProxy implements IEditorFactory {
* @return
*/
public IPageModel createIPageModel(Object pageIdentifier) {
- return getEditorFactory().createIPageModel(pageIdentifier);
+ try {
+ return getEditorFactory().createIPageModel(pageIdentifier);
+ } catch (Exception ex) {
+ //An error occurred in a contribution. Do not use this factory
+ return null;
+ }
}
/**
@@ -60,7 +65,12 @@ public class EditorFactoryProxy implements IEditorFactory {
* @return
*/
public boolean isPageModelFactoryFor(Object pageIdentifier) {
- return getEditorFactory().isPageModelFactoryFor(pageIdentifier);
+ try {
+ return getEditorFactory().isPageModelFactoryFor(pageIdentifier);
+ } catch (Exception ex) {
+ //An error occurred in a contribution. Do not use this factory
+ return false;
+ }
}
/**
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
index 3dfc11f0381..d737e060643 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
@@ -45,6 +45,7 @@ import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.EditingDomainManager;
+import org.eclipse.papyrus.infra.core.Activator;
import org.eclipse.papyrus.infra.core.resource.additional.AdditionalResourcesModel;
import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
@@ -112,6 +113,7 @@ public class ModelSet extends ResourceSetImpl {
getLoadOptions().put(XMLResource.OPTION_DEFER_ATTACHMENT, true);
getLoadOptions().put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
getLoadOptions().put(XMIResource.OPTION_LAX_FEATURE_PROCESSING, Boolean.TRUE);
+ getLoadOptions().put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
}
/**
@@ -176,6 +178,7 @@ public class ModelSet extends ResourceSetImpl {
try {
r = super.getResource(uri, loadOnDemand);
} catch (WrappedException e) {
+ Activator.log.error(e);
if(ModelUtils.isDegradedModeAllowed(e.getCause())) {
r = super.getResource(uri, false);
if(r == null) {
@@ -186,6 +189,11 @@ public class ModelSet extends ResourceSetImpl {
return setResourceOptions(r);
}
+ @Override
+ protected void handleDemandLoadException(Resource resource, IOException exception) throws RuntimeException {
+ super.handleDemandLoadException(resource, exception);
+ }
+
public void setTrackingModification(boolean isTrackingModification) {
boolean oldIsTrackingModification = modificationTrackingAdapter != null;
@@ -628,7 +636,7 @@ public class ModelSet extends ResourceSetImpl {
for(IModel model : modelList) {
Set<URI> uris = model.getModifiedURIs();
for(URI u : uris) {
- Optional<Boolean> res = getReadOnlyHandler().anyReadOnly(new URI[]{u});
+ Optional<Boolean> res = getReadOnlyHandler().anyReadOnly(new URI[]{ u });
if(res.isPresent() && res.get()) {
roUris.add(u);
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelUtils.java
index 96ddd2614cb..8ababea2ca9 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelUtils.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelUtils.java
@@ -32,6 +32,7 @@ public class ModelUtils {
* found.
* @deprecated Use ServiceUtilsForActionHandlers.getInstance().getModelSet()
*/
+ @Deprecated
public static ModelSet getModelSet() {
try {
@@ -55,6 +56,7 @@ public class ModelUtils {
* If an error occurs while getting or starting the service.
* @deprecated Use ServiceUtilsForActionHandlers.getInstance().getModelSet()
*/
+ @Deprecated
public static ModelSet getModelSetChecked() throws ServiceException {
return ServiceUtilsForActionHandlers.getInstance().getModelSet();
@@ -89,22 +91,19 @@ public class ModelUtils {
/**
* Determine if a throwable can be managed in degraded mode
+ *
* @param t
*/
- public static boolean isDegradedModeAllowed(Throwable t){
+ public static boolean isDegradedModeAllowed(Throwable t) {
return t instanceof org.eclipse.emf.ecore.xmi.ClassNotFoundException || t instanceof IllegalValueException;
}
- /**
- * Determine if a throwable can be managed in degraded mode
- * @param t
- */
- public static boolean resourceFailedOnLoad(Resource r){
- if (r.getErrors() != null){
- for (Diagnostic d : r.getErrors()){
- if (d instanceof WrappedException) {
- WrappedException wrapped = (WrappedException) d;
- if (wrapped.getCause() instanceof ResourceException && r.getContents().isEmpty()) {
+ public static boolean resourceFailedOnLoad(Resource r) {
+ if(r.getErrors() != null) {
+ for(Diagnostic d : r.getErrors()) {
+ if(d instanceof WrappedException) {
+ WrappedException wrapped = (WrappedException)d;
+ if(wrapped.getCause() instanceof ResourceException && r.getContents().isEmpty()) {
return true;
}
}

Back to the top