directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r524580 - in /directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui: dialogs/ valueeditors/internal/
Date Sun, 01 Apr 2007 11:03:28 GMT
Author: seelmann
Date: Sun Apr  1 04:03:25 2007
New Revision: 524580

URL: http://svn.apache.org/viewvc?view=rev&rev=524580
Log:
Added AttributeTypeValueEditor and IntegerValueEditor

Added:
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/AttributeTypeDialog.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/IntegerDialog.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/AttributeTypeValueEditor.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/IntegerValueEditor.java
Modified:
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/ObjectClassDialog.java

Added: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/AttributeTypeDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/AttributeTypeDialog.java?view=auto&rev=524580
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/AttributeTypeDialog.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/AttributeTypeDialog.java
Sun Apr  1 04:03:25 2007
@@ -0,0 +1,179 @@
+/*
+ *  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.ldapstudio.browser.ui.dialogs;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.ListContentProposalProvider;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.fieldassist.ComboContentAdapter;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.DecoratedField;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.IControlCreator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * This class provides a dialog to enter or select an attribute type.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AttributeTypeDialog extends Dialog
+{
+
+    /** The dialog title */
+    public static final String DIALOG_TITLE = "Attribute Type Editor";
+
+    /** The schema. */
+    private Schema schema;
+
+    /** The initial value. */
+    private String initialValue;
+
+    /** The attribute type combo field. */
+    private DecoratedField attributeTypeComboField;
+
+    /** The attribute type combo. */
+    private Combo attributeTypeCombo;
+
+    /** The attribute type content proposal adapter */
+    private ContentProposalAdapter attributeTypeCPA;
+
+    /** The return value. */
+    private String returnValue;
+
+
+    /**
+     * Creates a new instance of AttributeTypeDialog.
+     * 
+     * @param parentShell the parent shell
+     * @param schema the schema
+     * @param initialValue the initial value
+     */
+    public AttributeTypeDialog( Shell parentShell, Schema schema, String initialValue )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.initialValue = initialValue;
+        this.schema = schema;
+        this.returnValue = null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( DIALOG_TITLE );
+        shell.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_TEXTEDITOR
) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        super.createButtonsForButtonBar( parent );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void okPressed()
+    {
+        returnValue = attributeTypeCombo.getText();
+        super.okPressed();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        // create composite
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH
);
+        composite.setLayoutData( gd );
+
+        // combo widget
+        String[] allAtNames = schema.getAttributeTypeDescriptionNames();
+        Arrays.sort( allAtNames );
+        
+        final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
+            FieldDecorationRegistry.DEC_CONTENT_PROPOSAL );
+        attributeTypeComboField = new DecoratedField( composite, SWT.NONE, new IControlCreator()
+        {
+            public Control createControl( Composite parent, int style )
+            {
+                Combo combo = BaseWidgetUtils.createCombo( parent, new String[0], -1, 1 );
+                combo.setVisibleItemCount( 20 );
+                return combo;
+            }
+        } );
+        attributeTypeComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT,
true );
+        attributeTypeComboField.getLayoutControl().setLayoutData(
+            new GridData( SWT.FILL, SWT.CENTER, true, false ) );
+        attributeTypeCombo = ( Combo ) attributeTypeComboField.getControl();
+        attributeTypeCombo.setItems( allAtNames );
+        attributeTypeCombo.setText( initialValue );
+
+        // content proposal adapter
+        attributeTypeCPA = new ContentProposalAdapter (attributeTypeCombo, new ComboContentAdapter(),
+            new ListContentProposalProvider( attributeTypeCombo.getItems() ), null, null
);
+        attributeTypeCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE );
+        attributeTypeCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE
);  
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    /**
+     * Gets the attribute type.
+     * 
+     * @return the attribute type, null if canceled
+     */
+    public String getAttributeType()
+    {
+        return returnValue;
+    }
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/IntegerDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/IntegerDialog.java?view=auto&rev=524580
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/IntegerDialog.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/IntegerDialog.java
Sun Apr  1 04:03:25 2007
@@ -0,0 +1,139 @@
+/*
+ *  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.ldapstudio.browser.ui.dialogs;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Spinner;
+
+
+/**
+ * This class provides a dialog to enter or choose an integer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class IntegerDialog extends Dialog
+{
+
+    /** The dialog title */
+    public static final String DIALOG_TITLE = "Integer Editor";
+
+    /** The initial value. */
+    private int initialValue;
+
+    /** The return value. */
+    private int returnValue;
+
+    /** The spinner to select an integer */
+    private Spinner spinner = null;
+
+
+    /**
+     * Creates a new instance of IntegerDialog.
+     * 
+     * @param parentShell the parent shell
+     * @param initialValue the initial value
+     */
+    public IntegerDialog( Shell parentShell, int initialValue )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+        this.initialValue = initialValue;
+        this.returnValue = -1;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( DIALOG_TITLE );
+        shell.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_TEXTEDITOR
) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+        createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL,
false );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void okPressed()
+    {
+        returnValue = spinner.getSelection();
+        super.okPressed();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        // create composite
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        composite.setLayout( new GridLayout() );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        composite.setLayoutData( gd );
+
+        spinner = new Spinner( composite, SWT.BORDER );
+        spinner.setMinimum( 0 );
+        spinner.setMaximum( Integer.MAX_VALUE );
+        spinner.setDigits( 0 );
+        spinner.setIncrement( 1 );
+        spinner.setPageIncrement( 100 );
+        spinner.setSelection( initialValue );
+        spinner.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    /**
+     * Gets the integer.
+     * 
+     * @return the integer
+     */
+    public int getInteger()
+    {
+        return returnValue;
+    }
+}

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/ObjectClassDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/ObjectClassDialog.java?view=diff&rev=524580&r1=524579&r2=524580
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/ObjectClassDialog.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/dialogs/ObjectClassDialog.java
Sun Apr  1 04:03:25 2007
@@ -27,9 +27,16 @@
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
 import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.ListContentProposalProvider;
 
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.fieldassist.ComboContentAdapter;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.DecoratedField;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.IControlCreator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Combo;
@@ -38,24 +45,44 @@
 import org.eclipse.swt.widgets.Shell;
 
 
