directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1398267 - in /directory/studio/trunk/plugins/valueeditors: ./ src/main/java/org/apache/directory/studio/valueeditors/adtime/
Date Mon, 15 Oct 2012 12:22:21 GMT
Author: pamarcelot
Date: Mon Oct 15 12:22:20 2012
New Revision: 1398267

URL: http://svn.apache.org/viewvc?rev=1398267&view=rev
Log:
Fix for DIRSTUDIO-804 (Interpret Active Directory Timestamps)

Added:
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeUtils.java
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueDialog.java
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueEditor.java
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/Messages.java
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages.properties
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_de.properties
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_fr.properties
Modified:
    directory/studio/trunk/plugins/valueeditors/plugin.properties
    directory/studio/trunk/plugins/valueeditors/plugin.xml
    directory/studio/trunk/plugins/valueeditors/plugin_de.properties
    directory/studio/trunk/plugins/valueeditors/plugin_fr.properties

Modified: directory/studio/trunk/plugins/valueeditors/plugin.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/plugin.properties?rev=1398267&r1=1398266&r2=1398267&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/plugin.properties (original)
+++ directory/studio/trunk/plugins/valueeditors/plugin.properties Mon Oct 15 12:22:20 2012
@@ -23,6 +23,8 @@ ValueEditor_ImageValueEditor_name=Image 
 
 ValueEditor_GeneralizedTimeValueEditor_name=Date and Time Editor
 
+ValueEditor_ActiveDirectoryTimeValueEditor_name=MS AD Date and Time Editor
+
 ValueEditor_ObjectClassValueEditor_name=Object Class Editor
 
 ValueEditor_DnValueEditor_name=DN Editor

Modified: directory/studio/trunk/plugins/valueeditors/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/plugin.xml?rev=1398267&r1=1398266&r2=1398267&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/plugin.xml (original)
+++ directory/studio/trunk/plugins/valueeditors/plugin.xml Mon Oct 15 12:22:20 2012
@@ -40,6 +40,17 @@
        <syntax syntaxOID="1.3.6.1.4.1.1466.115.121.1.24"/>
     </valueEditor>
     <valueEditor
+          class="org.apache.directory.studio.valueeditors.adtime.ActiveDirectoryTimeValueEditor"
+          icon="resources/icons/generalizedtimeeditor.gif"
+          name="%ValueEditor_ActiveDirectoryTimeValueEditor_name">
+       <attribute attributeType="pwdLastSet"/>
+       <attribute attributeType="accountExpires"/>
+       <attribute attributeType="lastLogoff"/>
+       <attribute attributeType="lastLogon"/>
+       <attribute attributeType="lastLogonTimeStamp"/>
+       <attribute attributeType="badPasswordTime"/>
+    </valueEditor>
+    <valueEditor
           class="org.apache.directory.studio.valueeditors.objectclass.ObjectClassValueEditor"
           icon="resources/icons/objectclasseditor.png"
           name="%ValueEditor_ObjectClassValueEditor_name">

Modified: directory/studio/trunk/plugins/valueeditors/plugin_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/plugin_de.properties?rev=1398267&r1=1398266&r2=1398267&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/plugin_de.properties (original)
+++ directory/studio/trunk/plugins/valueeditors/plugin_de.properties Mon Oct 15 12:22:20 2012
@@ -21,6 +21,8 @@ ValueEditor_ImageValueEditor_name=Bild E
 
 ValueEditor_GeneralizedTimeValueEditor_name=Datum und Zeit Editor
 
+ValueEditor_ActiveDirectoryTimeValueEditor_name=MS AD Datum und Zeit Editor
+
 ValueEditor_ObjectClassValueEditor_name=Objektklassen Editor
 
 ValueEditor_AddressValueEditor_name=Adressen Editor

