Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-03-05 14:16:39 +0000
committerCamille Letavernier2014-03-05 14:16:39 +0000
commit5c76e8db71b7b74795fc66bac84040c830c19e46 (patch)
treeb7a5a9b30fbfce650cf04e5008c7e87fd5dcafb0 /plugins
parent282441c5d435c15da577dc58d35760ce42773bb0 (diff)
downloadorg.eclipse.papyrus-5c76e8db71b7b74795fc66bac84040c830c19e46.tar.gz
org.eclipse.papyrus-5c76e8db71b7b74795fc66bac84040c830c19e46.tar.xz
org.eclipse.papyrus-5c76e8db71b7b74795fc66bac84040c830c19e46.zip
429239: [Resource Management] Refactoring of the 3-files model and
PageManager https://bugs.eclipse.org/bugs/show_bug.cgi?id=429239 - Improve legacy sash model management (Wizards, model loading, save as)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java3
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java118
2 files changed, 89 insertions, 32 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java
index 789e30f1651..749da273e49 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* 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
@@ -45,6 +45,7 @@ public abstract class EMFLogicalModel extends AbstractBaseModel implements IEMFM
if(resource == null) {
return false;
}
+
return resource.getURI().fileExtension().equals(getModelFileExtension());
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
index 6d5edf566e9..de3009cde1d 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
@@ -1,6 +1,15 @@
-/**
+/*****************************************************************************
+ * Copyright (c) 2009-2014 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:
+ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Rewrite the sash model - store in the plugin's PreferenceStore (Bug 429239)
+ *****************************************************************************/
package org.eclipse.papyrus.infra.core.resource.sasheditor;
import java.util.Collections;
@@ -9,30 +18,29 @@ import java.util.Objects;
import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.papyrus.infra.core.Activator;
-import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource;
-import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource.ModelKind;
import org.eclipse.papyrus.infra.core.resource.EMFLogicalModel;
import org.eclipse.papyrus.infra.core.resource.IModel;
+import org.eclipse.papyrus.infra.core.sashwindows.di.util.DiUtils;
/**
- * Model for the sash system. <br>
- * This model can share its resource with other model. This model is declared as {@link ModelKind#master}. Other model whishing to share the resource
- * should
- * subclass {@link AbstractModelWithSharedResource}, be declared as {@link ModelKind#slave} (which is the default.), and set
- * {@link #getModelFileExtension()} to return the same file extension as this
- * model ({@link #MODEL_FILE_EXTENSION}).
- *
- * @author cedric dumoulin
+ * Model for the sash system.
*
+ * It may be stored in the *.di file (Legacy mode) or in a *.sash file in the user
+ * preference space (~workspace/.metadata/.plugins/org.eclipse.papyrus.infra.core/)
+ *
+ * @author Cedric Dumoulin
+ * @author Camille Letavernier
+ *
*/
public class SashModel extends EMFLogicalModel implements IModel {
/**
* File extension.
- *
+ *
* @deprecated Use {@link DiModel#MODEL_FILE_EXTENSION} instead. The SashModel has been moved to a separate file
*/
@Deprecated
@@ -49,9 +57,9 @@ public class SashModel extends EMFLogicalModel implements IModel {
public static final String MODEL_ID = "org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel"; //$NON-NLS-1$
/**
- *
+ *
* Constructor.
- *
+ *
*/
public SashModel() {
@@ -59,21 +67,34 @@ public class SashModel extends EMFLogicalModel implements IModel {
/**
* Get the file extension used for this model.
- *
+ *
* @see org.eclipse.papyrus.infra.core.resource.AbstractBaseModel#getModelFileExtension()
- *
+ *
* @return
*/
@Override
protected String getModelFileExtension() {
- return SASH_MODEL_FILE_EXTENSION;
+ if(isLegacy(resourceURI)) {
+ return MODEL_FILE_EXTENSION;
+ } else {
+ return SASH_MODEL_FILE_EXTENSION;
+ }
+ }
+
+ @Override
+ protected boolean isRelatedResource(Resource resource) {
+ if(resource == null) {
+ return false;
+ }
+ String fileExtension = resource.getURI().fileExtension();
+ return MODEL_FILE_EXTENSION.equals(fileExtension) || SASH_MODEL_FILE_EXTENSION.equals(fileExtension);
}
/**
* Get the identifier used to register this model.
- *
+ *
* @see org.eclipse.papyrus.infra.core.resource.AbstractBaseModel#getIdentifier()
- *
+ *
* @return
*/
@Override
@@ -86,38 +107,74 @@ public class SashModel extends EMFLogicalModel implements IModel {
URI sashModelURI = getSashModelURI(uriWithoutExtension);
+ this.resourceURI = sashModelURI;
+
try {
- super.loadModel(sashModelURI);
+ super.loadModel(sashModelURI.trimFileExtension());
} catch (Exception ex) {
- createModel(sashModelURI);
+ createModel(sashModelURI.trimFileExtension());
}
+
if(resource == null) {
- createModel(sashModelURI);
+ createModel(sashModelURI.trimFileExtension());
+ }
+ }
+
+ @Override
+ public void createModel(URI uriWithoutExtension) {
+ if(isLegacy(uriWithoutExtension)) {
+ super.createModel(getPreferenceStoreURI(uriWithoutExtension).trimFileExtension());
+ } else {
+ super.createModel(uriWithoutExtension);
}
}
@Override
public void setModelURI(URI uriWithoutExtension) {
- URI newURIWithoutExtension;
+ URI newURI;
if(resourceURI != null && isLegacy(resourceURI)) {
- newURIWithoutExtension = getLegacyURI(uriWithoutExtension);
+ newURI = getLegacyURI(uriWithoutExtension);
} else {
- newURIWithoutExtension = getPreferenceStoreURI(uriWithoutExtension);
+ newURI = getPreferenceStoreURI(uriWithoutExtension);
}
- super.setModelURI(newURIWithoutExtension);
+ super.setModelURI(newURI.trimFileExtension());
}
protected boolean isLegacy(URI uri) {
+ if(uri == null) {
+ return false;
+ }
return Objects.equals(uri.trimFileExtension(), getModelManager().getURIWithoutExtension());
}
+ /**
+ * Returns the sash model URI (With file extension)
+ *
+ * It may be either the Legacy URI (platform:/resource/model/model.di)
+ * or the 1.0.0 URI (file:/~workspace/.metadata/.plugins/org.eclipse.papyrus.infra.core/model/model.sash)
+ *
+ * @param uriWithoutExtension
+ * @return
+ *
+ */
protected URI getSashModelURI(URI uriWithoutExtension) {
URIConverter converter = getModelManager().getURIConverter();
URI legacyURI = getLegacyURI(uriWithoutExtension);
+ //If the DI file exists and contains a SashWindowsMngr, this is a legacy model
if(converter.exists(legacyURI, Collections.emptyMap())) {
- return legacyURI;
+ try {
+ Resource diResource = getModelManager().getResource(legacyURI, true);
+ if(DiUtils.lookupSashWindowsMngr(diResource) != null) {
+ return legacyURI;
+ }
+ } catch (Exception ex) {
+ //Temporary workaround: the DI file may exist and be empty
+ //(DiModel is currently disabled and doesn't properly init the di file)
+ //Log the error and continue
+ Activator.log.error(ex);
+ }
}
URI preferenceStoreURI = getPreferenceStoreURI(uriWithoutExtension);
@@ -126,8 +183,7 @@ public class SashModel extends EMFLogicalModel implements IModel {
}
protected URI getLegacyURI(URI uriWithoutExtension) {
- URI legacyURI = uriWithoutExtension.appendFileExtension(MODEL_FILE_EXTENSION);
- return legacyURI;
+ return uriWithoutExtension.appendFileExtension(MODEL_FILE_EXTENSION);
}
protected URI getPreferenceStoreURI(URI uriWithoutExtension) {
@@ -139,7 +195,7 @@ public class SashModel extends EMFLogicalModel implements IModel {
stateLocation = stateLocation.append(URI.decode(uriWithoutExtension.toString())); //TODO properly support and test non-platform URIs
}
- URI workspaceFileURI = URI.createFileURI(stateLocation.toString());
+ URI workspaceFileURI = URI.createFileURI(stateLocation.toString()).appendFileExtension(SASH_MODEL_FILE_EXTENSION);
return workspaceFileURI;
}

Back to the top