aboutsummaryrefslogtreecommitdiffstats
path: root/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java
blob: 380410d06f7c3bbc54fed67faa2d5f021def93c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package hu.bme.mit.inf.dslreasoner.application.ui.execute;

import java.util.Iterator;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

import hu.bme.mit.inf.dslreasoner.application.execution.ScriptExecutor;

public class ExecuteScriptHandler extends AbstractHandler implements IHandler {

	ScriptExecutor scriptExecutor = new ScriptExecutor(RuntimeConsoleBasedScriptConsole.FACTORY);
	
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		ISelection selection = HandlerUtil.getCurrentSelection(event);
		if(selection instanceof StructuredSelection) {
			StructuredSelection structuredSelection = (StructuredSelection) selection;
			Iterator<?> iterator = structuredSelection.iterator();
			while(iterator.hasNext()) {
				Object selectedElement = iterator.next();
				if (selectedElement instanceof IFile) {
					IFile selectedFile = (IFile) selectedElement;
					URI uri = URI.createPlatformResourceURI(selectedFile.getFullPath().toString(), true);
					scriptExecutor.executeScript(uri);
                }
			}
		}
		return null;
	} 

}