Modified: directory/studio/trunk/plugins/valueeditors/plugin_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/plugin_fr.properties?rev=1398267&r1=1398266&r2=1398267&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/plugin_fr.properties (original)
+++ directory/studio/trunk/plugins/valueeditors/plugin_fr.properties Mon Oct 15 12:22:20 2012
@@ -18,6 +18,7 @@
 ValueEditor_PasswordValueEditor_name=Editeur de mot de passe
 ValueEditor_ImageValueEditor_name=Editeur d'image
 ValueEditor_GeneralizedTimeValueEditor_name=Editeur de date et heure
+ValueEditor_ActiveDirectoryTimeValueEditor_name=Editeur de date et heure MS AD
 ValueEditor_ObjectClassValueEditor_name=Editeur d'object class
 ValueEditor_DnValueEditor_name=Editeur de DN
 ValueEditor_AddressValueEditor_name=Editeur d'addresse

Added: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeUtils.java?rev=1398267&view=auto
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeUtils.java
(added)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeUtils.java
Mon Oct 15 12:22:20 2012
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.valueeditors.adtime;
+
+
+import java.util.Calendar;
+
+
+/**
+ * Helper class to work with Active Directory time values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ActiveDirectoryTimeUtils
+{
+    /**
+     * Converts the given Active Directory time value to an equivalent calendar.
+     *
+     * @param adTimeValue the Active Directory time value
+     * @return the equivalent calendar
+     */
+    public static Calendar convertToCalendar( long adTimeValue )
+    {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTimeInMillis( ( adTimeValue - 116444736000000000L ) / 10000L );
+        return calendar;
+    }
+
+
+    /**
+     * Converts the given calendar to the equivalent Active Directory time.
+     *
+     * @param calendar the calendard
+     * @return the equivalent Active Directory time
+     */
+    public static long convertToActiveDirectoryTime( Calendar calendar )
+    {
+        return ( ( calendar.getTime().getTime() * 10000L ) + 116444736000000000L );
+    }
+}

