use of org.netxms.base.GeoLocation in project netxms by netxms.
the class MapBackground method applyChanges.
/**
* Apply changes
*
* @param isApply true if update operation caused by "Apply" button
*/
protected boolean applyChanges(final boolean isApply) {
final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
if (radioTypeNone.getSelection()) {
md.setMapBackground(NXCommon.EMPTY_GUID, new GeoLocation(false), 0, ColorConverter.rgbToInt(backgroundColor.getColorValue()));
} else if (radioTypeImage.getSelection()) {
md.setMapBackground(image.getImageGuid(), new GeoLocation(false), 0, ColorConverter.rgbToInt(backgroundColor.getColorValue()));
} else if (!disableGeolocationBackground && radioTypeGeoMap.getSelection()) {
GeoLocation location;
try {
location = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
} catch (GeoLocationFormatException e) {
MessageDialogHelper.openError(getShell(), Messages.get().MapBackground_Error, Messages.get().MapBackground_GeoLocFormatError);
return false;
}
md.setMapBackground(NetworkMap.GEOMAP_BACKGROUND, location, zoomSpinner.getSelection(), ColorConverter.rgbToInt(backgroundColor.getColorValue()));
}
if (isApply)
setValid(false);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().MapBackground_JobTitle + object.getObjectName(), null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.modifyObject(md);
}
@Override
protected String getErrorMessage() {
return Messages.get().MapBackground_JobError + object.getObjectName();
}
@Override
protected void jobFinalize() {
if (isApply) {
runInUIThread(new Runnable() {
@Override
public void run() {
MapBackground.this.setValid(true);
}
});
}
}
}.start();
return true;
}
use of org.netxms.base.GeoLocation in project netxms by netxms.
the class GeoLocationCache method onObjectChange.
/**
* Handle object change
*
* @param object
*/
private void onObjectChange(AbstractObject object) {
if ((object.getObjectClass() != AbstractObject.OBJECT_NODE) && (object.getObjectClass() != AbstractObject.OBJECT_MOBILEDEVICE) && (object.getObjectClass() != AbstractObject.OBJECT_CLUSTER) && (object.getObjectClass() != AbstractObject.OBJECT_CONTAINER) && (object.getObjectClass() != AbstractObject.OBJECT_RACK) && (object.getObjectClass() != AbstractObject.OBJECT_SENSOR))
return;
GeoLocation prevLocation = null;
boolean cacheChanged = false;
synchronized (locationTree) {
GeoLocation gl = object.getGeolocation();
if (gl.getType() == GeoLocation.UNSET) {
AbstractObject prevObject = objects.remove(object.getObjectId());
if (prevObject != null)
prevLocation = prevObject.getGeolocation();
cacheChanged = locationTree.remove(object.getObjectId());
} else {
if (!objects.containsKey(object.getObjectId())) {
locationTree.insert(gl.getLatitude(), gl.getLongitude(), object.getObjectId());
cacheChanged = true;
} else {
prevLocation = objects.get(object.getObjectId()).getGeolocation();
if (!gl.equals(prevLocation)) {
locationTree.remove(object.getObjectId());
locationTree.insert(gl.getLatitude(), gl.getLongitude(), object.getObjectId());
cacheChanged = true;
}
}
objects.put(object.getObjectId(), object);
}
}
// Notify listeners about cache change
if (cacheChanged)
synchronized (listeners) {
for (GeoLocationCacheListener l : listeners) l.geoLocationCacheChanged(object, prevLocation);
}
}
use of org.netxms.base.GeoLocation in project netxms by netxms.
the class WorldMap method createPartControl.
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.osm.views.AbstractGeolocationView#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
IDialogSettings settings = Activator.getDefault().getDialogSettings();
initialZoom = settings.get(ID + "zoom") != null ? settings.getInt(ID + "zoom") : 2;
if (settings.get(ID + "latitude") != null && settings.get(ID + "longitude") != null)
initialLocation = new GeoLocation(settings.getDouble(ID + "latitude"), settings.getDouble(ID + "longitude"));
filterEnabled = settings.get(ID + "filterEnabled") != null ? settings.getBoolean(ID + "filterEnabled") : true;
super.createPartControl(parent);
parent.setLayout(new FormLayout());
// Create filter area
filterControl = new FilterText(parent, SWT.NONE);
filterControl.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
filterControl.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
}
});
// Setup layout
FormData fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(filterControl);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(100, 0);
map.setLayoutData(fd);
fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
filterControl.setLayoutData(fd);
// Set initial focus to filter input line
if (filterEnabled)
filterControl.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
}
use of org.netxms.base.GeoLocation in project netxms by netxms.
the class GeoLocationHistoryViewer method getAdjacentLocations.
/**
* Get geolocations adjacent to given screen coordinates ordered by distance from that point
*
* @param x
* @param y
* @return
*/
public List<GeoLocation> getAdjacentLocations(int x, int y) {
Point p = new Point(x, y);
final GeoLocation center = getLocationAtPoint(p);
p.x -= 5;
p.y -= 5;
GeoLocation topLeft = getLocationAtPoint(p);
p.x += 10;
p.y += 10;
GeoLocation bottomRight = getLocationAtPoint(p);
Area area = new Area(topLeft.getLatitude(), topLeft.getLongitude(), bottomRight.getLatitude(), bottomRight.getLongitude());
List<GeoLocation> locations = locationTree.query(area);
Collections.sort(locations, new Comparator<GeoLocation>() {
@Override
public int compare(GeoLocation l1, GeoLocation l2) {
double d1 = Math.pow(Math.pow(l1.getLatitude() - center.getLatitude(), 2) + Math.pow(l1.getLongitude() - center.getLongitude(), 2), 0.5);
double d2 = Math.pow(Math.pow(l2.getLatitude() - center.getLatitude(), 2) + Math.pow(l2.getLongitude() - center.getLongitude(), 2), 0.5);
return (int) Math.signum(d1 - d2);
}
});
return locations;
}
use of org.netxms.base.GeoLocation in project netxms by netxms.
the class GeoLocationHistoryViewer method updateHistory.
/**
* Updates points for historical view
*/
private void updateHistory() {
final NXCSession session = ConsoleSharedData.getSession();
ConsoleJob job = new ConsoleJob(Messages.get().GeoMapViewer_DownloadJob_Title, viewPart, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final List<GeoLocation> pl = session.getLocationHistory(historyObject.getObjectId(), timePeriod.getPeriodStart(), timePeriod.getPeriodEnd());
runInUIThread(new Runnable() {
@Override
public void run() {
points = pl;
locationTree.removeAll();
for (int i = 0; i < points.size(); i++) locationTree.insert(points.get(i).getLatitude(), points.get(i).getLongitude(), points.get(i));
redraw();
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().GeoMapViewer_DownloadError;
}
};
job.setUser(false);
job.start();
}
Aggregations