Merge "Omaha #5511: Rewrite RPS List Editor dialog based on CaveSWTDialog." into omaha_16.2.1-lx

Former-commit-id: abb5864eb4587f0c25161ec750d31f3abc8024d1
This commit is contained in:
Ron Anderson 2016-03-29 16:39:09 -05:00 committed by Gerrit Code Review
commit 6c78854b57
6 changed files with 665 additions and 604 deletions

View file

@ -10,9 +10,10 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.databinding;bundle-version="1.1.1",
org.eclipse.jface.databinding;bundle-version="1.2.1",
com.raytheon.rcm.lib;bundle-version="1.0.0",
com.raytheon.uf.common.localization;bundle-version="1.12.1174"
com.raytheon.uf.common.localization;bundle-version="1.12.1174",
com.raytheon.viz.ui;bundle-version="1.15.2",
com.raytheon.uf.common.status;bundle-version="1.15.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Vendor: Raytheon
Export-Package: com.raytheon.uf.viz.radarapps.rps
Import-Package: com.raytheon.uf.common.status

View file

@ -1,188 +0,0 @@
/**
* 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.uf.viz.radarapps.rps;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.rcm.config.RadarType;
import com.raytheon.rcm.products.ElevationInfo;
import com.raytheon.rcm.request.Request;
import com.raytheon.rcm.request.RpsList;
import com.raytheon.rcm.request.RpsListFormatter;
/** Not an Eclipse editor. Main container class for an RPS list editing
* session.
*
*/
public class ListEditor {
ListEditorWindow window;
private boolean dirty;
private boolean untitled;
private File path = new File("");
private int vcp;
private String radarID;
private WritableList requestList;
public ListEditor() {
vcp = -1;
requestList = new WritableList();
window = new ListEditorWindow(this);
int vcp = -1;
try {
vcp = ElevationInfo.getInstance().getVcpInfo().iterator().next().vcp;
} catch (RuntimeException e) {
// nothing
}
newList(null, vcp);
}
public void newList(String radarID, int vcp) {
setRadarID(radarID);
setVcp(vcp);
getRequestList().clear();
String name = String.format("Untitled.%sVCP%d.rps",
radarID != null ? radarID.toUpperCase() + "." : "", getVcp());
setPath(new File(name));
setUntitled(true);
setDirty(false);
}
public void startEditor() {
window.open();
}
public void dispose() {
window.shell.dispose();
}
public Shell getShell() {
if (window != null)
return window.shell;
return null;
}
public RpsList getRpsList() {
RpsList list = new RpsList(
ElevationInfo.getInstance().getOpModeForVcp(getVcp()),
getVcp(),
(Request[]) getRequestList().toArray(new Request[0]));
return list;
}
public WritableList getRequestList() {
return requestList;
}
private void updateTitle() {
StringBuilder sb = new StringBuilder();
sb.append("RPS List Editor: ");
if (isDirty())
sb.append("* ");
if (path != null)
sb.append(path.getName());
getShell().setText(sb.toString());
}
public void setVcp(int vcp) {
this.vcp = vcp;
}
public int getVcp() {
return vcp;
}
public void setRadarID(String radarID) {
this.radarID = radarID;
}
public String getRadarID() {
return radarID;
}
public void setPath(File path) {
this.path = path;
updateTitle();
}
public File getPath() {
return path;
}
public boolean isTdwrVcp(int vcp) {
return vcp == 80 || vcp == 90;
}
public RadarType getTypeRestriction() {
if (vcp > 0)
return isTdwrVcp(vcp) ? RadarType.TDWR : RadarType.WSR;
else
return null;
}
public void setDirty(boolean dirty) {
this.dirty = dirty;
updateTitle();
}
public boolean isDirty() {
return dirty;
}
public void setUntitled(boolean untitled) {
this.untitled = untitled;
}
public boolean isUntitled() {
return untitled;
}
public boolean saveList() {
if (path.getName().length() == 0 || isUntitled())
return false;
try {
FileOutputStream fo = new FileOutputStream(path);
try {
PrintWriter p = new PrintWriter(fo);
RpsListFormatter.formatAwips1RpsList(getRpsList(), path.getName(),p);
p.flush();
} finally {
fo.close();
}
} catch (RuntimeException e) {
window.showError(String.format("Could not save list: %s",
e.getMessage()));
} catch (IOException e) {
window.showError(String.format("Could not write list to '%s: %s'",
path, e.getMessage()));
return false;
}
setDirty(false);
return true;
}
}

View file

