Merge "Issue #1229 Changes for non-blocking ProcedureDlg." into development

Former-commit-id: cc94e2c9e2 [formerly ab5f3fb23a] [formerly cc94e2c9e2 [formerly ab5f3fb23a] [formerly 6cd8592d80 [formerly bbd65e811b2a9ca5f69af1f8fe7eea9c8e2fc70e]]]
Former-commit-id: 6cd8592d80
Former-commit-id: f8b0807a69 [formerly 5f702fc834]
Former-commit-id: 7e2450cb52
This commit is contained in:
Lee Venable 2012-10-16 13:14:02 -05:00 committed by Gerrit Code Review
commit c6436317bc
3 changed files with 40 additions and 38 deletions

View file

@ -39,6 +39,7 @@ import com.raytheon.uf.viz.d2d.ui.dialogs.procedures.ProcedureDlg;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 13, 2007 chammack Initial Creation.
* Oct 16, 2012 1229 rferrel Change to use ProcedureDlg.displayDialog.
*
* </pre>
*
@ -57,10 +58,8 @@ public class AddAWIPSProcedure extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Procedure procedure = new Procedure();
ProcedureDlg dlg = ProcedureDlg.getOrCreateDialog(null, procedure,
ProcedureDlg.displayDialog(null, procedure,
HandlerUtil.getActiveShell(event));
dlg.open();
return null;
}

View file

@ -24,8 +24,6 @@ import java.io.File;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
import com.raytheon.uf.common.localization.LocalizationFile;
@ -33,7 +31,6 @@ import com.raytheon.uf.common.localization.LocalizationUtil;
import com.raytheon.uf.viz.core.procedures.Procedure;
import com.raytheon.uf.viz.d2d.ui.dialogs.procedures.OpenProcedureListDlg;
import com.raytheon.uf.viz.d2d.ui.dialogs.procedures.ProcedureDlg;
import com.raytheon.uf.viz.d2d.ui.dialogs.procedures.ProcedureListDlg;
import com.raytheon.viz.ui.VizWorkbenchManager;
import com.raytheon.viz.ui.actions.LoadSerializedXml;
@ -47,6 +44,7 @@ import com.raytheon.viz.ui.actions.LoadSerializedXml;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 13, 2007 chammack Initial Creation.
* Oct 16, 2012 1229 rferrel Change to use ProcedureDlg.displayDialog.
*
* </pre>
*
@ -55,8 +53,8 @@ import com.raytheon.viz.ui.actions.LoadSerializedXml;
*/
public class OpenAWIPSProcedure extends AbstractHandler {
private OpenProcedureListDlg dialog;
private OpenProcedureListDlg dialog;
/*
* (non-Javadoc)
*
@ -66,25 +64,23 @@ public class OpenAWIPSProcedure extends AbstractHandler {
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if(dialog != null){
dialog.open();
return null;
}
dialog = new OpenProcedureListDlg(
HandlerUtil.getActiveShell(event));
if (dialog != null) {
dialog.open();
return null;
}
dialog = new OpenProcedureListDlg(HandlerUtil.getActiveShell(event));
dialog.open();
LocalizationFile selectedFile = dialog.getSelectedFile();
dialog = null;
if (selectedFile != null) {
File f = selectedFile.getFile();
Procedure p = (Procedure) LoadSerializedXml.deserialize(f);
ProcedureDlg dlg = ProcedureDlg.getOrCreateDialog(
ProcedureDlg.displayDialog(
LocalizationUtil.extractName(selectedFile.getName()), p,
VizWorkbenchManager.getInstance().getCurrentWindow()
.getShell());
dlg.open();
}
return null;

View file

@ -23,7 +23,7 @@ package com.raytheon.uf.viz.d2d.ui.dialogs.procedures;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
@ -97,6 +97,7 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
* ------------ ---------- ----------- --------------------------
* Initial Creation
* Oct 16, 2012 1229 rferrel Changes for non-blocking AlterBundleDlg.
* Oct 16, 2012 1229 rferrel Changes to have displayDialog method.
*
* </pre>
*
@ -114,7 +115,7 @@ public class ProcedureDlg extends CaveSWTDialog {
public static final String PROCEDURES_DIR = "/procedures";
private static Collection<ProcedureDlg> openDialogs = new ArrayList<ProcedureDlg>();
private static final Map<String, ProcedureDlg> openDialogs = new HashMap<String, ProcedureDlg>();
private Font font;
@ -228,7 +229,7 @@ public class ProcedureDlg extends CaveSWTDialog {
protected void disposed() {
font.dispose();
synchronized (openDialogs) {
openDialogs.remove(this);
openDialogs.remove(fileName);
}
}
@ -927,6 +928,18 @@ public class ProcedureDlg extends CaveSWTDialog {
return;
}
ProcedureDlg oldDlg = getDialog(fn);
if (oldDlg != null) {
oldDlg.close();
}
// Update mapping to new file name.
synchronized (openDialogs) {
openDialogs.remove(fileName);
openDialogs.put(fn, this);
}
frozen = dlg.isFrozen();
fileName = fn;
saveProcedure();
@ -1040,36 +1053,30 @@ public class ProcedureDlg extends CaveSWTDialog {
* @return
*/
public static ProcedureDlg getDialog(String fileName) {
synchronized (openDialogs) {
if (fileName != null) {
for (ProcedureDlg dialog : openDialogs) {
if (fileName.equals(dialog.fileName)) {
return dialog;
}
}
}
return null;
synchronized (ProcedureDlg.openDialogs) {
ProcedureDlg dialog = openDialogs.get(fileName);
return dialog;
}
}
/**
* Get the ProcedureDlg for the given fileName. If the fileName is null or
* if there is no open dialog, create a new ProcedureDlg.
* Get the ProcedureDlg for the given fileName and display it.
*
* @param fileName
* @param p
* @param parent
* @return
*/
public static ProcedureDlg getOrCreateDialog(String fileName, Procedure p,
Shell parent) {
public static void displayDialog(String fileName, Procedure p, Shell parent) {
synchronized (openDialogs) {
ProcedureDlg dialog = getDialog(fileName);
if (dialog == null) {
if (dialog == null || dialog.getShell() == null
|| dialog.isDisposed()) {
dialog = new ProcedureDlg(fileName, p, parent);
openDialogs.add(dialog);
openDialogs.put(fileName, dialog);
dialog.open();
} else {
dialog.bringToTop();
}
return dialog;
}
}
}