Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java')
-rw-r--r--plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java422
1 files changed, 211 insertions, 211 deletions
diff --git a/plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java b/plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java
index 24d2897baa0..488e0d3e2fa 100644
--- a/plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java
+++ b/plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java
@@ -22,9 +22,8 @@ import org.eclipse.osee.framework.jdk.core.util.IConsoleInputListener;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.ui.plugin.internal.OseePluginUiActivator;
+import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IOConsole;
@@ -37,213 +36,214 @@ import org.eclipse.ui.console.IOConsoleOutputStream;
* @author Donald G. Dunne
*/
public class OseeConsole {
- private IOConsoleOutputStream streamOut = null;
-
- private IOConsoleOutputStream streamErr = null;
-
- private IOConsoleOutputStream streamPrompt = null;
-
- private final IOConsole console;
-
- private final HandleInput inputHandler;
-
- private final boolean time;
-
- private final Thread thread;
-
- public OseeConsole(String title) {
- this(title, true);
- }
-
- private OseeConsole(String title, boolean time) {
- console = new IOConsole(title, null);
- this.time = time;
- this.inputHandler = new HandleInput();
-
- thread = new Thread(inputHandler);
- thread.setName("Osee console input handler");
- ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console});
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
- public void run() {
- streamOut = console.newOutputStream();// newMessageStream();
- streamOut.setColor(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
- streamOut.setActivateOnWrite(false);
- streamErr = console.newOutputStream();
- streamErr.setColor(Display.getDefault().getSystemColor(SWT.COLOR_RED));
- streamErr.setActivateOnWrite(false);
- streamPrompt = console.newOutputStream();
- streamPrompt.setColor(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
- streamPrompt.setActivateOnWrite(false);
- }
- });
- thread.start();
- }
-
- public PrintStream getPrintStream() {
- return new PrintStream(streamOut);
- }
-
- public void shutdown() {
- thread.interrupt();
- try {
- thread.join(5000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] {console});
- }
- }
-
- public static final int CONSOLE_ERROR = 0;
-
- public static final int CONSOLE_OUT = 1;
-
- public static final int CONSOLE_PROMPT = 2;
-
- /**
- * Writes string to console without popping console forward
- *
- * @param str
- */
- public void write(String str) {
- write(str, false);
- }
-
- /**
- * Writes string to console without popping console forward
- *
- * @param str
- */
- public void writeError(String str) {
- write(str, CONSOLE_ERROR, true);
- }
-
- /**
- * Writes string to console
- *
- * @param str
- * @param popup bring console window forward
- */
- public void write(String str, boolean popup) {
- write(str, CONSOLE_OUT, popup);
- }
-
- /**
- * Write string to console
- *
- * @param str
- * @param type CONSOLE_ERROR, CONSOLE_OUT, CONSOLE_PROMPT
- */
- public void write(String str, int type) {
- write(str, type, false);
- }
-
- /**
- * Write string to console
- *
- * @param str
- * @param type CONSOLE_ERROR, CONSOLE_OUT, CONSOLE_PROMPT
- * @param popup bring console window forward
- */
- public void write(String str, int type, boolean popup) {
- String time = "";
- if (this.time) {
- Calendar cal = Calendar.getInstance();
- cal.setTime(new Date());
-
- if (cal.get(Calendar.HOUR) == 0) {
- time = "12";
- } else {
- time = "" + cal.get(Calendar.HOUR);
- }
- time = Lib.padLeading(time, '0', 2);
- String minute = "" + cal.get(Calendar.MINUTE);
- minute = Lib.padLeading(minute, '0', 2);
- time += ":" + minute + " => ";
- }
- try {
- sendToStreams(type, time);
- if (str.length() > 100000) {
- int i = 0;
-
- while (i < str.length()) {
- int endIndex = i + 100000;
- endIndex = endIndex > str.length() ? str.length() : endIndex;
- String chunk = str.substring(i, endIndex);
- sendToStreams(type, chunk);
- i = endIndex;
- }
- } else {
- sendToStreams(type, str);
- }
-
- sendToStreams(type, "\n");
- if (popup) {
- popup();
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
-
- public void prompt(String str) throws IOException {
- sendToStreams(CONSOLE_PROMPT, str);
- }
-
- private void sendToStreams(int type, String str) throws IOException {
- if (type == CONSOLE_ERROR && streamErr != null) {
- streamErr.write(str);
- }
- if (type == CONSOLE_PROMPT && streamPrompt != null) {
- streamPrompt.write(str);
- }
- if (type == CONSOLE_OUT && streamOut != null) {
- streamOut.write(str);
- }
- }
-
- public void popup() {
- ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
- }
-
- public void addInputListener(IConsoleInputListener listener) {
- inputHandler.addListener(listener);
- }
-
- public void removeInputListener(IConsoleInputListener listener) {
- inputHandler.removeListener(listener);
- }
-
- private class HandleInput implements Runnable {
-
- private final CopyOnWriteArrayList<IConsoleInputListener> listeners;
-
- public HandleInput() {
- listeners = new CopyOnWriteArrayList<IConsoleInputListener>();
- }
-
- public void addListener(IConsoleInputListener listener) {
- listeners.add(listener);
- }
-
- public void removeListener(IConsoleInputListener listener) {
- listeners.remove(listener);
- }
-
- public void run() {
- BufferedReader input = new BufferedReader(new InputStreamReader(console.getInputStream()));
- try {
- String line = null;
- while ((line = input.readLine()) != null) {
- for (IConsoleInputListener listener : listeners) {
- listener.lineRead(line);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- OseeLog.log(OseePluginUiActivator.class, Level.INFO, "done with the handling of input");
- }
-
- }
+ private IOConsoleOutputStream streamOut = null;
+
+ private IOConsoleOutputStream streamErr = null;
+
+ private IOConsoleOutputStream streamPrompt = null;
+
+ private final IOConsole console;
+
+ private final HandleInput inputHandler;
+
+ private final boolean time;
+
+ private final Thread thread;
+
+ public OseeConsole(String title) {
+ this(title, true);
+ }
+
+ private OseeConsole(String title, boolean time) {
+ console = new IOConsole(title, null);
+ this.time = time;
+ this.inputHandler = new HandleInput();
+
+ thread = new Thread(inputHandler);
+ thread.setName("Osee console input handler");
+ ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console});
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ streamOut = console.newOutputStream();// newMessageStream();
+ streamOut.setColor(Displays.getSystemColor(SWT.COLOR_BLACK));
+ streamOut.setActivateOnWrite(false);
+ streamErr = console.newOutputStream();
+ streamErr.setColor(Displays.getSystemColor(SWT.COLOR_RED));
+ streamErr.setActivateOnWrite(false);
+ streamPrompt = console.newOutputStream();
+ streamPrompt.setColor(Displays.getSystemColor(SWT.COLOR_BLUE));
+ streamPrompt.setActivateOnWrite(false);
+ }
+ });
+ thread.start();
+ }
+
+ public PrintStream getPrintStream() {
+ return new PrintStream(streamOut);
+ }
+
+ public void shutdown() {
+ thread.interrupt();
+ try {
+ thread.join(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } finally {
+ ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] {console});
+ }
+ }
+
+ public static final int CONSOLE_ERROR = 0;
+
+ public static final int CONSOLE_OUT = 1;
+
+ public static final int CONSOLE_PROMPT = 2;
+
+ /**
+ * Writes string to console without popping console forward
+ *
+ * @param str
+ */
+ public void write(String str) {
+ write(str, false);
+ }
+
+ /**
+ * Writes string to console without popping console forward
+ *
+ * @param str
+ */
+ public void writeError(String str) {
+ write(str, CONSOLE_ERROR, true);
+ }
+
+ /**
+ * Writes string to console
+ *
+ * @param str
+ * @param popup bring console window forward
+ */
+ public void write(String str, boolean popup) {
+ write(str, CONSOLE_OUT, popup);
+ }
+
+ /**
+ * Write string to console
+ *
+ * @param str
+ * @param type CONSOLE_ERROR, CONSOLE_OUT, CONSOLE_PROMPT
+ */
+ public void write(String str, int type) {
+ write(str, type, false);
+ }
+
+ /**
+ * Write string to console
+ *
+ * @param str
+ * @param type CONSOLE_ERROR, CONSOLE_OUT, CONSOLE_PROMPT
+ * @param popup bring console window forward
+ */
+ public void write(String str, int type, boolean popup) {
+ String time = "";
+ if (this.time) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date());
+
+ if (cal.get(Calendar.HOUR) == 0) {
+ time = "12";
+ } else {
+ time = "" + cal.get(Calendar.HOUR);
+ }
+ time = Lib.padLeading(time, '0', 2);
+ String minute = "" + cal.get(Calendar.MINUTE);
+ minute = Lib.padLeading(minute, '0', 2);
+ time += ":" + minute + " => ";
+ }
+ try {
+ sendToStreams(type, time);
+ if (str.length() > 100000) {
+ int i = 0;
+
+ while (i < str.length()) {
+ int endIndex = i + 100000;
+ endIndex = endIndex > str.length() ? str.length() : endIndex;
+ String chunk = str.substring(i, endIndex);
+ sendToStreams(type, chunk);
+ i = endIndex;
+ }
+ } else {
+ sendToStreams(type, str);
+ }
+
+ sendToStreams(type, "\n");
+ if (popup) {
+ popup();
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public void prompt(String str) throws IOException {
+ sendToStreams(CONSOLE_PROMPT, str);
+ }
+
+ private void sendToStreams(int type, String str) throws IOException {
+ if (type == CONSOLE_ERROR && streamErr != null) {
+ streamErr.write(str);
+ }
+ if (type == CONSOLE_PROMPT && streamPrompt != null) {
+ streamPrompt.write(str);
+ }
+ if (type == CONSOLE_OUT && streamOut != null) {
+ streamOut.write(str);
+ }
+ }
+
+ public void popup() {
+ ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
+ }
+
+ public void addInputListener(IConsoleInputListener listener) {
+ inputHandler.addListener(listener);
+ }
+
+ public void removeInputListener(IConsoleInputListener listener) {
+ inputHandler.removeListener(listener);
+ }
+
+ private class HandleInput implements Runnable {
+
+ private final CopyOnWriteArrayList<IConsoleInputListener> listeners;
+
+ public HandleInput() {
+ listeners = new CopyOnWriteArrayList<IConsoleInputListener>();
+ }
+
+ public void addListener(IConsoleInputListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(IConsoleInputListener listener) {
+ listeners.remove(listener);
+ }
+
+ public void run() {
+ BufferedReader input = new BufferedReader(new InputStreamReader(console.getInputStream()));
+ try {
+ String line = null;
+ while ((line = input.readLine()) != null) {
+ for (IConsoleInputListener listener : listeners) {
+ listener.lineRead(line);
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ OseeLog.log(OseePluginUiActivator.class, Level.INFO, "done with the handling of input");
+ }
+
+ }
} \ No newline at end of file

Back to the top