Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2014-10-15 09:50:37 +0000
committerEd Willink2014-10-25 12:52:34 +0000
commit1eeba29312c2d0bb0251a5cf22222fb2380acb4b (patch)
tree7d4e2110e4a7168df84284fa6a08b3f03003883b
parent90e54a38958e890649a5c5cd1e93987381711254 (diff)
downloadorg.eclipse.qvtd-archive/447935.tar.gz
org.eclipse.qvtd-archive/447935.tar.xz
org.eclipse.qvtd-archive/447935.zip
[wip] FlatQVTpivot UIarchive/447935
-rw-r--r--plugins/org.eclipse.qvtd.pivot.qvtbase/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.properties1
-rw-r--r--plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.xml19
-rw-r--r--plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/src/org/eclipse/qvtd/xtext/qvtrelation/ui/commands/SaveModelMorfASHandler.java127
4 files changed, 148 insertions, 1 deletions
diff --git a/plugins/org.eclipse.qvtd.pivot.qvtbase/META-INF/MANIFEST.MF b/plugins/org.eclipse.qvtd.pivot.qvtbase/META-INF/MANIFEST.MF
index d7ee6cb3c..935b88857 100644
--- a/plugins/org.eclipse.qvtd.pivot.qvtbase/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.qvtd.pivot.qvtbase/META-INF/MANIFEST.MF
@@ -18,4 +18,4 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ocl.examples.pivot;bundle-version="[3.4.0,4.0.0)";visibility:=reexport
Bundle-ActivationPolicy: lazy
Import-Package: com.google.inject,
- org.apache.log4j
+ org.apache.log4j;version="1.2.15"
diff --git a/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.properties b/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.properties
index 403ce2899..18fba9378 100644
--- a/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.properties
+++ b/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.properties
@@ -19,6 +19,7 @@ MF_Problem = QVTrelation Problem
MF_OpenQuickOutline = Open the quick outline.
MF_QuickOutline = Quick Outline
MF_Save_AS = Abstract Syntax
+MF_Save_ModelMorf_AS = ModelMorf Abstract Syntax
MF_Save_CS = Concrete (Xtext) Syntax
MF_TriggerExpensiveValidation = Trigger expensive validation
MF_Validate = Validate
diff --git a/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.xml b/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.xml
index 0d0d3d389..5d0d6d1d2 100644
--- a/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.xml
+++ b/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/plugin.xml
@@ -237,6 +237,15 @@
</markerResolutionGenerator>
</extension>
+ <extension point="org.eclipse.ui.commands">
+ <command id="org.eclipse.qvtd.xtext.qvtrelation.ui.SaveModelMorfASCommand"
+ name="%MF_Save_ModelMorf_AS_Command" description="%MF_Save_ModelMorf_AS_Description"/>
+ </extension>
+ <extension point="org.eclipse.ui.handlers">
+ <handler commandId="org.eclipse.qvtd.xtext.qvtrelation.ui.SaveModelMorfASCommand"
+ class="org.eclipse.qvtd.xtext.qvtrelation.ui.commands.SaveModelMorfASHandler"/>
+ </extension>
+
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ocl.examples.xtext.base.ui.Save?after=additions">
<command commandId="org.eclipse.ocl.examples.xtext.base.ui.SaveASCommand"
@@ -249,6 +258,16 @@
</command>
</menuContribution>
<menuContribution locationURI="popup:org.eclipse.ocl.examples.xtext.base.ui.Save?after=additions">
+ <command commandId="org.eclipse.qvtd.xtext.qvtrelation.ui.SaveModelMorfASCommand"
+ label="%MF_Save_ModelMorf_AS">
+ <visibleWhen checkEnabled="false">
+ <reference
+ definitionId="org.eclipse.qvtd.xtext.qvtrelation.QVTrelation.Editor.opened">
+ </reference>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <menuContribution locationURI="popup:org.eclipse.ocl.examples.xtext.base.ui.Save?after=additions">
<command commandId="org.eclipse.ocl.examples.xtext.base.ui.SaveCSCommand"
label="%MF_Save_CS">
<visibleWhen checkEnabled="false">
diff --git a/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/src/org/eclipse/qvtd/xtext/qvtrelation/ui/commands/SaveModelMorfASHandler.java b/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/src/org/eclipse/qvtd/xtext/qvtrelation/ui/commands/SaveModelMorfASHandler.java
new file mode 100644
index 000000000..4b769c45b
--- /dev/null
+++ b/plugins/org.eclipse.qvtd.xtext.qvtrelation.ui/src/org/eclipse/qvtd/xtext/qvtrelation/ui/commands/SaveModelMorfASHandler.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 E.D.Willink and others.
+ * 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:
+ * E.D.Willink - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.qvtd.xtext.qvtrelation.ui.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ocl.examples.xtext.base.ui.messages.BaseUIMessages;
+import org.eclipse.ocl.examples.xtext.base.utilities.BaseCSResource;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.dialogs.SaveAsDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.model.IXtextDocument;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
+
+public class SaveModelMorfASHandler extends AbstractHandler
+{
+ public SaveModelMorfASHandler() {}
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
+ if (window == null) {
+ return null;
+ }
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
+ if (!(editor instanceof XtextEditor)) {
+ return null;
+ }
+ IEditorInput editorInput = editor.getEditorInput();
+ if (!(editorInput instanceof IFileEditorInput)) {
+ return null;
+ }
+ IXtextDocument document = ((XtextEditor)editor).getDocument();
+ URI asURI = null;
+ try {
+ asURI = document.readOnly(new IUnitOfWork<URI, XtextResource>()
+ {
+ public URI exec(@Nullable XtextResource resource) throws Exception {
+ if (resource instanceof BaseCSResource) {
+ Resource asResource = ((BaseCSResource)resource).getASResource(null);
+ return asResource.getURI();
+ }
+ else {
+ return null;
+ }
+ }
+ });
+ } catch (Exception e) {}
+ if (asURI == null) {
+ return null;
+ }
+ IFile srcFile = ((IFileEditorInput)editorInput).getFile();
+ IProject srcProject = srcFile.getProject();
+ URI projectURI = URI.createPlatformResourceURI(srcProject.getFullPath().toString() + "/", true);
+ URI outURI = asURI.deresolve(projectURI);
+ IPath outPath = new Path(outURI.toString());
+ IFile outFile = srcProject.getFile(outPath);
+ Shell shell = editor.getEditorSite().getShell();
+ SaveAsDialog dlg = new SaveAsDialog(shell);
+ dlg.setOriginalFile(outFile);
+ dlg.create();
+ dlg.getShell().setText(BaseUIMessages.SaveAS_ShellTitle);
+ dlg.setTitle(BaseUIMessages.SaveAS_Title);
+ dlg.setMessage(NLS.bind(BaseUIMessages.SaveAS_Description, asURI));
+ int status = dlg.open();
+ if (status != SaveAsDialog.OK) {
+ return null;
+ }
+ final IPath file = dlg.getResult();
+ if (file == null) {
+ return null;
+ }
+ final URI newURI = URI.createPlatformResourceURI(file.toString(), true);
+ try {
+ document.modify(new IUnitOfWork<Object, XtextResource>()
+ {
+ public Object exec(@Nullable XtextResource resource) throws Exception {
+ if (resource instanceof BaseCSResource) {
+ Resource asResource = ((BaseCSResource)resource).getASResource(null);
+ URI oldURI = asResource.getURI();
+ try {
+ asResource.setURI(newURI);
+ asResource.save(null);
+ } finally {
+ asResource.setURI(oldURI);
+ }
+ }
+ return null;
+ }
+ });
+ } catch (Throwable e) {
+ MessageDialog.openError( shell, BaseUIMessages.SaveError_Title,
+ e.getLocalizedMessage());
+ }
+ return null;
+ }
+
+// public Resource createFlatObjects(@NonNull Collection asResource, @NonNull URI flatURI) {
+// for (TreeIterator<EObject> tit = asResource.getAllContents(); tit.hasNext(); ) {
+// EObject = tit.next();
+// }
+// }
+}

Back to the top