diff options
author | 2018-02-15 23:16:13 +0100 | |
---|---|---|
committer | 2018-02-15 23:16:13 +0100 | |
commit | 8824371f2d3aaf8ae00f8398609c9582823a482f (patch) | |
tree | 24c9488b993771c9e2d61e120b84c5b80d13f65c /Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner | |
parent | coloring refined (diff) | |
download | VIATRA-Generator-8824371f2d3aaf8ae00f8398609c9582823a482f.tar.gz VIATRA-Generator-8824371f2d3aaf8ae00f8398609c9582823a482f.tar.zst VIATRA-Generator-8824371f2d3aaf8ae00f8398609c9582823a482f.zip |
Execute action calls ScriptExecutor with selected files
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner')
-rw-r--r-- | Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java index 74e30ac6..a85ce953 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java +++ b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java | |||
@@ -1,16 +1,68 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.ui.execute; | 1 | package hu.bme.mit.inf.dslreasoner.application.ui.execute; |
2 | 2 | ||
3 | import java.util.Iterator; | ||
4 | |||
3 | import org.eclipse.core.commands.AbstractHandler; | 5 | import org.eclipse.core.commands.AbstractHandler; |
4 | import org.eclipse.core.commands.ExecutionEvent; | 6 | import org.eclipse.core.commands.ExecutionEvent; |
5 | import org.eclipse.core.commands.ExecutionException; | 7 | import org.eclipse.core.commands.ExecutionException; |
6 | import org.eclipse.core.commands.IHandler; | 8 | import org.eclipse.core.commands.IHandler; |
9 | import org.eclipse.core.resources.IFile; | ||
10 | import org.eclipse.emf.common.util.URI; | ||
11 | import org.eclipse.emf.ecore.EObject; | ||
12 | import org.eclipse.emf.ecore.resource.Resource; | ||
13 | import org.eclipse.emf.ecore.resource.ResourceSet; | ||
14 | import org.eclipse.emf.ecore.resource.URIConverter; | ||
15 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
16 | import org.eclipse.jface.viewers.ISelection; | ||
17 | import org.eclipse.jface.viewers.StructuredSelection; | ||
18 | import org.eclipse.ui.handlers.HandlerUtil; | ||
19 | |||
20 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript; | ||
21 | import hu.bme.mit.inf.dslreasoner.application.execution.ScriptExecutor; | ||
7 | 22 | ||
8 | public class ExecuteScriptHandler extends AbstractHandler implements IHandler { | 23 | public class ExecuteScriptHandler extends AbstractHandler implements IHandler { |
9 | 24 | ||
25 | ScriptExecutor scriptExecutor = new ScriptExecutor(); | ||
26 | |||
10 | @Override | 27 | @Override |
11 | public Object execute(ExecutionEvent event) throws ExecutionException { | 28 | public Object execute(ExecutionEvent event) throws ExecutionException { |
12 | System.out.println("Called"); | 29 | System.out.println("Called"); |
30 | ISelection selection = HandlerUtil.getCurrentSelection(event); | ||
31 | if(selection instanceof StructuredSelection) { | ||
32 | StructuredSelection structuredSelection = (StructuredSelection) selection; | ||
33 | Iterator<?> iterator = structuredSelection.iterator(); | ||
34 | while(iterator.hasNext()) { | ||
35 | Object selectedElement = iterator.next(); | ||
36 | if (selectedElement instanceof IFile) { | ||
37 | IFile selectedFile = (IFile) selectedElement; | ||
38 | executeFile(selectedFile); | ||
39 | } | ||
40 | } | ||
41 | } | ||
13 | return null; | 42 | return null; |
14 | } | 43 | } |
15 | 44 | ||
45 | private void executeFile(IFile selectedFile) { | ||
46 | URI uri = URI.createPlatformResourceURI(selectedFile.getFullPath().toString(), true); | ||
47 | |||
48 | ResourceSet rs = new ResourceSetImpl(); | ||
49 | Resource resource; | ||
50 | try { | ||
51 | resource = rs.getResource(uri, true); | ||
52 | } catch(RuntimeException e) { | ||
53 | return; | ||
54 | } | ||
55 | |||
56 | if(resource.getContents().size() == 1) { | ||
57 | EObject content = resource.getContents().get(0); | ||
58 | if(content instanceof ConfigurationScript) { | ||
59 | ConfigurationScript script = (ConfigurationScript) content; | ||
60 | scriptExecutor.executeScript(script); | ||
61 | } else { | ||
62 | return; | ||
63 | } | ||
64 | } else { | ||
65 | return; | ||
66 | } | ||
67 | } | ||
16 | } | 68 | } |