Browse Source

added new file wizard

Kenneth Lausdahl 6 years ago
parent
commit
b72b0c3a4f

+ 3 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.ui/META-INF/MANIFEST.MF

@@ -5,6 +5,7 @@ Bundle-Vendor: My Company
 Bundle-Version: 1.0.0.qualifier
 Bundle-SymbolicName: be.uantwerpen.ansymo.semanticadaptation.ui; singleton:=true
 Bundle-ActivationPolicy: lazy
+Bundle-Localization: plugin
 Require-Bundle: be.uantwerpen.ansymo.semanticadaptation,
  be.uantwerpen.ansymo.semanticadaptation.ide,
  org.eclipse.xtext.ui,
@@ -16,7 +17,8 @@ Require-Bundle: be.uantwerpen.ansymo.semanticadaptation,
  org.eclipse.compare,
  org.eclipse.xtext.builder,
  org.eclipse.xtend.lib;resolution:=optional,
- org.eclipse.xtext.xbase.lib
+ org.eclipse.xtext.xbase.lib,
+ org.apache.commons.io
 Import-Package: org.apache.log4j
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: be.uantwerpen.ansymo.semanticadaptation.ui.quickfix,

+ 2 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.ui/build.properties

@@ -3,4 +3,5 @@ source.. = src/,\
            xtend-gen/
 bin.includes = .,\
                META-INF/,\
-               plugin.xml
+               plugin.xml,\
+               plugin.properties

+ 1 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.ui/plugin.properties

@@ -0,0 +1 @@
+newSAWizardName=New Semantics Adaptation

+ 6 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.ui/plugin.xml

@@ -409,13 +409,16 @@
 	</extension>
  <extension
        point="org.eclipse.ui.newWizards">
+        <category
+            id="be.uantwerpen.ansymo.semanticadaptation.ui.wizard.category"
+            name="Semantic Adaptation">
+      </category>
     <wizard
             
             class="be.uantwerpen.ansymo.semanticadaptation.ui.wizard.SaNewFileWizard"
-            
-            icon="icons/cview16/vdmpp_file_tsk.png"
             id="be.uantwerpen.ansymo.semanticadaptation.ui.ui.newFileWizard"
-            name="%newProjectWizardName"
+            name="%newSAWizardName"
+            category="be.uantwerpen.ansymo.semanticadaptation.ui.wizard.category"
             project="false">
       </wizard>
  </extension>

+ 161 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.ui/src/be/uantwerpen/ansymo/semanticadaptation/ui/wizard/SaNewFileWizard.java

