Merge "Omaha #3974 save damage path to user localization" into omaha_15.1.1

Former-commit-id: 0e60cb9ff1156b0f7606d7daaae6b365e8076072
This commit is contained in:
Nate Jensen 2015-02-03 16:38:48 -06:00 committed by Gerrit Code Review
commit 86c2994048
6 changed files with 110 additions and 18 deletions

View file

@ -119,4 +119,11 @@
version="0.0.0"
unpack="false"/>
<plugin
id="com.raytheon.uf.common.json"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>

View file

@ -81,4 +81,10 @@
install-size="0"
version="0.0.0"/>
<plugin
id="org.codehaus.jackson"
download-size="0"
install-size="0"
version="0.0.0"/>
</feature>

View file

@ -8,5 +8,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: com.raytheon.uf.viz.core;bundle-version="1.14.6",
com.raytheon.uf.viz.drawing;bundle-version="1.14.0",
com.raytheon.uf.common.time;bundle-version="1.14.0",
com.raytheon.uf.common.geospatial;bundle-version="1.14.2"
com.raytheon.uf.common.geospatial;bundle-version="1.14.2",
com.raytheon.uf.common.json;bundle-version="1.0.0"
Export-Package: com.raytheon.uf.viz.damagepath

View file

@ -21,7 +21,18 @@ package com.raytheon.uf.viz.damagepath;
import java.io.File;
import com.raytheon.uf.common.json.geo.GeoJsonUtil;
import com.raytheon.uf.common.json.geo.GeoJsonUtilSimpleImpl;
import com.raytheon.uf.common.localization.FileUpdatedMessage;
import com.raytheon.uf.common.localization.ILocalizationFileObserver;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.LocalizationFileInputStream;
import com.raytheon.uf.common.localization.LocalizationFileOutputStream;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
@ -48,18 +59,28 @@ import com.vividsolutions.jts.geom.Polygon;
*/
public class DamagePathLayer<T extends DamagePathResourceData> extends
PolygonLayer<T> {
PolygonLayer<T> implements ILocalizationFileObserver {
protected static final String NAME = "Damage Path";
private static final String DIR = "damagepath";
private static final String FILE = "damagepath1.json";
private static final String PATH = DIR + IPathManager.SEPARATOR + FILE;
public DamagePathLayer(T resourceData, LoadProperties loadProperties) {
super(resourceData, loadProperties);
/*
* TODO default load from localization file that contains geoJSON
* version of the damage track
*/
// listen for changes to the directory
LocalizationFile dir = PathManagerFactory.getPathManager()
.getLocalizationFile(getUserContext(), DIR);
dir.addFileUpdatedObserver(this);
LocalizationFile prevFile = getDamagePathFile();
if (prevFile.exists()) {
loadDamagePath(prevFile);
}
}
@Override
@ -69,13 +90,15 @@ public class DamagePathLayer<T extends DamagePathResourceData> extends
polygon = PolygonUtil.makeDefaultPolygon(getResourceContainer()
.getActiveDisplayPane().getRenderableDisplay());
}
}
/*
* TODO potentially need to register to listen to changes to a damage
* track file at the site level to support showing the damage track on
* multiple workstations. That will get complicated if we are planning
* on supporting more than one damage path at a time though.
*/
@Override
protected void disposeInternal() {
LocalizationFile dir = PathManagerFactory.getPathManager()
.getLocalizationFile(getUserContext(), DIR);
dir.removeFileUpdatedObserver(this);
super.disposeInternal();
}
@Override
@ -119,11 +142,66 @@ public class DamagePathLayer<T extends DamagePathResourceData> extends
@Override
public void resetPolygon(Coordinate[] coords) {
Polygon prevPolygon = this.getPolygon();
// this call will alter the polygon unless coords is null
super.resetPolygon(coords);
Polygon newPolygon = this.getPolygon();
/*
* TODO need to save the polygon to a site level localization file
* only bother saving the polygon if they're done dragging
*/
if ((prevPolygon == null && newPolygon != null)
|| (newPolygon != null && !this.uiInput.isDragging())) {
LocalizationFile file = getDamagePathFile();
try (LocalizationFileOutputStream fos = file.openOutputStream()) {
GeoJsonUtil json = new GeoJsonUtilSimpleImpl();
json.serialize(this.getPolygon(), fos);
fos.closeAndSave();
} catch (Exception e) {
statusHandler.error(
"Error saving damage path file " + file.getName(), e);
}
}
}
private LocalizationContext getUserContext() {
return PathManagerFactory.getPathManager().getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
}
protected LocalizationFile getDamagePathFile() {
LocalizationContext ctx = getUserContext();
return PathManagerFactory.getPathManager().getLocalizationFile(ctx,
PATH);
}
@Override
public void fileUpdated(FileUpdatedMessage message) {
if (message.getFileName().equals(PATH)) {
LocalizationFile file = getDamagePathFile();
if (file.exists()) {
loadDamagePath(file);
}
}
}
protected void loadDamagePath(LocalizationFile file) {
try (LocalizationFileInputStream fis = file.openInputStream()) {
GeoJsonUtil json = new GeoJsonUtilSimpleImpl();
Polygon geometry = (Polygon) json.deserializeGeom(fis);
fis.close();
/*
* specifically call super.resetPolygon() cause this.resetPolygon()
* will save the file and we don't want to do that or we could
* infinite loop of load, save, load, save...
*/
Polygon current = this.getPolygon();
if (current == null || !current.equals(geometry)) {
super.resetPolygon(geometry.getExteriorRing().getCoordinates());
}
} catch (Exception e) {
statusHandler.error(
"Error loading damage path file " + file.getName(), e);
}
}
}

View file

@ -130,13 +130,14 @@ public class PolygonInputAdapter extends RscInputAdapter<PolygonLayer<?>> {
// user done dragging
blockOtherHandlers = isDragging();
if (draggedVertexIndex > -1) {
dragVertex(draggedVertexIndex, x, y);
int index = draggedVertexIndex;
draggedVertexIndex = -1;
dragVertex(index, x, y);
} else if (draggingPolygon) {
int diffX = x - lastX;
int diffY = y - lastY;
dragPolygon(diffX, diffY);
draggingPolygon = false;
dragPolygon(diffX, diffY);
}
}
}
@ -175,9 +176,9 @@ public class PolygonInputAdapter extends RscInputAdapter<PolygonLayer<?>> {
/**
* Checks if there is some kind of dragging operation related to the polygon
*
* @return
* @return if there is some kind of dragging operation currently going on
*/
protected boolean isDragging() {
public boolean isDragging() {
return (draggedVertexIndex > -1 || draggingPolygon);
}

View file

@ -173,7 +173,6 @@ public class PolygonLayer<T extends AbstractResourceData> extends
* @param coords
*/
public void resetPolygon(Coordinate[] coords) {
synchronized (shapeLock) {
if (coords != null) {
polygon = PolygonUtil.FACTORY.createPolygon(coords);