Web console use client time zone to display time
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 25 Sep 2015 10:21:12 +0000 (13:21 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 25 Sep 2015 10:21:12 +0000 (13:21 +0300)
ChangeLog
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/console/resources/RegionalSettings.java
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/shared/ConsoleSharedData.java
webui/webapp/Core/src/org/netxms/ui/eclipse/console/Application.java
webui/webapp/Core/src/org/netxms/ui/eclipse/console/resources/RegionalSettings.java
webui/webapp/Core/src/org/netxms/ui/eclipse/shared/ConsoleSharedData.java

index 9e57306..33d9a67 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,7 +17,8 @@
 - Management console:
        - Object context menu available on geo map
        - Filter in event template configurator
-- Fixed issues: #786, #831, #841, #852, #864, #890, #892, #896, #897, #902, #905, #913, #919, #921, #928
+       - Web console use client time zone to display time
+- Fixed issues: #786, #831, #841, #852, #864, #890, #892, #896, #897, #900, #902, #905, #913, #919, #921, #928
 
 
 *
index 5fb08f2..1bdd4f1 100644 (file)
@@ -21,6 +21,7 @@ package org.netxms.ui.eclipse.console.resources;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.TimeZone;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.netxms.client.NXCSession;
 import org.netxms.ui.eclipse.console.Activator;
@@ -59,23 +60,31 @@ public class RegionalSettings
         */
        public static DateFormat getDateTimeFormat()
        {
+          DateFormat df;
                switch(dateTimeFormat)
                {
                        case DATETIME_FORMAT_SERVER:
                                NXCSession session = ConsoleSharedData.getSession();
-                               return new SimpleDateFormat(session.getDateFormat() + " " + session.getTimeFormat()); //$NON-NLS-1$
+                               df = new SimpleDateFormat(session.getDateFormat() + " " + session.getTimeFormat()); //$NON-NLS-1$
+                               break;
                        case DATETIME_FORMAT_CUSTOM:
                                try
                                {
-                                       return new SimpleDateFormat(dateFormatString + " " + timeFormatString); //$NON-NLS-1$
+                                       df = new SimpleDateFormat(dateFormatString + " " + timeFormatString); //$NON-NLS-1$
                                }
                                catch(IllegalArgumentException e)
                                {
-                                       return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+                                       df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
                                }
+                               break;
                        default:
-                               return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+                               df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+                               break;
                }
+               TimeZone tz = ConsoleSharedData.getTimeZone();
+               if (tz != null)
+                  df.setTimeZone(tz);
+               return df;
        }
 
        /**
@@ -85,23 +94,31 @@ public class RegionalSettings
         */
        public static DateFormat getDateFormat()
        {
+      DateFormat df;
                switch(dateTimeFormat)
                {
                        case DATETIME_FORMAT_SERVER:
                                NXCSession session = ConsoleSharedData.getSession();
-                               return new SimpleDateFormat(session.getDateFormat());
+                               df = new SimpleDateFormat(session.getDateFormat());
+                               break;
                        case DATETIME_FORMAT_CUSTOM:
                                try
                                {
-                                       return new SimpleDateFormat(dateFormatString);
+                                  df = new SimpleDateFormat(dateFormatString);
                                }
                                catch(IllegalArgumentException e)
                                {
-                                       return DateFormat.getDateInstance(DateFormat.SHORT);
+                                  df = DateFormat.getDateInstance(DateFormat.SHORT);
                                }
+            break;
                        default:
-                               return DateFormat.getDateInstance(DateFormat.SHORT);
+                          df = DateFormat.getDateInstance(DateFormat.SHORT);
+            break;
                }
+      TimeZone tz = ConsoleSharedData.getTimeZone();
+      if (tz != null)
+         df.setTimeZone(tz);
+      return df;
        }
 
    /**
@@ -111,23 +128,31 @@ public class RegionalSettings
     */
    public static DateFormat getTimeFormat()
    {
+      DateFormat df;
       switch(dateTimeFormat)
       {
          case DATETIME_FORMAT_SERVER:
             NXCSession session = ConsoleSharedData.getSession();
-            return new SimpleDateFormat(session.getTimeFormat());
+            df = new SimpleDateFormat(session.getTimeFormat());
+            break;
          case DATETIME_FORMAT_CUSTOM:
             try
             {
-               return new SimpleDateFormat(timeFormatString);
+               df = new SimpleDateFormat(timeFormatString);
             }
             catch(IllegalArgumentException e)
             {
-               return DateFormat.getTimeInstance(DateFormat.MEDIUM);
+               df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
             }
+            break;
          default:
-            return DateFormat.getTimeInstance(DateFormat.MEDIUM);
+            df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
+            break;
       }
+      TimeZone tz = ConsoleSharedData.getTimeZone();
+      if (tz != null)
+         df.setTimeZone(tz);
+      return df;
    }
 
    /**
@@ -137,23 +162,31 @@ public class RegionalSettings
     */
    public static DateFormat getShortTimeFormat()
    {
+      DateFormat df;
       switch(dateTimeFormat)
       {
          case DATETIME_FORMAT_SERVER:
             NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-            return new SimpleDateFormat(session.getShortTimeFormat());
+            df = new SimpleDateFormat(session.getShortTimeFormat());
+            break;
          case DATETIME_FORMAT_CUSTOM:
             try
             {
-               return new SimpleDateFormat(shortTimeFormatString);
+               df = new SimpleDateFormat(shortTimeFormatString);
             }
             catch(IllegalArgumentException e)
             {
-               return DateFormat.getTimeInstance(DateFormat.SHORT);
+               df = DateFormat.getTimeInstance(DateFormat.SHORT);
             }
+            break;
          default:
-            return DateFormat.getTimeInstance(DateFormat.SHORT);
+            df = DateFormat.getTimeInstance(DateFormat.SHORT);
+            break;
       }
+      TimeZone tz = ConsoleSharedData.getTimeZone();
+      if (tz != null)
+         df.setTimeZone(tz);
+      return df;
    }
    
    /**
index 0095d26..f087563 100644 (file)
@@ -20,6 +20,7 @@ package org.netxms.ui.eclipse.shared;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.TimeZone;
 import org.eclipse.swt.widgets.TrayItem;
 import org.netxms.client.NXCSession;
 
@@ -30,6 +31,7 @@ import org.netxms.client.NXCSession;
 public class ConsoleSharedData
 {
        private static NXCSession session = null;
+       private static TimeZone timeZone = null;
        private static TrayItem trayIcon = null;
        private static Map<String, Object> consoleProperties = new HashMap<String, Object>(0);
        
@@ -53,6 +55,24 @@ public class ConsoleSharedData
                ConsoleSharedData.session = session;
        }
        
+   /**
+    * Get client timezone
+    * 
+    * @return
+    */
+   public static TimeZone getTimeZone()
+   {
+      return timeZone;
+   }
+   
+   /**
+    * Set server time zone
+    */
+   public void setServerTimeZone()
+   {
+      
+   }
+   
        /**
         * Get value of console property
         * 
index e6f7664..ce96e4c 100644 (file)
@@ -20,9 +20,11 @@ package org.netxms.ui.eclipse.console;
 
 import java.util.Locale;
 import java.util.Properties;
+import java.util.TimeZone;
 import org.eclipse.equinox.app.IApplication;
 import org.eclipse.equinox.app.IApplicationContext;
 import org.eclipse.rap.rwt.RWT;
+import org.eclipse.rap.rwt.client.service.ClientInfo;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.application.WorkbenchAdvisor;
@@ -67,6 +69,16 @@ public class Application implements IApplication
                        }
                });
                
+               ClientInfo clientInfo = RWT.getClient().getService(ClientInfo.class);
+               if (clientInfo != null)
+               {
+                  String[] tzList = TimeZone.getAvailableIDs(-clientInfo.getTimezoneOffset() * 60000);  // convert offset in minutes to milliseconds (in RAP - means ahead of UTC)
+                  if (tzList.length > 0)
+                  {
+                     RWT.getUISession().setAttribute(ConsoleSharedData.ATTRIBUTE_TIMEZONE, TimeZone.getTimeZone(tzList[0]));
+                  }
+               }
+               
                SharedIcons.init(display);
                WorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
                return PlatformUI.createAndRunWorkbench(display, advisor);
index 5fb08f2..1bdd4f1 100644 (file)
@@ -21,6 +21,7 @@ package org.netxms.ui.eclipse.console.resources;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.TimeZone;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.netxms.client.NXCSession;
 import org.netxms.ui.eclipse.console.Activator;
@@ -59,23 +60,31 @@ public class RegionalSettings
         */
        public static DateFormat getDateTimeFormat()
        {
+          DateFormat df;
                switch(dateTimeFormat)
                {
                        case DATETIME_FORMAT_SERVER:
                                NXCSession session = ConsoleSharedData.getSession();
-                               return new SimpleDateFormat(session.getDateFormat() + " " + session.getTimeFormat()); //$NON-NLS-1$
+                               df = new SimpleDateFormat(session.getDateFormat() + " " + session.getTimeFormat()); //$NON-NLS-1$
+                               break;
                        case DATETIME_FORMAT_CUSTOM:
                                try
                                {
-                                       return new SimpleDateFormat(dateFormatString + " " + timeFormatString); //$NON-NLS-1$
+                                       df = new SimpleDateFormat(dateFormatString + " " + timeFormatString); //$NON-NLS-1$
                                }
                                catch(IllegalArgumentException e)
                                {
-                                       return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+                                       df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
                                }
+                               break;
                        default:
-                               return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+                               df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+                               break;
                }
+               TimeZone tz = ConsoleSharedData.getTimeZone();
+               if (tz != null)
+                  df.setTimeZone(tz);
+               return df;
        }
 
        /**
@@ -85,23 +94,31 @@ public class RegionalSettings
         */
        public static DateFormat getDateFormat()
        {
+      DateFormat df;
                switch(dateTimeFormat)
                {
                        case DATETIME_FORMAT_SERVER:
                                NXCSession session = ConsoleSharedData.getSession();
-                               return new SimpleDateFormat(session.getDateFormat());
+                               df = new SimpleDateFormat(session.getDateFormat());
+                               break;
                        case DATETIME_FORMAT_CUSTOM:
                                try
                                {
-                                       return new SimpleDateFormat(dateFormatString);
+                                  df = new SimpleDateFormat(dateFormatString);
                                }
                                catch(IllegalArgumentException e)
                                {
-                                       return DateFormat.getDateInstance(DateFormat.SHORT);
+                                  df = DateFormat.getDateInstance(DateFormat.SHORT);
                                }
+            break;
                        default:
-                               return DateFormat.getDateInstance(DateFormat.SHORT);
+                          df = DateFormat.getDateInstance(DateFormat.SHORT);
+            break;
                }
+      TimeZone tz = ConsoleSharedData.getTimeZone();
+      if (tz != null)
+         df.setTimeZone(tz);
+      return df;
        }
 
    /**
@@ -111,23 +128,31 @@ public class RegionalSettings
     */
    public static DateFormat getTimeFormat()
    {
+      DateFormat df;
       switch(dateTimeFormat)
       {
          case DATETIME_FORMAT_SERVER:
             NXCSession session = ConsoleSharedData.getSession();
-            return new SimpleDateFormat(session.getTimeFormat());
+            df = new SimpleDateFormat(session.getTimeFormat());
+            break;
          case DATETIME_FORMAT_CUSTOM:
             try
             {
-               return new SimpleDateFormat(timeFormatString);
+               df = new SimpleDateFormat(timeFormatString);
             }
             catch(IllegalArgumentException e)
             {
-               return DateFormat.getTimeInstance(DateFormat.MEDIUM);
+               df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
             }
+            break;
          default:
-            return DateFormat.getTimeInstance(DateFormat.MEDIUM);
+            df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
+            break;
       }
+      TimeZone tz = ConsoleSharedData.getTimeZone();
+      if (tz != null)
+         df.setTimeZone(tz);
+      return df;
    }
 
    /**
@@ -137,23 +162,31 @@ public class RegionalSettings
     */
    public static DateFormat getShortTimeFormat()
    {
+      DateFormat df;
       switch(dateTimeFormat)
       {
          case DATETIME_FORMAT_SERVER:
             NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-            return new SimpleDateFormat(session.getShortTimeFormat());
+            df = new SimpleDateFormat(session.getShortTimeFormat());
+            break;
          case DATETIME_FORMAT_CUSTOM:
             try
             {
-               return new SimpleDateFormat(shortTimeFormatString);
+               df = new SimpleDateFormat(shortTimeFormatString);
             }
             catch(IllegalArgumentException e)
             {
-               return DateFormat.getTimeInstance(DateFormat.SHORT);
+               df = DateFormat.getTimeInstance(DateFormat.SHORT);
             }
+            break;
          default:
-            return DateFormat.getTimeInstance(DateFormat.SHORT);
+            df = DateFormat.getTimeInstance(DateFormat.SHORT);
+            break;
       }
+      TimeZone tz = ConsoleSharedData.getTimeZone();
+      if (tz != null)
+         df.setTimeZone(tz);
+      return df;
    }
    
    /**
index 9f596c5..9f68285 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.netxms.ui.eclipse.shared;
 
+import java.util.TimeZone;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.swt.widgets.Display;
 import org.netxms.client.NXCSession;
@@ -28,6 +29,7 @@ import org.netxms.client.NXCSession;
 public class ConsoleSharedData
 {
    public static final String ATTRIBUTE_SESSION = "netxms.session";
+   public static final String ATTRIBUTE_TIMEZONE = "netxms.timezone";
    
        /**
         * Get NetXMS session
@@ -38,6 +40,16 @@ public class ConsoleSharedData
        {
                return (NXCSession)RWT.getUISession().getAttribute(ATTRIBUTE_SESSION);
        }
+       
+       /**
+        * Get client timezone
+        * 
+        * @return
+        */
+       public static TimeZone getTimeZone()
+       {
+      return (TimeZone)RWT.getUISession().getAttribute(ATTRIBUTE_TIMEZONE);
+       }
 
        /**
         * Get value of console property