Skip to content

Commit

Permalink
ScriptingAction instead of JSAction & GroovyAction
Browse files Browse the repository at this point in the history
Was halfway into creating RAction when I realised they are all the same...
  • Loading branch information
jonalv committed Sep 4, 2012
1 parent d253268 commit cb60215
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 62 deletions.
Expand Up @@ -15,7 +15,7 @@
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.scripting.Activator;
import net.bioclipse.scripting.Hook;
import net.bioclipse.scripting.JsAction;
import net.bioclipse.scripting.ScriptAction;
import net.bioclipse.scripting.JsThread;
import net.bioclipse.scripting.ui.views.JsConsoleView;

Expand Down Expand Up @@ -84,7 +84,7 @@ public String eval( String command ) {
final String[] evalResult = new String[1];
final JsThread jsThread = Activator.getDefault().JS_THREAD;
jsThread.enqueue(
new JsAction(command, new Hook() {
new ScriptAction(command, new Hook() {
public void run( Object result ) {
evalResult[0] = result.toString();
}
Expand Down Expand Up @@ -117,7 +117,7 @@ protected IStatus run(final IProgressMonitor monitor) {
monitor.worked( 1 );
final JsThread jsThread = Activator.getDefault().JS_THREAD;
jsThread.enqueue(
new JsAction(contents, new Hook() {
new ScriptAction(contents, new Hook() {
public void run( Object result ) {
monitor.done();
if ( !"org.mozilla.javascript.Undefined".equals(
Expand Down
Expand Up @@ -31,9 +31,9 @@
import net.bioclipse.core.PublishedMethod;
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.scripting.Activator;
import net.bioclipse.scripting.GroovyAction;
import net.bioclipse.scripting.GroovyThread;
import net.bioclipse.scripting.Hook;
import net.bioclipse.scripting.ScriptAction;

import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PartInitException;
Expand Down Expand Up @@ -114,7 +114,7 @@ private void executeGroovyCommand(final String command) {
Activator.getDefault().GROOVY_THREAD = groovyThread = new GroovyThread();
groovyThread.start();
}
groovyThread.enqueue(new GroovyAction(command,
groovyThread.enqueue(new ScriptAction(command,
new Hook() {
public void run(final Object result) {
Display.getDefault().asyncExec(new Runnable() {
Expand Down Expand Up @@ -684,7 +684,7 @@ protected List<String> allNamesIn(String object) {
final List<String>[] variables = new List[1];

groovyThread.enqueue(
new GroovyAction( "zzz1 = new java.util.ArrayList();",
new ScriptAction( "zzz1 = new java.util.ArrayList();",
new Hook() {
public void run(Object o) {
synchronized (variables) {
Expand Down
Expand Up @@ -32,7 +32,7 @@
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.scripting.Activator;
import net.bioclipse.scripting.Hook;
import net.bioclipse.scripting.JsAction;
import net.bioclipse.scripting.ScriptAction;
import net.bioclipse.scripting.JsThread;

import org.apache.log4j.Logger;
Expand Down Expand Up @@ -77,7 +77,7 @@ private void executeJsCommand(final String command) {
Activator.getDefault().JS_THREAD = jsThread = new JsThread();
jsThread.start();
}
jsThread.enqueue(new JsAction(command,
jsThread.enqueue(new ScriptAction(command,
new Hook() {
public void run(final Object result) {
Display.getDefault().asyncExec(new Runnable() {
Expand Down Expand Up @@ -654,7 +654,7 @@ protected List<String> allNamesIn(String object) {
final List<String>[] variables = new List[1];

jsThread.enqueue(
new JsAction( "zzz1 = new java.util.ArrayList();"
new ScriptAction( "zzz1 = new java.util.ArrayList();"
+ "for (var zzz3 in " + object
+ ") { zzz1.add(zzz3) } zzz1",
new Hook() {
Expand Down
Expand Up @@ -35,7 +35,7 @@ public class GroovyThread extends ScriptingThread {
private static volatile boolean firstTime = true;

public static GroovyEnvironment groovy;
private LinkedList<GroovyAction> actions= new LinkedList<GroovyAction>();
private LinkedList<ScriptAction> actions= new LinkedList<ScriptAction>();

private static Writer outputWriter;

Expand Down Expand Up @@ -90,7 +90,7 @@ public void run() {
break;
}

final GroovyAction nextAction = actions.removeFirst();
final ScriptAction nextAction = actions.removeFirst();
final Object[] result = new Object[1];
busy = true;
final Boolean[] groovyRunning = { true };
Expand Down Expand Up @@ -192,7 +192,7 @@ protected IStatus run( IProgressMonitor pm ) {
}
}

public synchronized void enqueue(GroovyAction action) {
public synchronized void enqueue(ScriptAction action) {
synchronized (actions) {
actions.addLast( action );
actions.notifyAll();
Expand All @@ -204,7 +204,7 @@ public static synchronized boolean isBusy() {
}

public void enqueue(String command) {
enqueue( new GroovyAction( command,
enqueue( new ScriptAction( command,
new Hook() { public void run(Object s) {} } ) );
}

Expand Down

This file was deleted.

Expand Up @@ -34,7 +34,7 @@ public class JsThread extends ScriptingThread {
private static volatile boolean firstTime = true;

public static JsEnvironment js;
private LinkedList<JsAction> actions= new LinkedList<JsAction>();
private LinkedList<ScriptAction> actions= new LinkedList<ScriptAction>();

private static final Logger logger = Logger.getLogger(JsEnvironment.class);
private static boolean busy;
Expand Down Expand Up @@ -62,7 +62,7 @@ public void run() {

busy = false;
while (true) {
final JsAction[] nextAction = new JsAction[1];
final ScriptAction[] nextAction = new ScriptAction[1];
synchronized (actions) {
try {
while ( actions.isEmpty() )
Expand Down Expand Up @@ -172,7 +172,7 @@ protected IStatus run( IProgressMonitor pm ) {
}
}

public synchronized void enqueue(JsAction action) {
public synchronized void enqueue(ScriptAction action) {
synchronized (actions) {
actions.addLast( action );
actions.notifyAll();
Expand All @@ -184,7 +184,7 @@ public static synchronized boolean isBusy() {
}

public void enqueue(String command) {
enqueue( new JsAction( command,
enqueue( new ScriptAction( command,
new Hook() { public void run(Object s) {} } ) );
}

Expand Down
Expand Up @@ -8,16 +8,16 @@
*******************************************************************************/
package net.bioclipse.scripting;

public class GroovyAction {
public class ScriptAction {
private String command;
private Hook preCommandHook;
private Hook postCommandHook;

public GroovyAction(String command, Hook postCommandHook) {
public ScriptAction(String command, Hook postCommandHook) {
this(command, null, postCommandHook);
}

public GroovyAction(String command, Hook preCommandHook, Hook postCommandHook) {
public ScriptAction(String command, Hook preCommandHook, Hook postCommandHook) {

this.command = command;
this.preCommandHook = preCommandHook;
Expand Down

0 comments on commit cb60215

Please sign in to comment.