Issue #1229 Changes for non-blocking ViewMessagesDialog.

Change-Id: Id1bd1e36a2d16feec60c82997891577c98296fe7

Former-commit-id: e157187c72 [formerly 763c6ea58c [formerly 02e781832ab07685baf2b353df39e156a3190c2c]]
Former-commit-id: 763c6ea58c
Former-commit-id: 602c6d8d2e
This commit is contained in:
Roger Ferrel 2012-10-22 10:24:02 -05:00
parent 4729d5a6c8
commit 03e8d62864
3 changed files with 48 additions and 12 deletions

View file

@ -53,6 +53,7 @@ import com.raytheon.viz.ui.statusline.StatusStore.IStatusListener;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jul 14, 2008 #1223 randerso Initial creation
* Oct 22, 2012 #1229 rferrel Changes for non-blocking ViewMessageDialog.
*
* </pre>
*
@ -276,6 +277,6 @@ public class StatBar extends ContributionItem implements IStatusListener {
}
private void viewMessages() {
statusStore.getViewMessagesDialog().open();
statusStore.openViewMessagesDialog();
}
}

View file

@ -39,6 +39,7 @@ import com.raytheon.viz.ui.statusline.StatusMessage.Importance;
* ------------ ---------- ----------- --------------------------
* Jul 14, 2008 randerso Initial creation
* Sep 12, 2008 wdougherty Added updateStatusTextI() method
* Oct 22, 2012 1229 rferrel Changes for non-blocking ViewMessagesDialog.
*
* </pre>
*
@ -196,7 +197,8 @@ public class StatusStore {
}
// Update View Message display
if (viewDialog != null) {
if (viewDialog != null && viewDialog.getShell() != null
&& !viewDialog.isDisposed()) {
viewDialog.updateText();
}
// Update Urgent Messages display
@ -243,13 +245,17 @@ public class StatusStore {
});
}
public ViewMessagesDialog getViewMessagesDialog() {
if (viewDialog == null) {
public void openViewMessagesDialog() {
if (viewDialog == null || viewDialog.getShell() == null
|| viewDialog.isDisposed()) {
this.viewDialog = new ViewMessagesDialog(Display.getDefault()
.getActiveShell(), this.messageBuffer, this.importanceDict,
"View Messages");
viewDialog.setBlockOnOpen(false);
viewDialog.open();
} else {
viewDialog.bringToTop();
}
return viewDialog;
}
public StatBar getStatusBar() {

View file

@ -20,11 +20,11 @@
package com.raytheon.viz.ui.statusline;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
@ -32,12 +32,14 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
import com.raytheon.viz.ui.statusline.StatusMessage.Importance;
/**
@ -48,6 +50,7 @@ import com.raytheon.viz.ui.statusline.StatusMessage.Importance;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 19, 2008 Eric Babin Initial Creation
* Oct 22, 2012 1229 rferrel Converted to CaveJFACEDialog.
*
* </pre>
*
@ -55,7 +58,7 @@ import com.raytheon.viz.ui.statusline.StatusMessage.Importance;
* @version 1.0
*/
public class ViewMessagesDialog extends Dialog {
public class ViewMessagesDialog extends CaveJFACEDialog {
private SimpleDateFormat sdf;
@ -71,6 +74,11 @@ public class ViewMessagesDialog extends Dialog {
private Font font;
/**
* Track colors used so they can be reused and disposed.
*/
private final Map<RGB, Color> colorMap = new HashMap<RGB, Color>();
/**
* @param parent
*/
@ -130,7 +138,9 @@ public class ViewMessagesDialog extends Dialog {
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
* @see
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
* .Shell)
*/
@Override
protected void configureShell(Shell shell) {
@ -155,11 +165,21 @@ public class ViewMessagesDialog extends Dialog {
String s = sdf.format(m.getMessageDate()) + " "
+ m.getMessageText() + "\n";
// TODO: need to ensure colors are disposed
RGB rgb = importance.getForegroundColor();
Color foregroundColor = colorMap.get(rgb);
if (foregroundColor == null) {
foregroundColor = new Color(top.getDisplay(), rgb);
colorMap.put(rgb, foregroundColor);
}
rgb = importance.getBackgroundColor();
Color backgroundColor = colorMap.get(rgb);
if (backgroundColor == null) {
backgroundColor = new Color(top.getDisplay(), rgb);
colorMap.put(rgb, backgroundColor);
}
styleRanges[i++] = new StyleRange(startIndex, s.length(),
new Color(top.getDisplay(), importance
.getForegroundColor()), new Color(top
.getDisplay(), importance.getBackgroundColor()));
foregroundColor, backgroundColor);
styledText.setText(styledText.getText() + s);
@ -168,4 +188,13 @@ public class ViewMessagesDialog extends Dialog {
}
}
@Override
public boolean close() {
for (Color color : colorMap.values()) {
color.dispose();
}
colorMap.clear();
return super.close();
}
}