Skip to content

Commit

Permalink
keep track of ForgeRuntime in F1 StartAction
Browse files Browse the repository at this point in the history
  • Loading branch information
koentsje committed May 6, 2014
1 parent f74d4a0 commit 10c2fd6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Expand Up @@ -4,24 +4,29 @@

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.jboss.tools.forge.core.runtime.ForgeRuntime;
import org.jboss.tools.forge.core.runtime.ForgeRuntimeState;
import org.jboss.tools.forge.ui.internal.ForgeUIPlugin;
import org.jboss.tools.forge.ui.util.ForgeHelper;

public class StartAction extends Action {

ForgeRuntime runtime;

public StartAction() {
public StartAction(ForgeRuntime runtime) {
super();
this.runtime = runtime;
setImageDescriptor(createImageDescriptor());
}

@Override
public void run() {
ForgeHelper.startForge();
ForgeHelper.start(runtime);
}

@Override
public boolean isEnabled() {
return !ForgeHelper.isForgeRunning();
return ForgeRuntimeState.STOPPED.equals(runtime.getState());
}

private ImageDescriptor createImageDescriptor() {
Expand Down
Expand Up @@ -38,7 +38,7 @@ public Control createControl(Composite parent) {
@Override
public IAction[] createActions() {
return new IAction[] {
new StartAction(),
new StartAction(getRuntime()),
new StopAction(),
new GoToAction(),
new LinkAction()
Expand All @@ -53,6 +53,10 @@ public ForgeRuntime getRuntime() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (!ForgeRuntime.PROPERTY_STATE.equals(evt.getPropertyName())) return;
if (ForgeRuntimeState.STOPPED.equals(evt.getOldValue())
&& ForgeRuntimeState.STARTING.equals(evt.getNewValue())) {
forgeTextViewer.startConsole();
}
if (ForgeRuntimeState.STOPPED.equals(evt.getNewValue())) {
forgeTextViewer.stopConsole();
}
Expand Down
Expand Up @@ -171,4 +171,14 @@ public void run() {
});
}

public void startConsole() {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
forgeDocument.connect(getRuntime());
setDocument(forgeDocument);
}
});
}

}
Expand Up @@ -10,9 +10,14 @@
import org.jboss.tools.forge.core.runtime.ForgeRuntime;
import org.jboss.tools.forge.core.runtime.ForgeRuntimeState;
import org.jboss.tools.forge.ui.internal.document.ForgeDocument;
import org.jboss.tools.forge.ui.internal.ext.util.FurnaceHelper;

public class ForgeHelper {

public static void start(ForgeRuntime runtime) {
FurnaceHelper.createStartRuntimeJob(runtime).schedule();
}

public static void startForge() {
final ForgeRuntime runtime = ForgeCorePreferences.INSTANCE.getDefaultRuntime();
if (runtime == null || ForgeRuntimeState.RUNNING.equals(runtime.getState())) return;
Expand Down

0 comments on commit 10c2fd6

Please sign in to comment.