Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2017-06-02 14:06:00 +0000
committerJuergen Haug2017-06-07 14:56:06 +0000
commit687feea1286fec52b612960f854bd9ddee40d14e (patch)
tree9f57239e4af30eb1672fdf960a2896639ced56db /plugins/org.eclipse.etrice.ui.common.base
parent8ab07314b5c1fdab6f1c5754e1b5dca6cb4010b4 (diff)
downloadorg.eclipse.etrice-687feea1286fec52b612960f854bd9ddee40d14e.tar.gz
org.eclipse.etrice-687feea1286fec52b612960f854bd9ddee40d14e.tar.xz
org.eclipse.etrice-687feea1286fec52b612960f854bd9ddee40d14e.zip
Bug 471247 - Import (de)resolve is FILE-based in room + diagram
Diffstat (limited to 'plugins/org.eclipse.etrice.ui.common.base')
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomPersistencyBehavior.java12
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java2
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java36
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/RelativeFileURIHandler.java101
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java42
5 files changed, 154 insertions, 39 deletions
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomPersistencyBehavior.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomPersistencyBehavior.java
index c9c9010ed..930129a7a 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomPersistencyBehavior.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomPersistencyBehavior.java
@@ -15,6 +15,7 @@ package org.eclipse.etrice.ui.common.base.editor;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -59,6 +60,17 @@ public class CustomPersistencyBehavior extends DefaultPersistencyBehavior {
}
@Override
+ protected Map<Resource, Map<?, ?>> createSaveOptions() {
+ Map<Resource, Map<?, ?>> resMap = super.createSaveOptions();
+
+ @SuppressWarnings("unchecked")
+ Map<Object, Object> diagSaveOptions = (Map<Object, Object>) resMap.get(diagramBehavior.getDiagramTypeProvider().getDiagram().eResource());
+ RelativeFileURIHandler.addToOptions(diagSaveOptions);
+
+ return resMap;
+ }
+
+ @Override
public void saveDiagram(IProgressMonitor monitor) {
boolean valid = validateResourcesBeforeSave(monitor);
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java
index 1502fb98f..4a398aee4 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java
@@ -68,6 +68,8 @@ public class CustomUpdateBehavior extends DefaultUpdateBehavior {
resourceSet = new XtextResourceSet();
}
+ RelativeFileURIHandler.addToOptions(resourceSet.getLoadOptions());
+
final IWorkspaceCommandStack workspaceCommandStack = new GFWorkspaceCommandStackImpl(new DefaultOperationHistory());
final TransactionalEditingDomainImpl editingDomain = new TransactionalEditingDomainImpl(new ComposedAdapterFactory(
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java
index d2199e72e..8b02d6f61 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java
@@ -15,14 +15,13 @@ package org.eclipse.etrice.ui.common.base.editor;
import java.util.Collection;
import java.util.Map;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.common.ui.linking.GlobalNonPlatformURIEditorOpener;
import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
import org.eclipse.etrice.core.fsm.ui.FSMUiModule;
import org.eclipse.graphiti.mm.pictograms.Diagram;
@@ -85,8 +84,10 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU
ResourceSet resourceSet = getEditingDomain().getResourceSet();
Map<EObject, Collection<Setting>> result = EcoreUtil.UnresolvedProxyCrossReferencer.find(resourceSet);
- if (!result.isEmpty())
+ if (!result.isEmpty()){
System.err.println("ERROR in diagram viewer: could not resolve all proxies!");
+ //System.out.println(result);
+ }
mte.setTarget(getEditingDomain());
}
@@ -135,6 +136,10 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
+ if(!getDiagramBehavior().isAlive()){
+ // something is wrong, avoid further exceptions
+ return;
+ }
superClassListener = new SuperClassListener(this, textEditorClass);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(superClassListener);
@@ -162,11 +167,11 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU
ModelComponent editorSc = editor.getModelComponent();
if (editorSc!=null) {
- URI editorResURI = toCurrentPlatformURI(editorSc.eResource().getURI());
+ URI editorResURI = GlobalNonPlatformURIEditorOpener.getPlatformURI(editorSc.eResource().getURI());
ModelComponent base = getModelComponent();
while((base = base.getBase()) != null){
- URI baseResURI = toCurrentPlatformURI(base.eResource().getURI());
+ URI baseResURI = GlobalNonPlatformURIEditorOpener.getPlatformURI(base.eResource().getURI());
if(editorResURI.equals(baseResURI))
if(editorSc.getComponentName().equals(base.getComponentName()))
return true;
@@ -192,16 +197,16 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU
@Override
public Boolean exec(XtextResource resource) throws Exception {
- URI editorResURI = toCurrentPlatformURI(resource.getURI());
- URI thisScResURI = toCurrentPlatformURI(getModelComponent().eResource().getURI());
+ URI editorResURI = GlobalNonPlatformURIEditorOpener.getPlatformURI(resource.getURI());
+ URI thisScResURI = GlobalNonPlatformURIEditorOpener.getPlatformURI(getModelComponent().eResource().getURI());
// ignore if in same file (handled by graphiti)
- if(thisScResURI.equals(editorResURI))
+ if(thisScResURI == null || thisScResURI.equals(editorResURI))
return false;
ModelComponent base = getModelComponent();
while((base = base.getBase()) != null){
- URI baseResURI = toCurrentPlatformURI(base.eResource().getURI());
+ URI baseResURI = GlobalNonPlatformURIEditorOpener.getPlatformURI(base.eResource().getURI());
if(editorResURI.equals(baseResURI))
return true;
}
@@ -211,19 +216,6 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU
});
}
- private URI toCurrentPlatformURI(URI uri) {
- if(uri.isPlatform())
- return uri;
- else if(uri.isFile()){
- final IPath rootPath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
- String rootString = rootPath.toFile().toString();
- String fileString = uri.toFileString();
- if(fileString.startsWith(rootString))
- return URI.createPlatformResourceURI(fileString.replace(rootString, ""), false);
- }
- return null;
- }
-
protected abstract void handleMissingDiagramBo(Diagram diagram);
protected abstract void superClassChanged();
protected abstract EObject getModel();
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/RelativeFileURIHandler.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/RelativeFileURIHandler.java
new file mode 100644
index 000000000..5f3381e48
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/RelativeFileURIHandler.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.common.base.editor;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.xmi.XMIResource;
+import org.eclipse.emf.ecore.xmi.XMLResource.URIHandler;
+import org.eclipse.emf.ecore.xmi.impl.URIHandlerImpl;
+
+/**
+ * {@linkplain URIHandler} which deresolves to relative file uri and resolves to absolute file uri. <br>
+ * Used to persist portable model references. <br>
+ * <br>
+ * TODO serialize room includes path <=> deresolve in StandardModelLocator
+ */
+public class RelativeFileURIHandler extends URIHandlerImpl {
+
+ private final static Logger LOG = Logger.getLogger(RelativeFileURIHandler.class);
+
+ public static Map<Object, Object> addToOptions(Map<Object, Object> options) {
+ options.put(XMIResource.OPTION_URI_HANDLER, new RelativeFileURIHandler((URIHandler) options.get(XMIResource.OPTION_URI_HANDLER)));
+ return options;
+ }
+
+ final protected URIHandler fallback;
+
+ public RelativeFileURIHandler(URIHandler fallback) {
+ this.fallback = fallback;
+ }
+
+ /**
+ * @return absolute file uri
+ */
+ @Override
+ public URI resolve(URI uri) {
+ if (resolve && baseURI != null && uri.isFile() && uri.hasRelativePath()) {
+ URI baseFileURI = toFileURI(baseURI);
+ URI fileURI = toFileURI(uri);
+
+ URI resolvedFileURI = fileURI.resolve(baseFileURI, true);
+ // System.out.println("resolve: " + fileURI + " -> " + baseFileURI + " = " + resolvedFileURI);
+ return resolvedFileURI;
+ }
+
+ return (fallback != null) ? fallback.resolve(uri) : uri;
+ }
+
+ /**
+ * @return shorter relative file path
+ */
+ @Override
+ public URI deresolve(URI uri) {
+ if (resolve && baseURI != null) {
+ URI baseFileURI = toFileURI(baseURI);
+ URI fileURI = toFileURI(uri);
+
+ URI relativeFileURI = fileURI.deresolve(baseFileURI, true, true, true);
+ if(relativeFileURI.isFile() && relativeFileURI.hasRelativePath()) {
+ // System.out.println("deresolve: " + fileURI + " -> " + baseFileURI + " = " + relativeFileURI);
+ return relativeFileURI;
+ }
+ }
+
+ return (fallback != null) ? fallback.deresolve(uri) : uri;
+ }
+
+ private static URI toFileURI(URI uri) {
+ if (uri.isFile()) {
+ return uri;
+ } else if (uri.isPlatform()) {
+ IPath path = null;
+ if(uri.segmentCount() == 2){
+ path = ResourcesPlugin.getWorkspace().getRoot().getProject(uri.lastSegment()).getLocation();
+ } else if(uri.segmentCount() > 2){
+ path = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(false))).getLocation();
+ }
+ if(path != null) {
+ return URI.createFileURI(path.toOSString()).appendQuery(uri.query()).appendFragment(uri.fragment());
+ }
+ }
+
+ LOG.error("unhandled uri " + uri);
+ return uri;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java
index 42ef42770..d8acb04f2 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java
@@ -33,10 +33,12 @@ import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.etrice.core.common.ui.linking.GlobalNonPlatformURIEditorOpener;
import org.eclipse.etrice.ui.common.base.UIBaseActivator;
import org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase;
+import org.eclipse.etrice.ui.common.base.editor.RelativeFileURIHandler;
import org.eclipse.etrice.ui.common.base.preferences.UIBasePreferenceConstants;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
@@ -44,6 +46,7 @@ import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
+import com.google.common.collect.Maps;
import com.google.inject.Inject;
/**
@@ -131,7 +134,7 @@ public abstract class DiagramAccessBase {
populateDiagram(rootObject, diagram);
try {
- diagRes.save(Collections.EMPTY_MAP);
+ diagRes.save(RelativeFileURIHandler.addToOptions(Maps.newHashMap()));
} catch (IOException e) {
e.printStackTrace();
}
@@ -206,34 +209,39 @@ public abstract class DiagramAccessBase {
public DiagramEditorBase findDiagramEditor(EObject rootObject) {
IFileEditorInput input = getEditorInput(rootObject);
- return (DiagramEditorBase) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findEditor(input);
+ IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findEditor(input);
+ if(part instanceof DiagramEditorBase) {
+ return (DiagramEditorBase) part;
+ }
+
+ return null;
}
public DiagramEditorBase openDiagramEditor(EObject rootObject) {
IFileEditorInput input = getEditorInput(rootObject);
- try {
- return (DiagramEditorBase) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, getEditorId());
- } catch (PartInitException e) {
- String error = "Error while opening diagram editor";
- System.err.println(error);
+ if(input != null) {
+ try {
+ IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, getEditorId());
+ if(part instanceof DiagramEditorBase) {
+ return (DiagramEditorBase) part;
+ }
+ } catch (PartInitException e) {
+ String error = "Error while opening diagram editor";
+ System.err.println(error);
+ }
}
+
return null;
}
private IFileEditorInput getEditorInput(EObject rootObject) {
Diagram diagram = getDiagram(rootObject);
+ if(diagram == null) return null;
- URI uri = diagram.eResource().getURI();
- String platformString = null;
- if (uri.isPlatform()) {
- platformString = uri.toPlatformString(true);
- }
- else {
- uri = GlobalNonPlatformURIEditorOpener.getPlatformURI(uri);
- platformString = uri.toPlatformString(true);
- }
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformString));
+ URI uri = GlobalNonPlatformURIEditorOpener.getPlatformURI(diagram.eResource().getURI());
+ if(uri == null) return null;
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
IFileEditorInput input = new FileEditorInput(file);
return input;
}

Back to the top