directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r526693 [11/17] - in /directory/ldapstudio/trunk/ldapstudio-browser-common: ./ META-INF/ resources/ resources/icons/ resources/templates/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/di...
Date Mon, 09 Apr 2007 09:49:57 GMT
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSorter.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSorter.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSorter.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSorter.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,404 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import java.math.BigInteger;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.internal.model.DirectoryMetadataEntry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.RootDSE;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
+import org.apache.directory.ldapstudio.browser.core.model.RDN;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+
+/**
+ * The BrowserSorter implements the sorter for the browser widget. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserSorter extends ViewerSorter
+{
+
+    /** The browser preferences, used to get the sort settings */
+    private BrowserPreferences preferences;
+
+
+    /**
+     * Creates a new instance of BrowserSorter.
+     *
+     * @param preferences the browser preferences, used to get the sort settings
+     */
+    public BrowserSorter( BrowserPreferences preferences )
+    {
+        this.preferences = preferences;
+    }
+
+
+    /**
+     * Connects the tree viewer to this sorter.
+     *
+     * @param viewer the tree viewer
+     */
+    public void connect( TreeViewer viewer )
+    {
+        viewer.setSorter( this );
+    }
+
+
+    /**
+     * Disposes this sorter.
+     */
+    public void dispose()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * For performance reasons this implemention first checks if sorting is enabled 
+     * and if the number of elements is less than the sort limit.
+     */
+    public void sort( final Viewer viewer, final Object[] elements )
+    {
+        if ( elements != null && ( preferences.getSortLimit() <= 0 || elements.length < preferences.getSortLimit() )
+            && ( preferences.getSortBy() != BrowserCoreConstants.SORT_BY_NONE || preferences.isLeafEntriesFirst() ) )
+        {
+            BrowserSorter.super.sort( viewer, elements );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This method is used to categorize leaf entries, meta entries and normal entries.
+     */
+    public int category( Object element )
+    {
+        if ( preferences.isLeafEntriesFirst() || preferences.isMetaEntriesLast() )
+        {
+            if ( element instanceof IEntry )
+            {
+                IEntry entry = ( IEntry ) element;
+                if ( ( entry instanceof DirectoryMetadataEntry || entry instanceof RootDSE || entry.isAlias() || entry
+                    .isReferral() )
+                    && preferences.isMetaEntriesLast() )
+                {
+                    return 3;
+                }
+                else if ( entry.isSubentry() && preferences.isLeafEntriesFirst() )
+                {
+                    return 0;
+                }
+                else if ( !entry.hasChildren() && preferences.isLeafEntriesFirst() )
+                {
+                    return 1;
+                }
+                else
+                {
+                    return 2;
+                }
+            }
+            else
+            {
+                return 4;
+            }
+        }
+        else
+        {
+            return 0;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation compares IEntry or ISearchResult objects. Depending on
+     * the sort settings it delegates comparation to {@link #compareRdns(IEntry, IEntry)}
+     * or {@link #compareRdnValues(IEntry, IEntry)}.
+     */
+    public int compare( Viewer viewer, Object o1, Object o2 )
+    {
+        if ( o1 == null && o2 == null )
+        {
+            return equal();
+        }
+        else if ( o1 == null && o2 != null )
+        {
+            return lessThan();
+        }
+        else if ( o1 != null && o2 == null )
+        {
+            return greaterThan();
+        }
+        else if ( o1 instanceof IEntry || o2 instanceof IEntry )
+        {
+            if ( !( o1 instanceof IEntry ) && !( o2 instanceof IEntry ) )
+            {
+                return equal();
+            }
+            else if ( !( o1 instanceof IEntry ) && ( o2 instanceof IEntry ) )
+            {
+                return lessThan();
+            }
+            else if ( ( o1 instanceof IEntry ) && !( o2 instanceof IEntry ) )
+            {
+                return greaterThan();
+            }
+            else
+            {
+                IEntry entry1 = ( IEntry ) o1;
+                IEntry entry2 = ( IEntry ) o2;
+
+                int cat1 = category( entry1 );
+                int cat2 = category( entry2 );
+                if ( cat1 != cat2 )
+                {
+                    return cat1 - cat2;
+                }
+                else if ( preferences.getSortBy() == BrowserCoreConstants.SORT_BY_NONE )
+                {
+                    return equal();
+                }
+                else if ( preferences.getSortBy() == BrowserCoreConstants.SORT_BY_RDN )
+                {
+                    return compareRdns( entry1, entry2 );
+                }
+                else if ( preferences.getSortBy() == BrowserCoreConstants.SORT_BY_RDN_VALUE )
+                {
+                    return compareRdnValues( entry1, entry2 );
+                }
+                else
+                {
+                    return equal();
+                }
+            }
+        }
+        else if ( o1 instanceof ISearchResult || o2 instanceof ISearchResult )
+        {
+            if ( !( o1 instanceof ISearchResult ) && !( o2 instanceof ISearchResult ) )
+            {
+                return equal();
+            }
+            else if ( !( o1 instanceof ISearchResult ) && ( o2 instanceof ISearchResult ) )
+            {
+                return lessThan();
+            }
+            else if ( ( o1 instanceof ISearchResult ) && !( o2 instanceof ISearchResult ) )
+            {
+                return greaterThan();
+            }
+            else
+            {
+                ISearchResult sr1 = ( ISearchResult ) o1;
+                ISearchResult sr2 = ( ISearchResult ) o2;
+
+                int cat1 = category( sr1 );
+                int cat2 = category( sr2 );
+                if ( cat1 != cat2 )
+                {
+                    return cat1 - cat2;
+                }
+                else if ( preferences.getSortBy() == BrowserCoreConstants.SORT_BY_NONE )
+                {
+                    return equal();
+                }
+                else if ( preferences.getSortBy() == BrowserCoreConstants.SORT_BY_RDN )
+                {
+                    return compareRdns( sr1.getEntry(), sr2.getEntry() );
+                }
+                else if ( preferences.getSortBy() == BrowserCoreConstants.SORT_BY_RDN_VALUE )
+                {
+                    return compareRdnValues( sr1.getEntry(), sr2.getEntry() );
+                }
+                else
+                {
+                    return equal();
+                }
+            }
+        }
+        else
+        {
+            return equal();
+        }
+    }
+
+
+    /**
+     * Compares the string representation of the RDNs of two IEntry objects.
+     *  
+     * @param entry1 the first entry
+     * @param entry2 the second entry
+     * @return a negative integer, zero, or a positive integer
+     */
+    private int compareRdns( IEntry entry1, IEntry entry2 )
+    {
+        RDN rdn1 = entry1.getRdn();
+        RDN rdn2 = entry2.getRdn();
+
+        if ( rdn1 == null && rdn2 == null )
+        {
+            return equal();
+        }
+        else if ( rdn1 == null && rdn2 != null )
+        {
+            return greaterThan();
+        }
+        else if ( rdn1 != null && rdn2 == null )
+        {
+            return lessThan();
+        }
+        else
+        {
+            return compare( rdn1.toString(), rdn2.toString() );
+        }
+    }
+
+
+    /**
+     * Compares the RDN values of two IEntry objects.
+     * Numeric values are compared as numeric.
+     *  
+     * @param entry1 the first entry
+     * @param entry2 the second entry
+     * @return a negative integer, zero, or a positive integer
+     */
+    private int compareRdnValues( IEntry entry1, IEntry entry2 )
+    {
+
+        RDN rdn1 = entry1.getRdn();
+        RDN rdn2 = entry2.getRdn();
+
+        if ( ( rdn1 == null || rdn1.getValue() == null || "".equals( rdn1.getValue() ) )
+            && ( rdn2 == null || rdn2.getValue() == null || "".equals( rdn2.getValue() ) ) )
+        {
+            return equal();
+        }
+        else if ( ( rdn1 == null || rdn1.getValue() == null || "".equals( rdn1.getValue() ) )
+            && !( rdn2 == null || rdn2.getValue() == null || "".equals( rdn2.getValue() ) ) )
+        {
+            return greaterThan();
+        }
+        else if ( !( rdn1 == null || rdn1.getValue() == null || "".equals( rdn1.getValue() ) )
+            && ( rdn2 == null || rdn2.getValue() == null || "".equals( rdn2.getValue() ) ) )
+        {
+            return lessThan();
+        }
+
+        else if ( rdn1.getValue().matches( "\\d*" ) && !rdn2.getValue().matches( "\\d*" ) )
+        {
+            // return lessThan();
+            return compare( rdn1.getValue(), rdn2.getValue() );
+        }
+        else if ( !rdn1.getValue().matches( "\\d*" ) && rdn2.getValue().matches( "\\d*" ) )
+        {
+            // return greaterThan();
+            return compare( rdn1.getValue(), rdn2.getValue() );
+        }
+        else if ( rdn1.getValue().matches( "\\d*" ) && rdn2.getValue().matches( "\\d*" ) )
+        {
+            BigInteger bi1 = new BigInteger( rdn1.getValue() );
+            BigInteger bi2 = new BigInteger( rdn2.getValue() );
+            return compare( bi1, bi2 );
+            // return Integer.parseInt(rdn1.getValue()) -
+            // Integer.parseInt(rdn2.getValue());
+        }
+        else
+        {
+            return compare( rdn1.getValue(), rdn2.getValue() );
+        }
+    }
+
+
+    /**
+     * Returns +1 or -1, depending on the sort order.
+     *
+     * @return +1 or -1, depending on the sort order
+     */
+    private int lessThan()
+    {
+        return preferences.getSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? -1 : 1;
+    }
+
+
+    /**
+     * Returns 0.
+     *
+     * @return 0
+     */
+    private int equal()
+    {
+        return 0;
+    }
+
+
+    /**
+     * Returns +1 or -1, depending on the sort order.
+     *
+     * @return +1 or -1, depending on the sort order
+     */
+    private int greaterThan()
+    {
+        return preferences.getSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? 1 : -1;
+    }
+
+
+    /**
+     * Compares the two strings using the Strings's compareToIgnoreCase method, 
+     * pays attention for the sort order.
+     *
+     * @param s1 the first string to compare
+     * @param s2 the second string to compare
+     * @return a negative integer, zero, or a positive integer
+     * @see java.lang.String#compareToIgnoreCase(String)
+     */
+    private int compare( String s1, String s2 )
+    {
+        return preferences.getSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? s1.compareToIgnoreCase( s2 )
+            : s2.compareToIgnoreCase( s1 );
+    }
+
+
+    /**
+     * Compares the two numbers using the BigInteger compareTo method, 
+     * pays attention for the sort order.
+     *
+     * @param bi1 the first number to compare
+     * @param bi1 the second number to compare
+     * @return -1, 0 or 1 as this BigInteger is numerically less than, equal
+     *         to, or greater than
+     * @see java.math.BigInteger#compareTo(BigInteger)
+     */
+    private int compare( BigInteger bi1, BigInteger bi2 )
+    {
+        return preferences.getSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? bi1.compareTo( bi2 ) : bi2
+            .compareTo( bi1 );
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSorterDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSorterDialog.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSorterDialog.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSorterDialog.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,225 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+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.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * This class represents the dialog used to change the browser's sort settings.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserSorterDialog extends Dialog
+{
+
+    /** The dialog title. */
+    public static final String DIALOG_TITLE = "Browser Sorting";
+
+    /** The Constant SORT_BY_NONE. */
+    public static final String SORT_BY_NONE = "No Sorting";
+
+    /** The Constant SORT_BY_RDN. */
+    public static final String SORT_BY_RDN = "RDN";
+
+    /** The Constant SORT_BY_RDN_VALUE. */
+    public static final String SORT_BY_RDN_VALUE = "RDN Value";
+
+    /** The browser preferences. */
+    private BrowserPreferences preferences;
+
+    /** The sort by combo. */
+    private Combo sortByCombo;
+
+    /** The sort acending button. */
+    private Button sortAcendingButton;
+
+    /** The sort descending button. */
+    private Button sortDescendingButton;
+
+    /** The leaf entries first button. */
+    private Button leafEntriesFirstButton;
+
+    /** The meta entries last button. */
+    private Button metaEntriesLastButton;
+
+    /** The sort limit text. */
+    private Text sortLimitText;
+
+
+    /**
+     * Creates a new instance of BrowserSorterDialog.
+     *
+     * @param parentShell the parent shell
+     * @param preferences the browser preferences
+     */
+    public BrowserSorterDialog( Shell parentShell, BrowserPreferences preferences )
+    {
+        super( parentShell );
+        this.preferences = preferences;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation calls its super implementation and sets the dialog title.
+     */
+    protected void configureShell( Shell newShell )
+    {
+        super.configureShell( newShell );
+        newShell.setText( DIALOG_TITLE );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation save the changed settings when OK is pressed.
+     */
+    protected void buttonPressed( int buttonId )
+    {
+        if ( buttonId == IDialogConstants.OK_ID )
+        {
+            int sortLimit = preferences.getSortLimit();
+            try
+            {
+                sortLimit = Integer.parseInt( sortLimitText.getText().trim() );
+            }
+            catch ( NumberFormatException nfe )
+            {
+            }
+
+            IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
+            store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST, leafEntriesFirstButton
+                .getSelection() );
+            store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST, metaEntriesLastButton
+                .getSelection() );
+            store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_LIMIT, sortLimit );
+            store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_ORDER,
+                sortDescendingButton.getSelection() ? BrowserCoreConstants.SORT_ORDER_DESCENDING
+                    : BrowserCoreConstants.SORT_ORDER_ASCENDING );
+            store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BY,
+                sortByCombo.getSelectionIndex() == 2 ? BrowserCoreConstants.SORT_BY_RDN_VALUE : sortByCombo
+                    .getSelectionIndex() == 1 ? BrowserCoreConstants.SORT_BY_RDN : BrowserCoreConstants.SORT_BY_NONE );
+        }
+        else
+        {
+            // no changes
+        }
+
+        super.buttonPressed( buttonId );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridData gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL );
+        gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+        composite.setLayoutData( gd );
+
+        Group groupingGroup = BaseWidgetUtils.createGroup( composite, "Group entries", 1 );
+
+        leafEntriesFirstButton = BaseWidgetUtils.createCheckbox( groupingGroup, "Leaf enties first", 1 );
+        leafEntriesFirstButton
+            .setToolTipText( "This option displays entries without children before entries with children." );
+        leafEntriesFirstButton.setSelection( preferences.isLeafEntriesFirst() );
+
+        metaEntriesLastButton = BaseWidgetUtils.createCheckbox( groupingGroup, "Meta entries last", 1 );
+        metaEntriesLastButton
+            .setToolTipText( "This option displays meta entries after normal entries. Meta entries are e.g. the root DSE or the schema entry." );
+        metaEntriesLastButton.setSelection( preferences.isMetaEntriesLast() );
+
+        Group sortingGroup = BaseWidgetUtils.createGroup( composite, "Sort entries", 1 );
+
+        Composite sortByComposite = BaseWidgetUtils.createColumnContainer( sortingGroup, 4, 1 );
+        BaseWidgetUtils.createLabel( sortByComposite, "Sort by", 1 );
+        sortByCombo = BaseWidgetUtils.createReadonlyCombo( sortByComposite, new String[]
+            { SORT_BY_NONE, SORT_BY_RDN, SORT_BY_RDN_VALUE }, 0, 1 );
+        sortByCombo.select( preferences.getSortBy() == BrowserCoreConstants.SORT_BY_RDN_VALUE ? 2 : preferences
+            .getSortBy() == BrowserCoreConstants.SORT_BY_RDN ? 1 : 0 );
+        sortByCombo.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+                sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+                sortLimitText.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+            }
+        } );
+
+        sortAcendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, "Ascending", 1 );
+        sortAcendingButton.setSelection( preferences.getSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING );
+        sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+
+        sortDescendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, "Descending", 1 );
+        sortDescendingButton.setSelection( preferences.getSortOrder() == BrowserCoreConstants.SORT_ORDER_DESCENDING );
+        sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+
+        Composite sortLimitComposite = BaseWidgetUtils.createColumnContainer( sortingGroup, 2, 1 );
+        String sortLimitTooltip = "If there are more than the specified number of children they won't be sorted. Hint: For performance reason the maximum value should be 10.000!";
+        Label sortLimitLabel = BaseWidgetUtils.createLabel( sortLimitComposite, "Sort limit:", 1 );
+        sortLimitLabel.setToolTipText( sortLimitTooltip );
+        sortLimitText = BaseWidgetUtils.createText( sortLimitComposite, "" + preferences.getSortLimit(), 5, 1 );
+        sortLimitText.setToolTipText( sortLimitTooltip );
+        sortLimitText.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+        sortLimitText.addVerifyListener( new VerifyListener()
+        {
+            public void verifyText( VerifyEvent e )
+            {
+                if ( !e.text.matches( "[0-9]*" ) )
+                {
+                    e.doit = false;
+                }
+            }
+        } );
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserUniversalListener.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserUniversalListener.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserUniversalListener.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,194 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.AttributesInitializedEvent;
+import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EntryUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.ITreeViewerListener;
+import org.eclipse.jface.viewers.TreeExpansionEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+
+
+/**
+ * The BrowserUniversalListener manages all events for the browser widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserUniversalListener implements ConnectionUpdateListener, EntryUpdateListener
+{
+
+    /** The tree viewer */
+    protected TreeViewer viewer;
+
+    /** The tree viewer listener */
+    private ITreeViewerListener treeViewerListener = new ITreeViewerListener()
+    {
+        /**
+         * {@inheritDoc}
+         * 
+         * This implementation checks if the collapsed entry more children
+         * than currently fetched. If this is the case cached children are 
+         * cleared an must be fetched newly when expanding the tree.
+         * 
+         * This could happen when first using a search that returns
+         * only some of an entry's children. 
+         */
+        public void treeCollapsed( TreeExpansionEvent event )
+        {
+            if ( event.getElement() instanceof IEntry )
+            {
+                IEntry entry = ( IEntry ) event.getElement();
+                if ( entry.isChildrenInitialized() && entry.hasMoreChildren()
+                    && entry.getChildrenCount() < entry.getConnection().getCountLimit() )
+                {
+                    entry.setChildrenInitialized( false );
+                }
+            }
+        }
+
+
+        /**
+         * {@inheritDoc}
+         */
+        public void treeExpanded( TreeExpansionEvent event )
+        {
+        }
+    };
+
+    /** The double click listener. */
+    private IDoubleClickListener doubleClickListener = new IDoubleClickListener()
+    {
+
+        public void doubleClick( DoubleClickEvent event )
+        {
+            if ( event.getSelection() instanceof IStructuredSelection )
+            {
+                Object obj = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                if ( viewer.getExpandedState( obj ) )
+                {
+                    viewer.collapseToLevel( obj, 1 );
+                }
+                else if ( ( ( ITreeContentProvider ) viewer.getContentProvider() ).hasChildren( obj ) )
+                {
+                    viewer.expandToLevel( obj, 1 );
+                }
+            }
+        }
+
+    };
+
+
+    /**
+     * Creates a new instance of BrowserUniversalListener.
+     *
+     * @param viewer the tree viewer
+     */
+    public BrowserUniversalListener( TreeViewer viewer )
+    {
+        this.viewer = viewer;
+
+        viewer.addTreeListener( treeViewerListener );
+        viewer.addDoubleClickListener( doubleClickListener );
+
+        EventRegistry.addConnectionUpdateListener( this );
+        EventRegistry.addEntryUpdateListener( this );
+    }
+
+
+    /**
+     * Disposes this listener.
+     */
+    public void dispose()
+    {
+        if ( viewer != null )
+        {
+            viewer.removeTreeListener( treeViewerListener );
+            viewer.removeDoubleClickListener( doubleClickListener );
+
+            EventRegistry.removeConnectionUpdateListener( this );
+            EventRegistry.removeEntryUpdateListener( this );
+
+            viewer = null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation refreshes the tree and collapses the 
+     * tree when the connection is closed.
+     */
+    public void connectionUpdated( ConnectionUpdateEvent connectionUpdateEvent )
+    {
+        if ( connectionUpdateEvent.getDetail() == ConnectionUpdateEvent.CONNECTION_CLOSED )
+        {
+            viewer.collapseAll();
+        }
+        else if ( connectionUpdateEvent.getDetail() == ConnectionUpdateEvent.CONNECTION_OPENED )
+        {
+            viewer.refresh( connectionUpdateEvent.getConnection() );
+        }
+        else
+        {
+            viewer.refresh( connectionUpdateEvent.getConnection() );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation refreshes the tree.
+     */
+    public void entryUpdated( EntryModificationEvent event )
+    {
+        // Don't handle attribute initalization, could cause double
+        // retrieval of children. 
+        //
+        // When double-clicking an entry two Jobs/Threads are started:
+        // - InitializeAttributesJob and
+        // - InitializeChildrenJob
+        // If the InitializeAttributesJob is finished first the
+        // AttributesInitializedEvent is fired. If this causes
+        // a refresh of the tree before the children are initialized
+        // another InitializeChildrenJob is executed.
+        if ( event instanceof AttributesInitializedEvent )
+        {
+            return;
+        }
+
+        viewer.refresh( event.getModifiedEntry(), true );
+
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserWidget.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserWidget.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserWidget.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserWidget.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,214 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import org.apache.directory.ldapstudio.browser.common.widgets.ViewFormWidget;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.IActionBars;
+
+
+/**
+ * The BrowserWidget is a reusable widget that displays the DIT, searches
+ * and bookmarks of a connection a tree viewer.
+ * It is used by {@link BrowserView} and {@link SelectEntryDialog}.
+ * 
+ * It provides a context menu and a local toolbar with actions to
+ * manage entries, searches and bookmarks.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserWidget extends ViewFormWidget
+{
+
+    /** The widget's configuration with the content provider, label provider and menu manager */
+    private BrowserConfiguration configuration;
+
+    /** The action bars. */
+    private IActionBars actionBars;
+
+    /** The tree widget used by the tree viewer */
+    private Tree tree;
+
+    /** The tree viewer. */
+    private TreeViewer viewer;
+
+
+    /**
+     * Creates a new instance of BrowserWidget.
+     *
+     * @param configuration the configuration
+     * @param actionBars the action bars
+     */
+    public BrowserWidget( BrowserConfiguration configuration, IActionBars actionBars )
+    {
+        this.configuration = configuration;
+        this.actionBars = actionBars;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createWidget( Composite parent )
+    {
+        if ( actionBars == null )
+        {
+            super.createWidget( parent );
+        }
+        else
+        {
+            createContent( parent );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public IToolBarManager getToolBarManager()
+    {
+        if ( actionBars == null )
+        {
+            return super.getToolBarManager();
+        }
+        else
+        {
+            return actionBars.getToolBarManager();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public IMenuManager getMenuManager()
+    {
+        if ( actionBars == null )
+        {
+            return super.getMenuManager();
+        }
+        else
+        {
+            return actionBars.getMenuManager();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public IMenuManager getContextMenuManager()
+    {
+        if ( actionBars == null )
+        {
+            return super.getContextMenuManager();
+        }
+        else
+        {
+            return configuration.getContextMenuManager( viewer );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createContent( Composite parent )
+    {
+
+        // create tree widget and viewer
+        tree = new Tree( parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
+        GridData data = new GridData( GridData.FILL_BOTH );
+        data.widthHint = 450;
+        data.heightHint = 250;
+        tree.setLayoutData( data );
+        viewer = new TreeViewer( tree );
+        viewer.setUseHashlookup( true );
+
+        // setup sorter, filter and layout
+        configuration.getSorter().connect( viewer );
+        configuration.getPreferences().connect( viewer );
+
+        // setup providers
+        viewer.setContentProvider( configuration.getContentProvider( viewer ) );
+        viewer.setLabelProvider( configuration.getLabelProvider( viewer ) );
+
+        return tree;
+    }
+
+
+    /**
+     * Sets the input to the tree viewer.
+     *
+     * @param input the input
+     */
+    public void setInput( Object input )
+    {
+        viewer.setInput( input );
+    }
+
+
+    /**
+     * Sets focus to the table viewer.
+     */
+    public void setFocus()
+    {
+        viewer.getTree().setFocus();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+        if ( this.viewer != null )
+        {
+            this.configuration.dispose();
+            this.configuration = null;
+
+            this.tree.dispose();
+            this.tree = null;
+            this.viewer = null;
+        }
+    }
+
+
+    /**
+     * Gets the tree viewer.
+     * 
+     * @return the tree viewer
+     */
+    public TreeViewer getViewer()
+    {
+        return viewer;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/OpenSortDialogAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/OpenSortDialogAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/OpenSortDialogAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/OpenSortDialogAction.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,76 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This action opens the {@link BrowserSorterDialog}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class OpenSortDialogAction extends Action
+{
+
+    /** The preferences. */
+    private BrowserPreferences preferences;
+
+
+    /**
+     * Creates a new instance of OpenSortDialogAction.
+     *
+     * @param preferences the preferences
+     */
+    public OpenSortDialogAction( BrowserPreferences preferences )
+    {
+        super( "Sorting...", BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_SORT ) );
+        super.setEnabled( true );
+
+        this.preferences = preferences;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        BrowserSorterDialog dlg = new BrowserSorterDialog( PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+            preferences );
+        dlg.open();
+    }
+
+
+    /**
+     * Disposes this action.
+     */
+    public void dispose()
+    {
+        preferences = null;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionActionGroup.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionActionGroup.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionActionGroup.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionActionGroup.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,320 @@
+/*
+ *  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.common.widgets.connection;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.common.actions.CloseConnectionAction;
+import org.apache.directory.ldapstudio.browser.common.actions.CopyAction;
+import org.apache.directory.ldapstudio.browser.common.actions.DeleteAction;
+import org.apache.directory.ldapstudio.browser.common.actions.NewConnectionAction;
+import org.apache.directory.ldapstudio.browser.common.actions.OpenConnectionAction;
+import org.apache.directory.ldapstudio.browser.common.actions.PasteAction;
+import org.apache.directory.ldapstudio.browser.common.actions.PropertiesAction;
+import org.apache.directory.ldapstudio.browser.common.actions.RenameAction;
+import org.apache.directory.ldapstudio.browser.common.actions.proxy.BrowserActionProxy;
+import org.apache.directory.ldapstudio.browser.common.actions.proxy.ConnectionViewActionProxy;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.commands.ICommandService;
+
+
+/**
+ * This class manages all the actions of the connection widget.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionActionGroup implements IMenuListener
+{
+
+    /** The Constant newConnectionAction. */
+    protected static final String newConnectionAction = "newConnectionAction";
+
+    /** The Constant openConnectionAction. */
+    protected static final String openConnectionAction = "openConnectionAction";
+
+    /** The Constant closeConnectionAction. */
+    protected static final String closeConnectionAction = "closeConnectionAction";
+
+    /** The Constant copyConnectionAction. */
+    protected static final String copyConnectionAction = "copyConnectionAction";
+
+    /** The Constant pasteConnectionAction. */
+    protected static final String pasteConnectionAction = "pasteConnectionAction";
+
+    /** The Constant deleteConnectionAction. */
+    protected static final String deleteConnectionAction = "deleteConnectionAction";
+
+    /** The Constant renameConnectionAction. */
+    protected static final String renameConnectionAction = "renameConnectionAction";
+
+    /** The Constant propertyDialogAction. */
+    protected static final String propertyDialogAction = "propertyDialogAction";
+
+    /** The action map. */
+    protected Map<String, ConnectionViewActionProxy> connectionActionMap;
+
+    /** The action bars. */
+    protected IActionBars actionBars;
+
+    /** The connection main widget. */
+    protected ConnectionWidget mainWidget;
+
+
+    /**
+     * Creates a new instance of ConnectionActionGroup.
+     *
+     * @param mainWidget the connection main widget
+     * @param configuration the connection widget configuration
+     */
+    public ConnectionActionGroup( ConnectionWidget mainWidget, ConnectionConfiguration configuration )
+    {
+        this.mainWidget = mainWidget;
+        this.connectionActionMap = new HashMap<String, ConnectionViewActionProxy>();
+
+        TableViewer viewer = mainWidget.getViewer();
+        connectionActionMap
+            .put( newConnectionAction, new ConnectionViewActionProxy( viewer, new NewConnectionAction() ) );
+        connectionActionMap.put( openConnectionAction, new ConnectionViewActionProxy( viewer,
+            new OpenConnectionAction() ) );
+        connectionActionMap.put( closeConnectionAction, new ConnectionViewActionProxy( viewer,
+            new CloseConnectionAction() ) );
+        connectionActionMap.put( pasteConnectionAction, new ConnectionViewActionProxy( viewer, new PasteAction() ) );
+        connectionActionMap.put( copyConnectionAction, new ConnectionViewActionProxy( viewer, new CopyAction(
+            ( BrowserActionProxy ) connectionActionMap.get( pasteConnectionAction ) ) ) );
+        connectionActionMap.put( deleteConnectionAction, new ConnectionViewActionProxy( viewer, new DeleteAction() ) );
+        connectionActionMap.put( renameConnectionAction, new ConnectionViewActionProxy( viewer, new RenameAction() ) );
+        connectionActionMap.put( propertyDialogAction, new ConnectionViewActionProxy( viewer, new PropertiesAction() ) );
+    }
+
+
+    /**
+     * Disposes this action group.
+     */
+    public void dispose()
+    {
+        if ( mainWidget != null )
+        {
+            for ( Iterator it = connectionActionMap.keySet().iterator(); it.hasNext(); )
+            {
+                String key = ( String ) it.next();
+                ConnectionViewActionProxy action = ( ConnectionViewActionProxy ) this.connectionActionMap.get( key );
+                action.dispose();
+                action = null;
+                it.remove();
+            }
+            connectionActionMap.clear();
+            connectionActionMap = null;
+
+            actionBars = null;
+            mainWidget = null;
+        }
+    }
+
+
+    /**
+     * Enables the action handlers.
+     *
+     * @param actionBars the action bars
+     */
+    public void enableGlobalActionHandlers( IActionBars actionBars )
+    {
+        this.actionBars = actionBars;
+        activateGlobalActionHandlers();
+    }
+
+
+    /**
+     * Fills the tool bar.
+     *
+     * @param toolBarManager the tool bar manager
+     */
+    public void fillToolBar( IToolBarManager toolBarManager )
+    {
+        toolBarManager.add( ( IAction ) this.connectionActionMap.get( newConnectionAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( ( IAction ) this.connectionActionMap.get( openConnectionAction ) );
+        toolBarManager.add( ( IAction ) this.connectionActionMap.get( closeConnectionAction ) );
+
+        toolBarManager.update( true );
+    }
+
+
+    /**
+     * Fills the local menu.
+     *
+     * @param menuManager the local menu manager
+     */
+    public void fillMenu( IMenuManager menuManager )
+    {
+        // menuManager.add(this.openSortDialogAction);
+        // menuManager.add(new Separator());
+        // menuManager.update(true);
+    }
+
+
+    /**
+     * Fills the context menu.
+     *
+     * @param menuManager the context menu manager
+     */
+    public void fillContextMenu( IMenuManager menuManager )
+    {
+        menuManager.setRemoveAllWhenShown( true );
+        menuManager.addMenuListener( this );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation fills the context menu.
+     */
+    public void menuAboutToShow( IMenuManager menuManager )
+    {
+        // add
+        menuManager.add( ( IAction ) connectionActionMap.get( newConnectionAction ) );
+        menuManager.add( new Separator() );
+
+        // open/close
+        if ( ( ( IAction ) connectionActionMap.get( closeConnectionAction ) ).isEnabled() )
+        {
+            menuManager.add( ( IAction ) connectionActionMap.get( closeConnectionAction ) );
+        }
+        else if ( ( ( IAction ) connectionActionMap.get( openConnectionAction ) ).isEnabled() )
+        {
+            menuManager.add( ( IAction ) connectionActionMap.get( openConnectionAction ) );
+        }
+        menuManager.add( new Separator() );
+
+        // copy/paste/...
+        menuManager.add( ( IAction ) connectionActionMap.get( copyConnectionAction ) );
+        menuManager.add( ( IAction ) connectionActionMap.get( pasteConnectionAction ) );
+        menuManager.add( ( IAction ) connectionActionMap.get( deleteConnectionAction ) );
+        menuManager.add( ( IAction ) connectionActionMap.get( renameConnectionAction ) );
+        menuManager.add( new Separator() );
+
+        // additions
+        menuManager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) );
+
+        // properties
+        menuManager.add( ( IAction ) connectionActionMap.get( propertyDialogAction ) );
+    }
+
+
+    /**
+     * Activates the action handlers.
+     */
+    public void activateGlobalActionHandlers()
+    {
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), ( IAction ) connectionActionMap
+                .get( copyConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), ( IAction ) connectionActionMap
+                .get( pasteConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), ( IAction ) connectionActionMap
+                .get( deleteConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.RENAME.getId(), ( IAction ) connectionActionMap
+                .get( renameConnectionAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), ( IAction ) connectionActionMap
+                .get( propertyDialogAction ) );
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction ca = ( IAction ) connectionActionMap.get( copyConnectionAction );
+                ca.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.copy" );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( new ActionHandler( ca ) );
+
+                IAction pa = ( IAction ) connectionActionMap.get( pasteConnectionAction );
+                pa.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.paste" );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( new ActionHandler( pa ) );
+
+                IAction da = ( IAction ) connectionActionMap.get( deleteConnectionAction );
+                da.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.delete" );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( new ActionHandler( da ) );
+
+                IAction pda = ( IAction ) connectionActionMap.get( propertyDialogAction );
+                pda.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.properties" );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( new ActionHandler( pda ) );
+
+            }
+        }
+    }
+
+
+    /**
+     * Deactivates the action handlers.
+     */
+    public void deactivateGlobalActionHandlers()
+    {
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.RENAME.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), null );
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction ca = ( IAction ) connectionActionMap.get( copyConnectionAction );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( null );
+
+                IAction pa = ( IAction ) connectionActionMap.get( pasteConnectionAction );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( null );
+
+                IAction da = ( IAction ) connectionActionMap.get( deleteConnectionAction );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( null );
+
+                IAction pda = ( IAction ) connectionActionMap.get( propertyDialogAction );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( null );
+
+            }
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionConfiguration.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionConfiguration.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionConfiguration.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionConfiguration.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,147 @@
+/*
+ *  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.common.widgets.connection;
+
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.widgets.Menu;
+
+
+/**
+ * The ConnectionConfiguration contains the content provider, the
+ * label provider and the context menu manager for the
+ * connection widget. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionConfiguration
+{
+
+    /** The disposed flag */
+    private boolean disposed = false;
+
+    /** The content provider. */
+    private ConnectionContentProvider contentProvider;
+
+    /** The label provider. */
+    private ConnectionLabelProvider labelProvider;
+
+    /** The context menu manager. */
+    private MenuManager contextMenuManager;
+
+
+    /**
+     * Creates a new instance of ConnectionConfiguration.
+     */
+    public ConnectionConfiguration()
+    {
+    }
+
+
+    /**
+     * Disposes this configuration.
+     */
+    public void dispose()
+    {
+        if ( !disposed )
+        {
+
+            if ( contentProvider != null )
+            {
+                contentProvider.dispose();
+                contentProvider = null;
+            }
+
+            if ( labelProvider != null )
+            {
+                labelProvider.dispose();
+                labelProvider = null;
+            }
+
+            if ( contextMenuManager != null )
+            {
+                contextMenuManager.dispose();
+                contextMenuManager = null;
+            }
+
+            disposed = true;
+        }
+    }
+
+
+    /**
+     * Gets the context menu manager.
+     * 
+     * @param viewer the connection widget's table viewer 
+     * 
+     * @return the context menu manager
+     */
+    public IMenuManager getContextMenuManager( TableViewer viewer )
+    {
+        if ( this.contextMenuManager == null )
+        {
+            this.contextMenuManager = new MenuManager();
+            Menu menu = this.contextMenuManager.createContextMenu( viewer.getControl() );
+            viewer.getControl().setMenu( menu );
+        }
+        return this.contextMenuManager;
+    }
+
+
+    /**
+     * Gets the content provider.
+     * 
+     * @param viewer the connection widget's table viewer
+     * 
+     * @return the content provider
+     */
+    public ConnectionContentProvider getContentProvider( TableViewer viewer )
+    {
+        if ( contentProvider == null )
+        {
+            contentProvider = new ConnectionContentProvider();
+        }
+
+        return contentProvider;
+    }
+
+
+    /**
+     * Gets the label provider.
+     * 
+     * @param viewer the connection widget's table viewer
+     * 
+     * @return the label provider
+     */
+    public ConnectionLabelProvider getLabelProvider( TableViewer viewer )
+    {
+        if ( labelProvider == null )
+        {
+            labelProvider = new ConnectionLabelProvider();
+        }
+
+        return labelProvider;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionContentProvider.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionContentProvider.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionContentProvider.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,79 @@
+/*
+ *  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.common.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * The ConnectionContentProvider represents the content provider for
+ * the connection widget. It accepts the ConnectionManager as input
+ * and returns its connections as elements.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionContentProvider implements IStructuredContentProvider
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation does nothing.
+     */
+    public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation does nothing.
+     */
+    public void dispose()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation accepts the ConnectionManager and returns its connections.
+     */
+    public Object[] getElements( Object inputElement )
+    {
+        if ( inputElement != null && inputElement instanceof ConnectionManager )
+        {
+            ConnectionManager cm = ( ConnectionManager ) inputElement;
+            return cm.getConnections();
+        }
+        else
+        {
+            return new Object[]
+                {};
+        }
+    }
+
+}
\ No newline at end of file

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionLabelProvider.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionLabelProvider.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionLabelProvider.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,95 @@
+/*
+ *  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.common.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * The ConnectionLabelProvider represents the label provider for
+ * the connection widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionLabelProvider extends LabelProvider
+{
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation returns the connection name and appends information
+     * about the used encryption method.
+     */
+    public String getText( Object obj )
+    {
+        if ( obj instanceof IConnection )
+        {
+            IConnection conn = ( IConnection ) obj;
+            if ( conn.getEncryptionMethod() == IConnection.ENCYRPTION_LDAPS )
+            {
+                return conn.getName() + " (LDAPS)";
+            }
+            else if ( conn.getEncryptionMethod() == IConnection.ENCYRPTION_STARTTLS )
+            {
+                return conn.getName() + " (StartTLS)";
+            }
+            else
+            {
+                return conn.getName();
+            }
+        }
+        else if ( obj != null )
+        {
+            return obj.toString();
+        }
+        else
+        {
+            return "";
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation returns a icon for connected or disconnected state.
+     */
+    public Image getImage( Object obj )
+    {
+        if ( obj instanceof IConnection )
+        {
+            IConnection conn = ( IConnection ) obj;
+            return conn.isOpened() ? BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_CONNECTION_CONNECTED )
+                : BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_CONNECTION_DISCONNECTED );
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+}
\ No newline at end of file

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionPageModifyListener.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionPageModifyListener.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionPageModifyListener.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/connection/ConnectionPageModifyListener.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,71 @@
+/*
+ *  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.common.widgets.connection;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+
+
+/**
+ * A ConnectionPageModifyListener listens for modifications of the 
+ * ConnectionPageWrapper.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface ConnectionPageModifyListener
+{
+
+    /**
+     * Indicates that the connection page was modified.
+     */
+    public void connectionPageModified();
+
+
+    /**
+     * Sets a non-error message that should be displayed
+     * to the user. Null means no message so an existing
+     * message shuld be cleared.
+     * 
+     * @param message the message
+     */
+    public void setMessage( String message );
+
+
+    /**
+     * Sets an error message that should be displayed
+     * to the user. Null means no error message so an 
+     * existing error message shuld be cleared.
+     * 
+     * @param errorMessage the error message
+     */
+
+    public void setErrorMessage( String errorMessage );
+
+
+    /**
+     * Gets the real connection or null if none.
+     *
+     * @return the real connection
+     */
+    public IConnection getRealConnection();
+
+}



Mime
View raw message