Search in sources :

Example 1 with GeoLocation

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException) GeoLocation(org.netxms.base.GeoLocation) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException)

Example 2 with GeoLocation

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);
        }
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) GeoLocation(org.netxms.base.GeoLocation)

Example 3 with GeoLocation

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);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) FilterText(org.netxms.ui.eclipse.widgets.FilterText) GeoLocation(org.netxms.base.GeoLocation) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 4 with GeoLocation

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;
}
Also used : Area(org.netxms.ui.eclipse.osm.tools.Area) Point(org.eclipse.swt.graphics.Point) GeoLocation(org.netxms.base.GeoLocation)

Example 5 with GeoLocation

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) GeoLocation(org.netxms.base.GeoLocation)

Aggregations

GeoLocation (org.netxms.base.GeoLocation)26 Point (org.eclipse.swt.graphics.Point)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 GeoLocationFormatException (org.netxms.base.GeoLocationFormatException)4 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)4 NXCSession (org.netxms.client.NXCSession)3 Area (org.netxms.ui.eclipse.osm.tools.Area)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 Group (org.eclipse.swt.widgets.Group)2 NXCPMessage (org.netxms.base.NXCPMessage)2 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 AccessPoint (org.netxms.client.objects.AccessPoint)2 Node (org.netxms.client.objects.Node)2