postal address can be configured from GUI
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 7 Nov 2014 13:33:12 +0000 (15:33 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 7 Nov 2014 13:33:12 +0000 (15:33 +0200)
src/java/netxms-base/src/main/java/org/netxms/base/PostalAddress.java
src/java/netxms-client/src/main/java/org/netxms/client/objects/AbstractObject.java
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/Location.java
src/java/netxms-eclipse/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/elements/GeneralInfo.java
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/Location.java
webui/webapp/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/elements/GeneralInfo.java

index 1f4b727..0b37251 100644 (file)
@@ -21,6 +21,14 @@ public class PostalAddress
       postcode = "";
    }
    
+   public PostalAddress(String country, String city, String streetAddress, String postcode)
+   {
+      this.country = country;
+      this.city = city;
+      this.streetAddress = streetAddress;
+      this.postcode = postcode;
+   }
+
    public PostalAddress(PostalAddress src)
    {
       country = src.country;
@@ -48,4 +56,48 @@ public class PostalAddress
       msg.setVariable(NXCPCodes.VID_STREET_ADDRESS, streetAddress);
       msg.setVariable(NXCPCodes.VID_POSTCODE, postcode);
    }
+   
+   /**
+    * Get address as one line
+    * 
+    * @return
+    */
+   public String getAddressLine()
+   {
+      StringBuilder sb = new StringBuilder();
+      
+      if (!streetAddress.isEmpty())
+         sb.append(streetAddress);
+      
+      if (!city.isEmpty())
+      {
+         if (sb.length() > 0)
+            sb.append(", ");
+         sb.append(city);
+      }
+      
+      if (!postcode.isEmpty())
+      {
+         if (sb.length() > 0)
+            sb.append(", ");
+         sb.append(postcode);
+      }
+      
+      if (!country.isEmpty())
+      {
+         if (sb.length() > 0)
+            sb.append(", ");
+         sb.append(country);
+      }
+      
+      return sb.toString();
+   }
+   
+   /**
+    * @return
+    */
+   public boolean isEmpty()
+   {
+      return country.isEmpty() && city.isEmpty() && streetAddress.isEmpty() && postcode.isEmpty();
+   }
 }
index 69cb7c1..3219e1c 100644 (file)
@@ -838,4 +838,12 @@ public abstract class AbstractObject
    {
       return (moduleData != null) ? moduleData.get(module) : null;
    }
+
+   /**
+    * @return the postalAddress
+    */
+   public PostalAddress getPostalAddress()
+   {
+      return postalAddress;
+   }
 }
index 178e9c2..fdcfa17 100644 (file)
@@ -31,6 +31,7 @@ import org.eclipse.swt.widgets.Group;
 import org.eclipse.ui.dialogs.PropertyPage;
 import org.netxms.base.GeoLocation;
 import org.netxms.base.GeoLocationFormatException;
+import org.netxms.base.PostalAddress;
 import org.netxms.client.NXCObjectModificationData;
 import org.netxms.client.NXCSession;
 import org.netxms.client.objects.AbstractObject;
@@ -53,6 +54,10 @@ public class Location extends PropertyPage
        private Button radioTypeUndefined;
        private Button radioTypeManual;
        private Button radioTypeAuto;
+       private LabeledText country;
+   private LabeledText city;
+   private LabeledText streetAddress;
+   private LabeledText postcode;
 
        /* (non-Javadoc)
         * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
@@ -129,6 +134,26 @@ public class Location extends PropertyPage
                radioTypeUndefined.addSelectionListener(listener);
                radioTypeManual.addSelectionListener(listener);
                radioTypeAuto.addSelectionListener(listener);
+               
+               country = new LabeledText(dialogArea, SWT.NONE);
+               country.setLabel("Country");
+               country.setText(object.getPostalAddress().country);
+               country.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+      
+      city = new LabeledText(dialogArea, SWT.NONE);
+      city.setLabel("City");
+      city.setText(object.getPostalAddress().city);
+      city.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+      
+      streetAddress = new LabeledText(dialogArea, SWT.NONE);
+      streetAddress.setLabel("Street address");
+      streetAddress.setText(object.getPostalAddress().streetAddress);
+      streetAddress.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+      
+      postcode = new LabeledText(dialogArea, SWT.NONE);
+      postcode.setLabel("Postcode");
+      postcode.setText(object.getPostalAddress().postcode);
+      postcode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
       
                return dialogArea;
        }
@@ -165,7 +190,8 @@ public class Location extends PropertyPage
                }
                
                final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
-               md.setGeolocation(location);
+               md.setGeolocation(location);            
+               md.setPostalAddress(new PostalAddress(country.getText().trim(), city.getText().trim(), streetAddress.getText().trim(), postcode.getText().trim()));
                
                if (isApply)
                        setValid(false);
index 8bf99c4..735bec9 100644 (file)
@@ -172,6 +172,8 @@ public class GeneralInfo extends TableElement
                }
                if (object.getGeolocation().getType() != GeoLocation.UNSET)
                        addPair(Messages.get().GeneralInfo_Location, object.getGeolocation().toString());
+               if (!object.getPostalAddress().isEmpty())
+         addPair("Postal Address", object.getPostalAddress().getAddressLine());
        }
 
        /* (non-Javadoc)
index 178e9c2..29047ef 100644 (file)
@@ -31,6 +31,7 @@ import org.eclipse.swt.widgets.Group;
 import org.eclipse.ui.dialogs.PropertyPage;
 import org.netxms.base.GeoLocation;
 import org.netxms.base.GeoLocationFormatException;
+import org.netxms.base.PostalAddress;
 import org.netxms.client.NXCObjectModificationData;
 import org.netxms.client.NXCSession;
 import org.netxms.client.objects.AbstractObject;
@@ -53,6 +54,10 @@ public class Location extends PropertyPage
        private Button radioTypeUndefined;
        private Button radioTypeManual;
        private Button radioTypeAuto;
+       private LabeledText country;
+   private LabeledText city;
+   private LabeledText streetAddress;
+   private LabeledText postcode;
 
        /* (non-Javadoc)
         * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
@@ -130,6 +135,26 @@ public class Location extends PropertyPage
                radioTypeManual.addSelectionListener(listener);
                radioTypeAuto.addSelectionListener(listener);
       
+               country = new LabeledText(dialogArea, SWT.NONE);
+               country.setLabel("Country");
+               country.setText(object.getPostalAddress().country);
+               country.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+      
+      city = new LabeledText(dialogArea, SWT.NONE);
+      city.setLabel("City");
+      city.setText(object.getPostalAddress().city);
+      city.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+      
+      streetAddress = new LabeledText(dialogArea, SWT.NONE);
+      streetAddress.setLabel("Street address");
+      streetAddress.setText(object.getPostalAddress().streetAddress);
+      streetAddress.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+      
+      postcode = new LabeledText(dialogArea, SWT.NONE);
+      postcode.setLabel("Postcode");
+      postcode.setText(object.getPostalAddress().postcode);
+      postcode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+      
                return dialogArea;
        }
 
@@ -166,6 +191,7 @@ public class Location extends PropertyPage
                
                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);
index 8bf99c4..735bec9 100644 (file)
@@ -172,6 +172,8 @@ public class GeneralInfo extends TableElement
                }
                if (object.getGeolocation().getType() != GeoLocation.UNSET)
                        addPair(Messages.get().GeneralInfo_Location, object.getGeolocation().toString());
+               if (!object.getPostalAddress().isEmpty())
+         addPair("Postal Address", object.getPostalAddress().getAddressLine());
        }
 
        /* (non-Javadoc)