Search in sources :

Example 1 with GeoLocationFormatException

use of org.netxms.base.GeoLocationFormatException 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 GeoLocationFormatException

use of org.netxms.base.GeoLocationFormatException in project netxms by netxms.

the class Location method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    int type = GeoLocation.UNSET;
    if (radioTypeManual.getSelection())
        type = GeoLocation.MANUAL;
    else if (radioTypeAuto.getSelection())
        type = GeoLocation.GPS;
    GeoLocation location;
    if (type == GeoLocation.MANUAL) {
        try {
            location = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
        } catch (GeoLocationFormatException e) {
            MessageDialogHelper.openError(getShell(), Messages.get().Location_Error, Messages.get().Location_FormatError);
            return false;
        }
    } else {
        location = new GeoLocation(type == GeoLocation.GPS);
    }
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    md.setGeolocation(location);
    md.setPostalAddress(new PostalAddress(country.getText().trim(), city.getText().trim(), streetAddress.getText().trim(), postcode.getText().trim()));
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(String.format(Messages.get().Location_JobName, 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().Location_JobError;
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        Location.this.setValid(true);
                    }
                });
            }
        }
    }.start();
    return true;
}
Also used : PostalAddress(org.netxms.base.PostalAddress) 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 3 with GeoLocationFormatException

use of org.netxms.base.GeoLocationFormatException in project netxms by netxms.

the class GeoLocationTest method testParser.

public void testParser() throws Exception {
    GeoLocation g = GeoLocation.parseGeoLocation(" 47°20'50.79\"N", " 8°33'56,31\"E");
    assertEquals(47.34744, g.getLatitude(), 0.00005);
    assertEquals(8.56564, g.getLongitude(), 0.00005);
    System.out.println(g);
    g = GeoLocation.parseGeoLocation("47.34744", "E8.56564°");
    assertEquals(47.34744, g.getLatitude(), 0.00005);
    assertEquals(8.56564, g.getLongitude(), 0.00005);
    System.out.println(g);
    try {
        g = GeoLocation.parseGeoLocation("W47.34744°", "E8.56564°");
        assertFalse(true);
    } catch (GeoLocationFormatException e) {
    }
}
Also used : GeoLocationFormatException(org.netxms.base.GeoLocationFormatException) GeoLocation(org.netxms.base.GeoLocation)

Example 4 with GeoLocationFormatException

use of org.netxms.base.GeoLocationFormatException in project netxms by netxms.

the class GeoMap method performOk.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
	 */
@Override
public boolean performOk() {
    try {
        GeoLocation center = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
        config.setLatitude(center.getLatitude());
        config.setLongitude(center.getLongitude());
    } catch (GeoLocationFormatException e) {
        MessageDialogHelper.openError(getShell(), Messages.get().GeoMap_Error, Messages.get().GeoMap_ErrorText);
    }
    config.setTitle(title.getText());
    config.setZoom(zoom.getSelection());
    config.setRootObjectId(objectSelector.getObjectId());
    return true;
}
Also used : GeoLocationFormatException(org.netxms.base.GeoLocationFormatException) GeoLocation(org.netxms.base.GeoLocation)

Aggregations

GeoLocation (org.netxms.base.GeoLocation)4 GeoLocationFormatException (org.netxms.base.GeoLocationFormatException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)2 NXCSession (org.netxms.client.NXCSession)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 PostalAddress (org.netxms.base.PostalAddress)1