Issue #875 Modification based on reviewers comments.

Issue #875 Implement Drag and Drop and converted point files to JAXB.

Change-Id: I3056794e1c77a02117998ac3f2d242c3ede3392b

Former-commit-id: a4987d9d8e [formerly f7c56e0a73] [formerly ca52d45911] [formerly 23a67f458a [formerly ca52d45911 [formerly ea356c6c0ff3962542aad451a7a1ec65a5921628]]]
Former-commit-id: 23a67f458a
Former-commit-id: cde0c4c81702c1a1d3d4bd95d80532e046717eed [formerly 544ea1ff53]
Former-commit-id: c0f3f26eac
This commit is contained in:
Roger Ferrel 2012-08-17 11:44:39 -05:00
parent 25585ca8d7
commit 8bf9c837bb
17 changed files with 1299 additions and 588 deletions

View file

@ -40,9 +40,9 @@ import java.util.regex.Pattern;
*/
public class PointUtilities {
static final public char DELIM_CHAR = '~';
public static final char DELIM_CHAR = '~';
static final public String DELIMITER = String.valueOf(DELIM_CHAR);
public static final String DELIMITER = String.valueOf(DELIM_CHAR);
public static final int MAX_LATITUDE = 90;
@ -52,16 +52,6 @@ public class PointUtilities {
public static final double SECOND_PER_MINUTE = 60;
public final static int FONT_1 = 12;
public final static int FONT_2 = 14;
public final static int FONT_3 = 18;
public final static int FONT_4 = 24;
public final static int FONT_5 = 30;
private static final Pattern RedundantWhiteSpace = Pattern.compile("\\s+");
private static final Pattern SingleSpace = Pattern.compile("\\s");
@ -69,7 +59,11 @@ public class PointUtilities {
private static final Pattern invalidFileName = Pattern
.compile("[^A-Za-z0-9_ ]");
static public String removeRedundantWhiteSpace(String name) {
private PointUtilities() {
// Never need an instance of this class.
}
public static String removeRedundantWhiteSpace(String name) {
Matcher matcher = RedundantWhiteSpace.matcher(name);
String str = matcher.replaceAll(" ");
return str;
@ -81,7 +75,7 @@ public class PointUtilities {
* @param name
* @return str
*/
static public String convertSpaceToDelimiter(String name) {
public static String convertSpaceToDelimiter(String name) {
Matcher matcher = SingleSpace.matcher(name);
String str = matcher.replaceAll(DELIMITER);
return str;
@ -94,7 +88,7 @@ public class PointUtilities {
* @param str
* @return
*/
static public String trimAll(String str) {
public static String trimAll(String str) {
str = str.trim();
str = PointUtilities.removeRedundantWhiteSpace(str);
return str;
@ -107,7 +101,7 @@ public class PointUtilities {
* @param filename
* @return
*/
static public boolean isValidFileName(String filename) {
public static boolean isValidFileName(String filename) {
boolean isValid = true;
Matcher matcher = invalidFileName.matcher(filename);
if (matcher.find()) {

View file

@ -39,11 +39,15 @@ import org.eclipse.swt.graphics.RGB;
*/
public class GroupNode extends Point {
public GroupNode() {
super();
}
/**
* @param m
* @param node
*/
public GroupNode(Point m) {
super(m);
public GroupNode(Point node) {
super(node);
}
public GroupNode(String groupName) {

View file

@ -20,14 +20,23 @@
package com.raytheon.uf.viz.points.data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.viz.points.PointUtilities;
import com.vividsolutions.jts.geom.Coordinate;
/**
* A Point is a user-defined, named, geospatial location as defined by a
* latitude and longitude.
* latitude and longitude. This also allows the point to be hidden, the point to
* be movable, allow grouping with other points, and finally the font color and
* size to use to display the name on a map.
*
*
* <pre>
@ -45,72 +54,151 @@ import com.vividsolutions.jts.geom.Coordinate;
* @author epolster
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "point")
@DynamicSerialize
public class Point implements IPointNode, Comparable<IPointNode> {
@XmlElement(name = "name")
@DynamicSerializeElement
private String name;
private Coordinate location;
@XmlElement(name = "longitude")
@DynamicSerializeElement
private double longitude;
@XmlElement(name = "latitude")
@DynamicSerializeElement
private double latitude;
@XmlElement(name = "colorActive")
@DynamicSerializeElement
private boolean colorActive;
private RGB color;
@XmlElement(name = "red")
@DynamicSerializeElement
private int red;
private boolean isHidden;
@XmlElement(name = "green")
@DynamicSerializeElement
private int green;
private boolean isMovable;
@XmlElement(name = "blue")
@DynamicSerializeElement
private int blue;
@XmlElement(name = "hidden")
@DynamicSerializeElement
private boolean hidden;
@XmlElement(name = "movable")
@DynamicSerializeElement
private boolean movable;
@XmlElement(name = "fontSize")
@DynamicSerializeElement
private PointSize fontSize = PointSize.DEFAULT;
private transient String group;
private PointSize fontSize = PointSize.DEFAULT;
public Point() {
}
// copy ctor
/**
* Copy contructor.
*
* @param point
*/
public Point(Point point) {
this.name = point.name;
this.location = point.location;
this.longitude = point.longitude;
this.latitude = point.latitude;
this.colorActive = point.colorActive;
this.color = point.color;
this.red = point.red;
this.green = point.green;
this.blue = point.blue;
this.fontSize = point.fontSize;
this.isHidden = point.isHidden;
this.isMovable = point.isMovable;
this.hidden = point.hidden;
this.movable = point.movable;
this.group = point.group;
}
/**
* @param pointName
* @param p
* @param colorActive
* @param c
* @param hidden
* @param Movable
* @param ms
* @param group
*/
public Point(String pointName, Coordinate p, boolean colorActive, RGB c,
boolean hidden, boolean Movable, PointSize ms, String group) {
this.name = PointUtilities.trimAll(pointName);
this.location = p;
this.longitude = p.x;
this.latitude = p.y;
this.colorActive = colorActive;
this.color = c;
this.isHidden = hidden;
this.isMovable = Movable;
this.red = c.red;
this.green = c.green;
this.blue = c.blue;
this.hidden = hidden;
this.movable = Movable;
this.fontSize = ms;
this.group = group;
}
// constructor must take valid lat/lon coordinates!
/**
* Constructor must take valid lat/lon coordinates!
*
* @param pointName
* @param lat
* @param lon
* @param hidden
* @param movable
* @param colorActive
* @param c
* @param group
*/
public Point(String pointName, double lat, double lon, boolean hidden,
boolean movable, boolean colorActive, RGB c, String group) {
this.name = PointUtilities.trimAll(pointName);
this.fontSize = PointSize.DEFAULT;
this.colorActive = colorActive;
this.color = c;
this.isMovable = movable;
this.isHidden = hidden;
this.location = new Coordinate(lon, lat);
this.red = c.red;
this.green = c.green;
this.blue = c.blue;
this.movable = movable;
this.hidden = hidden;
this.longitude = lon;
this.latitude = lat;
this.group = group.replace(' ', PointUtilities.DELIM_CHAR);
}
// constructor must take valid lat/lon coordinates!
/**
* Constructor must take valid lat/lon coordinates!
*
* @param pointName
* @param lat
* @param lon
* @param movable
* @param colorActive
* @param c
* @param size
* @param group
*/
public Point(String pointName, double lat, double lon, boolean movable,
boolean colorActive, RGB c, PointSize size, String group) {
this.name = PointUtilities.trimAll(pointName);
this.fontSize = size;
this.colorActive = colorActive;
this.color = c;
this.isMovable = movable;
this.isHidden = false;
this.location = new Coordinate(lon, lat);
this.red = c.red;
this.green = c.green;
this.blue = c.blue;
this.movable = movable;
this.hidden = false;
this.longitude = lon;
this.latitude = lat;
this.group = group.replace(' ', PointUtilities.DELIM_CHAR);
}
@ -118,42 +206,43 @@ public class Point implements IPointNode, Comparable<IPointNode> {
* @return latitude
*/
public double getLatitude() {
return location.y;
return latitude;
}
/**
* @param latitude
*/
public void setLatitude(double latitude) {
location = new Coordinate(location.x, latitude);
this.latitude = latitude;
}
/**
* @return longitude
*/
public double getLongitude() {
return location.x;
return longitude;
}
/**
* @return coordinate
*/
public Coordinate getCoordinate() {
return new Coordinate(location);
return new Coordinate(longitude, latitude);
}
/**
* @param coordinate
*/
public void setCoordinate(Coordinate coordinate) {
location = coordinate;
this.longitude = coordinate.x;
this.latitude = coordinate.y;
}
/**
* @param longitude
*/
public void setLongitude(double longitude) {
location = new Coordinate(longitude, location.y);
this.longitude = longitude;
}
/*
@ -177,7 +266,7 @@ public class Point implements IPointNode, Comparable<IPointNode> {
* @param h
*/
public void setHidden(boolean h) {
isHidden = h;
hidden = h;
}
/*
@ -187,7 +276,7 @@ public class Point implements IPointNode, Comparable<IPointNode> {
*/
@Override
public boolean isHidden() {
return isHidden;
return hidden;
}
/**
@ -208,14 +297,16 @@ public class Point implements IPointNode, Comparable<IPointNode> {
* @return rgb
*/
public RGB getColor() {
return color;
return new RGB(red, green, blue);
}
/**
* @param c
*/
public void setColor(RGB c) {
color = c;
this.red = c.red;
this.green = c.green;
this.blue = c.blue;
}
/*
@ -224,8 +315,8 @@ public class Point implements IPointNode, Comparable<IPointNode> {
* @see java.lang.Object#clone()
*/
public Object clone() {
Point m = new Point(this);
return m;
Point point = new Point(this);
return point;
}
/**
@ -242,34 +333,6 @@ public class Point implements IPointNode, Comparable<IPointNode> {
fontSize = fs;
}
/**
* @return
*/
public boolean isAtMaxSize() {
return fontSize.isAtMaxSize();
}
/**
* @return
*/
public boolean isAtMinSize() {
return fontSize.isAtMinSize();
}
/**
*
*/
public void increaseFontSize() {
fontSize = fontSize.getNextHigher();
}
/**
*
*/
public void decreaseFontSize() {
fontSize = fontSize.getNextLower();
}
/*
* (non-Javadoc)
*
@ -277,14 +340,14 @@ public class Point implements IPointNode, Comparable<IPointNode> {
*/
@Override
public boolean isMovable() {
return isMovable;
return movable;
}
/**
* @param notAnchored
*/
public void setMovable(boolean notAnchored) {
isMovable = notAnchored;
movable = notAnchored;
}
/*
@ -314,6 +377,30 @@ public class Point implements IPointNode, Comparable<IPointNode> {
return false;
}
public int getRed() {
return red;
}
public void setRed(int red) {
this.red = red;
}
public int getGreen() {
return green;
}
public void setGreen(int green) {
this.green = green;
}
public int getBlue() {
return blue;
}
public void setBlue(int blue) {
this.blue = blue;
}
/*
* (non-Javadoc)
*
@ -324,14 +411,15 @@ public class Point implements IPointNode, Comparable<IPointNode> {
StringBuffer sb = new StringBuffer();
sb.append("Point: \n");
sb.append("\t Name: ").append(name).append("\n");
sb.append("\t Location: ").append(location).append("\n");
sb.append("\t longitude, latitude: ").append("{").append(longitude)
.append(", ").append(latitude).append("}\n");
sb.append("\t Color Active: ").append(colorActive).append("\n");
sb.append("\t Color: ")
.append(color == null ? "DEFAULT" : color.toString())
sb.append("\t Color: ").append("(").append(red).append(", ")
.append(green).append(", ").append(blue).append(")")
.append("\n");
sb.append("\t isHidden: ").append(Boolean.toString(isHidden))
sb.append("\t isHidden: ").append(Boolean.toString(hidden))
.append("\n");
sb.append("\t isMovable: ").append(Boolean.toString(isMovable))
sb.append("\t isMovable: ").append(Boolean.toString(movable))
.append("\n");
sb.append("\t fontSize: ").append(fontSize.toString()).append("\n");
sb.append("\t group: \"").append(group).append("\"\n");
@ -339,6 +427,15 @@ public class Point implements IPointNode, Comparable<IPointNode> {
return sb.toString();
}
public Coordinate getLocation() {
return new Coordinate(longitude, latitude);
}
public void setLocation(Coordinate location) {
this.longitude = location.x;
this.latitude = location.y;
}
/*
* (non-Javadoc)
*

View file

@ -19,10 +19,8 @@
**/
package com.raytheon.uf.viz.points.data;
import com.raytheon.uf.viz.points.PointUtilities;
/**
* This class handles determining the what size font to use for a point's label.
* This class for handling point's font sizes.
*
* <pre>
*
@ -30,101 +28,65 @@ import com.raytheon.uf.viz.points.PointUtilities;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* October-2010 epolster Initial Creation.
* Aug 08, 2012 #875 rferrel Initial Creation.
*
* </pre>
*
* @author epolster
* @author rferrel
* @version 1.0
*/
public enum PointSize {
SMALL(0, PointUtilities.FONT_1), DEFAULT(1, PointUtilities.FONT_2), LARGE(
2, PointUtilities.FONT_3), EXTRA_LARGE(3, PointUtilities.FONT_4), XXL(
4, PointUtilities.FONT_5);
public static final int MIN_ORDINAL = 0;
SMALL(12), DEFAULT(14), LARGE(18), EXTRA_LARGE(24), XXL(30);
public static final int MAX_ORDINAL = 4;
private static final String POINTS_NAME = " pt";
private int _ordinal = 0;
private transient int fontSize;
private int _fontSize = 0;
private transient String readableName;
private String POINTS_NAME = " pt";
PointSize(int ordinal, int fontSize) {
_ordinal = ordinal;
_fontSize = fontSize;
PointSize(int fontSize) {
this.fontSize = fontSize;
this.readableName = " " + fontSize + POINTS_NAME;
}
public int getFontSize() {
return _fontSize;
}
public int getOrdinal() {
return _ordinal;
return fontSize;
}
/**
* @param ordinal
* @return ps
*/
static public PointSize getPointSize(int ordinal) {
PointSize newMS = null;
PointSize newPS = null;
switch (ordinal) {
case 0:
newMS = SMALL;
newPS = SMALL;
break;
case 1:
newMS = DEFAULT;
newPS = DEFAULT;
break;
case 2:
newMS = LARGE;
newPS = LARGE;
break;
case 3:
newMS = EXTRA_LARGE;
newPS = EXTRA_LARGE;
break;
case 4:
newMS = XXL;
newPS = XXL;
break;
}
return newMS;
return newPS;
}
/**
* A descriptive name usable in a combo box item.
*
* @return name
*/
public String getReadableName() {
String is = Integer.toString(_fontSize);
is = is.concat(POINTS_NAME);
return " ".concat(is);
}
public boolean isAtMaxSize() {
return (_ordinal == PointSize.MAX_ORDINAL);
}
public boolean isAtMinSize() {
return (_ordinal == PointSize.MIN_ORDINAL);
}
public PointSize getNextHigher() {
PointSize newMS = null;
int o = _ordinal;
if (o == MAX_ORDINAL) {
newMS = this;
} else {
newMS = PointSize.getPointSize(o + 1);
}
return newMS;
}
public PointSize getNextLower() {
PointSize newMS = null;
int o = _ordinal;
if (o == MIN_ORDINAL) {
newMS = this;
} else {
newMS = PointSize.getPointSize(o - 1);
}
return newMS;
}
static public int getNumberOfFontSizes() {
return PointSize.MAX_ORDINAL;
return readableName;
}
}

View file

@ -0,0 +1,164 @@
/**
* 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.points.data;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.dnd.ByteArrayTransfer;
import org.eclipse.swt.dnd.TransferData;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
/**
* This singleton class converts an instance of the Point class to a byte array
* or an byte array to an instance of Point. This is used to support drag and
* drop.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 13, 2012 875 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public class PointTransfer extends ByteArrayTransfer {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(PointTransfer.class);
private static final String TYPE_NAME = "point_type";
private static final int TYPE_ID = registerType(TYPE_NAME);
private static PointTransfer instance = new PointTransfer();
public static PointTransfer getInstance() {
return instance;
}
private PointTransfer() {
}
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.dnd.ByteArrayTransfer#javaToNative(java.lang.Object,
* org.eclipse.swt.dnd.TransferData)
*/
@Override
protected void javaToNative(Object object, TransferData transferData) {
if (object == null || !(object instanceof Point[])) {
return;
}
if (isSupportedType(transferData)) {
Point[] points = (Point[]) object;
ArrayList<PointTransferObject> transfers = new ArrayList<PointTransferObject>();
for (Point point : points) {
PointTransferObject transfer = new PointTransferObject();
if (point.isGroup()) {
transfer.setPoint(new Point(point));
} else {
transfer.setPoint(point);
}
transfer.setGroupNode(point.isGroup());
transfer.setGroupName(point.getGroup());
transfers.add(transfer);
}
try {
byte[] buffer = SerializationUtil.transformToThrift(transfers);
super.javaToNative(buffer, transferData);
} catch (SerializationException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.dnd.ByteArrayTransfer#nativeToJava(org.eclipse.swt.dnd
* .TransferData)
*/
@SuppressWarnings("unchecked")
@Override
protected Object nativeToJava(TransferData transferData) {
Point[] points = null;
if (isSupportedType(transferData)) {
byte[] buffer = (byte[]) super.nativeToJava(transferData);
if (buffer != null) {
try {
List<PointTransferObject> transfers = (List<PointTransferObject>) SerializationUtil
.transformFromThrift(buffer);
points = new Point[transfers.size()];
int index = 0;
for (PointTransferObject transfer : transfers) {
Point point = transfer.getPoint();
if (transfer.isGroupNode()) {
point = new GroupNode(point);
}
point.setGroup(transfer.getGroupName());
points[index] = point;
++index;
}
} catch (SerializationException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
}
}
return points;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.dnd.Transfer#getTypeNames()
*/
@Override
protected String[] getTypeNames() {
return new String[] { TYPE_NAME };
}
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.dnd.Transfer#getTypeIds()
*/
@Override
protected int[] getTypeIds() {
return new int[] { TYPE_ID };
}
}

View file

@ -0,0 +1,81 @@
/**
* 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.points.data;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
/**
* This object used by PointTransfer to serialize a IPointNode preserving its
* group information.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 20, 2012 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
@DynamicSerialize
public class PointTransferObject {
@DynamicSerializeElement
private Point point;
@DynamicSerializeElement
private boolean groupNode;
@DynamicSerializeElement
private String groupName;
public PointTransferObject() {
}
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}
public boolean isGroupNode() {
return groupNode;
}
public void setGroupNode(boolean group) {
this.groupNode = group;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 B

After

Width:  |  Height:  |  Size: 67 B

View file

@ -373,12 +373,12 @@ public class PointEditDialog extends CaveJFACEDialog {
pointFontSizeChooser.setLayoutData(gd);
pointFontSizeChooser.setFont(FontManager.getFont("Tahoma",
PointEditDialog.PREFERRED_FONT_SIZE_MEDIUM, SWT.NORMAL));
for (int i = PointSize.MIN_ORDINAL; i <= PointSize.MAX_ORDINAL; i++) {
pointFontSizeChooser.add(PointSize.getPointSize(i)
.getReadableName());
for (PointSize ps : PointSize.values()) {
pointFontSizeChooser.add(ps.getReadableName());
}
if (currPoint != null) {
pointFontSizeChooser.select(currPoint.getFontSize().getOrdinal());
pointFontSizeChooser.select(currPoint.getFontSize().ordinal());
} else {
pointFontSizeChooser.select(0);
}
@ -414,12 +414,6 @@ public class PointEditDialog extends CaveJFACEDialog {
public void widgetSelected(SelectionEvent e) {
if (dialog.acceptChanges()) {
dialog.close();
if (dialogFlavor == EditOptions.EDIT
&& (!MOST_RECENTLY_MODIFIED_POINT.getName().equals(
currPoint.getName()) || !MOST_RECENTLY_MODIFIED_POINT
.getGroup().equals(currPoint.getGroup()))) {
PointsDataManager.getInstance().deletePoint(currPoint);
}
} else {
resetFocus();
}
@ -491,7 +485,7 @@ public class PointEditDialog extends CaveJFACEDialog {
pointNameText.setText(currPoint.getName());
coordinateInput.recalculateCoordinateFields(currPoint);
pointFontSizeChooser.select(currPoint.getFontSize().getOrdinal());
pointFontSizeChooser.select(currPoint.getFontSize().ordinal());
pointMovableButton.setSelection(currPoint.isMovable());
pointHiddenButton.setSelection(currPoint.isHidden());
RGB color = currPoint.getColor();
@ -520,7 +514,7 @@ public class PointEditDialog extends CaveJFACEDialog {
resetFocus();
pointFontSizeChooser.select(PointSize.DEFAULT.getOrdinal());
pointFontSizeChooser.select(PointSize.DEFAULT.ordinal());
pointMovableButton.setSelection(false);
pointHiddenButton.setSelection(false);
}
@ -543,7 +537,7 @@ public class PointEditDialog extends CaveJFACEDialog {
coordinateInput.setNorth(true);
coordinateInput.setWest(true);
pointFontSizeChooser.select(PointSize.DEFAULT.getOrdinal());
pointFontSizeChooser.select(PointSize.DEFAULT.ordinal());
pointMovableButton.setSelection(true);
pointHiddenButton.setSelection(false);
pointAssignColorButton.setSelection(false);
@ -553,7 +547,12 @@ public class PointEditDialog extends CaveJFACEDialog {
pointNameText.setText("");
}
// values must be pre-validated ...
/**
* Generate a point based on the user information provided by the dialog.
* This assumes validation of of the input has already been performed.
*
* @return point
*/
private Point createPointFromInput() {
String name = pointNameText.getText();
@ -568,10 +567,10 @@ public class PointEditDialog extends CaveJFACEDialog {
group = pointGroupChooser.getItem(selIndex);
}
boolean hidden = pointHiddenButton.getSelection();
Point m = new Point(name, latDeg, lonDeg, movable, colorActive,
Point point = new Point(name, latDeg, lonDeg, movable, colorActive,
currColor.getRGB(), PointSize.getPointSize(ordinal), group);
m.setHidden(hidden);
return m;
point.setHidden(hidden);
return point;
}
private void setCurrentColor(RGB rgb) {

View file

@ -25,6 +25,7 @@ import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import com.raytheon.uf.viz.points.data.IPointNode;
import com.raytheon.uf.viz.points.data.Point;
@ -80,6 +81,8 @@ public class PointHiddenEditingSupport extends EditingSupport {
protected void setValue(Object element, Object value) {
IPointNode node = (IPointNode) element;
try {
((TreeViewer) getViewer()).getTree().setCursor(
Display.getCurrent().getSystemCursor(SWT.CURSOR_WAIT));
if (!node.isGroup()) {
Point point = (Point) node;
point.setHidden((Boolean) value);

View file

@ -25,6 +25,7 @@ import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import com.raytheon.uf.viz.points.data.IPointNode;
import com.raytheon.uf.viz.points.data.Point;
@ -80,6 +81,8 @@ public class PointMovableEditingSupport extends EditingSupport {
protected void setValue(Object element, Object value) {
IPointNode node = (IPointNode) element;
try {
((TreeViewer) getViewer()).getTree().setCursor(
Display.getCurrent().getSystemCursor(SWT.CURSOR_WAIT));
if (!node.isGroup()) {
Point point = (Point) node;
point.setMovable((Boolean) value);

View file

@ -79,6 +79,6 @@ public class PointTreeContentProvider implements ITreeContentProvider {
@Override
public boolean hasChildren(Object element) {
IPointNode node = (IPointNode) element;
return node.isGroup();
return node.isGroup() && manager.getChildren(node).size() > 0;
}
}

View file

@ -0,0 +1,95 @@
/*****************************************************************************************
* COPYRIGHT (c), 2007, RAYTHEON COMPANY
* ALL RIGHTS RESERVED, An Unpublished Work
*
* RAYTHEON PROPRIETARY
* If the end user is not the U.S. Government or any agency thereof, use
* or disclosure of data contained in this source code file is subject to
* the proprietary restrictions set forth in the Master Rights File.
*
* U.S. GOVERNMENT PURPOSE RIGHTS NOTICE
* If the end user is the U.S. Government or any agency thereof, this source
* code is provided to the U.S. Government with Government Purpose Rights.
* Use or disclosure of data contained in this source code file is subject to
* the "Government Purpose Rights" restriction in the Master Rights File.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* Use or disclosure of data contained in this source code file is subject to
* the export restrictions set forth in the Master Rights File.
******************************************************************************************/
package com.raytheon.viz.awipstools.ui.dialog;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import com.raytheon.uf.viz.points.data.Point;
import com.raytheon.uf.viz.points.data.PointTransfer;
/**
* This implements a drag source listener for a Tree Viewer that contains point
* nodes.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 06, 2012 #875 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public class PointTreeDragSourceListener implements DragSourceListener {
private final TreeViewer viewer;
public PointTreeDragSourceListener(TreeViewer viewer) {
this.viewer = viewer;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.
* DragSourceEvent)
*/
@Override
public void dragStart(DragSourceEvent event) {
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd
* .DragSourceEvent)
*/
@SuppressWarnings("unchecked")
@Override
public void dragSetData(DragSourceEvent event) {
if (PointTransfer.getInstance().isSupportedType(event.dataType)) {
TreeSelection selection = (TreeSelection) viewer.getSelection();
Point[] points = (Point[]) selection.toList().toArray(
new Point[selection.size()]);
event.data = points;
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd
* .DragSourceEvent)
*/
@Override
public void dragFinished(DragSourceEvent event) {
}
}

View file

@ -0,0 +1,142 @@
/*****************************************************************************************
* COPYRIGHT (c), 2007, RAYTHEON COMPANY
* ALL RIGHTS RESERVED, An Unpublished Work
*
* RAYTHEON PROPRIETARY
* If the end user is not the U.S. Government or any agency thereof, use
* or disclosure of data contained in this source code file is subject to
* the proprietary restrictions set forth in the Master Rights File.
*
* U.S. GOVERNMENT PURPOSE RIGHTS NOTICE
* If the end user is the U.S. Government or any agency thereof, this source
* code is provided to the U.S. Government with Government Purpose Rights.
* Use or disclosure of data contained in this source code file is subject to
* the "Government Purpose Rights" restriction in the Master Rights File.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* Use or disclosure of data contained in this source code file is subject to
* the export restrictions set forth in the Master Rights File.
******************************************************************************************/
package com.raytheon.viz.awipstools.ui.dialog;
import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TransferData;
import com.raytheon.uf.viz.points.PointsDataManager;
import com.raytheon.uf.viz.points.data.IPointNode;
import com.raytheon.uf.viz.points.data.Point;
import com.raytheon.uf.viz.points.data.PointTransfer;
/**
* This handles moving nodes dropped onto the viewer.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 15, 2012 #875 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public class PointTreeDropListener extends ViewerDropAdapter {
private PointsDataManager manager;
private PointsMgrDialog dialog;
public PointTreeDropListener(PointsMgrDialog dialog) {
super(dialog.pointsTreeViewer);
this.dialog = dialog;
this.manager = PointsDataManager.getInstance();
}
IPointNode targetNode;
int location;
@Override
public void drop(DropTargetEvent event) {
location = determineLocation(event);
targetNode = (IPointNode) determineTarget(event);
super.drop(event);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
*/
@Override
public boolean performDrop(Object data) {
if (data instanceof Point[]) {
Point[] points = (Point[]) data;
if (targetNode != null) {
boolean state = false;
try {
for (Point node : points) {
IPointNode destGroup = null;
if (location == LOCATION_ON) {
if (targetNode.isGroup()) {
destGroup = targetNode;
} else {
destGroup = manager.getParent(targetNode);
}
} else if (location != LOCATION_NONE) {
destGroup = manager.getParent(targetNode);
}
if (destGroup != null
&& (manager.getParent(node)
.compareTo(destGroup) != 0)
&& !childGroupExists(destGroup, node.getName())) {
state = true;
dialog.setCursorBusy(true);
dialog.selectedNode = node;
manager.moveNode(node, destGroup);
}
}
return state;
} finally {
targetNode = null;
}
}
}
return false;
}
/**
* Determine if a child of a group node is a group node with the desired
* name.
*
* @param parent
* @param name
* @return true if child group node exists.
*/
private boolean childGroupExists(IPointNode parent, String name) {
for (IPointNode child : manager.getChildren(parent)) {
if (child.isGroup() && name.equals(child.getName())) {
return true;
}
}
return false;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object
* , int, org.eclipse.swt.dnd.TransferData)
*/
@Override
public boolean validateDrop(Object target, int operation,
TransferData transferType) {
return PointTransfer.getInstance().isSupportedType(transferType);
}
}

View file

@ -78,6 +78,8 @@ public class PointTreeLabelProvider implements ITableLabelProvider,
private Font boldFont;
private Color imageBackground;
IPointNode prevPoint = null;
private ImageRegistry imageReg;
@ -209,8 +211,6 @@ public class PointTreeLabelProvider implements ITableLabelProvider,
return image;
}
private Color imageBackground;
public void setImageBackground(Color color) {
imageBackground = color;
}

View file

@ -19,21 +19,7 @@
**/
package com.raytheon.viz.awipstools.ui.dialog;
/**
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* October-2010 epolster Initial Creation.
*
* </pre>
*
* @author epolster
* @version 1
*
*
*/
import java.io.File;
import java.util.Collection;
import java.util.Iterator;
@ -52,14 +38,15 @@ import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@ -85,8 +72,10 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.points.IPointChangedListener;
import com.raytheon.uf.viz.points.PointsDataManager;
import com.raytheon.uf.viz.points.data.GroupNode;
import com.raytheon.uf.viz.points.data.IPointNode;
import com.raytheon.uf.viz.points.data.Point;
import com.raytheon.uf.viz.points.data.PointTransfer;
import com.raytheon.viz.awipstools.ui.layer.PointsToolLayer;
import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
@ -99,11 +88,12 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* October-2010 epolster Initial Creation.
* Jul 31, 2012 #875 rferrel Integrated into CAVE.
*
* </pre>
*
* @author rferrel
* @author epolster
* @version 1.0
*/
public class PointsMgrDialog extends CaveJFACEDialog implements
@ -155,7 +145,7 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
private Shell currShell;
private TreeViewer pointsTreeViewer;
protected TreeViewer pointsTreeViewer;
private IPointNode topLevel;
@ -171,6 +161,10 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
private Action deleteNodeAction;
protected IPointNode selectedNode = null;
private boolean editSelectedNode = false;
/**
* Create the dialog.
*
@ -331,15 +325,13 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
menuMgr.setRemoveAllWhenShown(true);
pointsTreeViewer.getControl().setMenu(menu);
// TODO DND not yet working.
// int operations = DND.DROP_COPY | DND.DROP_MOVE;
// Transfer[] transferTypes = new Transfer[] {
// TextTransfer.getInstance() };
// pointsTreeViewer.addDragSupport(operations, transferTypes,
// new PointTreeDragSourceListener(pointsTreeViewer));
//
// pointsTreeViewer.addDropSupport(operations, transferTypes,
// new PointTreeDropListener(pointsTreeViewer));
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transferTypes = new Transfer[] { PointTransfer.getInstance() };
pointsTreeViewer.addDragSupport(operations, transferTypes,
new PointTreeDragSourceListener(pointsTreeViewer));
pointsTreeViewer.addDropSupport(operations, transferTypes,
new PointTreeDropListener(this));
return rootDialogArea;
}
@ -423,17 +415,17 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
}
private void createGroup() {
Tree tree = pointsTreeViewer.getTree();
IPointNode selectedNode = getSelectedPoint();
selectedNode = getSelectedPoint();
if (selectedNode == null) {
return;
}
IPointNode parentNode = dataManager.getParent(selectedNode);
IPointNode groupNode;
try {
groupNode = dataManager.createTempGroup(parentNode);
setCursorBusy(true);
editSelectedNode = true;
selectedNode = dataManager.createTempGroup(parentNode);
} catch (LocalizationOpFailedException e1) {
statusHandler.handle(
Priority.PROBLEM,
@ -441,13 +433,6 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
+ parentNode.getName());
return;
}
pointsTreeViewer.refresh();
TreeItem item = findItem(groupNode, tree.getItems());
if (item != null) {
tree.select(item);
editGroupName();
}
}
private void createPoint() {
@ -455,6 +440,8 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
Point newPoint = PointEditDialog.createNewPointViaDialog(toolLayer,
point);
if (newPoint != null) {
setCursorBusy(true);
selectedNode = newPoint;
toolLayer.addPoint(newPoint);
}
}
@ -485,7 +472,11 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
if (point.isGroup()) {
editGroupName();
} else {
toolLayer.editPoint(point);
setCursorBusy(true);
selectedNode = toolLayer.editPoint(point);
if (selectedNode == null) {
setCursorBusy(false);
}
}
} else {
MessageDialog.openInformation(getShell(), "Message",
@ -493,10 +484,24 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
}
}
private void selectNode(IPointNode node) {
if (node != null) {
Tree tree = pointsTreeViewer.getTree();
TreeItem item = findItem(node, tree.getItems());
if (item != null) {
tree.showItem(item);
tree.select(item);
}
}
}
private void deleteNode() {
Point point = getSelectedPoint();
if (point != null) {
toolLayer.deletePoint(point);
setCursorBusy(true);
if (!toolLayer.deletePoint(point)) {
setCursorBusy(false);
}
}
}
@ -517,19 +522,11 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
@Override
public void modifyText(ModifyEvent e) {
System.out.println("modifyText ...");
Text text = (Text) treeEditor.getEditor();
treeEditor.getItem().setText(text.getText());
}
});
text.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
System.out.println("dosomething: " + entry.getName());
}
}
});
final TreeItem item = pointsTreeViewer.getTree().getSelection()[0];
boolean showBorder = true;
final Composite composite = new Composite(pointsTreeViewer.getTree(),
@ -557,20 +554,22 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
}
case SWT.FocusOut:
final String text = modText.getText().trim();
if (text.length() == 0) {
if (text.length() == 0 || entry.getName().equals(text)
|| groupExists(dataManager.getParent(entry), text)) {
item.setText(entry.getName());
} else if (!entry.getName().equals(text)) {
System.out.println("FocusOut here rename group to: \""
+ entry.getName() + "\" ==> \"" + text + "\"");
item.setText(text);
VizApp.runAsync(new Runnable() {
} else {
GroupNode node = new GroupNode((GroupNode) entry);
node.setName(text);
StringBuilder sb = new StringBuilder(node.getGroup());
sb.setLength(sb.lastIndexOf(File.separator) + 1);
selectedNode = node;
sb.append(text);
@Override
public void run() {
dataManager.renameGroup(entry, text);
pointsTreeViewer.refresh();
}
});
item.setText(text);
setCursorBusy(true);
if (!dataManager.renameGroup(entry, text)) {
setCursorBusy(false);
}
}
composite.dispose();
break;
@ -581,7 +580,8 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
break;
default:
System.err.println("Unhandled type: " + e.type);
statusHandler.handle(Priority.PROBLEM, "Unhandled type: "
+ e.type);
}
}
};
@ -595,6 +595,15 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
modText.setFocus();
}
private boolean groupExists(IPointNode parent, String name) {
for (IPointNode child : dataManager.getChildren(parent)) {
if (child.isGroup() && name.equals(child.getName())) {
return true;
}
}
return false;
}
private Point getSelectedPoint() {
TreeItem[] selItems = pointsTreeViewer.getTree().getSelection();
Point point = null;
@ -604,6 +613,15 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
return point;
}
protected void setCursorBusy(boolean state) {
Cursor cursor = null;
if (state) {
cursor = getShell().getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
}
getShell().setCursor(cursor);
pointsTreeViewer.getTree().setCursor(cursor);
}
@Override
public boolean close() {
dataManager.removePointsChangedListener(this);
@ -622,7 +640,30 @@ public class PointsMgrDialog extends CaveJFACEDialog implements
@Override
public void run() {
pointsTreeViewer.refresh();
if (selectedNode == null) {
selectedNode = getSelectedPoint();
}
// Bug in viewers refresh that causes stack overflow when
// selected item no longer exists and sometimes when the
// selected item was modified.
pointsTreeViewer.setSelection(null);
pointsTreeViewer.refresh(topLevel);
if (selectedNode != null) {
Tree tree = pointsTreeViewer.getTree();
TreeItem item = findItem(selectedNode, tree.getItems());
if (item != null) {
tree.showItem(item);
tree.select(item);
if (editSelectedNode) {
editNode();
editSelectedNode = false;
}
}
selectedNode = null;
}
setCursorBusy(false);
}
});
}

View file

@ -399,7 +399,8 @@ public class PointsToolLayer extends AbstractMovableToolLayer<Point> implements
}
}
public void deletePoint(Point point) {
public boolean deletePoint(Point point) {
boolean state = false;
if (point != null) {
MessageBox d = new MessageBox(getResourceContainer()
.getActiveDisplayPane().getDisplay().getActiveShell(),
@ -414,16 +415,19 @@ public class PointsToolLayer extends AbstractMovableToolLayer<Point> implements
}
int status = d.open();
if (status == SWT.OK) {
state = true;
dataManager.deletePoint(point);
}
}
return state;
}
public void editPoint(Point point) {
public Point editPoint(Point point) {
Point em = PointEditDialog.editPointViaDialog(this, point);
if (em != null) {
dataManager.addPoint(em);
dataManager.updatePoint(point, em);
}
return em;
}
private void createPoint() {