+/**
+ * This class provides a dialog to enter or select an object class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class ObjectClassDialog extends Dialog
 {
 
+    /** The dialog title */
     public static final String DIALOG_TITLE = "Object Class Editor";
 
-    public static final double MAX_WIDTH = 250.0;
-
-    public static final double MAX_HEIGHT = 250.0;
-
+    /** The schema. */
     private Schema schema;
 
+    /** The initial value. */
     private String initialValue;
 
+    /** The object class combo field. */
+    private DecoratedField objectClassComboField;
+
+    /** The object class combo. */
     private Combo objectClassCombo;
 
+    /** The object class content proposal adapter */
+    private ContentProposalAdapter objectClassCPA;
+
+    /** The return value. */
     private String returnValue;
 
 
+    /**
+     * Creates a new instance of ObjectClassDialog.
+     * 
+     * @param parentShell the parent shell
+     * @param schema the schema
+     * @param initialValue the initial value
+     */
     public ObjectClassDialog( Shell parentShell, Schema schema, String initialValue )
     {
         super( parentShell );
@@ -66,12 +93,9 @@
     }
 
 
-    public boolean close()
-    {
-        return super.close();
-    }
-
-
+    /**
+     * {@inheritDoc}
+     */
     protected void configureShell( Shell shell )
     {
         super.configureShell( shell );
@@ -80,19 +104,28 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     protected void createButtonsForButtonBar( Composite parent )
     {
         super.createButtonsForButtonBar( parent );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     protected void okPressed()
     {
-        this.returnValue = this.objectClassCombo.getText();
+        returnValue = objectClassCombo.getText();
         super.okPressed();
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     protected Control createDialogArea( Composite parent )
     {
         // create composite
@@ -104,17 +137,43 @@
         // combo widget
         String[] allOcNames = schema.getObjectClassDescriptionNames();
         Arrays.sort( allOcNames );
-        objectClassCombo = BaseWidgetUtils.createReadonlyCombo( composite, allOcNames, 0,
1 );
+
+        final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
+            FieldDecorationRegistry.DEC_CONTENT_PROPOSAL );
+        objectClassComboField = new DecoratedField( composite, SWT.NONE, new IControlCreator()
+        {
+            public Control createControl( Composite parent, int style )
+            {
+                Combo combo = BaseWidgetUtils.createCombo( parent, new String[0], -1, 1 );
+                combo.setVisibleItemCount( 20 );
+                return combo;
+            }
+        } );
+        objectClassComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT, true
);
+        objectClassComboField.getLayoutControl().setLayoutData(
+            new GridData( SWT.FILL, SWT.CENTER, true, false ) );
+        objectClassCombo = ( Combo ) objectClassComboField.getControl();
+        objectClassCombo.setItems( allOcNames );
         objectClassCombo.setText( initialValue );
-        objectClassCombo.setVisibleItemCount( 20 );
 
+        // content proposal adapter
+        objectClassCPA = new ContentProposalAdapter (objectClassCombo, new ComboContentAdapter(),
+            new ListContentProposalProvider( objectClassCombo.getItems() ), null, null );
+        objectClassCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE );
+        objectClassCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE
); 
+        
         applyDialogFont( composite );
         return composite;
     }
 
 
+    /**
+     * Gets the object class.
+     * 
+     * @return the object class, null if canceled
+     */
     public String getObjectClass()
     {
-        return this.returnValue;
+        return returnValue;
     }
 }

