summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-31 09:17:04 (EDT)
committerEike Stepper2007-07-31 09:17:04 (EDT)
commit8ba36a249e4aeb3546eefd056dd040070aff4a2d (patch)
tree4593f37e7950b7a7922b590dfb6b8120413bb910
parentb6e345c9a16400ba4a74d8215d453536e95afdb7 (diff)
downloadcdo-8ba36a249e4aeb3546eefd056dd040070aff4a2d.zip
cdo-8ba36a249e4aeb3546eefd056dd040070aff4a2d.tar.gz
cdo-8ba36a249e4aeb3546eefd056dd040070aff4a2d.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/LogDialog.java81
-rw-r--r--plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/MonitorDialog.java41
-rw-r--r--plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/MonitorLogDialog.java45
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java6
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorUtil.java27
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMMonitorHandler.java (renamed from plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/IMessageHandler.java)4
6 files changed, 149 insertions, 55 deletions
diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/LogDialog.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/LogDialog.java
index d603366..a91ca47 100644
--- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/LogDialog.java
+++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/LogDialog.java
@@ -13,33 +13,83 @@ package org.eclipse.net4j.ui.widgets;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Eike Stepper
*/
public class LogDialog extends BaseDialog
{
- private String log;
+ private StringBuilder log = new StringBuilder();
+
+ private StyledText text;
+
+ private TextStyle textStyle;
+
+ private List<StyleRange> styleRanges = new ArrayList();
+
+ private StyleRange currentStyleRange = new StyleRange();
- private Text text;
+ private StyleRange lastStyleRange;
private Font font;
- public LogDialog(Shell parentShell, int shellStyle, String title, String message, String log, IDialogSettings settings)
+ public LogDialog(Shell parentShell, int shellStyle, String title, String message, IDialogSettings settings)
{
super(parentShell, shellStyle, title, message, settings);
- this.log = log;
}
- public LogDialog(Shell parentShell, String title, String message, String log, IDialogSettings settings)
+ public LogDialog(Shell parentShell, String title, String message, IDialogSettings settings)
+ {
+ this(parentShell, DEFAULT_SHELL_STYLE, title, message, settings);
+ }
+
+ public TextStyle getTextStyle()
+ {
+ return textStyle;
+ }
+
+ public void setTextStyle(TextStyle textStyle)
+ {
+ if (textStyle == null)
+ {
+ throw new IllegalArgumentException("textStyle == null");
+ }
+
+ if (textStyle.equals(this.textStyle))
+ {
+ return;
+ }
+
+ lastStyleRange = currentStyleRange;
+ this.textStyle = textStyle;
+
+ currentStyleRange = new StyleRange();
+ currentStyleRange.start = log.length();
+ currentStyleRange.rise = textStyle.rise;
+ currentStyleRange.background = textStyle.background;
+ currentStyleRange.font = textStyle.font;
+ currentStyleRange.foreground = textStyle.foreground;
+ currentStyleRange.metrics = textStyle.metrics;
+ currentStyleRange.strikeout = textStyle.strikeout;
+ currentStyleRange.underline = textStyle.underline;
+ }
+
+ public void append(String text)
{
- this(parentShell, DEFAULT_SHELL_STYLE, title, message, log, settings);
+ checkStyleRange();
+ log.append(text);
+ currentStyleRange.length += text.length();
}
@Override
@@ -62,11 +112,13 @@ public class LogDialog extends BaseDialog
composite.setLayout(grid);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- font = new Font(getShell().getDisplay(), "Courier", 5, SWT.NORMAL);
+ font = new Font(getShell().getDisplay(), "Courier New", 9, SWT.NORMAL);
+ checkStyleRange();
- text = new Text(composite, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ text = new StyledText(composite, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- text.setText(log);
+ text.setText(log.toString());
+ text.setStyleRanges(styleRanges.toArray(new StyleRange[styleRanges.size()]));
text.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
text.setFont(font);
}
@@ -76,4 +128,13 @@ public class LogDialog extends BaseDialog
{
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true);
}
+
+ private void checkStyleRange()
+ {
+ if (lastStyleRange != null)
+ {
+ styleRanges.add(lastStyleRange);
+ lastStyleRange = null;
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/MonitorDialog.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/MonitorDialog.java
index 1c5e8d1..04f829f 100644
--- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/MonitorDialog.java
+++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/MonitorDialog.java
@@ -11,19 +11,15 @@
package org.eclipse.net4j.ui.widgets;
import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.om.monitor.IMessageHandler;
import org.eclipse.net4j.util.om.monitor.MonitorUtil;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
/**
@@ -37,16 +33,7 @@ public class MonitorDialog extends ProgressMonitorDialog
private Exception exception;
- private StringBuilder log = new StringBuilder();
-
- private IMessageHandler logHandler = new IMessageHandler()
- {
- public void handleMessage(String msg, int level)
- {
- log.append(msg);
- log.append("\n");
- }
- };
+ private MonitorLogDialog log;
private IDialogSettings settings;
@@ -67,11 +54,12 @@ public class MonitorDialog extends ProgressMonitorDialog
{
try
{
+ log = new MonitorLogDialog(getShell(), getShellStyle(), "Log of " + title, "See the log for details.", settings);
super.run(fork, cancelable, new IRunnableWithProgress()
{
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
- MonitorUtil.Eclipse.startMonitoring(monitor, logHandler);
+ MonitorUtil.Eclipse.startMonitoring(monitor, log);
try
{
runnable.run();
@@ -79,10 +67,11 @@ public class MonitorDialog extends ProgressMonitorDialog
catch (RuntimeException ex)
{
exception = WrappedException.unwrap(ex);
- log.append(exception.getMessage());
- ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- exception.printStackTrace(new PrintStream(bytes));
- log.append(bytes);
+ // log.append(exception.getMessage());
+ // ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ // exception.printStackTrace(new PrintStream(bytes));
+ // log.append(bytes);
+ throw ex;
}
finally
{
@@ -101,19 +90,9 @@ public class MonitorDialog extends ProgressMonitorDialog
protected void finishedRun()
{
super.finishedRun();
- if (exception != null)
- {
- new LogDialog(getShell(), getShellStyle(), "Aborted " + title, "An error occured. See the log for details.", log
- .toString(), settings).open();
- }
- else if (log.length() != 0)
- {
- new LogDialog(getShell(), getShellStyle(), "Finished " + title,
- "The operation finished successfully. See the log for details.", log.toString(), settings).open();
- }
- else
+ if (log != null)
{
- MessageDialog.openInformation(getShell(), "Finished " + title, "The operation finished successfully.");
+ log.open();
}
}
diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/MonitorLogDialog.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/MonitorLogDialog.java
new file mode 100644
index 0000000..28df88e
--- /dev/null
+++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/MonitorLogDialog.java
@@ -0,0 +1,45 @@
+package org.eclipse.net4j.ui.widgets;
+
+import org.eclipse.net4j.util.om.monitor.OMMonitorHandler;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.TextStyle;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author Eike Stepper
+ */
+public final class MonitorLogDialog extends LogDialog implements OMMonitorHandler
+{
+ private TextStyle normal;
+
+ private TextStyle blue;
+
+ public MonitorLogDialog(Shell parentShell, int shellStyle, String title, String message, IDialogSettings settings)
+ {
+ super(parentShell, shellStyle, title, message, settings);
+ normal = new TextStyle(null, Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY), null);
+ blue = new TextStyle(null, Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE), null);
+ }
+
+ public MonitorLogDialog(Shell parentShell, String title, String message, IDialogSettings settings)
+ {
+ this(parentShell, DEFAULT_SHELL_STYLE, title, message, settings);
+ }
+
+ public void handleTask(String task, int level)
+ {
+ setTextStyle(blue);
+ append(task);
+ append("\n");
+ }
+
+ public void handleMessage(String msg, int level)
+ {
+ setTextStyle(normal);
+ append(msg);
+ append("\n");
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
index f64fcb8..21e663b 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
@@ -239,7 +239,7 @@ public abstract class Monitor implements OMMonitor, OMSubMonitor
}
else
{
- trace(task, level);
+ trace(task, level, true);
}
}
@@ -251,11 +251,11 @@ public abstract class Monitor implements OMMonitor, OMSubMonitor
}
else
{
- trace(msg, level);
+ trace(msg, level, false);
}
}
- protected void trace(String msg, int level)
+ protected void trace(String msg, int level, boolean isTask)
{
if (TRACER.isEnabled())
{
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorUtil.java
index 25c0a87..8a874ef 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorUtil.java
@@ -46,13 +46,20 @@ public final class MonitorUtil
return MON.begin(totalWork, task);
}
- static void handleMessage(final IMessageHandler messageHandler, String msg, int level)
+ static void handleTrace(final OMMonitorHandler messageHandler, String msg, int level, boolean isTask)
{
if (messageHandler != null)
{
try
{
- messageHandler.handleMessage(msg, level);
+ if (isTask)
+ {
+ messageHandler.handleTask(msg, level);
+ }
+ else
+ {
+ messageHandler.handleMessage(msg, level);
+ }
}
catch (RuntimeException ex)
{
@@ -66,15 +73,15 @@ public final class MonitorUtil
*/
public static final class Eclipse
{
- public static void startMonitoring(IProgressMonitor progressMonitor, final IMessageHandler messageHandler)
+ public static void startMonitoring(IProgressMonitor progressMonitor, final OMMonitorHandler messageHandler)
{
MON.startMonitoring(new EclipseMonitor(progressMonitor)
{
@Override
- protected void trace(String msg, int level)
+ protected void trace(String msg, int level, boolean isTask)
{
- super.trace(msg, level);
- handleMessage(messageHandler, msg, level);
+ super.trace(msg, level, isTask);
+ handleTrace(messageHandler, msg, level, isTask);
}
});
}
@@ -95,15 +102,15 @@ public final class MonitorUtil
*/
public static final class Legacy
{
- public static void startMonitoring(final IMessageHandler messageHandler)
+ public static void startMonitoring(final OMMonitorHandler messageHandler)
{
MON.startMonitoring(new LegacyMonitor()
{
@Override
- protected void trace(String msg, int level)
+ protected void trace(String msg, int level, boolean isTask)
{
- super.trace(msg, level);
- handleMessage(messageHandler, msg, level);
+ super.trace(msg, level, isTask);
+ handleTrace(messageHandler, msg, level, isTask);
}
});
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/IMessageHandler.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMMonitorHandler.java
index fc89439..a7ce289 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/IMessageHandler.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/OMMonitorHandler.java
@@ -13,7 +13,9 @@ package org.eclipse.net4j.util.om.monitor;
/**
* @author Eike Stepper
*/
-public interface IMessageHandler
+public interface OMMonitorHandler
{
+ public void handleTask(String task, int level);
+
public void handleMessage(String msg, int level);
}