Author: koen.aers(a)jboss.com
Date: 2011-07-07 09:29:35 -0400 (Thu, 07 Jul 2011)
New Revision: 32708
Added:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/CommandRecorder.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/Console.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsolePage.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsolePartitioner.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsoleViewer.java
Removed:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/CommandRecorder.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/Console.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/ConsolePartitioner.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsolePage.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsoleViewer.java
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/old/ConsolePartitioner.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ConsoleView.java
Log:
move console related classes to org.jboss.tools.forge.ui.console
Deleted:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/CommandRecorder.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/CommandRecorder.java 2011-07-07
13:26:33 UTC (rev 32707)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/CommandRecorder.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -1,266 +0,0 @@
-package org.jboss.tools.forge.console;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.ISourceRange;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.ui.IEditorPart;
-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.eclipse.ui.ide.IDE;
-import org.eclipse.ui.part.ISetSelectionTarget;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.jboss.tools.forge.ForgeUIPlugin;
-import org.jboss.tools.forge.importer.ProjectConfigurationUpdater;
-import org.jboss.tools.forge.importer.ProjectImporter;
-
-public class CommandRecorder implements IDocumentListener {
-
- private StringBuffer buffer = new StringBuffer();
- private String beforePrompt = null;
- private String currentPrompt = null;
- private String currentCommand = null;
-
- @Override
- public void documentAboutToBeChanged(DocumentEvent event) {
- }
-
- @Override
- public void documentChanged(DocumentEvent event) {
- if (event.getLength() == 1 && "".equals(event.getText())) {
- buffer.setLength(buffer.length() - 1);
- } else {
- buffer.append(event.getText());
- String newPrompt = getNewPrompt();
- if (newPrompt != null) {
- currentPrompt = newPrompt;
- beforePrompt = buffer.substring(0, buffer.length() - newPrompt.length());
- buffer.setLength(0);
- if (currentCommand != null) {
- postProcessCurrentCommand();
- currentCommand = null;
- }
- } else {
- if (currentPrompt != null) {
- String newCommand = getNewCommand();
- if (newCommand != null) {
- currentCommand = newCommand;
- }
- }
- }
- }
- }
-
- private String getNewPrompt() {
- int lastLineBreak = buffer.lastIndexOf("\n");
- if (lastLineBreak == -1) return null;
- String lastLine = buffer.substring(lastLineBreak + 1);
- if (lastLine.length() == 0) return null;
- if (lastLine.charAt(0) != '[') return null;
- int rightBracketIndex = lastLine.indexOf(']');
- if (rightBracketIndex == -1) return null;
- return lastLine.endsWith("$ ") ? lastLine : null;
- }
-
- private String getNewCommand() {
- String candidateCommand = buffer.toString();
- if ("pwd".equals(candidateCommand)) {
- return "pwd";
- } else if ("new-project".equals(candidateCommand)) {
- return "new-project";
- } else if ("persistence".equals(candidateCommand)) {
- return "persistence";
- } else if ("entity".equals(candidateCommand)) {
- return "entity";
- } else if ("field".equals(candidateCommand)) {
- return "field";
- } else if ("prettyfaces".equals(candidateCommand)) {
- return "prettyfaces";
- } else if ("build".equals(candidateCommand)) {
- return "build";
- } else {
- return null;
- }
- }
-
- private void postProcessCurrentCommand() {
- IWorkbenchWindow workbenchWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
- String projectName = currentPrompt.substring(1, currentPrompt.indexOf(']'));
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- if (project != null) {
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- ForgeUIPlugin.log(e);
- }
- }
- if ("pwd".equals(currentCommand)) {
- // do nothing
- } else if ("new-project".equals(currentCommand)) {
- int index = beforePrompt.lastIndexOf("***SUCCESS*** Created project [");
- if (index == -1) return;
- if (index + 31 > beforePrompt.length()) return;
- String str = beforePrompt.substring(index + 31);
- index = str.lastIndexOf("] in new working directory [");
- if (index == -1) return;
- if (index + 28 > str.length()) return;
- str = str.substring(index + 28);
- index = str.indexOf("]");
- if (index == -1) return;
- String projectPath = str.substring(0, index);
- index = projectPath.lastIndexOf('/');
- String projectDirName = projectPath.substring(index + 1);
- String projectBaseDirPath = projectPath.substring(0, index);
- ProjectImporter importer = new ProjectImporter(projectBaseDirPath, projectDirName);
- importer.importProject();
- } else if ("persistence".equals(currentCommand)) {
- int index = beforePrompt.lastIndexOf("***SUCCESS*** Installed [forge.spec.jpa]
successfully.\nWrote ");
- if (index == -1) return;
- try {
- IFile file =
project.getFile("/src/main/resources/META-INF/persistence.xml");
- if (file == null) return;
- Object objectToSelect = file;
- IDE.openEditor(workbenchPage, file);
- IViewPart projectExplorer =
workbenchPage.findView("org.eclipse.ui.navigator.ProjectExplorer");
- if (projectExplorer != null && projectExplorer instanceof
ISetSelectionTarget) {
- ((ISetSelectionTarget)projectExplorer).selectReveal(new
StructuredSelection(objectToSelect));
- }
- IViewPart packageExplorer =
workbenchPage.findView("org.eclipse.jdt.ui.PackageExplorer");
- if (packageExplorer == null && projectExplorer == null) {
- packageExplorer =
workbenchPage.showView("org.eclipse.jdt.ui.PackageExplorer");
- }
- if (packageExplorer != null && packageExplorer instanceof
ISetSelectionTarget) {
- ((ISetSelectionTarget)packageExplorer).selectReveal(new
StructuredSelection(objectToSelect));
- }
- } catch (PartInitException e) {
- ForgeUIPlugin.log(e);
- }
- } else if ("entity".equals(currentCommand)) {
- int index = beforePrompt.lastIndexOf("Picked up type <JavaResource>:
");
- if (index == -1) return;
- if (index + 31 > beforePrompt.length() -1) return;
- String entityName = beforePrompt.substring(index + 31, beforePrompt.length() -
1).replace('.', '/');
- try {
- IFile file = project.getFile("/src/main/java/" + entityName +
".java");
- if (file == null) return;
- Object objectToSelect = file;
- IDE.openEditor(workbenchPage, file);
- IJavaElement javaElement = JavaCore.create(file);
- if (javaElement != null && javaElement.getElementType() ==
IJavaElement.COMPILATION_UNIT) {
- try {
- objectToSelect = ((ICompilationUnit)javaElement).getTypes()[0];
- } catch (JavaModelException e) {
- ForgeUIPlugin.log(e);
- }
- }
- IViewPart projectExplorer =
workbenchPage.findView("org.eclipse.ui.navigator.ProjectExplorer");
- if (projectExplorer != null && projectExplorer instanceof
ISetSelectionTarget) {
- ((ISetSelectionTarget)projectExplorer).selectReveal(new
StructuredSelection(objectToSelect));
- }
- IViewPart packageExplorer =
workbenchPage.findView("org.eclipse.jdt.ui.PackageExplorer");
- if (packageExplorer == null && projectExplorer == null) {
- packageExplorer =
workbenchPage.showView("org.eclipse.jdt.ui.PackageExplorer");
- }
- if (packageExplorer != null && packageExplorer instanceof
ISetSelectionTarget) {
- ((ISetSelectionTarget)packageExplorer).selectReveal(new
StructuredSelection(objectToSelect));
- }
- } catch (PartInitException e) {
- ForgeUIPlugin.log(e);
- }
- } else if ("field".equals(currentCommand)) {
- try {
- int index = beforePrompt.lastIndexOf("Added field to ");
- if (index == -1) return;
- if (index + 15 > beforePrompt.length()) return;
- String str = beforePrompt.substring(index + 15);
- index = str.indexOf(':');
- if (index == -1) return;
- String entityName = str.substring(0, index);
- str = str.substring(index);
- index = str.lastIndexOf(';');
- if (index == -1) return;
- str = str.substring(0, index);
- index = str.lastIndexOf(' ');
- if (index == -1) return;
- String fieldName = str.substring(index + 1);
- IFile file = project.getFile("/src/main/java/" +
entityName.replace('.', '/') + ".java");
- if (file == null) return;
- IEditorPart editorPart = IDE.openEditor(workbenchPage, file);
- IJavaElement javaElement = JavaCore.create(file);
- if (javaElement != null && javaElement.getElementType() ==
IJavaElement.COMPILATION_UNIT) {
- try {
- IType type = ((ICompilationUnit)javaElement).getTypes()[0];
- IField field = type.getField(fieldName);
- if (field != null) {
- ISourceRange sourceRange = field.getSourceRange();
- if (sourceRange != null && editorPart != null && editorPart
instanceof ITextEditor) {
- ((ITextEditor)editorPart).selectAndReveal(sourceRange.getOffset(),
sourceRange.getLength());
- }
- }
- } catch (JavaModelException e) {
- ForgeUIPlugin.log(e);
- }
- }
- } catch (PartInitException e) {
- ForgeUIPlugin.log(e);
- }
- } else if ("prettyfaces".equals(currentCommand)) {
- int index = beforePrompt.lastIndexOf("***SUCCESS*** Installed
[com.ocpsoft.prettyfaces] successfully.");
- if (index == -1) return;
- String str = beforePrompt.substring(0, index - 1);
- index = str.lastIndexOf("Wrote ");
- if (index == -1) return;
- if (index + 6 > str.length()) return;
- str = str.substring(index + 6);
- String projectLocation = project.getLocation().toString();
- index = str.lastIndexOf(projectLocation);
- if (index != 0) return;
- str = str.substring(projectLocation.length());
- IFile file = project.getFile(str);
- if (file == null) return;
- Object objectToSelect = file;
- new ProjectConfigurationUpdater(project).updateProject();
- try {
- IDE.openEditor(workbenchPage, file);
- IViewPart projectExplorer =
workbenchPage.findView("org.eclipse.ui.navigator.ProjectExplorer");
- if (projectExplorer != null && projectExplorer instanceof
ISetSelectionTarget) {
- ((ISetSelectionTarget)projectExplorer).selectReveal(new
StructuredSelection(objectToSelect));
- }
- IViewPart packageExplorer =
workbenchPage.findView("org.eclipse.jdt.ui.PackageExplorer");
- if (packageExplorer == null && projectExplorer == null) {
- packageExplorer =
workbenchPage.showView("org.eclipse.jdt.ui.PackageExplorer");
- }
- if (packageExplorer != null && packageExplorer instanceof
ISetSelectionTarget) {
- ((ISetSelectionTarget)packageExplorer).selectReveal(new
StructuredSelection(objectToSelect));
- }
- } catch (PartInitException e) {
- ForgeUIPlugin.log(e);
- }
- } else if ("build".equals(currentCommand)) {
-
- } else {
-
- }
- try {
- workbenchPage.showView("org.jboss.tools.forge.console").setFocus();
- } catch (PartInitException e) {
- ForgeUIPlugin.log(e);
- }
- }
-
-}
Deleted:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/Console.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/Console.java 2011-07-07
13:26:33 UTC (rev 32707)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/Console.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -1,195 +0,0 @@
-package org.jboss.tools.forge.console;
-
-import java.io.IOException;
-
-import org.eclipse.debug.core.DebugEvent;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.IDebugEventSetListener;
-import org.eclipse.debug.core.IStreamListener;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.debug.core.model.IStreamMonitor;
-import org.eclipse.debug.core.model.IStreamsProxy;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.console.IConsoleDocumentPartitioner;
-import org.eclipse.ui.console.IConsoleView;
-import org.eclipse.ui.console.TextConsole;
-import org.eclipse.ui.part.IPageBookViewPage;
-import org.jboss.tools.forge.core.io.ForgeInputReadJob;
-
-public class Console extends TextConsole implements IDebugEventSetListener {
-
- private ConsolePartitioner partitioner;
- private ConsoleInputStream inputStream;
- private IProcess process = null;
- private IStreamListener outputStreamListener;
-
-
- public Console(IProcess process) {
- super("Forge Console", null, null, true);
- this.process = process;
- initInputStream();
- initPartitioner();
- initCommandRecorder();
- initOutputStream();
- initInputReadJob();
- }
-
- private void initCommandRecorder() {
- getDocument().addDocumentListener(new CommandRecorder());
- }
-
- private void initInputStream() {
- inputStream = new ConsoleInputStream();
- }
-
- private void initOutputStream() {
- outputStreamListener = new IStreamListener() {
- @Override
- public void streamAppended(String text, IStreamMonitor monitor) {
- appendString(text);
- }
- };
- IStreamMonitor streamMonitor = getOutputStreamMonitor();
- synchronized(streamMonitor) {
- streamMonitor.addListener(outputStreamListener);
- }
- }
-
- private IStreamMonitor getOutputStreamMonitor() {
- IStreamMonitor streamMonitor = null;
- IStreamsProxy streamsProxy = process.getStreamsProxy();
- if (streamsProxy != null) {
- streamMonitor = streamsProxy.getOutputStreamMonitor();
- }
- return streamMonitor;
- }
-
- private void initInputReadJob() {
- ForgeInputReadJob inputReadJob = new ForgeInputReadJob(process.getStreamsProxy(),
inputStream);
- inputReadJob.setSystem(true);
- inputReadJob.schedule();
- }
-
- private void initPartitioner() {
- partitioner = new ConsolePartitioner();
- partitioner.connect(getDocument());
- }
-
- public IPageBookViewPage createPage(IConsoleView view) {
- throw new UnsupportedOperationException();
- }
-
- public ConsoleInputStream getInputStream() {
- return inputStream;
- }
-
- protected IConsoleDocumentPartitioner getPartitioner() {
- return partitioner;
- }
-
- public void dispose() {
- super.dispose();
- partitioner.disconnect();
- closeStreams();
- disposeStreams();
- DebugPlugin.getDefault().removeDebugEventListener(this);
- }
-
- private synchronized void closeStreams() {
- try {
- inputStream.close();
- } catch (IOException e) {}
- }
-
- private synchronized void disposeStreams() {
- IStreamMonitor streamMonitor = getOutputStreamMonitor();
- if (streamMonitor != null) {
- synchronized(streamMonitor) {
- if (outputStreamListener != null) {
- streamMonitor.removeListener(outputStreamListener);
- }
- }
- }
- outputStreamListener = null;
- inputStream = null;
- }
-
- public void handleDebugEvents(DebugEvent[] events) {
- for (int i = 0; i < events.length; i++) {
- DebugEvent event = events[i];
- if (event.getSource().equals(process)) {
- if (event.getKind() == DebugEvent.TERMINATE) {
- closeStreams();
- DebugPlugin.getDefault().removeDebugEventListener(this);
- }
- }
- }
- }
-
- protected void init() {
- super.init();
- if (process.isTerminated()) {
- closeStreams();
- } else {
- DebugPlugin.getDefault().addDebugEventListener(this);
- }
- }
-
- private int lastLineLength = 0;
- private int lastLinePosition = 0;
- private StringBuffer escapeSequence = new StringBuffer();
- private boolean escapeSequenceStarted = false;
-
- public void appendString(final String str) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- try {
- for (int i = 0; i < str.length(); i++) {
- char c = str.charAt(i);
- if (c == '\r') continue; //ignore
- if (c == '[' && escapeSequenceStarted) continue;
- if (c == 27) {
- escapeSequenceStarted = true;
- continue;
- }
- if (escapeSequenceStarted) {
- int type = Character.getType(c);
- if (type == Character.LOWERCASE_LETTER || type == Character.UPPERCASE_LETTER) {
- if (c == 'G') {
- int columnNumber = Integer.valueOf(escapeSequence.toString());
- escapeSequence.setLength(0);
- lastLineLength = columnNumber - 1;
- escapeSequenceStarted = false;
- } else if (c == 'K') {
- int doclength = getDocument().getLength();
- int currentPosition = lastLinePosition + lastLineLength;
- getDocument().replace(currentPosition, doclength - currentPosition,
"");
- escapeSequenceStarted = false;
-// } else if (c == 'm') {
-//
- }
- } else {
- escapeSequence.append(c);
- }
- continue;
- }
- if (str.charAt(i) == '\b') {
- getDocument().replace(getDocument().getLength() - 1, 1, "");
- lastLineLength--;
- } else {
- getDocument().replace(getDocument().getLength(), 0, str.substring(i, i + 1));
- lastLineLength++;
- }
- if (c == '\n') {
- lastLineLength = 0;
- lastLinePosition = getDocument().getLength();
- }
- }
- } catch (BadLocationException e) {}
- }
- });
- }
-
-}
Deleted:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/ConsolePartitioner.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/ConsolePartitioner.java 2011-07-07
13:26:33 UTC (rev 32707)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/ConsolePartitioner.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -1,69 +0,0 @@
-package org.jboss.tools.forge.console;
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.ui.console.IConsoleDocumentPartitioner;
-
-public class ConsolePartitioner implements IConsoleDocumentPartitioner {
-
- @Override
- public void connect(IDocument document) {
-// System.out.println("connect");
- document.setDocumentPartitioner(this);
- }
-
- @Override
- public void disconnect() {
-// System.out.println("disconnect");
- }
-
- @Override
- public void documentAboutToBeChanged(DocumentEvent event) {
-// System.out.println("documentAboutToBeChanged");
- }
-
- @Override
- public boolean documentChanged(DocumentEvent event) {
-// System.out.println("documentChanged");
- return false;
- }
-
- @Override
- public String[] getLegalContentTypes() {
-// System.out.println("getLegalContentTypes");
- return null;
- }
-
- @Override
- public String getContentType(int offset) {
-// System.out.println("getContentType");
- return null;
- }
-
- @Override
- public ITypedRegion[] computePartitioning(int offset, int length) {
-// System.out.println("computePartitioning");
- return null;
- }
-
- @Override
- public ITypedRegion getPartition(int offset) {
-// System.out.println("getPartition");
- return null;
- }
-
- @Override
- public boolean isReadOnly(int offset) {
-// System.out.println("isReadOnly");
- return false;
- }
-
- @Override
- public StyleRange[] getStyleRanges(int offset, int length) {
-// System.out.println("getStyleRanges : [offset, " + offset + "] [length,
" + length + "]");
- return null;
- }
-
-}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/old/ConsolePartitioner.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/old/ConsolePartitioner.java 2011-07-07
13:26:33 UTC (rev 32707)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/old/ConsolePartitioner.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -25,8 +25,8 @@
import org.eclipse.ui.console.IConsoleDocumentPartitioner;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.progress.WorkbenchJob;
-import org.jboss.tools.forge.console.Console;
import org.jboss.tools.forge.console.ConsoleInputStream;
+import org.jboss.tools.forge.ui.console.Console;
/**
* Partitions an IOConsole's document
Copied:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/CommandRecorder.java
(from rev 32704,
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/CommandRecorder.java)
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/CommandRecorder.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/CommandRecorder.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -0,0 +1,266 @@
+package org.jboss.tools.forge.ui.console;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IEditorPart;
+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.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.ISetSelectionTarget;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.forge.ForgeUIPlugin;
+import org.jboss.tools.forge.importer.ProjectConfigurationUpdater;
+import org.jboss.tools.forge.importer.ProjectImporter;
+
+public class CommandRecorder implements IDocumentListener {
+
+ private StringBuffer buffer = new StringBuffer();
+ private String beforePrompt = null;
+ private String currentPrompt = null;
+ private String currentCommand = null;
+
+ @Override
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ }
+
+ @Override
+ public void documentChanged(DocumentEvent event) {
+ if (event.getLength() == 1 && "".equals(event.getText())) {
+ buffer.setLength(buffer.length() - 1);
+ } else {
+ buffer.append(event.getText());
+ String newPrompt = getNewPrompt();
+ if (newPrompt != null) {
+ currentPrompt = newPrompt;
+ beforePrompt = buffer.substring(0, buffer.length() - newPrompt.length());
+ buffer.setLength(0);
+ if (currentCommand != null) {
+ postProcessCurrentCommand();
+ currentCommand = null;
+ }
+ } else {
+ if (currentPrompt != null) {
+ String newCommand = getNewCommand();
+ if (newCommand != null) {
+ currentCommand = newCommand;
+ }
+ }
+ }
+ }
+ }
+
+ private String getNewPrompt() {
+ int lastLineBreak = buffer.lastIndexOf("\n");
+ if (lastLineBreak == -1) return null;
+ String lastLine = buffer.substring(lastLineBreak + 1);
+ if (lastLine.length() == 0) return null;
+ if (lastLine.charAt(0) != '[') return null;
+ int rightBracketIndex = lastLine.indexOf(']');
+ if (rightBracketIndex == -1) return null;
+ return lastLine.endsWith("$ ") ? lastLine : null;
+ }
+
+ private String getNewCommand() {
+ String candidateCommand = buffer.toString();
+ if ("pwd".equals(candidateCommand)) {
+ return "pwd";
+ } else if ("new-project".equals(candidateCommand)) {
+ return "new-project";
+ } else if ("persistence".equals(candidateCommand)) {
+ return "persistence";
+ } else if ("entity".equals(candidateCommand)) {
+ return "entity";
+ } else if ("field".equals(candidateCommand)) {
+ return "field";
+ } else if ("prettyfaces".equals(candidateCommand)) {
+ return "prettyfaces";
+ } else if ("build".equals(candidateCommand)) {
+ return "build";
+ } else {
+ return null;
+ }
+ }
+
+ private void postProcessCurrentCommand() {
+ IWorkbenchWindow workbenchWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
+ String projectName = currentPrompt.substring(1, currentPrompt.indexOf(']'));
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (project != null) {
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+ if ("pwd".equals(currentCommand)) {
+ // do nothing
+ } else if ("new-project".equals(currentCommand)) {
+ int index = beforePrompt.lastIndexOf("***SUCCESS*** Created project [");
+ if (index == -1) return;
+ if (index + 31 > beforePrompt.length()) return;
+ String str = beforePrompt.substring(index + 31);
+ index = str.lastIndexOf("] in new working directory [");
+ if (index == -1) return;
+ if (index + 28 > str.length()) return;
+ str = str.substring(index + 28);
+ index = str.indexOf("]");
+ if (index == -1) return;
+ String projectPath = str.substring(0, index);
+ index = projectPath.lastIndexOf('/');
+ String projectDirName = projectPath.substring(index + 1);
+ String projectBaseDirPath = projectPath.substring(0, index);
+ ProjectImporter importer = new ProjectImporter(projectBaseDirPath, projectDirName);
+ importer.importProject();
+ } else if ("persistence".equals(currentCommand)) {
+ int index = beforePrompt.lastIndexOf("***SUCCESS*** Installed [forge.spec.jpa]
successfully.\nWrote ");
+ if (index == -1) return;
+ try {
+ IFile file =
project.getFile("/src/main/resources/META-INF/persistence.xml");
+ if (file == null) return;
+ Object objectToSelect = file;
+ IDE.openEditor(workbenchPage, file);
+ IViewPart projectExplorer =
workbenchPage.findView("org.eclipse.ui.navigator.ProjectExplorer");
+ if (projectExplorer != null && projectExplorer instanceof
ISetSelectionTarget) {
+ ((ISetSelectionTarget)projectExplorer).selectReveal(new
StructuredSelection(objectToSelect));
+ }
+ IViewPart packageExplorer =
workbenchPage.findView("org.eclipse.jdt.ui.PackageExplorer");
+ if (packageExplorer == null && projectExplorer == null) {
+ packageExplorer =
workbenchPage.showView("org.eclipse.jdt.ui.PackageExplorer");
+ }
+ if (packageExplorer != null && packageExplorer instanceof
ISetSelectionTarget) {
+ ((ISetSelectionTarget)packageExplorer).selectReveal(new
StructuredSelection(objectToSelect));
+ }
+ } catch (PartInitException e) {
+ ForgeUIPlugin.log(e);
+ }
+ } else if ("entity".equals(currentCommand)) {
+ int index = beforePrompt.lastIndexOf("Picked up type <JavaResource>:
");
+ if (index == -1) return;
+ if (index + 31 > beforePrompt.length() -1) return;
+ String entityName = beforePrompt.substring(index + 31, beforePrompt.length() -
1).replace('.', '/');
+ try {
+ IFile file = project.getFile("/src/main/java/" + entityName +
".java");
+ if (file == null) return;
+ Object objectToSelect = file;
+ IDE.openEditor(workbenchPage, file);
+ IJavaElement javaElement = JavaCore.create(file);
+ if (javaElement != null && javaElement.getElementType() ==
IJavaElement.COMPILATION_UNIT) {
+ try {
+ objectToSelect = ((ICompilationUnit)javaElement).getTypes()[0];
+ } catch (JavaModelException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+ IViewPart projectExplorer =
workbenchPage.findView("org.eclipse.ui.navigator.ProjectExplorer");
+ if (projectExplorer != null && projectExplorer instanceof
ISetSelectionTarget) {
+ ((ISetSelectionTarget)projectExplorer).selectReveal(new
StructuredSelection(objectToSelect));
+ }
+ IViewPart packageExplorer =
workbenchPage.findView("org.eclipse.jdt.ui.PackageExplorer");
+ if (packageExplorer == null && projectExplorer == null) {
+ packageExplorer =
workbenchPage.showView("org.eclipse.jdt.ui.PackageExplorer");
+ }
+ if (packageExplorer != null && packageExplorer instanceof
ISetSelectionTarget) {
+ ((ISetSelectionTarget)packageExplorer).selectReveal(new
StructuredSelection(objectToSelect));
+ }
+ } catch (PartInitException e) {
+ ForgeUIPlugin.log(e);
+ }
+ } else if ("field".equals(currentCommand)) {
+ try {
+ int index = beforePrompt.lastIndexOf("Added field to ");
+ if (index == -1) return;
+ if (index + 15 > beforePrompt.length()) return;
+ String str = beforePrompt.substring(index + 15);
+ index = str.indexOf(':');
+ if (index == -1) return;
+ String entityName = str.substring(0, index);
+ str = str.substring(index);
+ index = str.lastIndexOf(';');
+ if (index == -1) return;
+ str = str.substring(0, index);
+ index = str.lastIndexOf(' ');
+ if (index == -1) return;
+ String fieldName = str.substring(index + 1);
+ IFile file = project.getFile("/src/main/java/" +
entityName.replace('.', '/') + ".java");
+ if (file == null) return;
+ IEditorPart editorPart = IDE.openEditor(workbenchPage, file);
+ IJavaElement javaElement = JavaCore.create(file);
+ if (javaElement != null && javaElement.getElementType() ==
IJavaElement.COMPILATION_UNIT) {
+ try {
+ IType type = ((ICompilationUnit)javaElement).getTypes()[0];
+ IField field = type.getField(fieldName);
+ if (field != null) {
+ ISourceRange sourceRange = field.getSourceRange();
+ if (sourceRange != null && editorPart != null && editorPart
instanceof ITextEditor) {
+ ((ITextEditor)editorPart).selectAndReveal(sourceRange.getOffset(),
sourceRange.getLength());
+ }
+ }
+ } catch (JavaModelException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+ } catch (PartInitException e) {
+ ForgeUIPlugin.log(e);
+ }
+ } else if ("prettyfaces".equals(currentCommand)) {
+ int index = beforePrompt.lastIndexOf("***SUCCESS*** Installed
[com.ocpsoft.prettyfaces] successfully.");
+ if (index == -1) return;
+ String str = beforePrompt.substring(0, index - 1);
+ index = str.lastIndexOf("Wrote ");
+ if (index == -1) return;
+ if (index + 6 > str.length()) return;
+ str = str.substring(index + 6);
+ String projectLocation = project.getLocation().toString();
+ index = str.lastIndexOf(projectLocation);
+ if (index != 0) return;
+ str = str.substring(projectLocation.length());
+ IFile file = project.getFile(str);
+ if (file == null) return;
+ Object objectToSelect = file;
+ new ProjectConfigurationUpdater(project).updateProject();
+ try {
+ IDE.openEditor(workbenchPage, file);
+ IViewPart projectExplorer =
workbenchPage.findView("org.eclipse.ui.navigator.ProjectExplorer");
+ if (projectExplorer != null && projectExplorer instanceof
ISetSelectionTarget) {
+ ((ISetSelectionTarget)projectExplorer).selectReveal(new
StructuredSelection(objectToSelect));
+ }
+ IViewPart packageExplorer =
workbenchPage.findView("org.eclipse.jdt.ui.PackageExplorer");
+ if (packageExplorer == null && projectExplorer == null) {
+ packageExplorer =
workbenchPage.showView("org.eclipse.jdt.ui.PackageExplorer");
+ }
+ if (packageExplorer != null && packageExplorer instanceof
ISetSelectionTarget) {
+ ((ISetSelectionTarget)packageExplorer).selectReveal(new
StructuredSelection(objectToSelect));
+ }
+ } catch (PartInitException e) {
+ ForgeUIPlugin.log(e);
+ }
+ } else if ("build".equals(currentCommand)) {
+
+ } else {
+
+ }
+ try {
+ workbenchPage.showView("org.jboss.tools.forge.console").setFocus();
+ } catch (PartInitException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+
+}
Copied:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/Console.java
(from rev 32704,
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/Console.java)
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/Console.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/Console.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -0,0 +1,196 @@
+package org.jboss.tools.forge.ui.console;
+
+import java.io.IOException;
+
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
+import org.eclipse.debug.core.IStreamListener;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IStreamMonitor;
+import org.eclipse.debug.core.model.IStreamsProxy;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.console.IConsoleDocumentPartitioner;
+import org.eclipse.ui.console.IConsoleView;
+import org.eclipse.ui.console.TextConsole;
+import org.eclipse.ui.part.IPageBookViewPage;
+import org.jboss.tools.forge.console.ConsoleInputStream;
+import org.jboss.tools.forge.core.io.ForgeInputReadJob;
+
+public class Console extends TextConsole implements IDebugEventSetListener {
+
+ private ConsolePartitioner partitioner;
+ private ConsoleInputStream inputStream;
+ private IProcess process = null;
+ private IStreamListener outputStreamListener;
+
+
+ public Console(IProcess process) {
+ super("Forge Console", null, null, true);
+ this.process = process;
+ initInputStream();
+ initPartitioner();
+ initCommandRecorder();
+ initOutputStream();
+ initInputReadJob();
+ }
+
+ private void initCommandRecorder() {
+ getDocument().addDocumentListener(new CommandRecorder());
+ }
+
+ private void initInputStream() {
+ inputStream = new ConsoleInputStream();
+ }
+
+ private void initOutputStream() {
+ outputStreamListener = new IStreamListener() {
+ @Override
+ public void streamAppended(String text, IStreamMonitor monitor) {
+ appendString(text);
+ }
+ };
+ IStreamMonitor streamMonitor = getOutputStreamMonitor();
+ synchronized(streamMonitor) {
+ streamMonitor.addListener(outputStreamListener);
+ }
+ }
+
+ private IStreamMonitor getOutputStreamMonitor() {
+ IStreamMonitor streamMonitor = null;
+ IStreamsProxy streamsProxy = process.getStreamsProxy();
+ if (streamsProxy != null) {
+ streamMonitor = streamsProxy.getOutputStreamMonitor();
+ }
+ return streamMonitor;
+ }
+
+ private void initInputReadJob() {
+ ForgeInputReadJob inputReadJob = new ForgeInputReadJob(process.getStreamsProxy(),
inputStream);
+ inputReadJob.setSystem(true);
+ inputReadJob.schedule();
+ }
+
+ private void initPartitioner() {
+ partitioner = new ConsolePartitioner();
+ partitioner.connect(getDocument());
+ }
+
+ public IPageBookViewPage createPage(IConsoleView view) {
+ throw new UnsupportedOperationException();
+ }
+
+ public ConsoleInputStream getInputStream() {
+ return inputStream;
+ }
+
+ protected IConsoleDocumentPartitioner getPartitioner() {
+ return partitioner;
+ }
+
+ public void dispose() {
+ super.dispose();
+ partitioner.disconnect();
+ closeStreams();
+ disposeStreams();
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ }
+
+ private synchronized void closeStreams() {
+ try {
+ inputStream.close();
+ } catch (IOException e) {}
+ }
+
+ private synchronized void disposeStreams() {
+ IStreamMonitor streamMonitor = getOutputStreamMonitor();
+ if (streamMonitor != null) {
+ synchronized(streamMonitor) {
+ if (outputStreamListener != null) {
+ streamMonitor.removeListener(outputStreamListener);
+ }
+ }
+ }
+ outputStreamListener = null;
+ inputStream = null;
+ }
+
+ public void handleDebugEvents(DebugEvent[] events) {
+ for (int i = 0; i < events.length; i++) {
+ DebugEvent event = events[i];
+ if (event.getSource().equals(process)) {
+ if (event.getKind() == DebugEvent.TERMINATE) {
+ closeStreams();
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ }
+ }
+ }
+ }
+
+ protected void init() {
+ super.init();
+ if (process.isTerminated()) {
+ closeStreams();
+ } else {
+ DebugPlugin.getDefault().addDebugEventListener(this);
+ }
+ }
+
+ private int lastLineLength = 0;
+ private int lastLinePosition = 0;
+ private StringBuffer escapeSequence = new StringBuffer();
+ private boolean escapeSequenceStarted = false;
+
+ public void appendString(final String str) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ for (int i = 0; i < str.length(); i++) {
+ char c = str.charAt(i);
+ if (c == '\r') continue; //ignore
+ if (c == '[' && escapeSequenceStarted) continue;
+ if (c == 27) {
+ escapeSequenceStarted = true;
+ continue;
+ }
+ if (escapeSequenceStarted) {
+ int type = Character.getType(c);
+ if (type == Character.LOWERCASE_LETTER || type == Character.UPPERCASE_LETTER) {
+ if (c == 'G') {
+ int columnNumber = Integer.valueOf(escapeSequence.toString());
+ escapeSequence.setLength(0);
+ lastLineLength = columnNumber - 1;
+ escapeSequenceStarted = false;
+ } else if (c == 'K') {
+ int doclength = getDocument().getLength();
+ int currentPosition = lastLinePosition + lastLineLength;
+ getDocument().replace(currentPosition, doclength - currentPosition,
"");
+ escapeSequenceStarted = false;
+// } else if (c == 'm') {
+//
+ }
+ } else {
+ escapeSequence.append(c);
+ }
+ continue;
+ }
+ if (str.charAt(i) == '\b') {
+ getDocument().replace(getDocument().getLength() - 1, 1, "");
+ lastLineLength--;
+ } else {
+ getDocument().replace(getDocument().getLength(), 0, str.substring(i, i + 1));
+ lastLineLength++;
+ }
+ if (c == '\n') {
+ lastLineLength = 0;
+ lastLinePosition = getDocument().getLength();
+ }
+ }
+ } catch (BadLocationException e) {}
+ }
+ });
+ }
+
+}
Copied:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsolePage.java
(from rev 32704,
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsolePage.java)
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsolePage.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsolePage.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -0,0 +1,40 @@
+package org.jboss.tools.forge.ui.console;
+
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.console.TextConsoleViewer;
+import org.eclipse.ui.part.Page;
+
+public class ConsolePage extends Page {
+
+ private TextConsoleViewer viewer;
+ private Console console;
+ private IProcess process;
+
+ public ConsolePage(IProcess process) {
+ this.process = process;
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ console = new Console(process);
+ viewer = new ConsoleViewer(parent, console);
+ console.initialize();
+ }
+
+ @Override
+ public Control getControl() {
+ return viewer == null ? null : viewer.getControl();
+ }
+
+ @Override
+ public void setFocus() {
+ viewer.getControl().setFocus();
+ }
+
+ public Console getConsole() {
+ return console;
+ }
+
+}
Copied:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsolePartitioner.java
(from rev 32704,
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/console/ConsolePartitioner.java)
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsolePartitioner.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsolePartitioner.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -0,0 +1,69 @@
+package org.jboss.tools.forge.ui.console;
+
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.ui.console.IConsoleDocumentPartitioner;
+
+public class ConsolePartitioner implements IConsoleDocumentPartitioner {
+
+ @Override
+ public void connect(IDocument document) {
+// System.out.println("connect");
+ document.setDocumentPartitioner(this);
+ }
+
+ @Override
+ public void disconnect() {
+// System.out.println("disconnect");
+ }
+
+ @Override
+ public void documentAboutToBeChanged(DocumentEvent event) {
+// System.out.println("documentAboutToBeChanged");
+ }
+
+ @Override
+ public boolean documentChanged(DocumentEvent event) {
+// System.out.println("documentChanged");
+ return false;
+ }
+
+ @Override
+ public String[] getLegalContentTypes() {
+// System.out.println("getLegalContentTypes");
+ return null;
+ }
+
+ @Override
+ public String getContentType(int offset) {
+// System.out.println("getContentType");
+ return null;
+ }
+
+ @Override
+ public ITypedRegion[] computePartitioning(int offset, int length) {
+// System.out.println("computePartitioning");
+ return null;
+ }
+
+ @Override
+ public ITypedRegion getPartition(int offset) {
+// System.out.println("getPartition");
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(int offset) {
+// System.out.println("isReadOnly");
+ return false;
+ }
+
+ @Override
+ public StyleRange[] getStyleRanges(int offset, int length) {
+// System.out.println("getStyleRanges : [offset, " + offset + "] [length,
" + length + "]");
+ return null;
+ }
+
+}
Copied:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsoleViewer.java
(from rev 32704,
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsoleViewer.java)
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsoleViewer.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/ConsoleViewer.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -0,0 +1,84 @@
+package org.jboss.tools.forge.ui.console;
+
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.console.TextConsoleViewer;
+
+public class ConsoleViewer extends TextConsoleViewer {
+
+ private static String BACKSPACE = new Character('\b').toString();
+ private static String UP_ARROW = new Character((char)16).toString();
+ private static String DOWN_ARROW = new Character((char)14).toString();
+
+ private Console console = null;
+
+ public ConsoleViewer(Composite parent, Console console) {
+ super(parent, console);
+ this.console = console;
+ getDocument().addDocumentListener(new DocumentListener());
+ }
+
+ protected void handleVerifyEvent(VerifyEvent e) {
+ console.getInputStream().appendData(e.text);
+ e.doit = false;
+ }
+
+ private void handleBackspace() {
+ console.getInputStream().appendData(BACKSPACE);
+ }
+
+ private void handleArrowUp() {
+ console.getInputStream().appendData(UP_ARROW);
+ }
+
+ private void handleArrowDown() {
+ console.getInputStream().appendData(DOWN_ARROW);
+ }
+
+ protected StyledText createTextWidget(Composite parent, int styles) {
+ StyledText styledText = super.createTextWidget(parent, styles);
+ styledText.addKeyListener(new ConsoleKeyListener());
+ return styledText;
+ }
+
+ private class DocumentListener implements IDocumentListener {
+
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ }
+
+
+ public void documentChanged(DocumentEvent event) {
+ revealEndOfDocument();
+ Control control = getControl();
+ if (control instanceof StyledText) {
+ StyledText text = (StyledText)control;
+ text.setCaretOffset(text.getCharCount());
+ }
+ }
+ }
+
+ private class ConsoleKeyListener implements KeyListener {
+
+ public void keyPressed(KeyEvent e) {
+ }
+
+ public void keyReleased(KeyEvent e) {
+ if (e.keyCode == SWT.BS) {
+ handleBackspace();
+ } else if (e.keyCode == SWT.ARROW_UP) {
+ handleArrowUp();
+ } else if (e.keyCode == SWT.ARROW_DOWN) {
+ handleArrowDown();
+ }
+ }
+
+ }
+
+}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ConsoleView.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ConsoleView.java 2011-07-07
13:26:33 UTC (rev 32707)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ConsoleView.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -13,10 +13,10 @@
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.PageSite;
import org.eclipse.ui.part.ViewPart;
-import org.jboss.tools.forge.console.Console;
import org.jboss.tools.forge.core.preferences.ForgeRuntimesPreferences;
import org.jboss.tools.forge.core.process.ForgeRuntime;
-import org.jboss.tools.forge.view.ConsolePage;
+import org.jboss.tools.forge.ui.console.Console;
+import org.jboss.tools.forge.ui.console.ConsolePage;
public class ConsoleView extends ViewPart implements PropertyChangeListener {
Deleted:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsolePage.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsolePage.java 2011-07-07
13:26:33 UTC (rev 32707)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsolePage.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -1,41 +0,0 @@
-package org.jboss.tools.forge.view;
-
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.console.TextConsoleViewer;
-import org.eclipse.ui.part.Page;
-import org.jboss.tools.forge.console.Console;
-
-public class ConsolePage extends Page {
-
- private TextConsoleViewer viewer;
- private Console console;
- private IProcess process;
-
- public ConsolePage(IProcess process) {
- this.process = process;
- }
-
- @Override
- public void createControl(Composite parent) {
- console = new Console(process);
- viewer = new ConsoleViewer(parent, console);
- console.initialize();
- }
-
- @Override
- public Control getControl() {
- return viewer == null ? null : viewer.getControl();
- }
-
- @Override
- public void setFocus() {
- viewer.getControl().setFocus();
- }
-
- public Console getConsole() {
- return console;
- }
-
-}
Deleted:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsoleViewer.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsoleViewer.java 2011-07-07
13:26:33 UTC (rev 32707)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/view/ConsoleViewer.java 2011-07-07
13:29:35 UTC (rev 32708)
@@ -1,85 +0,0 @@
-package org.jboss.tools.forge.view;
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.console.TextConsoleViewer;
-import org.jboss.tools.forge.console.Console;
-
-public class ConsoleViewer extends TextConsoleViewer {
-
- private static String BACKSPACE = new Character('\b').toString();
- private static String UP_ARROW = new Character((char)16).toString();
- private static String DOWN_ARROW = new Character((char)14).toString();
-
- private Console console = null;
-
- public ConsoleViewer(Composite parent, Console console) {
- super(parent, console);
- this.console = console;
- getDocument().addDocumentListener(new DocumentListener());
- }
-
- protected void handleVerifyEvent(VerifyEvent e) {
- console.getInputStream().appendData(e.text);
- e.doit = false;
- }
-
- private void handleBackspace() {
- console.getInputStream().appendData(BACKSPACE);
- }
-
- private void handleArrowUp() {
- console.getInputStream().appendData(UP_ARROW);
- }
-
- private void handleArrowDown() {
- console.getInputStream().appendData(DOWN_ARROW);
- }
-
- protected StyledText createTextWidget(Composite parent, int styles) {
- StyledText styledText = super.createTextWidget(parent, styles);
- styledText.addKeyListener(new ConsoleKeyListener());
- return styledText;
- }
-
- private class DocumentListener implements IDocumentListener {
-
- public void documentAboutToBeChanged(DocumentEvent event) {
- }
-
-
- public void documentChanged(DocumentEvent event) {
- revealEndOfDocument();
- Control control = getControl();
- if (control instanceof StyledText) {
- StyledText text = (StyledText)control;
- text.setCaretOffset(text.getCharCount());
- }
- }
- }
-
- private class ConsoleKeyListener implements KeyListener {
-
- public void keyPressed(KeyEvent e) {
- }
-
- public void keyReleased(KeyEvent e) {
- if (e.keyCode == SWT.BS) {
- handleBackspace();
- } else if (e.keyCode == SWT.ARROW_UP) {
- handleArrowUp();
- } else if (e.keyCode == SWT.ARROW_DOWN) {
- handleArrowDown();
- }
- }
-
- }
-
-}