Added: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueDialog.java?rev=1398267&view=auto
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueDialog.java
(added)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueDialog.java
Mon Oct 15 12:22:20 2012
@@ -0,0 +1,450 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.valueeditors.adtime;
+
+
+import java.util.Calendar;
+
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
+import org.apache.directory.studio.valueeditors.ValueEditorsConstants;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DateTime;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Spinner;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * This class provides a dialog to edit an Active Directory Date & Time value.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ActiveDirectoryTimeValueDialog extends Dialog
+{
+    /** The value */
+    private long value;
+
+    //
+    // UI Fields
+    //
+
+    // Time
+    private Spinner hoursSpinner;
+    private Spinner minutesSpinner;
+    private Spinner secondsSpinner;
+
+    // Date
+    private DateTime dateCalendar;
+
+    // Raw value
+    private Text rawValueText;
+
+    //
+    // Listeners
+    //
+
+    /**
+     * The modify listener of the hours field.
+     */
+    private ModifyListener hoursModifyListener = new ModifyListener()
+    {
+        public void modifyText( ModifyEvent e )
+        {
+            updateValueFromNonRawFields();
+
+            removeListeners();
+            updateRawFields();
+            addListeners();
+        }
+    };
+
+    /**
+     * The modify listener of the minutes field.
+     */
+    private ModifyListener minutesModifyListener = new ModifyListener()
+    {
+        public void modifyText( ModifyEvent e )
+        {
+            updateValueFromNonRawFields();
+
+            removeListeners();
+            updateRawFields();
+            addListeners();
+        }
+    };
+
+    /**
+     * The modify listener of the seconds field.
+     */
+    private ModifyListener secondsModifyListener = new ModifyListener()
+    {
+        public void modifyText( ModifyEvent e )
+        {
+            updateValueFromNonRawFields();
+
+            removeListeners();
+            updateRawFields();
+            addListeners();
+        }
+    };
+
+    /**
+     * The selection listener of the calendar.
+     */
+    private SelectionListener dateSelectionListener = new SelectionAdapter()
+    {
+        public void widgetSelected( SelectionEvent e )
+        {
+            updateValueFromNonRawFields();
+
+            removeListeners();
+            updateRawFields();
+            addListeners();
+        }
+    };
+
+    /**
+     * The modify listener of the raw field.
+     */
+    private ModifyListener rawValueModifyListener = new ModifyListener()
+    {
+        public void modifyText( ModifyEvent e )
+        {
+            try
+            {
+                value = Long.parseLong( rawValueText.getText() );
+
+                removeListeners();
+                updateNonRawFields();
+                addListeners();
+            }
+            catch ( NumberFormatException e1 )
+            {
+                return;
+            }
+        }
+    };
+
+    private VerifyListener rawValueVerifyListener = new VerifyListener()
+    {
+        public void verifyText( VerifyEvent e )
+        {
+            // Prevent the user from entering anything but an integer
+            if ( !e.text.matches( "(-)?([0-9])*" ) ) //$NON-NLS-1$
+            {
+                e.doit = false;
+            }
+        }
+    };
+
+
+    /**
+     * Creates a new instance of ActiveDirectoryTimeValueDialog.
+     * 
+     * @param parentShell
+     *      the parent shell
+     * @param value
+     *      the initial value
+     */
+    public ActiveDirectoryTimeValueDialog( Shell parentShell, long value )
+    {
+        this( parentShell );
+        this.value = value;
+    }
+
+
+    /**
+     * Creates a new instance of ActiveDirectoryTimeValueDialog.
+     * 
+     * @param parentShell
+     *      the parent shell
+     * @param value
+     *      the initial value
+     */
+    public ActiveDirectoryTimeValueDialog( Shell parentShell )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.value = ActiveDirectoryTimeUtils.convertToActiveDirectoryTime( Calendar.getInstance()
);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( Messages.getString( "ActiveDirectoryTimeValueDialog.DateAndTimeEditor"
) ); //$NON-NLS-1$
+        shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_GENERALIZEDTIMEEDITOR
) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        // Main composites
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        Composite dualComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1
);
+
+        // Creating dialog areas
+        createTimeDialogArea( dualComposite );
+        createDateDialogArea( dualComposite );
+        createRawValueDialogArea( dualComposite );
+
+        // Initializing with initial value
+        initWithInitialValue();
+
+        // Adding listeners
+        addListeners();
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    /**
+     * Creates the "Time" dialog area.
+     *
+     * @param parent
+     *      the parent composite
+     */
+    private void createTimeDialogArea( Composite parent )
+    {
+        // Label
+        Label timeLabel = new Label( parent, SWT.NONE );
+        timeLabel.setText( Messages.getString( "ActiveDirectoryTimeValueDialog.Time" ) );
//$NON-NLS-1$
+
+        Composite rightComposite = BaseWidgetUtils.createColumnContainer( parent, 5, 1 );
+
+        // Hours
+        hoursSpinner = new Spinner( rightComposite, SWT.BORDER );
+        hoursSpinner.setMinimum( 0 );
+        hoursSpinner.setMaximum( 23 );
+        hoursSpinner.setTextLimit( 2 );
+        hoursSpinner.setLayoutData( new GridData( SWT.LEFT, SWT.CENTER, false, false ) );
+
+        Label label1 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 ); //$NON-NLS-1$
+        label1.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, false ) );
+
+        // Minutes
+        minutesSpinner = new Spinner( rightComposite, SWT.BORDER );
+        minutesSpinner.setMinimum( 0 );
+        minutesSpinner.setMaximum( 59 );
+        minutesSpinner.setTextLimit( 2 );
+        minutesSpinner.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, false, false
) );
+
+        Label label2 = BaseWidgetUtils.createLabel( rightComposite, ":", 1 ); //$NON-NLS-1$
+        label2.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, false ) );
+
+        // Seconds
+        secondsSpinner = new Spinner( rightComposite, SWT.BORDER );
+        secondsSpinner.setMinimum( 0 );
+        secondsSpinner.setMaximum( 59 );
+        secondsSpinner.setTextLimit( 2 );
+        secondsSpinner.setLayoutData( new GridData( SWT.RIGHT, SWT.CENTER, false, false )
);
+    }
+
+
+    /**
+     * Creates the "Date" dialog area.
+     *
+     * @param parent
+     *      the parent composite
+     */
+    private void createDateDialogArea( Composite parent )
+    {
+        // Label
+        Label dateLabel = BaseWidgetUtils.createLabel( parent,
+            Messages.getString( "ActiveDirectoryTimeValueDialog.Date" ), 1 ); //$NON-NLS-1$
+        dateLabel.setLayoutData( new GridData( SWT.NONE, SWT.TOP, false, false ) );
+
+        Composite rightComposite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+        // Calendar
+        dateCalendar = new DateTime( rightComposite, SWT.CALENDAR | SWT.BORDER );
+        dateCalendar.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
+    }
+
+
+    /**
+     * Creates the "Raw value" dialog area.
+     *
+     * @param parent
+     *      the parent composite
+     */
+    private void createRawValueDialogArea( Composite parent )
+    {
+        // Separator
+        Label separatorLabel = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL );
+        separatorLabel.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2,
1 ) );
+
+        // Label
+        BaseWidgetUtils.createLabel( parent, Messages.getString( "ActiveDirectoryTimeValueDialog.RawValue"
), 1 ); //$NON-NLS-1$
+
+        // Text
+        rawValueText = BaseWidgetUtils.createText( parent, "", 1 ); //$NON-NLS-1$
+    }
+
+
+    /**
+     * Initializes the UI with the value.
+     */
+    private void initWithInitialValue()
+    {
+        updateNonRawFields();
+        updateRawFields();
+    }
+
+
+    /**
+     * Update the non-raw UI fields.
+     */
+    private void updateNonRawFields()
+    {
+        // Getting the calendar 
+        Calendar calendar = getCalendarFromValue();
+
+        // Time
+        hoursSpinner.setSelection( calendar.get( Calendar.HOUR_OF_DAY ) );
+        minutesSpinner.setSelection( calendar.get( Calendar.MINUTE ) );
+        secondsSpinner.setSelection( calendar.get( Calendar.SECOND ) );
+
+        // Date
+        dateCalendar.setDate( calendar.get( Calendar.YEAR ), calendar.get( Calendar.MONTH
), calendar
+            .get( Calendar.DAY_OF_MONTH ) );
+    }
+
+
+    /**
+     * Update the raw UI fields.
+     */
+    private void updateRawFields()
+    {
+        // Raw value
+        rawValueText.setText( "" + value );
+    }
+
+
+    /**
+     * Adds the listeners to the UI fields.
+     */
+    private void addListeners()
+    {
+        // Hours
+        hoursSpinner.addModifyListener( hoursModifyListener );
+
+        // Minutes
+        minutesSpinner.addModifyListener( minutesModifyListener );
+
+        // Seconds
+        secondsSpinner.addModifyListener( secondsModifyListener );
+
+        // Calendar
+        dateCalendar.addSelectionListener( dateSelectionListener );
+
+        // Raw value
+        rawValueText.addModifyListener( rawValueModifyListener );
+        rawValueText.addVerifyListener( rawValueVerifyListener );
+    }
+
+
+    /**
+     * Removes the listeners from the UI fields.
+     */
+    private void removeListeners()
+    {
+        // Hours
+        hoursSpinner.removeModifyListener( hoursModifyListener );
+
+        // Minutes
+        minutesSpinner.removeModifyListener( minutesModifyListener );
+
+        // Seconds
+        secondsSpinner.removeModifyListener( secondsModifyListener );
+
+        // Calendar
+        dateCalendar.removeSelectionListener( dateSelectionListener );
+
+        // Raw value
+        rawValueText.removeModifyListener( rawValueModifyListener );
+        rawValueText.removeVerifyListener( rawValueVerifyListener );
+    }
+
+
+    /**
+     * Updates the value using the non raw fields.
+     */
+    private void updateValueFromNonRawFields()
+    {
+        // Getting the calendar 
+        Calendar calendar = getCalendarFromValue();
+
+        // Time
+        calendar.set( Calendar.HOUR_OF_DAY, hoursSpinner.getSelection() );
+        calendar.set( Calendar.MINUTE, minutesSpinner.getSelection() );
+        calendar.set( Calendar.SECOND, secondsSpinner.getSelection() );
+
+        // Date
+        calendar.set( Calendar.YEAR, dateCalendar.getYear() );
+        calendar.set( Calendar.MONTH, dateCalendar.getMonth() );
+        calendar.set( Calendar.DAY_OF_MONTH, dateCalendar.getDay() );
+
+        value = ActiveDirectoryTimeUtils.convertToActiveDirectoryTime( calendar );
+    }
+
+
+    /**
+     * Gets a calendar from the current value.
+     *
+     * @return a calendar corresponding to the current value
+     */
+    private Calendar getCalendarFromValue()
+    {
+        return ActiveDirectoryTimeUtils.convertToCalendar( value );
+    }
+
+
+    /**
+     * Gets the value.
+     *
+     * @return
+     *      the value
+     */
+    public long getValue()
+    {
+        return value;
+    }
+}

