Merge "Issue #1353 Changes for non-blocking RetrieveMergeDlg and LoadSaveDelteSelectDlg close callbacks added to FFFGDlg." into development

Former-commit-id: 6a187c705a [formerly 6a187c705a [formerly e433fbe19e51138c78f69b8a3a89decffbb75f13]]
Former-commit-id: a0ba84d5e0
Former-commit-id: e76cb36b09
This commit is contained in:
Lee Venable 2012-12-03 13:09:53 -06:00 committed by Gerrit Code Review
commit 0f16eccdee
2 changed files with 225 additions and 190 deletions

View file

@ -60,6 +60,9 @@ import com.raytheon.uf.common.monitor.config.FFFGDataMgr;
import com.raytheon.uf.common.monitor.config.SourceCompData;
import com.raytheon.uf.common.monitor.config.ValueNameIdData;
import com.raytheon.uf.common.monitor.xml.FFFGBasinIdXML;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.SimulatedTime;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.monitor.ffmp.FFMPMonitor;
@ -67,6 +70,7 @@ import com.raytheon.uf.viz.monitor.ffmp.fffg.RetrieveMergeDlg.RetrieveMergeActio
import com.raytheon.uf.viz.monitor.ui.dialogs.LoadSaveDeleteSelectDlg;
import com.raytheon.uf.viz.monitor.ui.dialogs.LoadSaveDeleteSelectDlg.DialogType;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
/**
*
@ -83,6 +87,8 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* Changes for non-blocking AboutDlg.
* Changes for non-blocking AcknowledgmentsDlg.
* Changes for non-blocking HelpDlg.
* Changes for non-blocking RetrieveMergeDlg.
* Changes for non-blocking LoadSaveDeleteSelectDlg.
*
* </pre>
*
@ -91,6 +97,9 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
*/
public class FFFGDlg extends CaveSWTDialog implements ISourceCompAction,
IFFFGData {
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(FFFGDlg.class);
private final String MODIFIED = "Modified";
/**
@ -218,6 +227,21 @@ public class FFFGDlg extends CaveSWTDialog implements ISourceCompAction,
*/
private RetrieveMergeDlg retMergeDlg;
/**
* Dialog prompting the user for save file.
*/
private LoadSaveDeleteSelectDlg saveDlg;
/**
* Dialog prompting the user for delete file.
*/
private LoadSaveDeleteSelectDlg deleteDlg;
/**
* Dialog for getting file to retrieve.
*/
private LoadSaveDeleteSelectDlg loadDlg;
/**
* Popup for Help menu item
*/
@ -1575,32 +1599,73 @@ public class FFFGDlg extends CaveSWTDialog implements ISourceCompAction,
* Retrieve saved data.
*/
private void retrieveSavedData() {
RetrieveMergeAction action = RetrieveMergeDlg.RetrieveMergeAction.CANCEL;
if (isDialogClear() && (fileNameLbl.getText().trim().length() == 0)) {
action = RetrieveMergeAction.RETRIEVE;
} else {
if (retMergeDlg == null) {
retMergeDlg = new RetrieveMergeDlg(shell);
action = retMergeDlg.open();
retMergeDlg = null;
}
}
if (action == RetrieveMergeAction.CANCEL) {
if (loadDlg != null) {
// The RetriveMergeDlg has done its work but still waiting for the
// user to pick file to retrive.
loadDlg.open();
return;
}
if (isDialogClear() && (fileNameLbl.getText().trim().length() == 0)) {
return;
} else {
if (retMergeDlg == null) {
retMergeDlg = new RetrieveMergeDlg(shell);
retMergeDlg.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
if (returnValue instanceof RetrieveMergeAction) {
RetrieveMergeAction action = (RetrieveMergeAction) returnValue;
getRetrieveFilename(action);
}
retMergeDlg = null;
}
});
}
retMergeDlg.open();
}
}
/**
* Get file to retrieve and then perform the action.
*
* @param action
*/
private void getRetrieveFilename(final RetrieveMergeAction action) {
FFFGDataMgr fdm = FFFGDataMgr.getInstance();
LoadSaveDeleteSelectDlg loadDlg = new LoadSaveDeleteSelectDlg(shell,
DialogType.OPEN, fdm.getFFFGDataFilePath(),
fdm.getFFFGMasterFileName());
LocalizationFile fileName = (LocalizationFile) loadDlg.open();
loadDlg = new LoadSaveDeleteSelectDlg(shell, DialogType.OPEN,
fdm.getFFFGDataFilePath(), fdm.getFFFGMasterFileName());
loadDlg.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
if (returnValue instanceof LocalizationFile) {
LocalizationFile fileName = (LocalizationFile) returnValue;
doRetrieveSavedData(action, fileName);
}
loadDlg = null;
}
});
loadDlg.open();
}
/**
* Perform the desired and and update the display.
*
* @param action
* @param fileName
*/
private void doRetrieveSavedData(RetrieveMergeAction action,
LocalizationFile fileName) {
if (fileName == null) {
return;
}
FFFGDataMgr fdm = FFFGDataMgr.getInstance();
fdm.loadUserFFFGData(fileName.getFile().getName());
@ -1812,16 +1877,28 @@ public class FFFGDlg extends CaveSWTDialog implements ISourceCompAction,
* Save the file to a user selected file name.
*/
private void saveFileAs() {
FFFGDataMgr fdm = FFFGDataMgr.getInstance();
if (saveDlg == null) {
FFFGDataMgr fdm = FFFGDataMgr.getInstance();
LoadSaveDeleteSelectDlg loadDlg = new LoadSaveDeleteSelectDlg(shell,
DialogType.SAVE_AS, fdm.getFFFGDataFilePath(),
fdm.getFFFGMasterFileName());
LocalizationFile fileName = (LocalizationFile) loadDlg.open();
saveDlg = new LoadSaveDeleteSelectDlg(shell, DialogType.SAVE_AS,
fdm.getFFFGDataFilePath(), fdm.getFFFGMasterFileName());
saveDlg.setCloseCallback(new ICloseCallback() {
if (fileName == null) {
return;
@Override
public void dialogClosed(Object returnValue) {
if (returnValue instanceof LocalizationFile) {
LocalizationFile fileName = (LocalizationFile) returnValue;
doSaveFileAs(fileName);
}
saveDlg = null;
}
});
}
saveDlg.open();
}
private void doSaveFileAs(LocalizationFile fileName) {
FFFGDataMgr fdm = FFFGDataMgr.getInstance();
ArrayList<SourceCompData> srcCompData = getSourceCompData();
@ -1861,20 +1938,32 @@ public class FFFGDlg extends CaveSWTDialog implements ISourceCompAction,
}
/**
* Delete that user selected file.
* Delete the user selected file.
*/
private void deleteFile() {
FFFGDataMgr fdm = FFFGDataMgr.getInstance();
if (deleteDlg == null) {
FFFGDataMgr fdm = FFFGDataMgr.getInstance();
LoadSaveDeleteSelectDlg lsDlg = new LoadSaveDeleteSelectDlg(shell,
DialogType.DELETE, fdm.getFFFGDataFilePath(),
fdm.getFFFGMasterFileName());
LocalizationFile fileName = (LocalizationFile) lsDlg.open();
deleteDlg = new LoadSaveDeleteSelectDlg(shell, DialogType.DELETE,
fdm.getFFFGDataFilePath(), fdm.getFFFGMasterFileName());
deleteDlg.setCloseCallback(new ICloseCallback() {
if (fileName == null) {
setStatusMsg("FileName is null...");
return;
@Override
public void dialogClosed(Object returnValue) {
if (returnValue instanceof LocalizationFile) {
LocalizationFile fileName = (LocalizationFile) returnValue;
doDeleteFile(fileName);
}
deleteDlg = null;
};
});
}
deleteDlg.open();
}
private void doDeleteFile(LocalizationFile fileName) {
FFFGDataMgr fdm = FFFGDataMgr.getInstance();
String name = fileName.getFile().getName();
try {
if (fileName.getFile().getName().compareTo(fdm.getUserFileName()) == 0) {
@ -1882,12 +1971,13 @@ public class FFFGDlg extends CaveSWTDialog implements ISourceCompAction,
fileNameLbl.setText("");
updateFileStatusLabel(false);
}
String name = fileName.getFile().getName();
fileName.delete();
setStatusMsg("Deleted " + name + " successfully. ");
fileName = null;
} catch (Exception e) {
e.printStackTrace();
statusHandler.handle(Priority.PROBLEM, "Unable to delete file \""
+ fileName.toString() + "\"", e);
setStatusMsg("Problem deleting file: " + name);
}
}

View file

@ -20,273 +20,218 @@
package com.raytheon.uf.viz.monitor.ffmp.fffg;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
/**
* Dialog used to bring data in for the FFFG dialog. There are
* 3 options:
* Dialog used to bring data in for the FFFG dialog. There are 3 options:
*
* Retrieve - Clear current data entirely and load data from the selected file.
*
* Merge - Retain current data and load data from the selected file. Current
* data will NOT be overwritten by incoming data when the two conflict.
*
* Merge - Retain current data and load data from the selected file. Current
* data will NOT be overwritten by incoming data when the two conflict.
*
* Merge/Overwrite - Retain current data and load data from the selected file.
* Incoming data will overwrite current data when the two
* conflict.
* Incoming data will overwrite current data when the two conflict.
*
* <pre>
*
*
* SOFTWARE HISTORY
*
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 13, 2010 lvenable Initial creation
*
* Nov 29, 2012 1353 rferrel Convert to CavSWTDialog
* and make non-blocking
*
* </pre>
*
*
* @author lvenable
* @version 1.0
*/
public class RetrieveMergeDlg extends Dialog
{
/**
* Dialog shell.
*/
private Shell shell;
/**
* The display control.
*/
private Display display;
public class RetrieveMergeDlg extends CaveSWTDialog {
/**
* Enumeration of the retrieve options.
*/
public static enum RetrieveMergeAction
{
RETRIEVE("Retrieve"),
MERGE_OVERWRITE("Merge/Overwrite"),
MERGE("Merge"),
CANCEL("Cancel");
public static enum RetrieveMergeAction {
RETRIEVE("Retrieve"), MERGE_OVERWRITE("Merge/Overwrite"), MERGE("Merge"), CANCEL(
"Cancel");
private String actionName;
RetrieveMergeAction(String name)
{
RetrieveMergeAction(String name) {
actionName = name;
}
public String getActionName()
{
public String getActionName() {
return actionName;
}
}
/**
* Retrieve choice.
*/
private RetrieveMergeAction choice = RetrieveMergeAction.CANCEL;
/**
* Retrieve radio button.
*/
private Button retrieveRdo;
/**
* Merge/Overwrite button.
*/
private Button mergeOvrWriteRdo;
/**
* Merge button.
*/
private Button mergeRdo;
/**
* The selected button.
*/
private Button selectedRdo;
/**
* Constructor.
* @param parent Parent control.
*
* @param parent
* Parent control.
*/
public RetrieveMergeDlg(Shell parent)
{
super(parent, 0);
public RetrieveMergeDlg(Shell parent) {
super(parent, SWT.DIALOG_TRIM, CAVE.DO_NOT_BLOCK);
setText("Retrieve/Merge FFG File");
}
/**
* Open/Display the dialog.
* @return The choice made by the operator.
*/
public RetrieveMergeAction open()
{
Shell parent = getParent();
display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM);
shell.setText("Retrieve/Merge FFG File");
@Override
protected void initializeComponents(Shell shell) {
// Create the main layout for the shell.
GridLayout mainLayout = new GridLayout(1, false);
mainLayout.marginHeight = 3;
mainLayout.marginWidth = 3;
shell.setLayout(mainLayout);
// Initialize all of the controls and layouts
initializeComponents();
parent.addDisposeListener(new DisposeListener()
{
@Override
public void widgetDisposed(DisposeEvent e)
{
shell.dispose();
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
return choice;
}
/**
* Initialize the controls on the dialog.
*/
private void initializeComponents()
{
private void initializeComponents() {
createRetrieveMergeControls();
createBottomButtons();
}
/**
* Create the Retrieve, Merge/Overwrite, and Merge controls.
*/
private void createRetrieveMergeControls()
{
private void createRetrieveMergeControls() {
Group controlGrp = new Group(shell, SWT.BORDER);
GridLayout gl = new GridLayout(2, false);
gl.verticalSpacing = 20;
controlGrp.setLayout(gl);
controlGrp.setText(" Please choose your selection: ");
SelectionListener listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Button button = (Button) e.widget;
if (button.getSelection()) {
selectedRdo = button;
}
}
};
GridData gd = new GridData(SWT.DEFAULT, SWT.TOP, false, true);
retrieveRdo = new Button(controlGrp, SWT.RADIO);
retrieveRdo.setText("Retrieve: ");
retrieveRdo.setSelection(true);
selectedRdo = retrieveRdo;
selectedRdo.addSelectionListener(listener);
selectedRdo.setData(RetrieveMergeAction.RETRIEVE);
retrieveRdo.setLayoutData(gd);
Label retrieveLbl = new Label(controlGrp, SWT.NONE);
retrieveLbl.setText("Clear current data entirely and load data\nfrom the selected file.");
retrieveLbl
.setText("Clear current data entirely and load data\nfrom the selected file.");
/*
* ** NOTE:
* The merge features are disabled due to the limitations
* of having 4 sources to edit. If 3 unique sources are to
* be merged with 3 other unique sources on the display there
* would be 6 sources trying to fit into 4 available areas.
* I have ideas for a more elegant solution that will allow
* more than just 4 sources.
* ** NOTE: The merge features are disabled due to the limitations of
* having 4 sources to edit. If 3 unique sources are to be merged with 3
* other unique sources on the display there would be 6 sources trying
* to fit into 4 available areas. I have ideas for a more elegant
* solution that will allow more than just 4 sources.
*/
gd = new GridData(SWT.DEFAULT, SWT.TOP, false, true);
mergeOvrWriteRdo = new Button(controlGrp, SWT.RADIO);
mergeOvrWriteRdo.setText("Merge Overwrite: ");
mergeOvrWriteRdo.addSelectionListener(listener);
mergeOvrWriteRdo.setData(RetrieveMergeAction.MERGE_OVERWRITE);
mergeOvrWriteRdo.setLayoutData(gd);
Label mergeOvrWriteLbl = new Label(controlGrp, SWT.NONE);
mergeOvrWriteLbl.setText("Retain current data and load data from the\n" +
"selected file. Incoming data will overwrite\n" +
"current data when the two conflict.");
mergeOvrWriteLbl.setText("Retain current data and load data from the\n"
+ "selected file. Incoming data will overwrite\n"
+ "current data when the two conflict.");
gd = new GridData(SWT.DEFAULT, SWT.TOP, false, true);
mergeRdo = new Button(controlGrp, SWT.RADIO);
mergeRdo.setText("Merge: ");
mergeRdo.addSelectionListener(listener);
mergeRdo.setData(RetrieveMergeAction.MERGE);
mergeRdo.setLayoutData(gd);
Label mergeLbl = new Label(controlGrp, SWT.NONE);
mergeLbl.setText("Retain current data and load data from the\n" +
"selected file. Current data will NOT be\n" +
"overwritten by incoming data when the two\n" +
"conflict.");
mergeLbl.setText("Retain current data and load data from the\n"
+ "selected file. Current data will NOT be\n"
+ "overwritten by incoming data when the two\n" + "conflict.");
}
/**
* Create the buttons on the bottom of the display.
*/
private void createBottomButtons()
{
private void createBottomButtons() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
Composite buttonComp = new Composite(shell, SWT.NONE);
buttonComp.setLayout(new GridLayout(2, false));
buttonComp.setLayoutData(gd);
int buttonWidth = 100;
gd = new GridData(SWT.RIGHT, SWT.DEFAULT, true, false);
gd.widthHint = buttonWidth;
Button okBtn = new Button(buttonComp, SWT.PUSH);
okBtn.setText("OK");
okBtn.setLayoutData(gd);
okBtn.addSelectionListener(new SelectionAdapter()
{
okBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
updateChoice();
shell.dispose();
}
public void widgetSelected(SelectionEvent e) {
setReturnValue(selectedRdo.getData());
close();
}
});
gd = new GridData(SWT.LEFT, SWT.DEFAULT, true, false);
gd.widthHint = buttonWidth;
Button cancelBtn = new Button(buttonComp, SWT.PUSH);
cancelBtn.setText("Cancel");
cancelBtn.setLayoutData(gd);
cancelBtn.addSelectionListener(new SelectionAdapter()
{
cancelBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
choice = RetrieveMergeAction.CANCEL;
shell.dispose();
}
public void widgetSelected(SelectionEvent e) {
close();
}
});
}
/**
* Update the choice selected by the operator.
*/
private void updateChoice()
{
if (retrieveRdo.getSelection() == true)
{
choice = RetrieveMergeAction.RETRIEVE;
}
else if (mergeOvrWriteRdo.getSelection() == true)
{
choice = RetrieveMergeAction.MERGE_OVERWRITE;
}
else if (mergeRdo.getSelection() == true)
{
choice = RetrieveMergeAction.MERGE;
}
}
}