Author: koen.aers(a)jboss.com
Date: 2012-01-24 13:57:04 -0500 (Tue, 24 Jan 2012)
New Revision: 38114
Removed:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocumentPartitioner.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/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocument.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/startup/ForgeStarter.java
Log:
JBIDE-10685: Restart Forge When Default Runtime Preference Changes
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-24
18:17:47 UTC (rev 38113)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/preferences/ForgeRuntimesPreferences.java 2012-01-24
18:57:04 UTC (rev 38114)
@@ -20,6 +20,7 @@
import javax.xml.transform.stream.StreamResult;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import
org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.jboss.tools.forge.core.ForgeCorePlugin;
import org.jboss.tools.forge.core.process.ForgeEmbeddedRuntime;
@@ -34,8 +35,8 @@
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 String PREF_FORGE_RUNTIMES =
"org.jboss.tools.forge.core.runtimes";
+ public static final String PREF_FORGE_STARTUP =
"org.jboss.tools.forge.core.startup";
public static final ForgeRuntimesPreferences INSTANCE = new ForgeRuntimesPreferences();
@@ -159,6 +160,14 @@
}
}
+ public void addPreferenceChangeListener(IPreferenceChangeListener listener) {
+ getForgeCorePreferences().addPreferenceChangeListener(listener);
+ }
+
+ public void removePreferenceChangeListener(IPreferenceChangeListener listener) {
+ getForgeCorePreferences().removePreferenceChangeListener(listener);
+ }
+
private void saveRuntimes() {
try {
IEclipsePreferences eclipsePreferences = getForgeCorePreferences();
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-24
18:17:47 UTC (rev 38113)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java 2012-01-24
18:57:04 UTC (rev 38114)
@@ -51,7 +51,6 @@
}
}
-// private ForgeRuntime runtime;
private DocumentListener documentListener = new DocumentListener();
public ForgeTextViewer(Composite parent) {
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocument.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocument.java 2012-01-24
18:17:47 UTC (rev 38113)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocument.java 2012-01-24
18:57:04 UTC (rev 38114)
@@ -1,7 +1,5 @@
package org.jboss.tools.forge.ui.document;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -41,23 +39,7 @@
});
}
}
-
- private PropertyChangeListener pcl = new PropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- if (ForgeRuntime.PROPERTY_STATE.equals(evt.getPropertyName())) {
- if (ForgeRuntime.STATE_NOT_RUNNING.equals(evt.getNewValue())) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- disconnect();
- }
- });
- }
- }
- }
- };
-
+
private ForgeRuntime runtime;
private int cursorOffset = 0;
private StyleRange currentStyleRange;
@@ -76,8 +58,8 @@
}
public void connect(ForgeRuntime runtime) {
+ disconnect();
this.runtime = runtime;
- runtime.addPropertyChangeListener(pcl);
ForgeOutputListener target = new ForgeOutputListener() {
@Override
public void outputAvailable(String output) {
@@ -95,9 +77,10 @@
}
private void disconnect() {
- runtime.removeOutputListener(outputListener);
- runtime.removePropertyChangeListener(pcl);
- runtime = null;
+ if (runtime != null) {
+ runtime.removeOutputListener(outputListener);
+ runtime = null;
+ }
reset();
}
@@ -177,7 +160,6 @@
}
private void clearCurrentScreenPage(String command) {
- System.out.println("clearCurrentScreenPage(" + command + ")");
String str = command.substring(2, command.length() - 1);
if ("2".equals(str)) {
reset();
Deleted:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocumentPartitioner.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocumentPartitioner.java 2012-01-24
18:17:47 UTC (rev 38113)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocumentPartitioner.java 2012-01-24
18:57:04 UTC (rev 38114)
@@ -1,58 +0,0 @@
-package org.jboss.tools.forge.ui.document;
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.ITypedRegion;
-
-public class ForgeDocumentPartitioner implements IDocumentPartitioner {
-
- @Override
- public void connect(IDocument document) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void disconnect() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void documentAboutToBeChanged(DocumentEvent event) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean documentChanged(DocumentEvent event) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public String[] getLegalContentTypes() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getContentType(int offset) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ITypedRegion[] computePartitioning(int offset, int length) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ITypedRegion getPartition(int offset) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
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-24
18:17:47 UTC (rev 38113)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java 2012-01-24
18:57:04 UTC (rev 38114)
@@ -4,6 +4,8 @@
import java.beans.PropertyChangeListener;
import org.eclipse.core.resources.IResource;
+import
org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -29,6 +31,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
{
@@ -60,6 +63,7 @@
private Page runningPage;
private MessagePage notRunningPage;
private String notRunningMessage;
+ private ForgeRuntime currentRuntime;
private ISelection selection;
private SelectionSynchronizer synchronizer;
@@ -70,6 +74,24 @@
}
};
+ private IPreferenceChangeListener preferenceChangeListener = new
IPreferenceChangeListener() {
+ @Override
+ public void preferenceChange(PreferenceChangeEvent event) {
+ if (ForgeRuntimesPreferences.PREF_FORGE_RUNTIMES.equals(event.getKey())) {
+ ForgeRuntime newRuntime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
+ if (!newRuntime.getName().equals(currentRuntime.getName())) {
+ ForgeRuntime oldRuntime = currentRuntime;
+ oldRuntime.stop(null);
+ oldRuntime.removePropertyChangeListener(ForgeView.this);
+ currentRuntime = newRuntime;
+ currentRuntime.addPropertyChangeListener(ForgeView.this);
+ ForgeDocument.INSTANCE.connect(currentRuntime);
+ ForgeHelper.startForge();
+ }
+ }
+ }
+ };
+
@Override
public void createPartControl(Composite parent) {
synchronizer = new SelectionSynchronizer(this);
@@ -77,11 +99,12 @@
createRunningPage();
createNotRunningPage();
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(selectionListener);
- ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
- if (runtime != null) {
- updatePages(runtime.getState());
- runtime.addPropertyChangeListener(this);
+ currentRuntime = ForgeRuntimesPreferences.INSTANCE.getDefaultRuntime();
+ if (currentRuntime != null) {
+ updatePages(currentRuntime.getState());
+ currentRuntime.addPropertyChangeListener(this);
}
+ ForgeRuntimesPreferences.INSTANCE.addPreferenceChangeListener(preferenceChangeListener);
}
public ISelection getSelection() {
Modified:
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 2012-01-24
18:17:47 UTC (rev 38113)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/startup/ForgeStarter.java 2012-01-24
18:57:04 UTC (rev 38114)
@@ -1,5 +1,6 @@
package org.jboss.tools.forge.ui.startup;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IStartup;
import org.jboss.tools.forge.core.preferences.ForgeRuntimesPreferences;
import org.jboss.tools.forge.ui.util.ForgeHelper;
@@ -9,7 +10,12 @@
@Override
public void earlyStartup() {
if (ForgeRuntimesPreferences.INSTANCE.getStartup()) {
- ForgeHelper.startForge();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ ForgeHelper.startForge();
+ }
+ });
}
}