directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r592079 [9/17] - in /directory/sandbox/felixk/studio-ldapbrowser-common: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ ...
Date Mon, 05 Nov 2007 16:48:54 GMT
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BaseWidgetUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BaseWidgetUtils.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BaseWidgetUtils.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BaseWidgetUtils.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,474 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * This class provides utility methods to create SWT widgets.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BaseWidgetUtils
+{
+
+    /**
+     * Creates a SWT {@link Group} under the given parent.
+     *
+     * @param parent the parent
+     * @param label the label of the group
+     * @param span the horizontal span
+     * @return the created group
+     */
+    public static Group createGroup( Composite parent, String label, int span )
+    {
+        Group group = new Group( parent, SWT.NONE );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.horizontalSpan = span;
+        group.setLayoutData( gd );
+        group.setText( label );
+        group.setLayout( new GridLayout() );
+        return group;
+    }
+
+
+    /**
+     * Creates a SWT {@link Composite} under the given parent. 
+     * A GridLayout with the given number of columns is used.
+     *
+     * @param parent the parent
+     * @param columnCount the number of columns
+     * @param span the horizontal span
+     * @return the created composite
+     */
+    public static Composite createColumnContainer( Composite parent, int columnCount, int span )
+    {
+        Composite container = new Composite( parent, SWT.NONE );
+        GridLayout gl = new GridLayout( columnCount, false );
+        gl.marginHeight = gl.marginWidth = 0;
+        container.setLayout( gl );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        container.setLayoutData( gd );
+        return container;
+    }
+
+
+    /**
+     * Creates a SWT {@link Label} under the given parent. 
+     *
+     * @param parent the parent
+     * @param text the label's text
+     * @param span the horizontal span
+     * @return the created label
+     */
+    public static Label createLabel( Composite parent, String text, int span )
+    {
+        Label l = new Label( parent, SWT.NONE );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        // gd.verticalAlignment = SWT.BEGINNING;
+        l.setLayoutData( gd );
+        l.setText( text );
+        return l;
+    }
+
+
+    /**
+     * Creates a SWT {@link Label} under the given parent. 
+     * The label is created with the SWT.WRAP style to enable line wrapping.
+     *
+     * @param parent the parent
+     * @param text the label's text
+     * @param span the horizontal span
+     * @return the created label
+     */
+    public static Label createWrappedLabel( Composite parent, String text, int span )
+    {
+        Label l = new Label( parent, SWT.WRAP );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        // gd.verticalAlignment = SWT.BEGINNING;
+        l.setLayoutData( gd );
+        l.setText( text );
+        return l;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control is modifyable.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control is modifyable.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param textWidth the width of the text control
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createText( Composite parent, String text, int textWidth, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        gd.widthHint = 9 * textWidth;
+        t.setLayoutData( gd );
+        t.setText( text );
+        t.setTextLimit( textWidth );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control is created with the SWT.PASSWORD style.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createPasswordText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control is created with the SWT.PASSWORD and 
+     * SWT.READ_ONLY style. So the created controls is not modifyable.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createReadonlyPasswordText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD | SWT.READ_ONLY );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setEditable( false );
+        t.setBackground( parent.getBackground() );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control behaves like a label: it has no border, 
+     * a grayed background and is not modifyable. 
+     * But the text is selectable and could be copied.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createLabeledText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setEditable( false );
+        t.setBackground( parent.getBackground() );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The created text control behaves like a label: it has no border, 
+     * a grayed background and is not modifyable. 
+     * But the text is selectable and could be copied.
+     * The label is created with the SWT.WRAP style to enable line wrapping.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createWrappedLabeledText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.WRAP );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        gd.widthHint = 10;
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalAlignment = GridData.FILL;
+        t.setLayoutData( gd );
+        t.setEditable( false );
+        t.setBackground( parent.getBackground() );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Text} under the given parent.
+     * The text is not modifyable, but the text is selectable 
+     * and could be copied.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Text createReadonlyText( Composite parent, String text, int span )
+    {
+        Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.READ_ONLY );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        t.setLayoutData( gd );
+        t.setEditable( false );
+        t.setBackground( parent.getBackground() );
+        t.setText( text );
+        return t;
+    }
+
+
+    /**
+     * Creates a SWT {@link Combo} under the given parent.
+     * Beside the selection of an item it is also possible to type
+     * free text into the combo.
+     *
+     * @param parent the parent
+     * @param items the initial visible items
+     * @param selectedIndex the initial selected item, zero-based
+     * @param span the horizontal span
+     * @return the created combo
+     */
+    public static Combo createCombo( Composite parent, String[] items, int selectedIndex, int span )
+    {
+        Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        c.setLayoutData( gd );
+        c.setItems( items );
+        c.select( selectedIndex );
+        c.setVisibleItemCount( 20 );
+        return c;
+    }
+
+
+    /**
+     * Creates a SWT {@link Combo} under the given parent.
+     * It is not possible to type free text into the combo, only 
+     * selection of predefined items is possible.
+     *
+     * @param parent the parent
+     * @param items the initial visible items
+     * @param selectedIndex the initial selected item, zero-based
+     * @param span the horizontal span
+     * @return the created combo
+     */
+    public static Combo createReadonlyCombo( Composite parent, String[] items, int selectedIndex, int span )
+    {
+        Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        c.setLayoutData( gd );
+        // c.setBackground(parent.getBackground());
+        c.setItems( items );
+        c.select( selectedIndex );
+        c.setVisibleItemCount( 20 );
+        return c;
+    }
+
+
+    /**
+     * Creates a checkbox under the given parent.
+     *
+     * @param parent the parent
+     * @param text the label of the checkbox 
+     * @param span the horizontal span
+     * @return the created checkbox
+     */
+    public static Button createCheckbox( Composite parent, String text, int span )
+    {
+        Button checkbox = new Button( parent, SWT.CHECK );
+        checkbox.setText( text );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        checkbox.setLayoutData( gd );
+        return checkbox;
+    }
+
+
+    /**
+     * Creates a radio button under the given parent.
+     *
+     * @param parent the parent
+     * @param text the label of the radio button 
+     * @param span the horizontal span
+     * @return the created radio button
+     */
+    public static Button createRadiobutton( Composite parent, String text, int span )
+    {
+        Button radio = new Button( parent, SWT.RADIO );
+        radio.setText( text );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        radio.setLayoutData( gd );
+        return radio;
+    }
+
+
+    /**
+     * Creates a button under the given parent. 
+     * The button width is set to the default width.
+     *
+     * @param parent the parent
+     * @param text the label of the button 
+     * @param span the horizontal span
+     * @return the created button
+     */
+    public static Button createButton( Composite parent, String text, int span )
+    {
+        GC gc = new GC( parent );
+        gc.setFont( JFaceResources.getDialogFont() );
+        FontMetrics fontMetrics = gc.getFontMetrics();
+        gc.dispose();
+
+        Button button = new Button( parent, SWT.PUSH );
+        GridData gd = new GridData();
+        gd.widthHint = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH );
+        button.setLayoutData( gd );
+        button.setText( text );
+        return button;
+    }
+
+
+    /**
+     * Adds some space to indent radio buttons.
+     *
+     * @param parent the parent
+     * @param span the horizontal span
+     */
+    public static void createRadioIndent( Composite parent, int span )
+    {
+        Label l = new Label( parent, SWT.NONE );
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        gd.horizontalIndent = 22;
+        l.setLayoutData( gd );
+    }
+
+
+    /**
+     * Creates a spacer.
+     *
+     * @param parent the parent
+     * @param span the horizontal span
+     */
+    public static void createSpacer( Composite parent, int span )
+    {
+        Label l = new Label( parent, SWT.NONE );
+        // GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+        GridData gd = new GridData();
+        gd.horizontalSpan = span;
+        gd.heightHint = 1;
+        l.setLayoutData( gd );
+    }
+
+
+    /**
+     * Creates a separator line.
+     *
+     * @param parent the parent
+     * @param span the horizontal span
+     */
+    public static void createSeparator( Composite parent, int span )
+    {
+        Label l = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL );
+        GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+        gd.horizontalSpan = span;
+        // gd.heightHint = 1;
+        l.setLayoutData( gd );
+    }
+
+
+    /**
+     * Creates a SWT {@link Link} under the given parent.
+     *
+     * @param parent the parent
+     * @param text the initial text
+     * @param span the horizontal span
+     * @return the created text
+     */
+    public static Link createLink( Composite parent, String text, int span )
+    {
+        Link link = new Link( parent, SWT.NONE );
+        link.setText( text );
+        GridData gd = new GridData( SWT.FILL, SWT.BEGINNING, true, false );
+        gd.horizontalSpan = span;
+        gd.widthHint = 150;
+        link.setLayoutData( gd );
+        return link;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BaseWidgetUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BinaryEncodingInput.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BinaryEncodingInput.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BinaryEncodingInput.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BinaryEncodingInput.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,103 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+
+
+/**
+ * The BinaryEncodingInput is an OptionInput with fixed options. 
+ * It is used to select the encoding of binary attributes. The default
+ * value is always {@link BrowserCoreConstants#BINARYENCODING_IGNORE}.
+ * The other options are always {@link BrowserCoreConstants#BINARYENCODING_IGNORE},
+ * {@link BrowserCoreConstants#BINARYENCODING_BASE64} and
+ * {@link BrowserCoreConstants#BINARYENCODING_HEX}. No custom input is allowed.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BinaryEncodingInput extends OptionsInput
+{
+
+    /**
+     * Creates a new instance of BinaryEncodingInput.
+     *
+     * @param initialRawValue the initial raw value
+     * @param asGroup the asGroup flag
+     */
+    public BinaryEncodingInput( String initialRawValue, boolean asGroup )
+    {
+        super( "Binary Encoding", getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(),
+            getOtherRawValues(), initialRawValue, asGroup, false );
+
+    }
+
+
+    /**
+     * Gets the default display value, always "Ignore".
+     * 
+     * @return the default display value
+     */
+    private static String getDefaultDisplayValue()
+    {
+        return "Ignore";
+    }
+
+
+    /**
+     * Gets the default raw value, always 
+     * {@link BrowserCoreConstants.BINARYENCODING_IGNORE}.
+     * 
+     * @return the default raw value
+     */
+    private static String getDefaultRawValue()
+    {
+        return Integer.toString( BrowserCoreConstants.BINARYENCODING_IGNORE );
+    }
+
+
+    /**
+     * Gets the other display values.
+     * 
+     * @return the other display values
+     */
+    private static String[] getOtherDisplayValues()
+    {
+        return new String[]
+            { "Ignore", "BASE-64", "HEX" };
+    }
+
+
+    /**
+     * Gets the other raw values.
+     * 
+     * @return the other raw values
+     */
+    private static String[] getOtherRawValues()
+    {
+        return new String[]
+            { Integer.toString( BrowserCoreConstants.BINARYENCODING_IGNORE ),
+                Integer.toString( BrowserCoreConstants.BINARYENCODING_BASE64 ),
+                Integer.toString( BrowserCoreConstants.BINARYENCODING_HEX ) };
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BinaryEncodingInput.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BrowserWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BrowserWidget.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BrowserWidget.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BrowserWidget.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,91 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+/**
+ * Base class that provides support for {@link WidgetModifyListener} 
+ * registration and notification.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class BrowserWidget
+{
+
+    /** The listener list */
+    protected List<WidgetModifyListener> modifyListenerList;
+
+
+    /**
+     * Creates a new instance of BrowserWidget.
+     */
+    protected BrowserWidget()
+    {
+        modifyListenerList = new ArrayList<WidgetModifyListener>( 3 );
+    }
+
+
+    /**
+     * Adds the widget modify listener.
+     * 
+     * @param listener the listener
+     */
+    public void addWidgetModifyListener( WidgetModifyListener listener )
+    {
+        if ( !modifyListenerList.contains( listener ) )
+        {
+            modifyListenerList.add( listener );
+        }
+    }
+
+
+    /**
+     * Removes the widget modify listener.
+     * 
+     * @param listener the listener
+     */
+    public void removeWidgetModifyListener( WidgetModifyListener listener )
+    {
+        if ( modifyListenerList.contains( listener ) )
+            modifyListenerList.remove( listener );
+    }
+
+
+    /**
+     * Notifies the listeners.
+     */
+    protected void notifyListeners()
+    {
+        WidgetModifyEvent event = new WidgetModifyEvent( this );
+        for ( Iterator<WidgetModifyListener> it = modifyListenerList.iterator(); it.hasNext(); )
+        {
+            WidgetModifyListener listener = it.next();
+            listener.widgetModified( event );
+        }
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BrowserWidget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DialogContentAssistant.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DialogContentAssistant.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DialogContentAssistant.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DialogContentAssistant.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,220 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.jface.contentassist.ComboContentAssistSubjectAdapter;
+import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
+import org.eclipse.jface.contentassist.TextContentAssistSubjectAdapter;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+
+
+/**
+ * The DialogContentAssistant is used to provide content assist and 
+ * a proposal popup within a SWT {@link Text}, {@link Combo} or
+ * {@link ITextViewer}. 
+ * 
+ * It provides a special handling of ESC keystrokes: 
+ * When the proposal popup is shown ESC is catched and the popup is closed.
+ * This ensures that a dialog isn't closed on a ESC keystroke
+ * while the proposal popup is opened. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DialogContentAssistant extends SubjectControlContentAssistant implements FocusListener
+{
+
+    /** The control */
+    private Control control;
+
+    /** The handler activation. */
+    private IHandlerActivation handlerActivation;
+
+    /** The possible completions visible. */
+    private boolean possibleCompletionsVisible;
+
+
+    /**
+     * Creates a new instance of DialogContentAssistant.
+     */
+    public DialogContentAssistant()
+    {
+        this.possibleCompletionsVisible = false;
+    }
+
+
+    /**
+     * Installs content assist on the given text.
+     *
+     * @param text the text
+     */
+    public void install( Text text )
+    {
+        control = text;
+        control.addFocusListener( this );
+        super.install( new TextContentAssistSubjectAdapter( text ) );
+    }
+
+
+    /**
+     * Installs content assist on the given combo.
+     *
+     * @param combo the combo
+     */
+    public void install( Combo combo )
+    {
+        control = combo;
+        control.addFocusListener( this );
+        super.install( new ComboContentAssistSubjectAdapter( combo ) );
+    }
+
+
+    /**
+     * Installs content assist on the given text viewer.
+     *
+     * @param viewer the text viewer
+     */
+    public void install( ITextViewer viewer )
+    {
+        control = viewer.getTextWidget();
+        control.addFocusListener( this );
+
+        // stop traversal (ESC) if popup is shown
+        control.addTraverseListener( new TraverseListener()
+        {
+            public void keyTraversed( TraverseEvent e )
+            {
+                if ( possibleCompletionsVisible )
+                {
+                    e.doit = false;
+                }
+            }
+        } );
+
+        super.install( viewer );
+    }
+
+
+    /**
+     * Uninstalls content assist on the control.
+     */
+    public void uninstall()
+    {
+        if ( handlerActivation != null )
+        {
+            IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter(
+                IHandlerService.class );
+            handlerService.deactivateHandler( handlerActivation );
+            handlerActivation = null;
+        }
+
+        if ( control != null )
+        {
+            control.removeFocusListener( this );
+        }
+
+        super.uninstall();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Point restoreCompletionProposalPopupSize()
+    {
+        possibleCompletionsVisible = true;
+        return super.restoreCompletionProposalPopupSize();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String showPossibleCompletions()
+    {
+        possibleCompletionsVisible = true;
+        return super.showPossibleCompletions();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void possibleCompletionsClosed()
+    {
+        possibleCompletionsVisible = false;
+        super.possibleCompletionsClosed();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void focusGained( FocusEvent e )
+    {
+        IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter(
+            IHandlerService.class );
+        if ( handlerService != null )
+        {
+            IHandler handler = new org.eclipse.core.commands.AbstractHandler()
+            {
+                public Object execute( ExecutionEvent event ) throws org.eclipse.core.commands.ExecutionException
+                {
+                    showPossibleCompletions();
+                    return null;
+                }
+            };
+            handlerActivation = handlerService.activateHandler(
+                ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, handler );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void focusLost( FocusEvent e )
+    {
+        if ( handlerActivation != null )
+        {
+            IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter(
+                IHandlerService.class );
+            handlerService.deactivateHandler( handlerActivation );
+            handlerActivation = null;
+        }
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DialogContentAssistant.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,601 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.studio.ldapbrowser.common.widgets.search.EntryWidget;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.utils.DnUtils;
+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.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * The DnBuilderWidget provides input elements to select a parent DN
+ * and to build a (multivalued) RDN.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DnBuilderWidget extends BrowserWidget implements ModifyListener
+{
+
+    /** The attribute names that could be selected from drop-down list. */
+    private String[] attributeNames;
+
+    /** The initial RDN. */
+    private Rdn currentRdn;
+
+    /** The initial parent DN. */
+    private LdapDN currentParentDn;
+
+    /** True if the RDN input elements should be shown. */
+    private boolean showRDN;
+
+    /** True if the parent DN input elements should be shown. */
+    private boolean showParent;
+
+    /** The shell. */
+    private Shell shell;
+
+    /** The selected parent DN. */
+    private LdapDN parentDn;
+
+    /** The entry widget to enter/select the parent DN. */
+    private EntryWidget parentEntryWidget;
+
+    /** The composite that contains the RdnLines. */
+    private Composite rdnComposite;
+
+    /** The resulting RDN. */
+    private Rdn rdn;
+
+    /** The list of RdnLines. */
+    private ArrayList<RdnLine> rdnLineList;
+
+    /** The preview text. */
+    private Text previewText;
+
+
+    /**
+     * Creates a new instance of DnBuilderWidget.
+     * 
+     * @param showParent true if the parent DN input elements should be shown
+     * @param showRDN true if the RDN input elements should be shown
+     */
+    public DnBuilderWidget( boolean showRDN, boolean showParent )
+    {
+        this.showRDN = showRDN;
+        this.showParent = showParent;
+    }
+
+
+    /**
+     * Disposes this widget.
+     */
+    public void dispose()
+    {
+    }
+
+
+    /**
+     * Sets the input.
+     * 
+     * @param rdn the initial RDN
+     * @param attributeNames the attribute names that could be selected from drop-down list
+     * @param browserConnection the connection
+     * @param parentDn the initial parent DN
+     */
+    public void setInput( IBrowserConnection browserConnection, String[] attributeNames, Rdn rdn, LdapDN parentDn )
+    {
+        this.attributeNames = attributeNames;
+        this.currentRdn = rdn;
+        this.currentParentDn = parentDn;
+
+        if ( showRDN )
+        {
+            for ( int i = 0; i < rdnLineList.size(); i++ )
+            {
+                RdnLine rdnLine = rdnLineList.get( i );
+                String oldName = rdnLine.rdnTypeCombo.getText();
+                rdnLine.rdnTypeCombo.setItems( attributeNames );
+                rdnLine.rdnNameCPA.setContentProposalProvider( new ListContentProposalProvider( attributeNames ) );
+                if ( Arrays.asList( rdnLine.rdnTypeCombo.getItems() ).contains( oldName ) )
+                {
+                    rdnLine.rdnTypeCombo.setText( oldName );
+                }
+            }
+        }
+
+        if ( showRDN )
+        {
+            while ( !rdnLineList.isEmpty() )
+            {
+                deleteRdnLine( rdnComposite, 0 );
+            }
+            if ( currentRdn == null || currentRdn.size() == 0 )
+            {
+                addRdnLine( rdnComposite, 0 );
+                rdnLineList.get( 0 ).rdnTypeCombo.setFocus();
+            }
+            else
+            {
+                int i = 0;
+                Iterator<AttributeTypeAndValue> atavIterator = currentRdn.iterator();
+                while(atavIterator.hasNext())
+                {
+                    AttributeTypeAndValue atav = atavIterator.next();
+                    addRdnLine( rdnComposite, i );
+                    rdnLineList.get( i ).rdnTypeCombo.setText( atav.getUpType() );
+                    rdnLineList.get( i ).rdnValueText.setText( ( String ) atav.getUpValue() );
+                    if ( i == 0 )
+                    {
+                        if ( "".equals( rdnLineList.get( i ).rdnTypeCombo ) )
+                        {
+                            rdnLineList.get( i ).rdnTypeCombo.setFocus();
+                        }
+                        else
+                        {
+                            rdnLineList.get( i ).rdnValueText.selectAll();
+                            rdnLineList.get( i ).rdnValueText.setFocus();
+                        }
+                    }
+                    i++;
+                }
+            }
+        }
+
+        if ( showParent )
+        {
+            parentEntryWidget.setInput( browserConnection, currentParentDn );
+        }
+
+        validate();
+    }
+
+
+    /**
+     * Gets the RDN.
+     * 
+     * @return the RDN
+     */
+    public Rdn getRdn()
+    {
+        return rdn;
+    }
+
+
+    /**
+     * Gets the parent DN.
+     * 
+     * @return the parent DN
+     */
+    public LdapDN getParentDn()
+    {
+        return parentDn;
+    }
+
+
+    /**
+     * Creates the contents.
+     * 
+     * @param parent the parent composite
+     * 
+     * @return the created composite
+     */
+    public Composite createContents( Composite parent )
+    {
+        this.shell = parent.getShell();
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
+
+        // draw parent
+        if ( showParent )
+        {
+            BaseWidgetUtils.createLabel( composite, "Parent:", 1 );
+            parentEntryWidget = new EntryWidget();
+            parentEntryWidget.createWidget( composite );
+            parentEntryWidget.addWidgetModifyListener( new WidgetModifyListener()
+            {
+                public void widgetModified( WidgetModifyEvent event )
+                {
+                    validate();
+                }
+            } );
+
+            BaseWidgetUtils.createSpacer( composite, 3 );
+        }
+
+        // draw RDN group
+        if ( showRDN )
+        {
+            BaseWidgetUtils.createLabel( composite, "RDN:", 1 );
+            rdnComposite = BaseWidgetUtils.createColumnContainer( composite, 5, 2 );
+            rdnLineList = new ArrayList<RdnLine>();
+            BaseWidgetUtils.createSpacer( composite, 3 );
+        }
+
+        // draw dn/rdn preview
+        if ( showRDN )
+        {
+            BaseWidgetUtils.createLabel( composite, showParent ? "DN Preview: " : "RDN Preview: ", 1 );
+            previewText = BaseWidgetUtils.createReadonlyText( composite, "", 2 );
+            BaseWidgetUtils.createSpacer( composite, 3 );
+        }
+
+        return composite;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void modifyText( ModifyEvent e )
+    {
+        validate();
+    }
+
+
+    /**
+     * Saves the dialog settings.
+     */
+    public void saveDialogSettings()
+    {
+        if ( parentEntryWidget != null )
+        {
+            parentEntryWidget.saveDialogSettings();
+        }
+    }
+
+
+    /**
+     * Validates the input elements.
+     */
+    public void validate()
+    {
+
+        Exception rdnE = null;
+        if ( showRDN )
+        {
+            try
+            {
+                // calculate RDN
+                String[] rdnTypes = new String[rdnLineList.size()];
+                String[] rdnValues = new String[rdnLineList.size()];
+                for ( int i = 0; i < rdnLineList.size(); i++ )
+                {
+                    RdnLine rdnLine = ( RdnLine ) rdnLineList.get( i );
+                    rdnTypes[i] = rdnLine.rdnTypeCombo.getText();
+                    rdnValues[i] = rdnLine.rdnValueText.getText();
+
+                    if ( rdnLineList.size() > 1 )
+                    {
+                        rdnLine.rdnDeleteButton.setEnabled( true );
+                    }
+                    else
+                    {
+                        rdnLine.rdnDeleteButton.setEnabled( false );
+                    }
+                }
+                rdn = DnUtils.composeRdn( rdnTypes, rdnValues );
+            }
+            catch ( Exception e )
+            {
+                rdnE = e;
+                rdn = null;
+            }
+        }
+
+        Exception parentE = null;
+        if ( showParent )
+        {
+            try
+            {
+                // calculate DN
+                parentDn = new LdapDN( parentEntryWidget.getDn() );
+            }
+            catch ( Exception e )
+            {
+                parentE = e;
+                parentDn = null;
+            }
+        }
+
+        String s = "";
+        if ( rdnE != null )
+        {
+            s += rdnE.getMessage() != null ? rdnE.getMessage() : "Error in RDN ";
+        }
+        if ( parentE != null )
+        {
+            s += ", " + parentE.getMessage() != null ? parentE.getMessage() : "Error in Parent DN ";
+        }
+
+        if ( previewText != null )
+        {
+            if ( s.length() > 0 )
+            {
+                previewText.setText( s );
+            }
+            else
+            {
+                LdapDN dn;
+                if ( showParent && showRDN )
+                {
+                    dn = DnUtils.composeDn( rdn, parentDn );
+                }
+                else if ( showParent )
+                {
+                    dn = parentDn;
+                }
+                else if ( showRDN )
+                {
+                    dn = new LdapDN();
+                    dn.add( rdn );
+                }
+                else
+                {
+                    dn = new LdapDN();
+                }
+                previewText.setText( dn.toString() );
+            }
+        }
+
+        notifyListeners();
+    }
+
+
+    /**
+     * Adds an RDN line at the given index.
+     * 
+     * @param rdnComposite the RDN composite
+     * @param index the index
+     */
+    private void addRdnLine( Composite rdnComposite, int index )
+    {
+        RdnLine[] rdnLines = ( RdnLine[] ) rdnLineList.toArray( new RdnLine[rdnLineList.size()] );
+
+        if ( rdnLines.length > 0 )
+        {
+            for ( int i = 0; i < rdnLines.length; i++ )
+            {
+                RdnLine oldRdnLine = rdnLines[i];
+
+                // remember values
+                String oldName = oldRdnLine.rdnTypeCombo.getText();
+                String oldValue = oldRdnLine.rdnValueText.getText();
+
+                // delete old
+                oldRdnLine.rdnNameComboField.getLayoutControl().dispose();
+                oldRdnLine.rdnEqualsLabel.dispose();
+                oldRdnLine.rdnValueText.dispose();
+                oldRdnLine.rdnAddButton.dispose();
+                oldRdnLine.rdnDeleteButton.dispose();
+                rdnLineList.remove( oldRdnLine );
+
+                // add new
+                RdnLine newRdnLine = createRdnLine( rdnComposite );
+                rdnLineList.add( newRdnLine );
+
+                // restore value
+                newRdnLine.rdnTypeCombo.setText( oldName );
+                newRdnLine.rdnValueText.setText( oldValue );
+
+                // check
+                if ( index == i + 1 )
+                {
+                    RdnLine rdnLine = createRdnLine( rdnComposite );
+                    rdnLineList.add( rdnLine );
+                }
+            }
+        }
+        else
+        {
+            RdnLine rdnLine = createRdnLine( rdnComposite );
+            rdnLineList.add( rdnLine );
+        }
+
+        shell.layout( true, true );
+    }
+
+
+    /**
+     * Creates and returns an RDN line.
+     * 
+     * @param rdnComposite the RDN composite
+     * 
+     * @return the created RDN line
+     */
+    private RdnLine createRdnLine( final Composite rdnComposite )
+    {
+        final RdnLine rdnLine = new RdnLine();
+
+        final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
+            FieldDecorationRegistry.DEC_CONTENT_PROPOSAL );
+        rdnLine.rdnNameComboField = new DecoratedField( rdnComposite, SWT.NONE, new IControlCreator()
+        {
+            public Control createControl( Composite parent, int style )
+            {
+                Combo combo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
+                GridData gd = new GridData();
+                gd.widthHint = 180;
+                combo.setLayoutData( gd );
+                combo.setVisibleItemCount( 20 );
+                return combo;
+            }
+        } );
+        rdnLine.rdnNameComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT, true );
+        GridData gd = new GridData();
+        gd.widthHint = 180;
+        rdnLine.rdnNameComboField.getLayoutControl().setLayoutData( gd );
+        rdnLine.rdnTypeCombo = ( Combo ) rdnLine.rdnNameComboField.getControl();
+
+        rdnLine.rdnNameCPA = new ContentProposalAdapter( rdnLine.rdnTypeCombo, new ComboContentAdapter(),
+            new ListContentProposalProvider( attributeNames ), null, null );
+        rdnLine.rdnNameCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE );
+        rdnLine.rdnNameCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE );
+
+        rdnLine.rdnEqualsLabel = new Label( rdnComposite, SWT.NONE );
+        rdnLine.rdnEqualsLabel.setText( "=" );
+
+        rdnLine.rdnValueText = new Text( rdnComposite, SWT.BORDER );
+        gd = new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL );
+        rdnLine.rdnValueText.setLayoutData( gd );
+
+        rdnLine.rdnAddButton = new Button( rdnComposite, SWT.PUSH );
+        rdnLine.rdnAddButton.setText( "  +   " );
+        rdnLine.rdnAddButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                int index = rdnLineList.size();
+                for ( int i = 0; i < rdnLineList.size(); i++ )
+                {
+                    RdnLine rdnLine = ( RdnLine ) rdnLineList.get( i );
+                    if ( rdnLine.rdnAddButton == e.widget )
+                    {
+                        index = i + 1;
+                    }
+                }
+                addRdnLine( rdnComposite, index );
+
+                validate();
+            }
+        } );
+
+        rdnLine.rdnDeleteButton = new Button( rdnComposite, SWT.PUSH );
+        rdnLine.rdnDeleteButton.setText( "  \u2212  " ); // \u2013
+        rdnLine.rdnDeleteButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                int index = 0;
+                for ( int i = 0; i < rdnLineList.size(); i++ )
+                {
+                    RdnLine rdnLine = ( RdnLine ) rdnLineList.get( i );
+                    if ( rdnLine.rdnDeleteButton == e.widget )
+                    {
+                        index = i;
+                    }
+                }
+                deleteRdnLine( rdnComposite, index );
+
+                validate();
+            }
+        } );
+
+        if ( attributeNames != null )
+        {
+            rdnLine.rdnTypeCombo.setItems( attributeNames );
+        }
+
+        rdnLine.rdnTypeCombo.addModifyListener( this );
+        rdnLine.rdnValueText.addModifyListener( this );
+
+        return rdnLine;
+    }
+
+
+    /**
+     * Delete thd RDN line on the given index.
+     * 
+     * @param rdnComposite the RDN composite
+     * @param index the index
+     */
+    private void deleteRdnLine( Composite rdnComposite, int index )
+    {
+        RdnLine rdnLine = ( RdnLine ) rdnLineList.remove( index );
+        if ( rdnLine != null )
+        {
+            rdnLine.rdnNameComboField.getLayoutControl().dispose();
+            rdnLine.rdnEqualsLabel.dispose();
+            rdnLine.rdnValueText.dispose();
+            rdnLine.rdnAddButton.dispose();
+            rdnLine.rdnDeleteButton.dispose();
+
+            if ( !rdnComposite.isDisposed() )
+            {
+                shell.layout( true, true );
+            }
+        }
+    }
+
+    /**
+     * The Class RdnLine is a wrapper for all input elements
+     * of an RDN line. It contains a combo for the RDN attribute, 
+     * an input field for the RDN value and + and - buttons
+     * to add and remove other RDN lines. It looks like this:
+     * <pre>
+     * --------------------------------------------------
+     * | attribute type v | = | attribute value | + | - |
+     * --------------------------------------------------
+     * </pre>
+     */
+    private class RdnLine
+    {
+
+        /** The rdn name combo. */
+        private DecoratedField rdnNameComboField;
+
+        /** The rdn name combo. */
+        private Combo rdnTypeCombo;
+
+        /** The content proposal adapter */
+        private ContentProposalAdapter rdnNameCPA;
+
+        /** The rdn value text. */
+        private Text rdnValueText;
+
+        /** The rdn equals label. */
+        private Label rdnEqualsLabel;
+
+        /** The rdn add button. */
+        private Button rdnAddButton;
+
+        /** The rdn delete button. */
+        private Button rdnDeleteButton;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileBrowserWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileBrowserWidget.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileBrowserWidget.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileBrowserWidget.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,199 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import java.io.File;
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+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.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+
+
+/**
+ * The FileBrowserWidget provides a combo with a history of recently
+ * used files an a browse button to open the file browser.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class FileBrowserWidget extends BrowserWidget
+{
+
+    /** The Constant TYPE_OPEN is used to create a Open file dialog. */
+    public static final int TYPE_OPEN = SWT.OPEN;
+
+    /** The Constant TYPE_SAVE is used to create a Save file dialog. */
+    public static final int TYPE_SAVE = SWT.SAVE;
+
+    /** The combo with the history of recently used files */
+    private Combo fileCombo;
+
+    /** The button to launch the file browser */
+    private Button browseButton;
+
+    /** The title */
+    private String title;
+
+    /** File extensions used within the lauched file browser */
+    private String[] extensions;
+
+    /** The type */
+    private int type;
+
+
+    /**
+     * Creates a new instance of FileBrowserWidget.
+     *
+     * @param title The title
+     * @param extensions The valid file extensions
+     * @param type The type, one of {@link #TYPE_OPEN} or {@link #TYPE_SAVE}
+     */
+    public FileBrowserWidget( String title, String[] extensions, int type )
+    {
+        this.title = title;
+        this.extensions = extensions;
+        this.type = type;
+    }
+
+
+    /**
+     * Creates the widget.
+     * 
+     * @param parent the parent
+     */
+    public void createWidget( final Composite parent )
+    {
+
+        // Combo
+        fileCombo = BaseWidgetUtils.createCombo( parent, new String[0], -1, 1 );
+        fileCombo.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                notifyListeners();
+            }
+        } );
+
+        // Button
+        browseButton = BaseWidgetUtils.createButton( parent, "Bro&wse...", 1 );
+        browseButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent event )
+            {
+                FileDialog fileDialog = new FileDialog( parent.getShell(), type );
+                fileDialog.setText( title );
+
+                fileDialog.setFilterExtensions( extensions );
+
+                File file = new File( fileCombo.getText() );
+                if ( file.isFile() )
+                {
+                    fileDialog.setFilterPath( file.getParent() );
+                    fileDialog.setFileName( file.getName() );
+                }
+                else if ( file.isDirectory() )
+                {
+                    fileDialog.setFilterPath( file.getPath() );
+                }
+                else
+                {
+                    fileDialog.setFilterPath( BrowserCommonActivator.getDefault().getDialogSettings().get(
+                        BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH ) );
+                }
+
+                String returnedFileName = fileDialog.open();
+                if ( returnedFileName != null )
+                {
+                    fileCombo.setText( returnedFileName );
+                    File file2 = new File( returnedFileName );
+                    BrowserCommonActivator.getDefault().getDialogSettings().put(
+                        BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH, file2.getParent() );
+                }
+            }
+        } );
+
+        // file history
+        String[] history = HistoryUtils.load( BrowserCommonConstants.DIALOGSETTING_KEY_FILE_HISTORY );
+        fileCombo.setItems( history );
+    }
+
+
+    /**
+     * Gets the filename.
+     * 
+     * @return the filename
+     */
+    public String getFilename()
+    {
+        return fileCombo.getText();
+    }
+
+
+    /**
+     * Sets the filename.
+     * 
+     * @param filename the filename
+     */
+    public void setFilename( String filename )
+    {
+        fileCombo.setText( filename );
+    }
+
+
+    /**
+     * Saves dialog settings.
+     */
+    public void saveDialogSettings()
+    {
+        HistoryUtils.save( BrowserCommonConstants.DIALOGSETTING_KEY_FILE_HISTORY, fileCombo.getText() );
+    }
+
+
+    /**
+     * Sets the focus.
+     */
+    public void setFocus()
+    {
+        fileCombo.setFocus();
+    }
+
+
+    /**
+     * Enables or disables the widget.
+     * 
+     * @param b true to enable the widget, false otherwise
+     */
+    public void setEnabled( boolean b )
+    {
+        fileCombo.setEnabled( b );
+        browseButton.setEnabled( b );
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileBrowserWidget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileEncodingInput.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileEncodingInput.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileEncodingInput.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileEncodingInput.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,130 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import java.nio.charset.Charset;
+
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+
+
+/**
+ * The FileEncodingInput is an OptionInput with fixed options. 
+ * It is used to select the file encoding. The default
+ * value is always the platform's default encoding.
+ * The other options are the values return from 
+ * {@link Charset#availableCharsets()}. No custom input is allowed.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class FileEncodingInput extends OptionsInput
+{
+
+    /**
+     * Creates a new instance of FileEncodingInput.
+     *
+     * @param initialRawValue the initial raw value
+     * @param asGroup the asGroup flag
+     */
+    public FileEncodingInput( String initialRawValue, boolean asGroup )
+    {
+        super( "File Encoding", getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(),
+            getOtherRawValues(), initialRawValue, asGroup, false );
+
+    }
+
+
+    /**
+     * Gets the default display value.
+     * 
+     * @return the default display value
+     */
+    private static String getDefaultDisplayValue()
+    {
+        return getCharsetDisplayValue( getDefaultRawValue() );
+    }
+
+
+    /**
+     * Gets the default raw value, always the platform's
+     * default encoding.
+     * 
+     * @return the default raw value
+     */
+    private static String getDefaultRawValue()
+    {
+        return BrowserCoreConstants.DEFAULT_ENCODING;
+    }
+
+
+    /**
+     * Gets the other display values.
+     * 
+     * @return the other display values
+     */
+    private static String[] getOtherDisplayValues()
+    {
+        String[] otherEncodingsRawValues = getOtherRawValues();
+        String[] otherEncodingsDisplayValues = new String[otherEncodingsRawValues.length];
+        for ( int i = 0; i < otherEncodingsDisplayValues.length; i++ )
+        {
+            String rawValue = otherEncodingsRawValues[i];
+            otherEncodingsDisplayValues[i] = getCharsetDisplayValue( rawValue );
+        }
+        return otherEncodingsDisplayValues;
+    }
+
+
+    /**
+     * Gets the other raw values. That are all values
+     * returned from {@link Charset#availableCharsets()}. 
+     * 
+     * @return the other raw values
+     */
+    private static String[] getOtherRawValues()
+    {
+        String[] otherEncodingsRawValues = ( String[] ) Charset.availableCharsets().keySet().toArray( new String[0] );
+        return otherEncodingsRawValues;
+    }
+
+
+    /**
+     * Gets the charset display value.
+     * 
+     * @param charsetRawValue the charset raw value
+     * 
+     * @return the charset display value
+     */
+    private static String getCharsetDisplayValue( String charsetRawValue )
+    {
+        try
+        {
+            Charset charset = Charset.forName( charsetRawValue );
+            return charset.displayName();
+        }
+        catch ( Exception e )
+        {
+            return charsetRawValue;
+        }
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileEncodingInput.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/HistoryUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/HistoryUtils.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/HistoryUtils.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/HistoryUtils.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,89 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+
+
+/**
+ * The HistoryUtils are used to save and load the history of input fields.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class HistoryUtils
+{
+
+    /**
+     * Saves the the given value under the given key in the dialog settings.
+     *
+     * @param key the key
+     * @param value the value
+     */
+    public static void save( String key, String value )
+    {
+        // get current history
+        String[] history = load( key );
+        List<String> list = new ArrayList<String>( Arrays.asList( history ) );
+
+        // add new value or move to first position
+        if ( list.contains( value ) )
+        {
+            list.remove( value );
+        }
+        list.add( 0, value );
+
+        // check history size
+        while ( list.size() > BrowserCommonConstants.HISTORYSIZE )
+        {
+            list.remove( list.size() - 1 );
+        }
+
+        // save
+        history = list.toArray( new String[list.size()] );
+        BrowserCommonActivator.getDefault().getDialogSettings().put( key, history );
+
+    }
+
+
+    /**
+     * Loads the value of the given key from the dialog settings
+     *
+     * @param key the key
+     * @return the value
+     */
+    public static String[] load( String key )
+    {
+        String[] history = BrowserCommonActivator.getDefault().getDialogSettings().getArray( key );
+        if ( history == null )
+        {
+            history = new String[0];
+        }
+        return history;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/HistoryUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/LineSeparatorInput.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/LineSeparatorInput.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/LineSeparatorInput.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/LineSeparatorInput.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,133 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.eclipse.core.runtime.Platform;
+
+
+/**
+ * The LineSeparatorInput is an OptionInput with fixed options. 
+ * It is used to select the line separator. The default
+ * value is always the platform's default line separator.
+ * The other options are the values return from 
+ * {@link Platform#knownPlatformLineSeparators()}. 
+ * No custom input is allowed.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LineSeparatorInput extends OptionsInput
+{
+
+    /**
+     * Creates a new instance of LineSeparatorInput.
+     *
+     * @param initialRawValue the initial raw value
+     * @param asGroup the asGroup flag
+     */
+    public LineSeparatorInput( String initialRawValue, boolean asGroup )
+    {
+        super( "Line Separator", getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(),
+            getOtherRawValues(), initialRawValue, asGroup, false );
+
+    }
+
+
+    /**
+     * Gets the default display value.
+     * 
+     * @return the default display value
+     */
+    private static String getDefaultDisplayValue()
+    {
+        Map lsMap = Platform.knownPlatformLineSeparators();
+        for ( Iterator iter = lsMap.keySet().iterator(); iter.hasNext(); )
+        {
+            String k = ( String ) iter.next();
+            String v = ( String ) lsMap.get( k );
+            if ( v.equals( getDefaultRawValue() ) )
+            {
+                k = k + " (" + ( v.replaceAll( "\n", "\\\\n" ).replaceAll( "\r", "\\\\r" ) ) + ")";
+                return k;
+            }
+        }
+        return getDefaultRawValue();
+    }
+
+
+    /**
+     * Gets the default raw value, always the platform's default
+     * line separator.
+     * 
+     * @return the default raw value
+     */
+    private static String getDefaultRawValue()
+    {
+        return BrowserCoreConstants.LINE_SEPARATOR;
+    }
+
+
+    /**
+     * Gets the other display values That are all values
+     * returned from {@link Platform#knownPlatformLineSeparators()}. 
+     * 
+     * @return the other display values
+     */
+    @SuppressWarnings("unchecked")
+    private static String[] getOtherDisplayValues()
+    {
+        Map<String, String> lsMap = Platform.knownPlatformLineSeparators();
+        String[] displayValues = lsMap.keySet().toArray( new String[lsMap.size()] );
+        for ( int i = 0; i < displayValues.length; i++ )
+        {
+            displayValues[i] = displayValues[i]
+                + " ("
+                + ( ( ( String ) lsMap.get( displayValues[i] ) ).replaceAll( "\n", "\\\\n" ).replaceAll( "\r", "\\\\r" ) )
+                + ")";
+        }
+        return displayValues;
+    }
+
+
+    /**
+     * Gets the other raw values.
+     * 
+     * @return the other raw values
+     */
+    @SuppressWarnings("unchecked")
+    private static String[] getOtherRawValues()
+    {
+        Map<String, String> lsMap = Platform.knownPlatformLineSeparators();
+        String[] displayValues = lsMap.keySet().toArray( new String[lsMap.size()] );
+        String[] rawValues = new String[displayValues.length];
+        for ( int i = 0; i < rawValues.length; i++ )
+        {
+            rawValues[i] = ( String ) lsMap.get( displayValues[i] );
+        }
+        return rawValues;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/LineSeparatorInput.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/ListContentProposalProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/ListContentProposalProvider.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/ListContentProposalProvider.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/ListContentProposalProvider.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,131 @@
+/*
+ *  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.ldapbrowser.common.widgets;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+
+
+/**
+ * ListContentProposalProvider is a class designed to map a dynamic list of
+ * Strings to content proposals.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ListContentProposalProvider implements IContentProposalProvider
+{
+
+    /** The dynamic list of proposals */
+    private List<String> proposals;
+
+
+    /**
+     * Creates a new instance of ListContentProposalProvider.
+     *
+     * @param proposals the dynamic list of proposals
+     */
+    public ListContentProposalProvider( List<String> proposals )
+    {
+        setProposals( proposals );
+    }
+
+
+    /**
+     * Creates a new instance of ListContentProposalProvider.
+     *
+     * @param proposals the proposals
+     */
+    public ListContentProposalProvider( String[] proposals )
+    {
+        setProposals( new ArrayList<String>( Arrays.asList( proposals ) ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public IContentProposal[] getProposals( String contents, int position )
+    {
+        String string = contents.substring( 0, position );
+
+        Collections.sort( proposals );
+
+        List<IContentProposal> proposalList = new ArrayList<IContentProposal>();
+        for ( int k = 0; k < proposals.size(); k++ )
+        {
+            final String proposal = proposals.get( k );
+            if ( proposal.toUpperCase().startsWith( string.toUpperCase() ) && !proposal.equalsIgnoreCase( string )
+                && !"".equals( string ) )
+            {
+                IContentProposal p = new IContentProposal()
+                {
+                    public String getContent()
+                    {
+                        return proposal;
+                    }
+
+
+                    public String getDescription()
+                    {
+                        return proposal;
+                    }
+
+
+                    public String getLabel()
+                    {
+                        return proposal;
+                    }
+
+
+                    public int getCursorPosition()
+                    {
+                        return proposal.length();
+                    }
+                };
+                proposalList.add( p );
+            }
+        }
+        return proposalList.toArray( new IContentProposal[proposalList.size()] );
+    }
+
+
+    /**
+     * Sets the possible strings.
+     * 
+     * @param proposals the possible strings
+     */
+    public void setProposals( List<String> proposals )
+    {
+        if ( proposals == null )
+        {
+            proposals = new ArrayList<String>();
+        }
+
+        this.proposals = proposals;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/ListContentProposalProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message