@ -22,25 +22,48 @@ package com.raytheon.uf.viz.radarapps.rps;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* An abstract handler for showing the RPS List Editor dialog.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* ??? ??, 20?? ???????? Initial creation
* Mar 28, 2016 #5511 dgilling Code cleanup.
*
* </pre>
*
* @author ????????
* @version 1.0
*/
public class RPSListEditorCommandHandler extends AbstractHandler {
static ListEditor listEditor;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (listEditor == null) {
listEditor = new ListEditor();
listEditor.getShell().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
listEditor = null;
}
});
}
listEditor.startEditor();
return null;
}
protected RpsListEditorDlg dialog;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (dialog == null) {
Shell parent = HandlerUtil.getActiveShellChecked(event);
dialog = new RpsListEditorDlg(parent, new RpsListRequestContainer());
dialog.addListener(SWT.Dispose, new Listener() {
@Override
public void handleEvent(Event event) {
dialog = null;
}
});
}
dialog.open();
return null;
}
}

View file

@ -0,0 +1,203 @@
/**
* 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.uf.viz.radarapps.rps;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.eclipse.core.databinding.observable.list.WritableList;
import com.raytheon.rcm.config.RadarType;
import com.raytheon.rcm.products.ElevationInfo;
import com.raytheon.rcm.products.ElevationInfo.VCPInfo;
import com.raytheon.rcm.request.Request;
import com.raytheon.rcm.request.RpsList;
import com.raytheon.rcm.request.RpsListFormatter;
/**
* Not an Eclipse editor. Main container class for an RPS list editing session.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* ??? ??, 20?? ???????? Initial creation
* Mar 28, 2016 #5511 dgilling Renamed from ListEditor, code cleanup.
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class RpsListRequestContainer {
private final WritableList requestList;
private boolean dirty;
private boolean untitled;
private File path;
private int vcp;
private String radarID;
public RpsListRequestContainer() {
this.requestList = new WritableList();
this.path = null;
Collection<VCPInfo> vcpInfo = ElevationInfo.getInstance().getVcpInfo();
this.vcp = (vcpInfo.isEmpty()) ? -1 : vcpInfo.iterator().next().vcp;
newList(null, vcp);
}
public void newList(String radarID, int vcp) {
setRadarID(radarID);
setVcp(vcp);
getRequestList().clear();
String name = String.format("Untitled.%sVCP%d.rps",
radarID != null ? radarID.toUpperCase() + "." : "", getVcp());
setPath(new File(name));
setUntitled(true);
setDirty(false);
}
public RpsList getRpsList() {
RpsList list = new RpsList(ElevationInfo.getInstance().getOpModeForVcp(
getVcp()), getVcp(), (Request[]) getRequestList().toArray(
new Request[0]));
return list;
}
public WritableList getRequestList() {
return requestList;
}
public void add(Request req) {
getRequestList().add(req);
setDirty(true);
}
public void removeAll(List<?> list) {
setDirty(getRequestList().removeAll(list));
}
public void setItem(int i, Request newReq) {
getRequestList().set(i, newReq);
setDirty(true);
}
private void setVcp(int vcp) {
this.vcp = vcp;
}
public int getVcp() {
return vcp;
}
private void setRadarID(String radarID) {
this.radarID = radarID;
}
public String getRadarID() {
return radarID;
}
private void setPath(File path) {
this.path = path;
}
public File getPath() {
return path;
}
public boolean isTdwrVcp(int vcp) {
return vcp == 80 || vcp == 90;
}
public RadarType getTypeRestriction() {
if (vcp > 0) {
return isTdwrVcp(vcp) ? RadarType.TDWR : RadarType.WSR;
} else {
return null;
}
}
private void setDirty(boolean dirty) {
this.dirty = dirty;
}
public boolean isDirty() {
return dirty;
}
private void setUntitled(boolean untitled) {
this.untitled = untitled;
}
public boolean isUntitled() {
return untitled;
}
public boolean saveList() throws FileNotFoundException, IOException {
if (path.getName().length() == 0 || isUntitled()) {
return false;
}
try (OutputStream outStream = new FileOutputStream(path);
PrintWriter out = new PrintWriter(outStream)) {
RpsListFormatter.formatAwips1RpsList(getRpsList(), path.getName(),
out);
}
setDirty(false);
return true;
}
public boolean saveList(File file) throws FileNotFoundException,
IOException {
setPath(file);
setUntitled(false);
return saveList();
}
public void replaceList(RpsList newList, String radarID, File file) {
replaceList(newList, radarID, file, false);
}
public void replaceList(RpsList newList, String radarID, File file,
boolean isDummyFileName) {
newList(radarID, newList.getVcp());
getRequestList().addAll(Arrays.asList(newList.getRequests()));
setPath(file);
setUntitled(isDummyFileName);
}
}

View file

@ -65,7 +65,7 @@ import com.raytheon.uf.viz.radarapps.core.RadarApps;
*/
public class StoreDialog extends Dialog {
ListEditor listEditor;
RpsListRequestContainer listEditor;
ArrayList<String> selectedRadarIDs = new ArrayList<String>();
@ -75,7 +75,7 @@ public class StoreDialog extends Dialog {
TableViewer vcpViewer;
public StoreDialog(Shell parentShell, ListEditor listEditor) {
public StoreDialog(Shell parentShell, RpsListRequestContainer listEditor) {
super(parentShell);
this.listEditor = listEditor;
}