Added: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueEditor.java?rev=1398267&view=auto
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueEditor.java
(added)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/ActiveDirectoryTimeValueEditor.java
Mon Oct 15 12:22:20 2012
@@ -0,0 +1,137 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.valueeditors.adtime;
+
+
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * Implementation of IValueEditor for attributes:
+ * - pwdLastSet
+ * - accountExpires
+ * - lastLogoff
+ * - lastLogon
+ * - lastLogonTimeStamp
+ * - badPasswordTime
+ * 
+ * Currently only the getDisplayXXX() methods are implemented.
+ * For modification the raw string must be edited.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ActiveDirectoryTimeValueEditor extends AbstractDialogStringValueEditor
+{
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns the proper formatted date and time, timezone is 
+     * converted to the default locale. 
+     */
+    public String getDisplayValue( IValue value )
+    {
+        String displayValue = super.getDisplayValue( value );
+
+        if ( !showRawValues() )
+        {
+            DateFormat targetFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM,
DateFormat.LONG );
+
+            try
+            {
+                long adTimeValue = Long.parseLong( displayValue );
+                Date date = ActiveDirectoryTimeUtils.convertToCalendar( adTimeValue ).getTime();
+                displayValue = targetFormat.format( date ) + " (" + displayValue + ")"; //$NON-NLS-1$
//$NON-NLS-2$
+            }
+            catch ( NumberFormatException e )
+            {
+                // show the raw value in that case
+            }
+        }
+
+        return displayValue;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean openDialog( Shell shell )
+    {
+        Object value = getValue();
+        if ( value != null && value instanceof String )
+        {
+            String s = ( String ) value;
+            long adTimeValue = 0;
+
+            if ( !"".equals( s ) ) //$NON-NLS-1$
+            {
+                // Trying to parse the value
+                try
+                {
+                    adTimeValue = Long.parseLong( s );
+                }
+                catch ( NumberFormatException pe )
+                {
+                    // The value could not be parsed correctly
+
+                    // Displaying an error window indicating to the user that the value is
bogus
+                    // and asking him if he wants to continue to edit the value with current
date and time selected
+                    if ( MessageDialog.openConfirm( PlatformUI.getWorkbench().getDisplay().getActiveShell(),
Messages
+                        .getString( "ActiveDirectoryTimeValueEditor.BogusDateAndTimeValue"
), NLS.bind( //$NON-NLS-1$
+                        Messages.getString( "ActiveDirectoryTimeValueEditor.TheValueIsBogus"
), new String[] //$NON-NLS-1$
+                        { s } ) ) )
+                    {
+                        // Generating today's date and time
+                        adTimeValue = ActiveDirectoryTimeUtils.convertToActiveDirectoryTime(
Calendar.getInstance() );
+                    }
+                    else
+                    {
+                        return false;
+                    }
+                }
+            }
+            else
+            {
+                // Generating today's date and time
+                adTimeValue = ActiveDirectoryTimeUtils.convertToActiveDirectoryTime( Calendar.getInstance()
);
+            }
+
+            // Creating and opening the dialog
+            ActiveDirectoryTimeValueDialog dialog = new ActiveDirectoryTimeValueDialog( shell,
adTimeValue );
+            if ( dialog.open() == ActiveDirectoryTimeValueDialog.OK )
+            {
+                setValue( "" + dialog.getValue() );
+                return true;
+            }
+        }
+
+        return false;
+    }
+}