@@ -0,0 +1,161 @@
+package be.uantwerpen.ansymo.semanticadaptation.ui.wizard;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.eclipse.ui.ide.IDE;
+
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation;
+
+public class SaNewFileWizard extends Wizard implements IWorkbenchWizard {
+
+	private static final String WIZARD_NAME = "VDM New File Wizard";
+
+	private WizardNewFileCreationPage _pageOne;
+	private String fPageName;
+	private String fPageTitle;
+	private String fPageDescription;
+	private IStructuredSelection fStructuredSelection;
+
+	public SaNewFileWizard() {
+		setWindowTitle(WIZARD_NAME);
+		this.fPageName = getPageName();
+		this.fPageTitle = getPageTitle();
+		this.fPageDescription = getPageDescription();
+	}
+
+	@Override
+	public void addPages() {
+		super.addPages();
+		_pageOne = new WizardNewFileCreationPage(this.fPageName, this.fStructuredSelection);
+		_pageOne.setFileExtension(getFileExtension());
+		_pageOne.setTitle(this.fPageTitle);
+		_pageOne.setDescription(this.fPageDescription);
+
+		addPage(_pageOne);
+
+	}
+
+	/*
+	 * Gets the main page name
+	 */
+	protected String getPageName() {
+		return "New Semantic Adaptation";
+	}
+
+	/*
+	 * Gets the main page title to be displayed
+	 */
+	protected String getPageTitle() {
+		return getPageName();
+	}
+
+	/*
+	 * Gets the main page description
+	 */
+	protected String getPageDescription() {
+		return "Create a new basic semantic adaptation";
+	}
+
+	/*
+	 * Gets the file extension of the file to create
+	 */
+	protected String getFileExtension() {
+		return "sa";
+	}
+
+	/*
+	 * Gets the file template or null if none is provided
+	 */
+	protected String getFileTemplate(String fileName) {
+		InputStream stream = null;
+		try {
+			stream = SemanticAdaptation.class.getResourceAsStream("/templates/new_file_template.sa");
+			return IOUtils.toString(stream);
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return null;
+		} finally {
+			IOUtils.closeQuietly(stream);
+		}
+	}
+
+	@Override
+	public boolean canFinish() {
+		return super.canFinish() && _pageOne.getErrorMessage() == null;
+	}
+
+	@Override
+	public boolean performFinish() {
+		IFile file = _pageOne.createNewFile();
+		if (file.exists()) {
+			String fileName = file.getName();
+			if (fileName.contains(".")) {
+				fileName = fileName.substring(0, fileName.indexOf("."));
+			}
+
+			boolean isClean = false;
+			InputStream in = null;
+			try {
+				in = file.getContents();
+				if (file.getContents().read() == -1) {
+					isClean = true;
+				}
+			} catch (IOException e) {
+			} catch (CoreException e) {
+			} finally {
+				if (in != null) {
+					try {
+						in.close();
+					} catch (IOException e) {
+					}
+				}
+			}
+
+			if (isClean) {
+				String fileTemplate = getFileTemplate(fileName);
+				if (fileTemplate != null) {
+					applyTemplate(file, fileTemplate);
+				}
+			}
+
+		}
+		try {
+			IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, true);
+			file.touch(null);
+			file.refreshLocal(IResource.DEPTH_ONE, null);
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+		return true;
+	}
+
+	private void applyTemplate(IFile file, String fileTemplate) {
+		InputStream stream;
+		try {
+			stream = new ByteArrayInputStream(fileTemplate.getBytes());
+			file.setContents(stream, IFile.FORCE, null);
+		} catch (CoreException e) {
+			e.printStackTrace();
+
+		}
+
+	}
+
+	public void init(IWorkbench workbench, IStructuredSelection selection) {
+		this.fStructuredSelection = selection;
+	}
+
+}

+ 2 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/build.properties

@@ -4,7 +4,8 @@ source.. = src/,\
 bin.includes = model/generated/,\
                .,\
                META-INF/,\
-               plugin.xml
+               plugin.xml,\
+               templates/
 additional.bundles = org.eclipse.xtext.xbase,\
                      org.eclipse.xtext.common.types,\
                      org.eclipse.xtext.xtext.generator,\

+ 44 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/templates/new_file_template.sa

@@ -0,0 +1,44 @@
+semantic adaptation reactive mealy MyAdaptation myAdaptationInstance
+at "./MyAdaptation.fmu" // generated fmu path
+
+/* Internal scenario description */
+	for inner fmu OriginalFMU originalFMUInstance
+		at "./OriginalFMU.fmu"
+		with input ports inPort1 (m/s), inPort2 (N)
+		with output ports outPort1 (m/s), outPort2 (N)
+
+/* Input and Output ports description */
+input ports extInPort1 (km/s),
+			extInPort2 -> inPort2
+
+output ports extOutPort1 <- outPort1,
+			extOutPort2 (N)
+
+/* Parameters */
+param Real INIT_EXTINPORT1 := 0.0;
+
+/* Control rules */
+control rules {
+	var H_window := do_step(originalFMUInstance, t, H);
+	return H_window; 
+}
+
+/* Input rules */
+in var Real stored__inPort1 := INIT_EXTINPORT1;
+in rules {
+	true -> {
+		stored__inPort1 := myAdaptationInstance.extInPort1 ;
+	} --> {
+		originalFMUInstance.inPort1 := stored__inPort1 * 100;
+	}; 
+}
+
+/* Output rules */
+out var Real stored__outPort2 := 0.0;
+out rules {
+	true -> {
+		stored__outPort2 := originalFMUInstance.outPort2;
+	} --> {
+		myAdaptationInstance.extOutPort2 := stored__outPort2;
+	};
+}