Added: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/AttributeTypeValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/AttributeTypeValueEditor.java?view=auto&rev=524580
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/AttributeTypeValueEditor.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/AttributeTypeValueEditor.java
Sun Apr  1 04:03:25 2007
@@ -0,0 +1,172 @@
+/*
+ *  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.ldapstudio.browser.ui.valueeditors.internal;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.browser.ui.dialogs.AttributeTypeDialog;
+import org.apache.directory.ldapstudio.browser.ui.dialogs.ObjectClassDialog;
+import org.apache.directory.ldapstudio.browser.ui.dialogs.TextDialog;
+import org.apache.directory.ldapstudio.browser.ui.valueeditors.AbstractDialogStringValueEditor;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * Implementation of IValueEditor for attribute types.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AttributeTypeValueEditor extends AbstractDialogStringValueEditor
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation opens the AttributeTypeDialog.
+     */
+    public boolean openDialog( Shell shell )
+    {
+        Object value = getValue();
+        if ( value != null && value instanceof AttributeTypeValueEditorRawValueWrapper
)
+        {
+            AttributeTypeValueEditorRawValueWrapper wrapper = ( AttributeTypeValueEditorRawValueWrapper
) value;
+            AttributeTypeDialog dialog = new AttributeTypeDialog( shell, wrapper.schema,
wrapper.attributeType );
+            if ( dialog.open() == TextDialog.OK && !"".equals( dialog.getAttributeType()
) )
+            {
+                setValue( dialog.getAttributeType() );
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns always the string value.
+     * 
+     * Reimplementation, because getRawValue() returns an 
+     * AttributeTypeValueEditorRawValueWrapper.
+     */
+    public String getDisplayValue( IValue value )
+    {
+        if ( value == null )
+        {
+            return "NULL";
+        }
+
+        String displayValue = value.getStringValue();
+        return displayValue;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns null.
+     * Modification in search result editor not supported.
+     */
+    public Object getRawValue( AttributeHierarchy attributeHierarchy )
+    {
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns a AttributeTypeValueEditorRawValueWrapper.
+     */
+    public Object getRawValue( IValue value )
+    {
+        if ( value == null || !value.isString() )
+        {
+            return null;
+        }
+        else
+        {
+            return getRawValue( value.getAttribute().getEntry().getConnection(), value.getStringValue()
);
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Returns a AttributeTypeValueEditorRawValueWrapper.
+     */
+    public Object getRawValue( IConnection connection, Object value )
+    {
+        Schema schema = null;
+        if ( connection != null )
+        {
+            schema = connection.getSchema();
+        }
+        if ( schema == null || value == null || !( value instanceof String ) )
+        {
+            return null;
+        }
+
+        String atValue = ( String ) value;
+        AttributeTypeValueEditorRawValueWrapper wrapper = new AttributeTypeValueEditorRawValueWrapper(
schema, atValue );
+        return wrapper;
+    }
+
+    /**
+     * The AttributeTypeValueEditorRawValueWrapper is used to pass contextual 
+     * information to the opened AttributeTypeDialog.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    private class AttributeTypeValueEditorRawValueWrapper
+    {
+        /** 
+         * The schema, used in AttributeTypeDialog to build the list
+         * with possible attribute types.
+         */
+        private Schema schema;
+
+        /** The attribute type, used as initial value in AttributeTypeDialog. */
+        private String attributeType;
+
+
+        /**
+         * Creates a new instance of AttributeTypeValueEditorRawValueWrapper.
+         *
+         * @param schema the schema
+         * @param attributeType the attribute type
+         */
+        private AttributeTypeValueEditorRawValueWrapper( Schema schema, String attributeType
)
+        {
+            super();
+            this.schema = schema;
+            this.attributeType = attributeType;
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/IntegerValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/IntegerValueEditor.java?view=auto&rev=524580
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/IntegerValueEditor.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/valueeditors/internal/IntegerValueEditor.java
Sun Apr  1 04:03:25 2007
@@ -0,0 +1,68 @@
+/*
+ *  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.ldapstudio.browser.ui.valueeditors.internal;
+
+
+import org.apache.directory.ldapstudio.browser.ui.dialogs.IntegerDialog;
+import org.apache.directory.ldapstudio.browser.ui.valueeditors.AbstractDialogStringValueEditor;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * Implementation of IValueEditor for integer values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class IntegerValueEditor extends AbstractDialogStringValueEditor
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation opens the IntegerDialog.
+     */
+    public boolean openDialog( Shell shell )
+    {
+        Object value = getValue();
+        if ( value != null && value instanceof String )
+        {
+            String stringValue = ( String ) value;
+            int intValue;
+            try
+            {
+                intValue = Integer.valueOf( stringValue );
+            }
+            catch ( NumberFormatException e )
+            {
+                intValue = 0;
+            }
+            IntegerDialog dialog = new IntegerDialog( shell, intValue );
+            if ( dialog.open() == IntegerDialog.OK && dialog.getInteger() != -1 )
+            {
+                setValue( Integer.toString( dialog.getInteger() ) );
+                return true;
+            }
+        }
+        return false;
+    }
+
+}



Mime
View raw message