Added: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/Messages.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/Messages.java?rev=1398267&view=auto
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/Messages.java
(added)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/Messages.java
Mon Oct 15 12:22:20 2012
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.valueeditors.adtime;
+
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+
+public class Messages
+{
+    private static final String BUNDLE_NAME = "org.apache.directory.studio.valueeditors.adtime.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/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages.properties?rev=1398267&view=auto
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages.properties
(added)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages.properties
Mon Oct 15 12:22:20 2012
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+ActiveDirectoryTimeValueDialog.Date=Date:
+ActiveDirectoryTimeValueDialog.DateAndTimeEditor=MS AD Date & Time Editor
+ActiveDirectoryTimeValueDialog.RawValue=Raw value:
+ActiveDirectoryTimeValueDialog.Time=Time:
+ActiveDirectoryTimeValueEditor.BogusDateAndTimeValue=Bogus Date & Time Value
+ActiveDirectoryTimeValueEditor.TheValueIsBogus=The value ''{0}'' is bogus and cannot be edited
in the MS AD Date and Time Editor.\n\nWould you like to open the MS AD Date and Time Editor
with the current date and time ?\n\n\nNote: To edit the bogus value, you can use the In-Place
Text Editor.

Added: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_de.properties?rev=1398267&view=auto
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_de.properties
(added)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_de.properties
Mon Oct 15 12:22:20 2012
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+ActiveDirectoryTimeValueDialog.Date=Datum\:
+ActiveDirectoryTimeValueDialog.DateAndTimeEditor=MS AD Datum & Zeit Editor
+ActiveDirectoryTimeValueDialog.RawValue=Unbearbeiteter Wert\:
+ActiveDirectoryTimeValueDialog.Time=Zeit\:
+ActiveDirectoryTimeValueEditor.BogusDateAndTimeValue=Ung\u00fcltiger Wert f\u00fcr Datum
& Zeit
+ActiveDirectoryTimeValueEditor.TheValueIsBogus=Der Wert ''{0}'' ist ung\u00fcltig und kann
nicht bearbeitet werden.\n\nM\u00f6chten Sie den MS AD Datum & Zeit Editor mit den aktuellen
Datum- und Zeitwerten öffnen?\n\n\nHinweis: Zum bearbeiten des ung\u00fcltigen Wertes kann
der In-Place Text Editor verwendet werden.

Added: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_fr.properties?rev=1398267&view=auto
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_fr.properties
(added)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/adtime/messages_fr.properties
Mon Oct 15 12:22:20 2012
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+ActiveDirectoryTimeValueDialog.Date=Date:
+ActiveDirectoryTimeValueDialog.DateAndTimeEditor=Editeur de date & heure MS AD
+ActiveDirectoryTimeValueDialog.RawValue=Valeur brute:
+ActiveDirectoryTimeValueDialog.Time=Heure:
+ActiveDirectoryTimeValueEditor.BogusDateAndTimeValue=Valeur de date et heure erron\u00E9e
+ActiveDirectoryTimeValueEditor.TheValueIsBogus=La valeur ''{0}'' est erron\u00E9e et ne peut
pas \u00EAtre \u00E9dit\u00E9e dans l''\u00E9diteur de date et heure MS AD.\n\nVoulez-vous
ouvrir l''\u00E9diteur de date et heure MS AD avec la date et l''heure courante ?\n\n\nNote:
Pour \u00E9diter la valeur erron\u00E9e, vous pouvez utiliser l''\u00E9diteur de texte en-place.



Mime
View raw message