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

View file

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

View file

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