Author: koen.aers(a)jboss.com
Date: 2012-01-22 06:57:42 -0500 (Sun, 22 Jan 2012)
New Revision: 38017
Added:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/preferences/ForgeStartupPreferencePage.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/startup/
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/startup/ForgeStarter.java
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/preferences/ForgeRuntimesPreferences.java
trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.xml
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/ForgeCommandListHandler.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/StartHandler.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/StopHandler.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeCommandProcessor.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/NewProjectPostProcessor.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/dialog/ForgeCommandListDialog.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/preferences/ForgeInstallationsPreferencePage.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/util/ForgeHelper.java
Log:
JBIDE-10272: Automatically Start Forge When Eclipse Starts
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/preferences/ForgeRuntimesPreferences.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/preferences/ForgeRuntimesPreferences.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/preferences/ForgeRuntimesPreferences.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -35,6 +35,7 @@
public class ForgeRuntimesPreferences {
static final String PREF_FORGE_RUNTIMES =
"org.jboss.tools.forge.core.runtimes";
+ static final String PREF_FORGE_STARTUP =
"org.jboss.tools.forge.core.startup";
public static final ForgeRuntimesPreferences INSTANCE = new ForgeRuntimesPreferences();
@@ -50,13 +51,18 @@
return (ForgeRuntime[])runtimes.toArray(new ForgeRuntime[runtimes.size()]);
}
- public ForgeRuntime getDefault() {
+ public ForgeRuntime getDefaultRuntime() {
if (defaultRuntime == null) {
initializeRuntimes();
}
return defaultRuntime;
}
+ public boolean getStartup() {
+ return getForgeCorePreferences().getBoolean(PREF_FORGE_STARTUP, false);
+
+ }
+
private IEclipsePreferences getForgeCorePreferences() {
return InstanceScope.INSTANCE.getNode(ForgeCorePlugin.PLUGIN_ID);
}
@@ -143,6 +149,16 @@
saveRuntimes();
}
+ public void setStartup(boolean startup) {
+ try {
+ IEclipsePreferences eclipsePreferences = getForgeCorePreferences();
+ eclipsePreferences.putBoolean(PREF_FORGE_STARTUP, startup);
+ eclipsePreferences.flush();
+ } catch (BackingStoreException e) {
+ ForgeCorePlugin.log(e);
+ }
+ }
+
private void saveRuntimes() {
try {
IEclipsePreferences eclipsePreferences = getForgeCorePreferences();
Modified: trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.xml
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.xml 2012-01-21 22:05:19 UTC (rev
38016)
+++ trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.xml 2012-01-22 11:57:42 UTC (rev
38017)
@@ -19,7 +19,7 @@
<extension point="org.eclipse.ui.preferencePages">
<page
name="Forge"
- class="org.jboss.tools.forge.ui.preferences.ForgeEmptyPreferencePage"
+ class="org.jboss.tools.forge.ui.preferences.ForgeStartupPreferencePage"
id="org.jboss.tools.forge">
</page>
<page
@@ -185,4 +185,10 @@
</variable>
</sourceProvider>
</extension>
+ <extension
+ point="org.eclipse.ui.startup">
+ <startup
+ class="org.jboss.tools.forge.ui.startup.ForgeStarter">
+ </startup>
+ </extension>
</plugin>
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/ForgeCommandListHandler.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/ForgeCommandListHandler.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/ForgeCommandListHandler.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -5,7 +5,6 @@
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
@@ -14,6 +13,7 @@
import org.jboss.tools.forge.ui.ForgeUIPlugin;
import org.jboss.tools.forge.ui.dialog.ForgeCommandListDialog;
import org.jboss.tools.forge.ui.part.ForgeView;
+import org.jboss.tools.forge.ui.util.ForgeHelper;
public class ForgeCommandListHandler extends AbstractHandler {
@@ -22,31 +22,24 @@
if (window == null) {
return null;
}
- ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
- if (isStarting(runtime)) {
+ showForgeView(window);
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
+ if (ForgeHelper.isForgeStarting()) {
showWaitUntilStartedMessage();
- } else if (!(isRunning(runtime))) {
- askUserToStartRuntime(window);
+ } else if (!ForgeHelper.isForgeRunning()) {
+ askUserToStartRuntime();
}
if (runtime != null && ForgeRuntime.STATE_RUNNING.equals(runtime.getState()))
{
new ForgeCommandListDialog(window, runtime).open();
}
- return null;
+ return null;
}
- private boolean isStarting(ForgeRuntime runtime) {
- return runtime != null &&
ForgeRuntime.STATE_STARTING.equals(runtime.getState());
- }
-
- private boolean isRunning(ForgeRuntime runtime) {
- return runtime != null &&
ForgeRuntime.STATE_RUNNING.equals(runtime.getState());
- }
-
private void showWaitUntilStartedMessage() {
MessageDialog.openInformation(null, "Forge Starting", "Forge is
starting. Please wait until the Forge runtime is started");
}
- private void askUserToStartRuntime(final IWorkbenchWindow window) {
+ private void askUserToStartRuntime() {
boolean start = MessageDialog.open(
MessageDialog.QUESTION,
null,
@@ -57,17 +50,18 @@
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
- try {
- IViewPart part = window.getActivePage().showView(ForgeView.ID);
- if (part != null && part instanceof ForgeView) {
- ((ForgeView)part).startForge();
- }
- } catch (PartInitException e) {
- ForgeUIPlugin.log(e);
- }
+ ForgeHelper.startForge();
}
});
}
}
+
+ private void showForgeView(IWorkbenchWindow window) {
+ try {
+ window.getActivePage().showView(ForgeView.ID);
+ } catch (PartInitException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
}
\ No newline at end of file
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/StartHandler.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/StartHandler.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/StartHandler.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -10,7 +10,7 @@
public Object execute(ExecutionEvent executionEvent) {
ForgeView forgeView = ForgeHelper.getForgeView();
if (forgeView != null) {
- forgeView.startForge();
+ ForgeHelper.startForge();
}
return null;
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/StopHandler.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/StopHandler.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/StopHandler.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -2,16 +2,12 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
-import org.jboss.tools.forge.ui.part.ForgeView;
import org.jboss.tools.forge.ui.util.ForgeHelper;
public class StopHandler extends AbstractHandler {
public Object execute(ExecutionEvent executionEvent) {
- ForgeView forgeView = ForgeHelper.getForgeView();
- if (forgeView != null) {
- forgeView.stopForge();
- }
+ ForgeHelper.stopForge();
return null;
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeCommandProcessor.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeCommandProcessor.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeCommandProcessor.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -7,9 +7,9 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.forge.ui.ForgeUIPlugin;
import org.jboss.tools.forge.ui.part.ForgeView;
@@ -81,13 +81,17 @@
}
private void showForgeConsole() {
- try {
+// try {
IWorkbenchWindow workbenchWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
- workbenchPage.showView(ForgeView.ID).setFocus();
- } catch (PartInitException e) {
- ForgeUIPlugin.log(e);
- }
+ IViewPart forgeView = workbenchPage.findView(ForgeView.ID);
+ if (forgeView != null) {
+ forgeView.setFocus();
+ }
+// workbenchPage.showView(ForgeView.ID).setFocus();
+// } catch (PartInitException e) {
+// ForgeUIPlugin.log(e);
+// }
}
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -129,7 +129,7 @@
}
private ForgeRuntime getRuntime() {
- return ForgeRuntimesPreferences.INSTANCE.getDefault();
+ return ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
}
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/NewProjectPostProcessor.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/NewProjectPostProcessor.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/NewProjectPostProcessor.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -69,7 +69,7 @@
private void resetRuntime() {
ForgeView forgeView = ForgeHelper.getForgeView();
if (forgeView != null) {
- ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
if (runtime != null && ForgeRuntime.STATE_RUNNING.equals(runtime.getState()))
{
runtime.sendInput("reset\n");
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/dialog/ForgeCommandListDialog.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/dialog/ForgeCommandListDialog.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/dialog/ForgeCommandListDialog.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -191,5 +191,5 @@
protected Control getFocusControl() {
return filterText;
}
-
+
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -4,10 +4,6 @@
import java.beans.PropertyChangeListener;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -33,7 +29,7 @@
import org.jboss.tools.forge.ui.ForgeUIPlugin;
import org.jboss.tools.forge.ui.commands.SourceProvider;
import org.jboss.tools.forge.ui.console.ForgeTextViewer;
-import org.jboss.tools.forge.ui.document.ForgeDocument;
+import org.jboss.tools.forge.ui.util.ForgeHelper;
public class ForgeView extends ViewPart implements PropertyChangeListener, IShowInTarget
{
@@ -67,6 +63,12 @@
private ISelection selection;
private SelectionSynchronizer synchronizer;
+ private ISelectionListener selectionListener = new ISelectionListener() {
+ @Override
+ public void selectionChanged(IWorkbenchPart part, ISelection newSelection) {
+ selection = newSelection;
+ }
+ };
@Override
public void createPartControl(Composite parent) {
@@ -74,13 +76,12 @@
pageBook = new PageBook(parent, SWT.NONE);
createRunningPage();
createNotRunningPage();
- showPage(notRunning);
- getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(new
ISelectionListener() {
- @Override
- public void selectionChanged(IWorkbenchPart part, ISelection newSelection) {
- selection = newSelection;
- }
- });
+ getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(selectionListener);
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
+ if (runtime != null) {
+ updatePages(runtime.getState());
+ runtime.addPropertyChangeListener(this);
+ }
}
public ISelection getSelection() {
@@ -116,22 +117,52 @@
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (ForgeRuntime.PROPERTY_STATE.equals(evt.getPropertyName())) {
- if (ForgeRuntime.STATE_STARTING.equals(evt.getNewValue())) {
- handleStateStarting();
- } else if (ForgeRuntime.STATE_RUNNING.equals(evt.getNewValue())) {
- handleStateRunning();
- } else if (ForgeRuntime.STATE_NOT_RUNNING.equals(evt.getNewValue())) {
- handleStateNotRunning();
- }
+ updatePages(evt.getNewValue());
}
}
+ public void dispose() {
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
+ if (runtime != null) {
+ runtime.removePropertyChangeListener(this);
+ }
+ getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(selectionListener);
+ runningPage.dispose();
+ notRunningPage.dispose();
+ pageBook.dispose();
+ super.dispose();
+ }
+
+ private void updatePages(Object state) {
+ if (ForgeRuntime.STATE_STARTING.equals(state)) {
+ handleStateStarting();
+ } else if (ForgeRuntime.STATE_RUNNING.equals(state)) {
+ handleStateRunning();
+ } else if (ForgeRuntime.STATE_NOT_RUNNING.equals(state)) {
+ handleStateNotRunning();
+ }
+ }
+
private void handleStateStarting() {
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
notRunningMessage = STARTING_MESSAGE;
notRunningPage.setMessage(notRunningMessage);
+ Thread waitThread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ while (!ForgeHelper.isForgeRunning()) {
+ try {
+ Thread.sleep(1000);
+ updateNonRunningPage();
+ } catch (InterruptedException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+ }
+ });
+ waitThread.start();
}
});
}
@@ -147,10 +178,6 @@
}
private void handleStateNotRunning() {
- ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
- if (runtime != null) {
- runtime.removePropertyChangeListener(this);
- }
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
@@ -183,50 +210,6 @@
}
}
-// private void createRunningPage() {
-// Control oldForgeIsRunning = running;
-// Page oldForgeIsRunningPage = runningPage;
-// runningPage = new ForgePage(runtime);
-// runningPage.createControl(pageBook);
-// runningPage.init(new PageSite(getViewSite()));
-// running = runningPage.getControl();
-// if (oldForgeIsRunningPage != null) {
-// oldForgeIsRunningPage.dispose();
-// }
-// if (oldForgeIsRunning != null) {
-// oldForgeIsRunning.dispose();
-// }
-// }
-
- public void startForge() {
- final ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
- if (ForgeRuntime.STATE_RUNNING.equals(runtime.getState())) return;
- ForgeDocument.INSTANCE.connect(runtime);
- runtime.addPropertyChangeListener(this);
- Job job = new Job("Starting Forge") {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- runtime.start(monitor);
- return Status.OK_STATUS;
- }
- };
- job.schedule();
- Thread waitThread = new Thread(new Runnable() {
- @Override
- public void run() {
- while (runtime != null &&
!ForgeRuntime.STATE_RUNNING.equals(runtime.getState())) {
- try {
- Thread.sleep(1000);
- updateNonRunningPage();
- } catch (InterruptedException e) {
- ForgeUIPlugin.log(e);
- }
- }
- }
- });
- waitThread.start();
- }
-
private void updateNonRunningPage() {
getDisplay().asyncExec(new Runnable() {
@Override
@@ -237,12 +220,6 @@
});
}
- public void stopForge() {
- IProgressMonitor progressMonitor =
getViewSite().getActionBars().getStatusLineManager().getProgressMonitor();
- ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
- runtime.stop(progressMonitor);
- }
-
private Display getDisplay() {
return getSite().getShell().getDisplay();
}
@@ -251,8 +228,7 @@
if (context == null) {
return false;
}
- ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
- if (runtime != null &&
ForgeRuntime.STATE_RUNNING.equals(runtime.getState())) {
+ if (ForgeHelper.isForgeRunning()) {
return goToSelection(context.getSelection());
} else {
return startForgeIsOK(context);
@@ -267,12 +243,11 @@
"Forge is not running. Do you want to start the Forge runtime?",
SWT.NONE);
if (start) {
- startForge();
+ ForgeHelper.startForge();
Thread waitThread = new Thread(new Runnable() {
@Override
public void run() {
- ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
- while (runtime != null &&
!ForgeRuntime.STATE_RUNNING.equals(runtime.getState())) {
+ while (!ForgeHelper.isForgeRunning()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@@ -315,7 +290,7 @@
if (str.indexOf(' ') != -1) {
str = '\"' + str + '\"';
}
- ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
runtime.sendInput("pick-up " + str + "\n");
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -43,7 +43,7 @@
if (path.indexOf(' ') != -1) {
path = '\"' + path + '\"';
}
- ForgeRuntime forgeRuntime = ForgeRuntimesPreferences.INSTANCE.getDefault();
+ ForgeRuntime forgeRuntime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
if (forgeRuntime != null &&
ForgeRuntime.STATE_RUNNING.equals(forgeRuntime.getState())) {
forgeRuntime.sendInput("pick-up " + path + "\n");
}
@@ -84,7 +84,7 @@
if (path.indexOf(' ') != -1) {
path = '\"' + path + '\"';
}
- ForgeRuntime forgeRuntime = ForgeRuntimesPreferences.INSTANCE.getDefault();
+ ForgeRuntime forgeRuntime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
if (forgeRuntime != null &&
ForgeRuntime.STATE_RUNNING.equals(forgeRuntime.getState())) {
forgeRuntime.sendInput("pick-up " + path + "\n");
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/preferences/ForgeInstallationsPreferencePage.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/preferences/ForgeInstallationsPreferencePage.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/preferences/ForgeInstallationsPreferencePage.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -245,7 +245,7 @@
} else if (runtime instanceof ForgeExternalRuntime) {
copy = new ForgeExternalRuntime(runtime.getName(), runtime.getLocation());
}
- if (runtime == ForgeRuntimesPreferences.INSTANCE.getDefault()) {
+ if (runtime == ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime()) {
defaultRuntime = copy;
}
runtimes.add(copy);
Added:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/preferences/ForgeStartupPreferencePage.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/preferences/ForgeStartupPreferencePage.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/preferences/ForgeStartupPreferencePage.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -0,0 +1,49 @@
+package org.jboss.tools.forge.ui.preferences;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.jboss.tools.forge.core.preferences.ForgeRuntimesPreferences;
+
+public class ForgeStartupPreferencePage extends PreferencePage implements
+ IWorkbenchPreferencePage {
+
+ private Button startupButton;
+
+ protected Control createContents(Composite parent) {
+ noDefaultAndApplyButton();
+ Composite clientArea = createClientArea(parent);
+ createStartupButton(clientArea);
+ return null;
+ }
+
+ private void createStartupButton(Composite parent) {
+ startupButton = new Button(parent, SWT.CHECK);
+ startupButton.setText("Start Forge when Eclipse starts." );
+ startupButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ startupButton.setSelection(ForgeRuntimesPreferences.INSTANCE.getStartup());
+ }
+
+ private Composite createClientArea(Composite parent) {
+ Composite clientArea = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ clientArea.setLayout(layout);
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ clientArea.setLayoutData(gridData);
+ return clientArea;
+ }
+
+ public void init(IWorkbench workbench) {}
+
+ public boolean performOk() {
+ ForgeRuntimesPreferences.INSTANCE.setStartup(startupButton.getSelection());
+ return true;
+ }
+}
Property changes on:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/preferences/ForgeStartupPreferencePage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/startup/ForgeStarter.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/startup/ForgeStarter.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/startup/ForgeStarter.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -0,0 +1,18 @@
+package org.jboss.tools.forge.ui.startup;
+
+import org.eclipse.ui.IStartup;
+import org.jboss.tools.forge.core.preferences.ForgeRuntimesPreferences;
+import org.jboss.tools.forge.ui.util.ForgeHelper;
+
+public class ForgeStarter implements IStartup {
+
+ @Override
+ public void earlyStartup() {
+ if (ForgeRuntimesPreferences.INSTANCE.getStartup()) {
+ ForgeHelper.startForge();
+ }
+ }
+
+
+
+}
Property changes on:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/startup/ForgeStarter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/util/ForgeHelper.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/util/ForgeHelper.java 2012-01-21
22:05:19 UTC (rev 38016)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/util/ForgeHelper.java 2012-01-22
11:57:42 UTC (rev 38017)
@@ -1,10 +1,17 @@
package org.jboss.tools.forge.ui.util;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.forge.core.preferences.ForgeRuntimesPreferences;
+import org.jboss.tools.forge.core.process.ForgeRuntime;
+import org.jboss.tools.forge.ui.document.ForgeDocument;
import org.jboss.tools.forge.ui.part.ForgeView;
public class ForgeHelper {
@@ -24,4 +31,41 @@
}
}
+ public static void startForge() {
+ final ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
+ if (runtime == null || ForgeRuntime.STATE_RUNNING.equals(runtime.getState())) return;
+ ForgeDocument.INSTANCE.connect(runtime);
+ Job job = new Job("Starting Forge") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ runtime.start(monitor);
+ return Status.OK_STATUS;
+ }
+ };
+ job.schedule();
+ }
+
+ public static void stopForge() {
+ final ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
+ if (runtime == null || ForgeRuntime.STATE_NOT_RUNNING.equals(runtime.getState()))
return;
+ Job job = new Job("Stopping Forge") {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ runtime.stop(monitor);
+ return Status.OK_STATUS;
+ }
+ };
+ job.schedule();
+ }
+
+ public static boolean isForgeRunning() {
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
+ return runtime != null &&
ForgeRuntime.STATE_RUNNING.equals(runtime.getState());
+ }
+
+ public static boolean isForgeStarting() {
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
+ return runtime != null &&
ForgeRuntime.STATE_STARTING.equals(runtime.getState());
+ }
+
}