Author: koen.aers(a)jboss.com
Date: 2012-01-20 17:18:46 -0500 (Fri, 20 Jan 2012)
New Revision: 38007
Added:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/
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/ForgeDocumentPartitioner.java
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/console/ForgeCommandFilter.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/part/ForgeView.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java
Log:
JBIDE-10000: Decouple Forge Runtime and Forge Console
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-20
21:26:21 UTC (rev 38006)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/ForgeCommandListHandler.java 2012-01-20
22:18:46 UTC (rev 38007)
@@ -9,6 +9,7 @@
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.forge.core.preferences.ForgeRuntimesPreferences;
import org.jboss.tools.forge.core.process.ForgeRuntime;
import org.jboss.tools.forge.ui.ForgeUIPlugin;
import org.jboss.tools.forge.ui.dialog.ForgeCommandListDialog;
@@ -21,7 +22,7 @@
if (window == null) {
return null;
}
- ForgeRuntime runtime = getForgeRuntime(window);
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
if (isStarting(runtime)) {
showWaitUntilStartedMessage();
} else if (!(isRunning(runtime))) {
@@ -41,20 +42,6 @@
return runtime != null &&
ForgeRuntime.STATE_RUNNING.equals(runtime.getState());
}
- private ForgeRuntime getForgeRuntime(IWorkbenchWindow window) {
- try {
- IViewPart part = window.getActivePage().showView(ForgeView.ID);
- if (part != null && part instanceof ForgeView) {
- return ((ForgeView)part).getRuntime();
- } else {
- return null;
- }
- } catch (PartInitException e) {
- ForgeUIPlugin.log(e);
- return null;
- }
- }
-
private void showWaitUntilStartedMessage() {
MessageDialog.openInformation(null, "Forge Starting", "Forge is
starting. Please wait until the Forge runtime is started");
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeCommandFilter.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeCommandFilter.java 2012-01-20
21:26:21 UTC (rev 38006)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeCommandFilter.java 2012-01-20
22:18:46 UTC (rev 38007)
@@ -26,5 +26,5 @@
}
}
}
-
+
}
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-20
21:26:21 UTC (rev 38006)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ForgeTextViewer.java 2012-01-20
22:18:46 UTC (rev 38007)
@@ -1,11 +1,6 @@
package org.jboss.tools.forge.ui.console;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.jface.text.TextViewer;
@@ -15,13 +10,10 @@
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.custom.VerifyKeyListener;
import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.jboss.tools.forge.core.io.ForgeAnsiCommandFilter;
-import org.jboss.tools.forge.core.io.ForgeOutputListener;
+import org.jboss.tools.forge.core.preferences.ForgeRuntimesPreferences;
import org.jboss.tools.forge.core.process.ForgeRuntime;
-import org.jboss.tools.forge.ui.ForgeUIPlugin;
+import org.jboss.tools.forge.ui.document.ForgeDocument;
public class ForgeTextViewer extends TextViewer {
@@ -34,98 +26,94 @@
private static String NEXT_HISTORY = new Character((char)14).toString();
private static String DELETE_NEXT_CHAR = new Character((char)127).toString();
- private class RuntimeStopListener implements PropertyChangeListener {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- if (ForgeRuntime.PROPERTY_STATE.equals(evt.getPropertyName()) &&
- ForgeRuntime.STATE_NOT_RUNNING.equals(evt.getNewValue())) {
- handleRuntimeStopped();
- }
- }
- }
-
- private class DocumentListener implements IDocumentListener {
+ private class DocumentListener implements IDocumentListener,
ForgeDocument.CursorListener {
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
}
@Override
public void documentChanged(final DocumentEvent event) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- StyledText textWidget = getTextWidget();
- if (textWidget != null && !textWidget.isDisposed()) {
- int lineCount = textWidget.getLineCount();
- textWidget.setTopIndex(lineCount - 1);
- }
- }
- });
+ StyledText textWidget = getTextWidget();
+ if (textWidget != null && !textWidget.isDisposed()) {
+ int lineCount = textWidget.getLineCount();
+ textWidget.setTopIndex(lineCount - 1);
+ StyleRange styleRange = ForgeDocument.INSTANCE.getCurrentStyleRange();
+ if (styleRange != null) {
+ textWidget.setStyleRange(styleRange);
+ }
+ }
}
+ @Override
+ public void cursorMoved() {
+ StyledText textWidget = getTextWidget();
+ if (textWidget != null && !textWidget.isDisposed()) {
+ textWidget.setCaretOffset(ForgeDocument.INSTANCE.getCursorOffset());
+ }
+ }
}
- private RuntimeStopListener stopListener;
- private ForgeOutputListener outputListener;
- private ForgeRuntime runtime;
- private Document document;
- private StyleRange currentStyleRange = null;
- private int caretOffset = 0;
+// private ForgeRuntime runtime;
+ private DocumentListener documentListener = new DocumentListener();
- public ForgeTextViewer(Composite parent, ForgeRuntime runtime) {
+ public ForgeTextViewer(Composite parent) {
super(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
- this.runtime = runtime;
initialize();
}
private void initialize() {
initDocument();
initViewer();
- initOutputListener();
- initStopListener();
}
private void initDocument() {
- document = new Document();
- document.addDocumentListener(new DocumentListener());
- setDocument(document);
+ ForgeDocument.INSTANCE.addDocumentListener(documentListener);
+ ForgeDocument.INSTANCE.addCursorListener(documentListener);
+ setDocument(ForgeDocument.INSTANCE);
}
private void initViewer() {
+ getTextWidget().setStyleRanges(ForgeDocument.INSTANCE.getStyleRanges());
getTextWidget().setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
getTextWidget().addVerifyKeyListener(new VerifyKeyListener() {
@Override
public void verifyKey(VerifyEvent event) {
if ((event.stateMask & SWT.CTRL) == SWT.CTRL ) {
if (event.keyCode == 'd') {
- runtime.sendInput(CTRL_D);
+ getRuntime().sendInput(CTRL_D);
} else if (event.keyCode == 'c') {
- runtime.sendInput(CTRL_C);
+ getRuntime().sendInput(CTRL_C);
}
}
}
});
}
+ protected void handleDispose() {
+ ForgeDocument.INSTANCE.removeCursorListener(documentListener);
+ ForgeDocument.INSTANCE.removeDocumentListener(documentListener);
+ super.handleDispose();
+ }
+
protected StyledText createTextWidget(Composite parent, int styles) {
StyledText styledText= new StyledText(parent, styles) {
public void invokeAction(int action) {
switch (action) {
case ST.LINE_UP:
- runtime.sendInput(PREV_HISTORY);
+ getRuntime().sendInput(PREV_HISTORY);
break;
case ST.LINE_DOWN:
- runtime.sendInput(NEXT_HISTORY);
+ getRuntime().sendInput(NEXT_HISTORY);
break;
case ST.COLUMN_PREVIOUS:
- runtime.sendInput(PREV_CHAR);
+ getRuntime().sendInput(PREV_CHAR);
break;
case ST.COLUMN_NEXT:
- runtime.sendInput(NEXT_CHAR);
+ getRuntime().sendInput(NEXT_CHAR);
break;
case ST.DELETE_PREVIOUS:
- runtime.sendInput(DELETE_PREV_CHAR);
+ getRuntime().sendInput(DELETE_PREV_CHAR);
break;
case ST.DELETE_NEXT:
- runtime.sendInput(DELETE_NEXT_CHAR);
+ getRuntime().sendInput(DELETE_NEXT_CHAR);
break;
default: super.invokeAction(action);
}
@@ -135,143 +123,13 @@
return styledText;
}
- private Color getColor(int colorCode) {
- return Display.getDefault().getSystemColor(colorCode);
- }
-
- private void initOutputListener() {
- ForgeOutputListener target = new ForgeOutputListener() {
- @Override
- public void outputAvailable(final String output) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- try {
- String filteredOutput = output.replaceAll("\r", "");
- document.replace(caretOffset, document.getLength() - caretOffset,
filteredOutput);
- getTextWidget().setCaretOffset(caretOffset = caretOffset +
filteredOutput.length());
- if (currentStyleRange != null) {
- currentStyleRange.length = currentStyleRange.length + filteredOutput.length();
- getTextWidget().setStyleRange(currentStyleRange);
- }
- } catch (BadLocationException e) {
- ForgeUIPlugin.log(e);
- }
- }
- });
- }
- };
- ForgeAnsiCommandFilter ansiCommandFilter = new ForgeAnsiCommandFilter(target) {
- @Override
- public void ansiCommandAvailable(String command) {
- executeAnsiCommand(command);
- }
- };
- outputListener = new ForgeCommandFilter(ansiCommandFilter);
- runtime.addOutputListener(outputListener);
- }
-
- private void initStopListener() {
- stopListener = new RuntimeStopListener();
- runtime.addPropertyChangeListener(stopListener);
- }
-
- private void handleRuntimeStopped() {
- runtime.removePropertyChangeListener(stopListener);
- stopListener = null;
- runtime.removeOutputListener(outputListener);
- outputListener = null;
- }
-
protected void handleVerifyEvent(VerifyEvent e) {
- runtime.sendInput(e.text);
+ getRuntime().sendInput(e.text);
e.doit = false;
}
- private void executeAnsiCommand(final String command) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- char c = command.charAt(command.length() - 1);
- switch (c) {
- case 'G' : moveCursorAbsoluteInLine(command); break;
- case 'K' : clearCurrentLine(command); break;
- case 'm' : changeColor(command); break;
- case 'H' : setCursorPosition(command); break;
- case 'J' : clearCurrentScreenPage(command); break;
- default : ForgeUIPlugin.log(new RuntimeException("Unhandled Ansi control
sequence in ForgeTextViewer: "+ command));
- }
- }
- });
+ private ForgeRuntime getRuntime() {
+ return ForgeRuntimesPreferences.INSTANCE.getDefault();
}
- private void moveCursorAbsoluteInLine(final String command) {
- try {
- int column = Integer.valueOf(command.substring(2, command.length() - 1));
- int lineStart = document.getLineOffset(document.getLineOfOffset(caretOffset));
- getTextWidget().setCaretOffset(caretOffset = lineStart + column - 1);
- } catch (BadLocationException e) {
- ForgeUIPlugin.log(e);
- }
- }
-
- private void clearCurrentLine(String command) {
- try {
- document.replace(caretOffset, document.getLength() - caretOffset,
"");
- } catch (BadLocationException e) {
- ForgeUIPlugin.log(e);
- }
- }
-
- private void changeColor(String command) {
- String str = command.substring(2, command.length() - 1);
- Color newColor = null;
- if ("30".equals(str)) {
- newColor = getColor(SWT.COLOR_BLACK);
- } else if ("31".equals(str)) {
- newColor = getColor(SWT.COLOR_RED);
- } else if ("32".equals(str)) {
- newColor = getColor(SWT.COLOR_GREEN);
- } else if ("33".equals(str)) {
- newColor = getColor(SWT.COLOR_DARK_YELLOW);
- } else if ("34".equals(str)) {
- newColor = getColor(SWT.COLOR_BLUE);
- } else if ("35".equals(str)) {
- newColor = getColor(SWT.COLOR_MAGENTA);
- } else if ("36".equals(str)) {
- newColor = getColor(SWT.COLOR_CYAN);
- } else if ("37".equals(str)) {
- newColor = getColor(SWT.COLOR_GRAY);
- }
- if (newColor != null) {
- currentStyleRange = new StyleRange(getTextWidget().getCharCount(), 0, newColor,
null);
- } else {
- currentStyleRange = null;
- }
- }
-
- private void setCursorPosition(String command) {
- String str = command.substring(2, command.length() - 1);
- int i = str.indexOf(';');
- int line = 0, column = 0;
- if (i != -1) {
- line = Integer.valueOf(str.substring(0, i));
- column = Integer.valueOf(str.substring(i + 1));
- } else if (str.length() > 0) {
- line = Integer.valueOf(str);
- }
- StyledText textWidget = getTextWidget();
- int offset = textWidget.getOffsetAtLine(line);
- int maxColumn = textWidget.getLine(line).length();
- offset += Math.min(maxColumn, column);
- getTextWidget().setCaretOffset(caretOffset = offset);
- }
-
- private void clearCurrentScreenPage(String command) {
- String str = command.substring(2, command.length() - 1);
- if ("2".equals(str)) {
- getDocument().set("");
- }
- }
-
}
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-20
21:26:21 UTC (rev 38006)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/NewProjectPostProcessor.java 2012-01-20
22:18:46 UTC (rev 38007)
@@ -7,6 +7,7 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
+import org.jboss.tools.forge.core.preferences.ForgeRuntimesPreferences;
import org.jboss.tools.forge.core.process.ForgeRuntime;
import org.jboss.tools.forge.importer.ProjectImporter;
import org.jboss.tools.forge.ui.part.ForgeView;
@@ -68,7 +69,7 @@
private void resetRuntime() {
ForgeView forgeView = ForgeHelper.getForgeView();
if (forgeView != null) {
- ForgeRuntime runtime = forgeView.getRuntime();
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
if (runtime != null && ForgeRuntime.STATE_RUNNING.equals(runtime.getState()))
{
runtime.sendInput("reset\n");
}
Added:
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
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocument.java 2012-01-20
22:18:46 UTC (rev 38007)
@@ -0,0 +1,240 @@
+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;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+import org.jboss.tools.forge.core.io.ForgeAnsiCommandFilter;
+import org.jboss.tools.forge.core.io.ForgeOutputListener;
+import org.jboss.tools.forge.core.process.ForgeRuntime;
+import org.jboss.tools.forge.ui.ForgeUIPlugin;
+import org.jboss.tools.forge.ui.console.ForgeCommandFilter;
+
+public class ForgeDocument extends Document {
+
+ public static final ForgeDocument INSTANCE = new ForgeDocument();
+
+ public interface CursorListener {
+ void cursorMoved();
+ }
+
+ private class AsyncForgeCommandFilter extends ForgeCommandFilter {
+ public AsyncForgeCommandFilter(ForgeOutputListener listener) {
+ super(listener);
+ }
+ public void outputAvailable(final String output) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ AsyncForgeCommandFilter.super.outputAvailable(output);
+ }
+ });
+ }
+ }
+
+ 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;
+ private ForgeOutputListener outputListener;
+ private Map<String, Color> colors;
+ private List<StyleRange> styleRanges = new ArrayList<StyleRange>();
+ private Set<CursorListener> cursorListeners = new
HashSet<CursorListener>();
+
+ private ForgeDocument() {
+ initColors();
+ }
+
+ public void finalize() throws Throwable {
+ disposeColors();
+ super.finalize();
+ }
+
+ public void connect(ForgeRuntime runtime) {
+ this.runtime = runtime;
+ runtime.addPropertyChangeListener(pcl);
+ ForgeOutputListener target = new ForgeOutputListener() {
+ @Override
+ public void outputAvailable(String output) {
+ handleAvailableOutput(output);
+ }
+ };
+ ForgeAnsiCommandFilter facf = new ForgeAnsiCommandFilter(target) {
+ @Override
+ public void ansiCommandAvailable(String command) {
+ executeAnsiCommand(command);
+ }
+ };
+ outputListener = new AsyncForgeCommandFilter(facf);
+ runtime.addOutputListener(outputListener);
+ }
+
+ private void disconnect() {
+ runtime.removeOutputListener(outputListener);
+ runtime.removePropertyChangeListener(pcl);
+ runtime = null;
+ reset();
+ }
+
+ private void executeAnsiCommand(final String command) {
+ char c = command.charAt(command.length() - 1);
+ switch (c) {
+ case 'G' : moveCursorAbsoluteInLine(command); break;
+ case 'K' : clearCurrentLine(command); break;
+ case 'm' : changeColor(command); break;
+ case 'H' : setCursorPosition(command); break;
+ case 'J' : clearCurrentScreenPage(command); break;
+ default : ForgeUIPlugin.log(new RuntimeException("Unhandled Ansi control
sequence in ForgeTextViewer: "+ command));
+ }
+
+ }
+
+ private void handleAvailableOutput(String output) {
+ try {
+ String filteredOutput = output.replaceAll("\r", "");
+ if (currentStyleRange != null) {
+ currentStyleRange.length = currentStyleRange.length + filteredOutput.length();
+ }
+ replace(cursorOffset, getLength() - cursorOffset, filteredOutput);
+ moveCursorTo(cursorOffset + filteredOutput.length());
+ } catch (BadLocationException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+
+ private void moveCursorAbsoluteInLine(final String command) {
+ try {
+ int column = Integer.valueOf(command.substring(2, command.length() - 1));
+ int lineStart = getLineOffset(getLineOfOffset(cursorOffset));
+ moveCursorTo(lineStart + column - 1);
+ } catch (BadLocationException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+
+ private void clearCurrentLine(String command) {
+ try {
+ replace(cursorOffset, getLength() - cursorOffset, "");
+ } catch (BadLocationException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+
+ private void changeColor(String command) {
+ String str = command.substring(2, command.length() - 1);
+ Color newColor = colors.get(str);
+ if (newColor != null) {
+ currentStyleRange = new StyleRange(getLength(), 0, newColor, null);
+ styleRanges.add(currentStyleRange);
+ } else {
+ currentStyleRange = null;
+ }
+ }
+
+ private void setCursorPosition(String command) {
+ String str = command.substring(2, command.length() - 1);
+ int i = str.indexOf(';');
+ int line = 0, column = 0;
+ if (i != -1) {
+ line = Integer.valueOf(str.substring(0, i));
+ column = Integer.valueOf(str.substring(i + 1));
+ } else if (str.length() > 0) {
+ line = Integer.valueOf(str);
+ }
+ try {
+ int offset = getLineOffset(line);
+ int maxColumn = getLineLength(line);
+ offset += Math.min(maxColumn, column);
+ moveCursorTo(offset);
+ } catch (BadLocationException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+
+ private void clearCurrentScreenPage(String command) {
+ System.out.println("clearCurrentScreenPage(" + command + ")");
+ String str = command.substring(2, command.length() - 1);
+ if ("2".equals(str)) {
+ reset();
+ }
+ }
+
+ private void reset() {
+ set("");
+ moveCursorTo(0);
+ styleRanges.clear();
+ currentStyleRange = null;
+ }
+
+ private void initColors() {
+ colors = new HashMap<String, Color>();
+ colors.put("30", new Color (Display.getDefault(), 0,0,0));
+ colors.put("31", new Color (Display.getDefault(), 0xFF,0,0));
+ colors.put("32", new Color (Display.getDefault(), 0,0xFF,0));
+ colors.put("33", new Color (Display.getDefault(), 0x80,0x80,0));
+ colors.put("34", new Color (Display.getDefault(), 0,0,0xFF));
+ colors.put("35", new Color (Display.getDefault(), 0xFF,0,0xFF));
+ colors.put("36", new Color (Display.getDefault(), 0,0xFF,0xFF));
+ colors.put("37", new Color (Display.getDefault(), 0xC0,0xC0,0xC0));
+ }
+
+ private void disposeColors() {
+ for (Color color : colors.values()) {
+ color.dispose();
+ }
+ colors = null;
+ }
+
+ public StyleRange getCurrentStyleRange() {
+ return currentStyleRange;
+ }
+
+ public StyleRange[] getStyleRanges() {
+ return styleRanges.toArray(new StyleRange[styleRanges.size()]);
+ }
+
+ public int getCursorOffset() {
+ return cursorOffset;
+ }
+
+ public void addCursorListener(CursorListener listener) {
+ cursorListeners.add(listener);
+ }
+
+ public void removeCursorListener(CursorListener listener) {
+ cursorListeners.remove(listener);
+ }
+
+ private void moveCursorTo(int newOffset) {
+ cursorOffset = newOffset;
+ for (CursorListener listener : cursorListeners) {
+ listener.cursorMoved();
+ }
+ }
+
+}
Property changes on:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocument.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocumentPartitioner.java 2012-01-20
22:18:46 UTC (rev 38007)
@@ -0,0 +1,58 @@
+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;
+ }
+
+}
Property changes on:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/document/ForgeDocumentPartitioner.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-20
21:26:21 UTC (rev 38006)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java 2012-01-20
22:18:46 UTC (rev 38007)
@@ -33,6 +33,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;
public class ForgeView extends ViewPart implements PropertyChangeListener, IShowInTarget
{
@@ -41,30 +42,20 @@
private static final String NOT_RUNNING_MESSAGE = "Forge is not running.";
private static final String STARTING_MESSAGE = "Please wait while Forge is
starting";
- private class ForgePage extends Page {
-
+ private class ForgePage extends Page {
private ForgeTextViewer viewer;
- private ForgeRuntime runtime;
-
- public ForgePage(ForgeRuntime runtime) {
- this.runtime = runtime;
- }
-
@Override
public void createControl(Composite parent) {
- viewer = new ForgeTextViewer(parent, runtime);
+ viewer = new ForgeTextViewer(parent);
}
-
@Override
public Control getControl() {
return viewer == null ? null : viewer.getControl();
}
-
@Override
public void setFocus() {
viewer.getControl().setFocus();
- }
-
+ }
}
private PageBook pageBook = null;
@@ -74,7 +65,6 @@
private MessagePage notRunningPage;
private String notRunningMessage;
- private ForgeRuntime runtime;
private ISelection selection;
private SelectionSynchronizer synchronizer;
@@ -82,7 +72,8 @@
public void createPartControl(Composite parent) {
synchronizer = new SelectionSynchronizer(this);
pageBook = new PageBook(parent, SWT.NONE);
- createNotRunningPage(parent);
+ createRunningPage();
+ createNotRunningPage();
showPage(notRunning);
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(new
ISelectionListener() {
@Override
@@ -100,7 +91,7 @@
synchronizer.setEnabled(synced);
}
- private void createNotRunningPage(Composite parent) {
+ private void createNotRunningPage() {
MessagePage page = new MessagePage();
page.createControl(pageBook);
page.init(new PageSite(getViewSite()));
@@ -110,11 +101,16 @@
notRunningPage = page;
}
+ private void createRunningPage() {
+ runningPage = new ForgePage();
+ runningPage.createControl(pageBook);
+ runningPage.init(new PageSite(getViewSite()));
+ running = runningPage.getControl();
+ }
+
@Override
public void setFocus() {
- if (runtime != null && ForgeRuntime.STATE_RUNNING.equals(runtime.getState()))
{
- runningPage.setFocus();
- }
+ runningPage.setFocus();
}
@Override
@@ -136,7 +132,6 @@
public void run() {
notRunningMessage = STARTING_MESSAGE;
notRunningPage.setMessage(notRunningMessage);
- createRunningPage();
}
});
}
@@ -152,9 +147,9 @@
}
private void handleStateNotRunning() {
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
if (runtime != null) {
runtime.removePropertyChangeListener(this);
- runtime = null;
}
getDisplay().asyncExec(new Runnable() {
@Override
@@ -188,31 +183,25 @@
}
}
- 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();
- }
- }
+// 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 dispose() {
- if (runtime != null && ForgeRuntime.STATE_RUNNING.equals(runtime.getState()))
{
- stopForge();
- }
- super.dispose();
- }
-
public void startForge() {
- if (runtime != null) return;
- runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
+ 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
@@ -249,24 +238,20 @@
}
public void stopForge() {
- if (runtime == null) return;
- final IProgressMonitor progressMonitor =
getViewSite().getActionBars().getStatusLineManager().getProgressMonitor();
+ IProgressMonitor progressMonitor =
getViewSite().getActionBars().getStatusLineManager().getProgressMonitor();
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
runtime.stop(progressMonitor);
- runtime = null;
}
private Display getDisplay() {
return getSite().getShell().getDisplay();
}
- public ForgeRuntime getRuntime() {
- return runtime;
- }
-
public boolean show(ShowInContext context) {
if (context == null) {
return false;
}
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
if (runtime != null &&
ForgeRuntime.STATE_RUNNING.equals(runtime.getState())) {
return goToSelection(context.getSelection());
} else {
@@ -286,6 +271,7 @@
Thread waitThread = new Thread(new Runnable() {
@Override
public void run() {
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
while (runtime != null &&
!ForgeRuntime.STATE_RUNNING.equals(runtime.getState())) {
try {
Thread.sleep(1000);
@@ -329,6 +315,7 @@
if (str.indexOf(' ') != -1) {
str = '\"' + str + '\"';
}
+ ForgeRuntime runtime = ForgeRuntimesPreferences.INSTANCE.getDefault();
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-20
21:26:21 UTC (rev 38006)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java 2012-01-20
22:18:46 UTC (rev 38007)
@@ -10,6 +10,7 @@
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
+import org.jboss.tools.forge.core.preferences.ForgeRuntimesPreferences;
import org.jboss.tools.forge.core.process.ForgeRuntime;
@@ -42,7 +43,7 @@
if (path.indexOf(' ') != -1) {
path = '\"' + path + '\"';
}
- ForgeRuntime forgeRuntime = forgeView.getRuntime();
+ ForgeRuntime forgeRuntime = ForgeRuntimesPreferences.INSTANCE.getDefault();
if (forgeRuntime != null &&
ForgeRuntime.STATE_RUNNING.equals(forgeRuntime.getState())) {
forgeRuntime.sendInput("pick-up " + path + "\n");
}
@@ -83,7 +84,7 @@
if (path.indexOf(' ') != -1) {
path = '\"' + path + '\"';
}
- ForgeRuntime forgeRuntime = forgeView.getRuntime();
+ ForgeRuntime forgeRuntime = ForgeRuntimesPreferences.INSTANCE.getDefault();
if (forgeRuntime != null &&
ForgeRuntime.STATE_RUNNING.equals(forgeRuntime.getState())) {
forgeRuntime.sendInput("pick-up " + path + "\n");
}