Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 57355 invoked from network); 13 Mar 2009 10:05:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Mar 2009 10:05:43 -0000 Received: (qmail 12150 invoked by uid 500); 13 Mar 2009 10:05:43 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 12115 invoked by uid 500); 13 Mar 2009 10:05:43 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 12106 invoked by uid 99); 13 Mar 2009 10:05:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Mar 2009 03:05:43 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Mar 2009 10:05:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4B44423888F1; Fri, 13 Mar 2009 10:05:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r753190 - in /directory/studio/trunk/valueeditors: ./ resources/icons/ src/main/java/org/apache/directory/studio/valueeditors/ src/main/java/org/apache/directory/studio/valueeditors/time/ Date: Fri, 13 Mar 2009 10:05:16 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090313100517.4B44423888F1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pamarcelot Date: Fri Mar 13 10:05:15 2009 New Revision: 753190 URL: http://svn.apache.org/viewvc?rev=753190&view=rev Log: Fix for DIRSTUDIO-449 (Add a new GeneralizedTime Value Editor). Added: directory/studio/trunk/valueeditors/resources/icons/textfield_error.png (with props) directory/studio/trunk/valueeditors/resources/icons/textfield_ok.png (with props) directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeTimeZones.java directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.java directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueEditor.java Removed: directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/InPlaceGeneralizedTimeValueEditor.java Modified: directory/studio/trunk/valueeditors/plugin.properties directory/studio/trunk/valueeditors/plugin.xml directory/studio/trunk/valueeditors/plugin_de.properties directory/studio/trunk/valueeditors/plugin_fr.properties directory/studio/trunk/valueeditors/pom.xml directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsConstants.java Modified: directory/studio/trunk/valueeditors/plugin.properties URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/plugin.properties?rev=753190&r1=753189&r2=753190&view=diff ============================================================================== --- directory/studio/trunk/valueeditors/plugin.properties (original) +++ directory/studio/trunk/valueeditors/plugin.properties Fri Mar 13 10:05:15 2009 @@ -21,7 +21,7 @@ ValueEditor_ImageValueEditor_name=Image Editor -ValueEditor_InPlaceGeneralizedTimeValueEditor_name=In-Place Generalized Time Editor +ValueEditor_GeneralizedTimeValueEditor_name=Generalized Time Editor ValueEditor_ObjectClassValueEditor_name=Object Class Editor Modified: directory/studio/trunk/valueeditors/plugin.xml URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/plugin.xml?rev=753190&r1=753189&r2=753190&view=diff ============================================================================== --- directory/studio/trunk/valueeditors/plugin.xml (original) +++ directory/studio/trunk/valueeditors/plugin.xml Fri Mar 13 10:05:15 2009 @@ -34,9 +34,9 @@ + name="%ValueEditor_GeneralizedTimeValueEditor_name"> workbench provided + + org.eclipse.core + commands + provided + \ No newline at end of file Added: directory/studio/trunk/valueeditors/resources/icons/textfield_error.png URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/resources/icons/textfield_error.png?rev=753190&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/studio/trunk/valueeditors/resources/icons/textfield_error.png ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: directory/studio/trunk/valueeditors/resources/icons/textfield_ok.png URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/resources/icons/textfield_ok.png?rev=753190&view=auto ============================================================================== Binary file - no diff available. Propchange: directory/studio/trunk/valueeditors/resources/icons/textfield_ok.png ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsConstants.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsConstants.java?rev=753190&r1=753189&r2=753190&view=diff ============================================================================== --- directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsConstants.java (original) +++ directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsConstants.java Fri Mar 13 10:05:15 2009 @@ -45,7 +45,7 @@ public static final String IMG_PASSWORDEDITOR = "resources/icons/passwordeditor.gif"; //$NON-NLS-1$ /** The relative path to the generalized time editor icon */ - public static final String IMG_INPLACE_GENERALIZEDTIMEEDITOR = "resources/icons/inplace_generalizedtimeeditor.gif"; //$NON-NLS-1$ + public static final String IMG_GENERALIZEDTIMEEDITOR = "resources/icons/generalizedtimeeditor.gif"; //$NON-NLS-1$ /** The relative path to the object class editor icon */ public static final String IMG_OCDEDITOR = "resources/icons/objectclasseditor.png"; //$NON-NLS-1$ @@ -56,4 +56,9 @@ /** The relative path to the administrative role editor icon */ public static final String IMG_ADMINISTRATIVEROLEEDITOR = "resources/icons/administrativeroleeditor.gif"; //$NON-NLS-1$ + /** The relative path to the text field error icon */ + public static final String IMG_TEXTFIELD_ERROR = "resources/icons/textfield_error.png"; //$NON-NLS-1$ + + /** The relative path to the text field ok icon */ + public static final String IMG_TEXTFIELD_OK = "resources/icons/textfield_ok.png"; //$NON-NLS-1$ } Added: directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeTimeZones.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeTimeZones.java?rev=753190&view=auto ============================================================================== --- directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeTimeZones.java (added) +++ directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeTimeZones.java Fri Mar 13 10:05:15 2009 @@ -0,0 +1,156 @@ +package org.apache.directory.studio.valueeditors.time; + + +import java.util.ArrayList; +import java.util.List; + + +/** + * This enum represents a GeneralizedTime time zones. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public enum GeneralizedTimeTimeZones +{ + UTC_MINUS_12 ( "UTC-12", -1 * ( 12 * 60 * 60 * 1000 ) ), + UTC_MINUS_11 ( "UTC-11", -1 * ( 11 * 60 * 60 * 1000 ) ), + UTC_MINUS_10 ( "UTC-10", -1 * ( 10 * 60 * 60 * 1000 ) ), + UTC_MINUS_9_30 ( "UTC-9:30", -1 * ( ( ( 9 * 60 ) + 30 ) * 60 * 1000 ) ), + UTC_MINUS_9 ( "UTC-9", -1 * ( 9 * 60 * 60 * 1000 ) ), + UTC_MINUS_8 ( "UTC-8", -1 * ( 8 * 60 * 60 * 1000 ) ), + UTC_MINUS_7 ( "UTC-7", -1 * ( 7 * 60 * 60 * 1000 ) ), + UTC_MINUS_6 ( "UTC-6", -1 * ( 6 * 60 * 60 * 1000 ) ), + UTC_MINUS_5 ( "UTC-5", -1 * ( 5 * 60 * 60 * 1000 ) ), + UTC_MINUS_4_30 ( "UTC-4:30", -1 * ( ( ( 4 * 60 ) + 30 ) * 60 * 1000 ) ), + UTC_MINUS_4 ( "UTC-4", -1 * ( 4 * 60 * 60 * 1000 ) ), + UTC_MINUS_3_30 ( "UTC-3:30", -1 * ( ( ( 3 * 60 ) + 30 ) * 60 * 1000 ) ), + UTC_MINUS_3 ( "UTC-3", -1 * ( 3 * 60 * 60 * 1000 ) ), + UTC_MINUS_2 ( "UTC-2", -1 * ( 2 * 60 * 60 * 1000 ) ), + UTC_MINUS_1 ( "UTC-1", -1 * ( 1 * 60 * 60 * 1000 ) ), + UTC ( "UTC", 0 ), + UTC_PLUS_1 ( "UTC+1", 1 * 60 * 60 * 1000 ), + UTC_PLUS_2 ( "UTC+2", 2 * 60 * 60 * 1000 ), + UTC_PLUS_3 ( "UTC+3", 3 * 60 * 60 * 1000 ), + UTC_PLUS_3_30 ( "UTC+3:30", ( ( 3 * 60 ) + 30 ) * 60 * 1000 ), + UTC_PLUS_4 ( "UTC+4", 4 * 60 * 60 * 1000 ), + UTC_PLUS_4_30 ( "UTC+4:30", ( ( 4 * 60 ) + 30 ) * 60 * 1000 ), + UTC_PLUS_5 ( "UTC+5", 5 * 60 * 60 * 1000 ), + UTC_PLUS_5_30 ( "UTC+5:30", ( ( 5 * 60 ) + 30 ) * 60 * 1000 ), + UTC_PLUS_5_45 ( "UTC+5:45", ( ( 5 * 60 ) + 45 ) * 60 * 1000 ), + UTC_PLUS_6 ( "UTC+6", 6 * 60 * 60 * 1000 ), + UTC_PLUS_6_30 ( "UTC+6:30", ( ( 6 * 60 ) + 30 ) * 60 * 1000 ), + UTC_PLUS_7 ( "UTC+7", 7 * 60 * 60 * 1000 ), + UTC_PLUS_8 ( "UTC+8", 8 * 60 * 60 * 1000 ), + UTC_PLUS_8_45 ( "UTC+8:45", ( ( 8 * 60 ) + 45 ) * 60 * 1000 ), + UTC_PLUS_9 ( "UTC+9", 9 * 60 * 60 * 1000 ), + UTC_PLUS_9_30 ( "UTC+9:30", ( ( 9 * 60 ) + 30 ) * 60 * 1000 ), + UTC_PLUS_10 ( "UTC+10", 10 * 60 * 60 * 1000 ), + UTC_PLUS_10_30 ( "UTC+10:30", ( ( 10 * 60 ) + 30 ) * 60 * 1000 ), + UTC_PLUS_11 ( "UTC+11", 11 * 60 * 60 * 1000 ), + UTC_PLUS_11_30 ( "UTC+11:30", ( ( 11 * 60 ) + 30 ) * 60 * 1000 ), + UTC_PLUS_12 ( "UTC+12", 12 * 60 * 60 * 1000 ), + UTC_PLUS_12_45 ( "UTC+12:45", ( ( 12 * 60 ) + 45 ) * 60 * 1000 ), + UTC_PLUS_13 ( "UTC+13", 13 * 60 * 60 * 1000 ), + UTC_PLUS_14 ( "UTC+14", 14 * 60 * 60 * 1000 ); + + /** The name */ + private String name; + + /** The raw offset */ + private int rawOffset; + + + /** + * Creates a new instance of GeneralizedTimeTimeZones. + * + * @param name + * the name + * @param rawOffset + * the rawOffset + */ + GeneralizedTimeTimeZones( String name, int rawOffset ) + { + this.name = name; + this.rawOffset = rawOffset; + } + + + /** + * Gets the name. + * + * @return + * the name + */ + public String getName() + { + return name; + } + + + /** + * Gets the raw offset. + * + * @return + * the raw offset + */ + public int getRawOffset() + { + return rawOffset; + } + + + /** + * Get all the time zones. + * + * @return + * a {@link List} containing all the time zones + */ + public static List getAllTimezones() + { + List timezones = new ArrayList(); + + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_12 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_11 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_10 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_9_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_9 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_8 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_7 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_6 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_5 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_4_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_4 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_3_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_3 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_2 ); + timezones.add( GeneralizedTimeTimeZones.UTC_MINUS_1 ); + timezones.add( GeneralizedTimeTimeZones.UTC ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_1 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_2 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_3 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_3_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_4 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_4_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_5 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_5_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_5_45 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_6 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_6_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_7 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_8 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_8_45 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_9 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_9_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_10 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_10_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_11 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_11_30 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_12 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_12_45 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_13 ); + timezones.add( GeneralizedTimeTimeZones.UTC_PLUS_14 ); + + return timezones; + } +} \ No newline at end of file Added: 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=753190&view=auto ============================================================================== --- directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.java (added) +++ directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueDialog.java Fri Mar 13 10:05:15 2009 @@ -0,0 +1,567 @@ +/* + * 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.time; + + +import java.text.ParseException; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; + +import org.apache.directory.shared.ldap.util.GeneralizedTime; +import org.apache.directory.studio.connection.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.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +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.layout.GridData; +import org.eclipse.swt.widgets.Button; +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 define a generalized time. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class GeneralizedTimeValueDialog extends Dialog +{ + /** The value */ + private GeneralizedTime value; + + private List timezonesList = null; + + private Map timezonesMap = null; + + // + // UI Fields + // + + // Time + private Spinner hoursSpinner; + private Spinner minutesSpinner; + private Spinner secondsSpinner; + + // Date + private DateTime dateCalendar; + + // Time zone + private ComboViewer timezoneComboViewer; + + // Raw value + private Text rawText; + + // Raw validator + private Label rawValidatorImage; + + /** The OK button of the dialog */ + private Button okButton; + + // + // Listeners + // + + private ModifyListener hoursModifyListener = new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + updateValueFromNonRawFields(); + + removeListeners(); + updateRawFields(); + addListeners(); + } + }; + + private ModifyListener minutesModifyListener = new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + updateValueFromNonRawFields(); + + removeListeners(); + updateRawFields(); + addListeners(); + } + }; + + private ModifyListener secondsModifyListener = new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + updateValueFromNonRawFields(); + + removeListeners(); + updateRawFields(); + addListeners(); + } + }; + + private SelectionListener dateSelectionListener = new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + updateValueFromNonRawFields(); + + removeListeners(); + updateRawFields(); + addListeners(); + } + }; + + private ISelectionChangedListener timezoneSelectionChangedListener = new ISelectionChangedListener() + { + public void selectionChanged( SelectionChangedEvent event ) + { + updateValueFromNonRawFields(); + + removeListeners(); + updateRawFields(); + addListeners(); + } + }; + + private ModifyListener rawModifyListener = new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + try + { + value = new GeneralizedTime( rawText.getText() ); + + removeListeners(); + updateNonRawFields(); + addListeners(); + + validateRawValue( true ); + } + catch ( ParseException e1 ) + { + validateRawValue( false ); + + return; + } + } + }; + + + /** + * Creates a new instance of GeneralizedTimeValueDialog. + * + * @param parentShell + * the parent shell + * @param value + * the initial value + */ + public GeneralizedTimeValueDialog( Shell parentShell, GeneralizedTime value ) + { + super( parentShell ); + super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); + this.value = value; + + // If the initial value is null, we take the current date/time + if ( this.value == null ) + { + this.value = new GeneralizedTime( Calendar.getInstance() ); + } + } + + + /** + * {@inheritDoc} + */ + protected void configureShell( Shell shell ) + { + super.configureShell( shell ); + shell.setText( "Generalized Time Editor" ); + shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_GENERALIZEDTIMEEDITOR ) ); + } + + + /** + * {@inheritDoc} + */ + protected void createButtonsForButtonBar( Composite parent ) + { + okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); + createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); + } + + + /** + * {@inheritDoc} + */ + protected void okPressed() + { + super.okPressed(); + } + + + /** + * {@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 ); + createTimeZoneDialogArea( dualComposite ); + createRawDialogArea( 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( "Time:" ); + + 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 ); + 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 ); + 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, "Date:", 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 "Time Zone" dialog area. + * + * @param parent + * the parent composite + */ + private void createTimeZoneDialogArea( Composite parent ) + { + // Label + BaseWidgetUtils.createLabel( parent, "Time zone:", 1 ); + + // Combo viewer + timezoneComboViewer = new ComboViewer( parent ); + timezoneComboViewer.getCombo().setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); + + // Adding ContentProvider, LabelProvider + timezoneComboViewer.setContentProvider( new ArrayContentProvider() ); + timezoneComboViewer.setLabelProvider( new LabelProvider() + { + public String getText( Object element ) + { + return ( ( GeneralizedTimeTimeZones ) element ).getName(); + } + } ); + + // Initializing the time zones list and map + timezonesList = GeneralizedTimeTimeZones.getAllTimezones(); + timezonesMap = new HashMap(); + for ( GeneralizedTimeTimeZones timezone : timezonesList ) + { + timezonesMap.put( new Integer( timezone.getRawOffset() ), timezone ); + } + + timezoneComboViewer.setInput( timezonesList ); + } + + + /** + * Creates the "Time Zone" dialog area. + * + * @param parent + * the parent composite + */ + private void createRawDialogArea( 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, "Raw:", 1 ); + + // Raw composite + Composite rawComposite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 ); + + // Text + rawText = BaseWidgetUtils.createText( rawComposite, "", 1 ); + + // Validator image + rawValidatorImage = new Label( rawComposite, SWT.NONE ); + validateRawValue( true ); + } + + + /** + * Initializes the UI with the value. + */ + private void initWithInitialValue() + { + updateNonRawFields(); + updateRawFields(); + } + + + /** + * Update the non-raw UI fields. + */ + private void updateNonRawFields() + { + Calendar calendar = value.getCalendar(); + + // 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 ) ); + + // Time zone + GeneralizedTimeTimeZones timezone = timezonesMap.get( new Integer( calendar.getTimeZone().getRawOffset() ) ); + if ( timezone == null ) + { + timezoneComboViewer.setSelection( null ); + } + else + { + timezoneComboViewer.setSelection( new StructuredSelection( timezone ) ); + } + } + + + /** + * Update the raw UI fields. + */ + private void updateRawFields() + { + // Raw + rawText.setText( value.toGeneralizedTime() ); + + validateRawValue( true ); + } + + + /** + * Validates the raw value. + * + * @param bool + * true to set the raw value as valid + * false to set the raw value as invalid + */ + private void validateRawValue( boolean bool ) + { + if ( bool ) + { + rawValidatorImage.setImage( ValueEditorsActivator.getDefault().getImage( + ValueEditorsConstants.IMG_TEXTFIELD_OK ) ); + } + else + { + rawValidatorImage.setImage( ValueEditorsActivator.getDefault().getImage( + ValueEditorsConstants.IMG_TEXTFIELD_ERROR ) ); + } + + if ( okButton != null && !okButton.isDisposed() ) + { + okButton.setEnabled( bool ); + } + } + + + /** + * 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 ); + + // Time zone + timezoneComboViewer.addSelectionChangedListener( timezoneSelectionChangedListener ); + + // Raw value + rawText.addModifyListener( rawModifyListener ); + } + + + /** + * 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 ); + + // Time zone + timezoneComboViewer.removeSelectionChangedListener( timezoneSelectionChangedListener ); + + // Raw value + rawText.removeModifyListener( rawModifyListener ); + } + + + /** + * Updates the value using the non raw fields. + */ + private void updateValueFromNonRawFields() + { + Calendar calendar = Calendar.getInstance(); + + // 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() ); + + // Time zone + 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] ) ); + } + } + else + { + calendar.setTimeZone( value.getCalendar().getTimeZone() ); + } + + // Replacing the value + value = new GeneralizedTime( calendar ); + } + + + /** + * Gets the {@link GeneralizedTime}. + * + * @return + */ + public GeneralizedTime getGeneralizedTime() + { + return value; + } +} Added: directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueEditor.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueEditor.java?rev=753190&view=auto ============================================================================== --- directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueEditor.java (added) +++ directory/studio/trunk/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/time/GeneralizedTimeValueEditor.java Fri Mar 13 10:05:15 2009 @@ -0,0 +1,104 @@ +/* + * 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.time; + + +import java.text.DateFormat; +import java.text.ParseException; +import java.util.Date; + +import org.apache.directory.shared.ldap.util.GeneralizedTime; +import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog; +import org.apache.directory.studio.ldapbrowser.core.model.IValue; +import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; +import org.eclipse.swt.widgets.Shell; + + +/** + * Implementation of IValueEditor for syntax 1.3.6.1.4.1.1466.115.121.1.24 + * (Generalized Time). + * + * Currently only the getDisplayXXX() methods are implemented. + * For modification the raw string must be edited. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class GeneralizedTimeValueEditor 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 + { + GeneralizedTime generalizedTime = new GeneralizedTime( displayValue ); + Date date = generalizedTime.getCalendar().getTime(); + displayValue = targetFormat.format( date ) + " (" + displayValue + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + } + catch ( ParseException pe ) + { + // show the raw value in that case + } + } + + return displayValue; + } + + + /** + * {@inheritDoc} + */ + protected boolean openDialog( Shell shell ) + { + Object value = getValue(); + if ( value != null && value instanceof String ) + { + try + { + GeneralizedTime generalizedTime = new GeneralizedTime( ( String ) value ); + GeneralizedTimeValueDialog dialog = new GeneralizedTimeValueDialog( shell, + generalizedTime ); + if ( dialog.open() == TextDialog.OK ) + { + setValue( dialog.getGeneralizedTime().toGeneralizedTime() ); + return true; + } + } + catch ( ParseException pe ) + { + return false; + } + + } + return false; + } +}