diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/CaveJFACEDialog.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/CaveJFACEDialog.java index 7944663adf..594cfb53f9 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/CaveJFACEDialog.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/CaveJFACEDialog.java @@ -20,6 +20,8 @@ package com.raytheon.viz.ui.dialogs; +import java.util.concurrent.RejectedExecutionException; + import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; @@ -47,6 +49,9 @@ import com.raytheon.viz.ui.perspectives.VizPerspectiveListener; * ---------- ---------- ----------- -------------------------- * 12/20/07 561 Dan Fitch Initial Creation. * 04/22/08 1088 chammack Added dialog event propagation fix + * 09/13/12 1165 lvenable Update for the initial process + * of removing the dialog blocking capability. + * * * * @author Dan Fitch @@ -55,10 +60,18 @@ import com.raytheon.viz.ui.perspectives.VizPerspectiveListener; public class CaveJFACEDialog extends Dialog implements IPerspectiveSpecificDialog { + /** Dialog last location on the screen. */ protected Point lastLocation; + /** Flag indicating of the dialog was visible. */ private boolean wasVisible = true; + /** Callback called when the dialog is disposed. */ + private ICloseCallback closeCallback = null; + + /** Flag indicating if the dialog was blocked when opened. */ + private boolean blockedOnOpen = false; + /** * * @param parentShell @@ -111,6 +124,8 @@ public class CaveJFACEDialog extends Dialog implements if (mgr != null) { mgr.removePespectiveDialog(CaveJFACEDialog.this); } + + callCloseCallback(); } }); @@ -165,4 +180,71 @@ public class CaveJFACEDialog extends Dialog implements shell.setLocation(lastLocation); } } + + /** + * Call the callback method as this dialog has been disposed. + */ + private void callCloseCallback() { + if (closeCallback != null) { + closeCallback.dialogClosed(new Integer(getReturnCode())); + } + } + + /** + * Returns whether the dialog has been opened yet or not + * + * @return True if the dialog was opened, false otherwise. + */ + public final boolean isOpen() { + return (getShell() != null && !getShell().isDisposed()); + } + + /** + * Add a callback to the dialog. This callback will be called when the + * dialog is disposed. + * + * @param callback + * Callback to be called when the dialog is disposed. + */ + public void setCloseCallback(ICloseCallback callback) { + + /* + * Since JFACE allows you to call setBlockOnOpen() after the + * constructor, if the open() method is called before setBlockOnOpen + * then the block is ignored. Here we are checking if the block was set + * and if the dialog is already open because that makes the callback + * pointless. + */ + if (blockedOnOpen && isOpen()) { + StringBuilder sb = new StringBuilder(); + sb.append("The method setBlockOnOpen() was called and set to true. The callback method "); + sb.append("will not run correctly as the dialog has been opened and blocked before this "); + sb.append("method was called."); + throw new RejectedExecutionException(sb.toString()); + } + + this.closeCallback = callback; + } + + /** + * This method overrides the existing setBlockOnOpen() method. This will + * eventually be a catch method that will prevent blocking the dialog on + * open. At this time it serves as a placeholder for upcoming work. + * + * @param blockOnOpen + * Flag indicating if the dialog should block when opened. + */ + public void setBlockOnOpen(boolean blockOnOpen) { + /* + * If the dialog is already opened then just return because setting the + * block won't work. In JFACE the setBlockOnOpen needs to be set before + * the open() call, otherwise it is ignored. + */ + if (isOpen()) { + return; + } + + super.setBlockOnOpen(blockOnOpen); + blockedOnOpen = blockOnOpen; + } } diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/CaveSWTDialogBase.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/CaveSWTDialogBase.java index 49050f43db..fe35207c2e 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/CaveSWTDialogBase.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/CaveSWTDialogBase.java @@ -21,6 +21,7 @@ package com.raytheon.viz.ui.dialogs; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.RejectedExecutionException; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; @@ -48,7 +49,9 @@ import org.eclipse.swt.widgets.Shell; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Nov 2, 2010 mschenke Initial creation + * Nov 2, 2010 mschenke Initial creation + * Sep 12, 2012 #1165 lvenable Update for the initial process + * of removing the dialog blocking capability. * * * @@ -113,20 +116,29 @@ public abstract class CaveSWTDialogBase extends Dialog { } } + /** Style used to determine how the dialog will function. */ private int caveStyle = CAVE.NONE; + /** Display reference. */ private Display display; + /** Dialog last location on the screen. */ protected Point lastLocation; + /** Flag indicating of the dialog was visible. */ protected boolean wasVisible = true; + /** Return value. */ private Object returnValue; + /** Shell reference. */ protected Shell shell; private List listenersToAdd; + /** Callback called when the dialog is disposed. */ + private ICloseCallback closeCallback = null; + /** * Construct default cave dialog * @@ -220,6 +232,7 @@ public abstract class CaveSWTDialogBase extends Dialog { @Override public void widgetDisposed(DisposeEvent e) { disposed(); + callCloseCallback(); } }); @@ -282,6 +295,16 @@ public abstract class CaveSWTDialogBase extends Dialog { } + /** + * Call the callback method as this dialog has been disposed. This action is + * in a separate method since the disposed method can be overridden. + */ + private void callCloseCallback() { + if (closeCallback != null) { + closeCallback.dialogClosed(returnValue); + } + } + /** * Construct the layout for the shell. Defaults to a GridLayout with one * column and margins set to 3 @@ -405,10 +428,25 @@ public abstract class CaveSWTDialogBase extends Dialog { return true; } + /** + * Check if the caveStyle contains a specified attribute. + * + * @param attribute + * Attribute to check for. + * @return True if caveStyle contains the attribute. False if it doesn't. + */ protected boolean hasAttribute(int attribute) { return (caveStyle & attribute) == attribute; } + /** + * Check if the caveStyle does not contain a specified attribute. + * + * @param attribute + * Attribute to check for. + * @return True if caveStyle does not contain the attribute. False if it + * does. + */ protected boolean doesNotHaveAttribute(int attribute) { return (caveStyle & attribute) != attribute; } @@ -443,4 +481,29 @@ public abstract class CaveSWTDialogBase extends Dialog { } } } + + /** + * Add a callback to the dialog. This callback will be called when the + * dialog is disposed. Also, the caveStyle is updated to include + * DO_NOT_BLOCK. + * + * @param callback + * Callback to be called when the dialog is disposed. + * @throws Throws + * a RejectedExecutionException with a message indicating that + * this method needs to be called before the open method. + */ + public void setCloseCallback(ICloseCallback callback) { + + if (isOpen()) { + StringBuilder sb = new StringBuilder(); + sb.append("The method addCloseCallback() needs to be called before the open(). "); + sb.append("This is due to addCloseCallback setting the caveStyle to DO_NOT_BLOCK"); + throw new RejectedExecutionException(sb.toString()); + } + + // Set the DO_NOT_BLOCK on the cave style + this.caveStyle = caveStyle | CAVE.DO_NOT_BLOCK; + this.closeCallback = callback; + } } diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/ICloseCallback.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/ICloseCallback.java new file mode 100644 index 0000000000..d9df521477 --- /dev/null +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/dialogs/ICloseCallback.java @@ -0,0 +1,47 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.ui.dialogs; + +/** + * + * Callback interface used when a dialog using CaveSWTDialog is disposed. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Sep 11, 2012 #1165      lvenable    Initial creation
+ * 
+ * 
+ * + * @author lvenable + * @version 1.0 + */ +public interface ICloseCallback { + /** + * Method called when a dialog is closed. + * + * @param returnValue + * Return value set in a dialog. + */ + public void dialogClosed(Object returnValue); +}