Search in sources :

Example 1 with PostalAddress

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

Aggregations

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