directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r753229 - in /directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time: GeneralizedTimeTimeZones.java GeneralizedTimeValueDialog.java Messages.java messages.properties messages_fr.properties
Date Fri, 13 Mar 2009 13:07:27 GMT
Author: pamarcelot
Date: Fri Mar 13 13:07:27 2009
New Revision: 753229

URL: http://svn.apache.org/viewvc?rev=753229&view=rev
Log:
Added continents and cities time zones at the end of the time zone combo.
Removed the GeneralizedTimeTimeZones enum, which is no longer necessary.
Externalized strings, added french translation.

Added:
    directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/Messages.java
    directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages.properties
    directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages_fr.properties
Removed:
    directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeTimeZones.java
Modified:
    directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.java

Modified: directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.java?rev=753229&r1=753228&r2=753229&view=diff
==============================================================================
--- directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.java
(original)
+++ directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.java
Fri Mar 13 13:07:27 2009
@@ -22,10 +22,14 @@
 
 
 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.SimpleTimeZone;
 import java.util.TimeZone;
 
 import org.apache.directory.shared.ldap.util.GeneralizedTime;
@@ -68,9 +72,11 @@
     /** The value */
     private GeneralizedTime value;
 
-    private List<GeneralizedTimeTimeZones> timezonesList = null;
+    /** The list, containing all time zones, bound to the combo viewer */
+    private ArrayList<TimeZone> allTimezonesList = new ArrayList<TimeZone>();
 
-    private Map<Integer, GeneralizedTimeTimeZones> timezonesMap = null;
+    /** The UTC times zones map */
+    private Map<Integer, TimeZone> utcTimezonesMap = new HashMap<Integer, TimeZone>();
 
     //
     // UI Fields
@@ -100,6 +106,9 @@
     // Listeners
     //
 
+    /**
+     * The modify listener of the hours field.
+     */
     private ModifyListener hoursModifyListener = new ModifyListener()
     {
         public void modifyText( ModifyEvent e )
@@ -112,6 +121,9 @@
         }
     };
 
+    /**
+     * The modify listener of the minutes field.
+     */
     private ModifyListener minutesModifyListener = new ModifyListener()
     {
         public void modifyText( ModifyEvent e )
@@ -124,6 +136,9 @@
         }
     };
 
+    /**
+     * The modify listener of the seconds field.
+     */
     private ModifyListener secondsModifyListener = new ModifyListener()
     {
         public void modifyText( ModifyEvent e )
@@ -136,6 +151,9 @@
         }
     };
 
+    /**
+     * The selection listener of the calendar.
+     */
     private SelectionListener dateSelectionListener = new SelectionAdapter()
     {
         public void widgetSelected( SelectionEvent e )
@@ -148,6 +166,9 @@
         }
     };
 
+    /**
+     * The selection changed listener of the time zone combo.
+     */
     private ISelectionChangedListener timezoneSelectionChangedListener = new ISelectionChangedListener()
     {
         public void selectionChanged( SelectionChangedEvent event )
@@ -160,6 +181,9 @@
         }
     };
 
+    /**
+     * The modify listener of the raw field.
+     */
     private ModifyListener rawModifyListener = new ModifyListener()
     {
         public void modifyText( ModifyEvent e )
@@ -212,7 +236,7 @@
     protected void configureShell( Shell shell )
     {
         super.configureShell( shell );
-        shell.setText( "Generalized Time Editor" );
+        shell.setText( Messages.getString( "GeneralizedTimeValueDialog.DateAndTimeEditor"
) ); //$NON-NLS-1$
         shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_GENERALIZEDTIMEEDITOR
) );
     }
 
@@ -230,15 +254,6 @@
     /**
      * {@inheritDoc}
      */
-    protected void okPressed()
-    {
-        super.okPressed();
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
     protected Control createDialogArea( Composite parent )
     {
         // Main composites
@@ -272,7 +287,7 @@
     {
         // Label
         Label timeLabel = new Label( parent, SWT.NONE );
-        timeLabel.setText( "Time:" );
+        timeLabel.setText( Messages.getString( "GeneralizedTimeValueDialog.Time" ) ); //$NON-NLS-1$
 
         Composite rightComposite = BaseWidgetUtils.createColumnContainer( parent, 5, 1 );
 
@@ -283,7 +298,7 @@
         hoursSpinner.setTextLimit( 2 );
         hoursSpinner.setLayoutData( new GridData( SWT.LEFT, SWT.CENTER, false, false ) );
 
-        Label label1 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 );
+        Label label1 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 ); //$NON-NLS-1$
         label1.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, false ) );
 
         // Minutes
@@ -293,7 +308,7 @@
         minutesSpinner.setTextLimit( 2 );
         minutesSpinner.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, false, false
) );
 
-        Label label2 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 );
+        Label label2 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 ); //$NON-NLS-1$
         label2.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, false ) );
 
         // Seconds
@@ -314,7 +329,8 @@
     private void createDateDialogArea( Composite parent )
     {
         // Label
-        Label dateLabel = BaseWidgetUtils.createLabel( parent, "Date:", 1 );
+        Label dateLabel = BaseWidgetUtils.createLabel( parent,
+            Messages.getString( "GeneralizedTimeValueDialog.Date" ), 1 ); //$NON-NLS-1$
         dateLabel.setLayoutData( new GridData( SWT.NONE, SWT.TOP, false, false ) );
 
         Composite rightComposite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
@@ -334,7 +350,7 @@
     private void createTimeZoneDialogArea( Composite parent )
     {
         // Label
-        BaseWidgetUtils.createLabel( parent, "Time zone:", 1 );
+        BaseWidgetUtils.createLabel( parent, Messages.getString( "GeneralizedTimeValueDialog.Timezone"
), 1 ); //$NON-NLS-1$
 
         // Combo viewer
         timezoneComboViewer = new ComboViewer( parent );
@@ -346,24 +362,129 @@
         {
             public String getText( Object element )
             {
-                return ( ( GeneralizedTimeTimeZones ) element ).getName();
+                return ( ( TimeZone ) element ).getID();
             }
         } );
 
         // Initializing the time zones list and map
-        timezonesList = GeneralizedTimeTimeZones.getAllTimezones();
-        timezonesMap = new HashMap<Integer, GeneralizedTimeTimeZones>();
-        for ( GeneralizedTimeTimeZones timezone : timezonesList )
+        initAllTimezones();
+
+        timezoneComboViewer.setInput( allTimezonesList );
+    }
+
+
+    /**
+     * Initializes all the time zones.
+     */
+    private void initAllTimezones()
+    {
+        initUtcTimezones();
+        initContinentsAndCitiesTimezones();
+    }
+
+
+    /**
+     * Initializes all the "UTC+/-xxxx" time zones.
+     */
+    private void initUtcTimezones()
+    {
+        addUtcTimezone( "UTC-12", -1 * ( 12 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-11", -1 * ( 11 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-10", -1 * ( 10 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-9:30", -1 * ( ( ( 9 * 60 ) + 30 ) * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-9", -1 * ( 9 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-8", -1 * ( 8 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-7", -1 * ( 7 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-6", -1 * ( 6 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-5", -1 * ( 5 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-4:30", -1 * ( ( ( 4 * 60 ) + 30 ) * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-4", -1 * ( 4 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-3:30", -1 * ( ( ( 3 * 60 ) + 30 ) * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-3", -1 * ( 3 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-2", -1 * ( 2 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC-1", -1 * ( 1 * 60 * 60 * 1000 ) ); //$NON-NLS-1$
+        addUtcTimezone( "UTC", 0 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+1", 1 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+2", 2 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+3", 3 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+3:30", ( ( 3 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+4", 4 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+4:30", ( ( 4 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+5", 5 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+5:30", ( ( 5 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+5:45", ( ( 5 * 60 ) + 45 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+6", 6 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+6:30", ( ( 6 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+7", 7 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+8", 8 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+8:45", ( ( 8 * 60 ) + 45 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+9", 9 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+9:30", ( ( 9 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+10", 10 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+10:30", ( ( 10 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+11", 11 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+11:30", ( ( 11 * 60 ) + 30 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+12", 12 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+12:45", ( ( 12 * 60 ) + 45 ) * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+13", 13 * 60 * 60 * 1000 ); //$NON-NLS-1$
+        addUtcTimezone( "UTC+14", 14 * 60 * 60 * 1000 ); //$NON-NLS-1$
+    }
+
+
+    /**
+     * Adds an UTC time zone.
+     *
+     * @param tz
+     *      a time zone to add
+     */
+    private void addUtcTimezone( String id, int rawOffset )
+    {
+        TimeZone tz = new SimpleTimeZone( rawOffset, id );
+
+        allTimezonesList.add( tz );
+        utcTimezonesMap.put( rawOffset, tz );
+    }
+
+
+    /**
+     * Initializes all the continents and cities time zones.
+     */
+    private void initContinentsAndCitiesTimezones()
+    {
+        List<TimeZone> continentsAndCitiesTimezonesList = new ArrayList<TimeZone>();
+
+        // Getting all e time zones from the following continents :
+        //     * Africa
+        //     * America
+        //     * Asia
+        //     * Atlantic
+        //     * Australia
+        //     * Europe
+        //     * Indian
+        //     * Pacific
+        for ( String timezoneId : TimeZone.getAvailableIDs() )
         {
-            timezonesMap.put( new Integer( timezone.getRawOffset() ), timezone );
+            if ( timezoneId.matches( "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*"
) ) //$NON-NLS-1$
+            {
+                continentsAndCitiesTimezonesList.add( TimeZone.getTimeZone( timezoneId )
);
+            }
         }
 
-        timezoneComboViewer.setInput( timezonesList );
+        // Sorting the list by ID
+        Collections.sort( continentsAndCitiesTimezonesList, new Comparator<TimeZone>()
+        {
+            public int compare( final TimeZone a, final TimeZone b )
+            {
+                return a.getID().compareTo( b.getID() );
+            }
+        } );
+
+        allTimezonesList.addAll( continentsAndCitiesTimezonesList );
     }
 
 
     /**
-     * Creates the "Time Zone" dialog area.
+     * Creates the "Raw" dialog area.
      *
      * @param parent
      *      the parent composite
@@ -375,13 +496,13 @@
         separatorLabel.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2,
1 ) );
 
         // Label
-        BaseWidgetUtils.createLabel( parent, "Raw:", 1 );
+        BaseWidgetUtils.createLabel( parent, Messages.getString( "GeneralizedTimeValueDialog.Raw"
), 1 ); //$NON-NLS-1$
 
         // Raw composite
         Composite rawComposite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 );
 
         // Text
-        rawText = BaseWidgetUtils.createText( rawComposite, "", 1 );
+        rawText = BaseWidgetUtils.createText( rawComposite, "", 1 ); //$NON-NLS-1$
 
         // Validator image
         rawValidatorImage = new Label( rawComposite, SWT.NONE );
@@ -416,7 +537,7 @@
             .get( Calendar.DAY_OF_MONTH ) );
 
         // Time zone
-        GeneralizedTimeTimeZones timezone = timezonesMap.get( new Integer( calendar.getTimeZone().getRawOffset()
) );
+        TimeZone timezone = utcTimezonesMap.get( new Integer( calendar.getTimeZone().getRawOffset()
) );
         if ( timezone == null )
         {
             timezoneComboViewer.setSelection( null );
@@ -538,12 +659,7 @@
         StructuredSelection selection = ( StructuredSelection ) timezoneComboViewer.getSelection();
         if ( ( selection != null ) && ( !selection.isEmpty() ) )
         {
-            GeneralizedTimeTimeZones timezone = ( GeneralizedTimeTimeZones ) selection.getFirstElement();
-            String[] timezoneIds = TimeZone.getAvailableIDs( timezone.getRawOffset() );
-            if ( ( timezoneIds != null ) && ( timezoneIds.length > 0 ) )
-            {
-                calendar.setTimeZone( TimeZone.getTimeZone( timezoneIds[0] ) );
-            }
+            calendar.setTimeZone( ( TimeZone ) selection.getFirstElement() );
         }
         else
         {
@@ -556,9 +672,10 @@
 
 
     /**
-     * Gets the {@link GeneralizedTime}.
+     * Gets the {@link GeneralizedTime} value.
      *
      * @return
+     *      the {@link GeneralizedTime} value
      */
     public GeneralizedTime getGeneralizedTime()
     {

Added: directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/Messages.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/Messages.java?rev=753229&view=auto
==============================================================================
--- directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/Messages.java
(added)
+++ directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/Messages.java
Fri Mar 13 13:07:27 2009
@@ -0,0 +1,31 @@
+package org.apache.directory.studio.valueeditors.time;
+
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+
+public class Messages
+{
+    private static final String BUNDLE_NAME = "org.apache.directory.studio.valueeditors.time.messages";
//$NON-NLS-1$
+
+    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME
);
+
+
+    private Messages()
+    {
+    }
+
+
+    public static String getString( String key )
+    {
+        try
+        {
+            return RESOURCE_BUNDLE.getString( key );
+        }
+        catch ( MissingResourceException e )
+        {
+            return '!' + key + '!';
+        }
+    }
+}

Added: directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages.properties?rev=753229&view=auto
==============================================================================
--- directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages.properties
(added)
+++ directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages.properties
Fri Mar 13 13:07:27 2009
@@ -0,0 +1,5 @@
+GeneralizedTimeValueDialog.Date=Date:
+GeneralizedTimeValueDialog.DateAndTimeEditor=Date & Time Editor
+GeneralizedTimeValueDialog.Raw=Raw:
+GeneralizedTimeValueDialog.Time=Time:
+GeneralizedTimeValueDialog.Timezone=Time zone:

Added: directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages_fr.properties?rev=753229&view=auto
==============================================================================
--- directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages_fr.properties
(added)
+++ directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/messages_fr.properties
Fri Mar 13 13:07:27 2009
@@ -0,0 +1,5 @@
+GeneralizedTimeValueDialog.Date=Date:
+GeneralizedTimeValueDialog.DateAndTimeEditor=Editeur de Date & Heure
+GeneralizedTimeValueDialog.Raw=Brut:
+GeneralizedTimeValueDialog.Time=Heure:
+GeneralizedTimeValueDialog.Timezone=Fuseau horaire:



Mime
View raw message