directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r592079 [13/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/entryeditor/EntryEditorWidgetContentProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetContentProvider.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetContentProvider.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetContentProvider.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,230 @@
+/*
+ *  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.entryeditor;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesJob;
+import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * The EntryEditorWidgetContentProvider implements the content provider for
+ * the entry editor widget. It accepts an {@link IEntry} or an 
+ * {@link AttributeHierarchy} as input.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetContentProvider implements ITreeContentProvider
+{
+
+    /** The preferences. */
+    protected EntryEditorWidgetPreferences preferences;
+
+    /** The main widget. */
+    protected EntryEditorWidget mainWidget;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetContentProvider.
+     * 
+     * @param preferences the preferences
+     * @param mainWidget the main widget
+     */
+    public EntryEditorWidgetContentProvider( EntryEditorWidgetPreferences preferences, EntryEditorWidget mainWidget )
+    {
+        this.preferences = preferences;
+        this.mainWidget = mainWidget;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementations updates the enabled state and the info text.
+     */
+    public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+    {
+        if ( mainWidget != null )
+        {
+            String dn = "";
+            boolean enabled = true;
+
+            if ( newInput != null && newInput instanceof IEntry )
+            {
+                IEntry entry = ( IEntry ) newInput;
+                dn = "DN: " + entry.getDn().getUpName();
+            }
+            else if ( newInput != null && newInput instanceof AttributeHierarchy )
+            {
+                AttributeHierarchy ah = ( AttributeHierarchy ) newInput;
+                dn = "DN: " + ah.getAttribute().getEntry().getDn().getUpName();
+            }
+            else
+            {
+                dn = "No entry selected";
+                enabled = false;
+            }
+
+            if ( mainWidget.getInfoText() != null && !mainWidget.getInfoText().isDisposed() )
+            {
+                mainWidget.getInfoText().setText( dn );
+            }
+            if ( mainWidget.getQuickFilterWidget() != null )
+            {
+                mainWidget.getQuickFilterWidget().setEnabled( enabled );
+            }
+            if ( mainWidget.getViewer() != null && !mainWidget.getViewer().getTree().isDisposed() )
+            {
+                mainWidget.getViewer().getTree().setEnabled( enabled );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+        preferences = null;
+        mainWidget = null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object[] getElements( Object inputElement )
+    {
+
+        if ( inputElement != null && inputElement instanceof IEntry )
+        {
+            IEntry entry = ( IEntry ) inputElement;
+
+            if ( !entry.isAttributesInitialized() && entry.isDirectoryEntry() )
+            {
+                boolean soa = BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+                    BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES );
+                InitializeAttributesJob job = new InitializeAttributesJob( new IEntry[]
+                    { entry }, soa );
+                job.execute();
+                return new Object[0];
+            }
+            else
+            {
+                IAttribute[] attributes = entry.getAttributes();
+                Object[] values = getValues( attributes );
+                return values;
+            }
+        }
+        else if ( inputElement != null && inputElement instanceof AttributeHierarchy )
+        {
+            AttributeHierarchy ah = ( AttributeHierarchy ) inputElement;
+            IAttribute[] attributes = ah.getAttributes();
+            Object[] values = getValues( attributes );
+            return values;
+        }
+        else
+        {
+            return new Object[0];
+        }
+    }
+
+
+    /**
+     * Gets the values of the given attributes.
+     * 
+     * @param attributes the attributes
+     * 
+     * @return the values
+     */
+    private Object[] getValues( IAttribute[] attributes )
+    {
+        List<Object> valueList = new ArrayList<Object>();
+        for ( int i = 0; attributes != null && i < attributes.length; i++ )
+        {
+            IValue[] values = attributes[i].getValues();
+            if ( this.preferences == null || !this.preferences.isUseFolding()
+                || ( values.length <= this.preferences.getFoldingThreshold() ) )
+            {
+                for ( int j = 0; j < values.length; j++ )
+                {
+                    valueList.add( values[j] );
+                }
+            }
+            else
+            {
+                // if folding threshold is exceeded then return the attribute itself
+                valueList.add( attributes[i] );
+            }
+        }
+        return valueList.toArray();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object[] getChildren( Object parentElement )
+    {
+        if ( parentElement instanceof IAttribute )
+        {
+            IAttribute attribute = ( IAttribute ) parentElement;
+            IValue[] values = attribute.getValues();
+            return values;
+        }
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object getParent( Object element )
+    {
+        if ( element instanceof IValue )
+        {
+            return ( ( IValue ) element ).getAttribute();
+        }
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasChildren( Object element )
+    {
+        return ( element instanceof IAttribute );
+    }
+
+}
\ No newline at end of file

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetFilter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetFilter.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetFilter.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetFilter.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,285 @@
+/*
+ *  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.entryeditor;
+
+
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+
+/**
+ * The EntryEditorWidgetFilter implements the filter for
+ * the entry editor widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetFilter extends ViewerFilter
+{
+
+    /** The viewer to filter. */
+    protected TreeViewer viewer;
+
+    /** The quick filter attribute. */
+    protected String quickFilterAttribute;
+
+    /** The quick filter value. */
+    protected String quickFilterValue;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetFilter.
+     */
+    public EntryEditorWidgetFilter()
+    {
+        this.quickFilterAttribute = "";
+        this.quickFilterValue = "";
+    }
+
+
+    /**
+     * Connects this filter with the given viewer.
+     * 
+     * @param viewer the viewer
+     */
+    public void connect( TreeViewer viewer )
+    {
+        this.viewer = viewer;
+        viewer.addFilter( this );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean select( Viewer viewer, Object parentElement, Object element )
+    {
+        if ( element instanceof IAttribute )
+        {
+            IAttribute attribute = ( IAttribute ) element;
+
+            // check if one of the values goes through the quick filter
+            boolean oneGoesThrough = false;
+            IValue[] values = attribute.getValues();
+            for ( int i = 0; i < values.length; i++ )
+            {
+                if ( goesThroughQuickFilter( values[i] ) )
+                {
+                    oneGoesThrough = true;
+                    break;
+                }
+            }
+            if ( !oneGoesThrough )
+            {
+                return false;
+            }
+
+            return true;
+        }
+        else if ( element instanceof IValue )
+        {
+            IValue value = ( IValue ) element;
+
+            // check quick filter
+            if ( !goesThroughQuickFilter( value ) )
+            {
+                return false;
+            }
+
+            // filter attribute types
+            if ( value.getAttribute().isObjectClassAttribute() )
+            {
+                return isShowObjectClassAttribute();
+            }
+            else if ( value.getAttribute().isMustAttribute() )
+            {
+                return isShowMustAttributes();
+            }
+            else if ( value.getAttribute().isMayAttribute() )
+            {
+                return isShowMayAttributes();
+            }
+            else if ( value.getAttribute().isOperationalAttribute() )
+            {
+                return isShowOperationalAttributes();
+            }
+            else
+            {
+                return true;
+            }
+        }
+        else
+        {
+            return true;
+        }
+    }
+
+
+    /**
+     * Checks if the given value goes through quick filter.
+     * 
+     * @param value the value
+     * 
+     * @return true, if goes through quick filter
+     */
+    private boolean goesThroughQuickFilter( IValue value )
+    {
+        // filter attribute description
+        if ( quickFilterAttribute != null && !"".equals( quickFilterAttribute ) )
+        {
+            if ( value.getAttribute().getDescription().toUpperCase().indexOf( quickFilterAttribute.toUpperCase() ) == -1 )
+            {
+                return false;
+            }
+        }
+
+        // fitler value
+        if ( quickFilterValue != null && !"".equals( quickFilterValue ) )
+        {
+            if ( value.isString()
+                && value.getStringValue().toUpperCase().indexOf( quickFilterValue.toUpperCase() ) == -1 )
+            {
+                return false;
+            }
+            else if ( value.isBinary() )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+
+    /**
+     * Disposes this filter.
+     */
+    public void dispose()
+    {
+        viewer = null;
+    }
+
+
+    /**
+     * Gets the quick filter attribute.
+     * 
+     * @return the quick filter attribute
+     */
+    public String getQuickFilterAttribute()
+    {
+        return quickFilterAttribute;
+    }
+
+
+    /**
+     * Sets the quick filter attribute.
+     * 
+     * @param quickFilterAttribute the quick filter attribute
+     */
+    public void setQuickFilterAttribute( String quickFilterAttribute )
+    {
+        if ( !this.quickFilterAttribute.equals( quickFilterAttribute ) )
+        {
+            this.quickFilterAttribute = quickFilterAttribute;
+            if ( viewer != null )
+            {
+                viewer.refresh();
+            }
+        }
+    }
+
+
+    /**
+     * Gets the quick filter value.
+     * 
+     * @return the quick filter value
+     */
+    public String getQuickFilterValue()
+    {
+        return quickFilterValue;
+    }
+
+
+    /**
+     * Sets the quick filter value.
+     * 
+     * @param quickFilterValue the quick filter value
+     */
+    public void setQuickFilterValue( String quickFilterValue )
+    {
+        if ( !this.quickFilterValue.equals( quickFilterValue ) )
+        {
+            this.quickFilterValue = quickFilterValue;
+            if ( viewer != null )
+            {
+                viewer.refresh();
+            }
+        }
+    }
+
+
+    /**
+     * Checks if may attributes should be shown.
+     * 
+     * @return true, if may attributes should be shown
+     */
+    public boolean isShowMayAttributes()
+    {
+        return true;
+    }
+
+
+    /**
+     * Checks if must attributes should be shown.
+     * 
+     * @return true, if must attributes should be shown
+     */
+    public boolean isShowMustAttributes()
+    {
+        return true;
+    }
+
+
+    /**
+     * Checks if the objectClass attribute should be shown.
+     * 
+     * @return true, if the objectClass attribute should be shown
+     */
+    public boolean isShowObjectClassAttribute()
+    {
+        return true;
+    }
+
+
+    /**
+     * Checks if operational attributes should be shown.
+     * 
+     * @return true, if operational attributes should be shown
+     */
+    public boolean isShowOperationalAttributes()
+    {
+        return true;
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,283 @@
+/*
+ *  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.entryeditor;
+
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.valueeditors.IValueEditor;
+import org.apache.directory.studio.valueeditors.ValueEditorManager;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
+
+
+/**
+ * The EntryEditorWidgetLabelProvider implements the label provider for
+ * the entry editor widget.
+ * 
+ * It provides the type value pairs for {@link IValue} objects and type plus 
+ * the number of values for {@link IAttribute} objects. It also implements 
+ * {@link IFontProvider} and {@link IColorProvider} to set the font and color
+ * depending on whether the attribte is a must, may or operational attribute.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetLabelProvider extends LabelProvider implements ITableLabelProvider, IFontProvider,
+    IColorProvider
+{
+
+    /** The value editor manager. */
+    private ValueEditorManager valueEditorManager;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetLabelProvider.
+     * 
+     * @param valueEditorManager the value editor manager
+     */
+    public EntryEditorWidgetLabelProvider( ValueEditorManager valueEditorManager )
+    {
+        this.valueEditorManager = valueEditorManager;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+        super.dispose();
+        valueEditorManager = null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public final String getColumnText( Object obj, int index )
+    {
+        if ( obj != null && obj instanceof IValue )
+        {
+            IValue value = ( IValue ) obj;
+            switch ( index )
+            {
+                case EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX:
+                    return value.getAttribute().getDescription();
+                case EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX:
+                    IValueEditor vp = this.valueEditorManager.getCurrentValueEditor( value );
+                    String dv = vp.getDisplayValue( value );
+                    return dv;
+                default:
+                    return "";
+            }
+        }
+        else if ( obj != null && obj instanceof IAttribute )
+        {
+            IAttribute attribute = ( IAttribute ) obj;
+            if ( index == EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX )
+            {
+                return attribute.getDescription() + " (" + attribute.getValueSize() + " values)";
+            }
+            else
+            {
+                return "";
+            }
+        }
+        else
+        {
+            return "";
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public final Image getColumnImage( Object element, int index )
+    {
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Font getFont( Object element )
+    {
+        IAttribute attribute = null;
+        IValue value = null;
+        if ( element instanceof IAttribute )
+        {
+            attribute = ( IAttribute ) element;
+        }
+        else if ( element instanceof IValue )
+        {
+            value = ( IValue ) element;
+            attribute = value.getAttribute();
+        }
+
+        // inconsistent attributes and values
+        if ( value != null )
+        {
+            if ( value.isEmpty() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+                    .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_ERROR_FONT );
+                return BrowserCommonActivator.getDefault().getFont( fontData );
+            }
+        }
+        if ( attribute != null && value == null )
+        {
+            if ( !attribute.isConsistent() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+                    .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_ERROR_FONT );
+                return BrowserCommonActivator.getDefault().getFont( fontData );
+            }
+        }
+
+        // attribute type
+        if ( attribute != null )
+        {
+            if ( attribute.isObjectClassAttribute() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+                    .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_OBJECTCLASS_FONT );
+                return BrowserCommonActivator.getDefault().getFont( fontData );
+            }
+            else if ( attribute.isMustAttribute() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+                    .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_FONT );
+                return BrowserCommonActivator.getDefault().getFont( fontData );
+            }
+            else if ( attribute.isOperationalAttribute() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+                    .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_FONT );
+                return BrowserCommonActivator.getDefault().getFont( fontData );
+            }
+            else
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+                    .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_FONT );
+                return BrowserCommonActivator.getDefault().getFont( fontData );
+            }
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Color getForeground( Object element )
+    {
+        IAttribute attribute = null;
+        IValue value = null;
+        if ( element instanceof IAttribute )
+        {
+            attribute = ( IAttribute ) element;
+        }
+        else if ( element instanceof IValue )
+        {
+            value = ( IValue ) element;
+            attribute = value.getAttribute();
+        }
+
+        // inconsistent attributes and values
+        if ( value != null )
+        {
+            if ( value.isEmpty() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                    BrowserCommonConstants.PREFERENCE_ERROR_COLOR );
+                return BrowserCommonActivator.getDefault().getColor( rgb );
+            }
+        }
+        if ( attribute != null && value == null )
+        {
+            if ( !attribute.isConsistent() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                    BrowserCommonConstants.PREFERENCE_ERROR_COLOR );
+                return BrowserCommonActivator.getDefault().getColor( rgb );
+            }
+        }
+
+        // attribute type
+        if ( attribute != null )
+        {
+            if ( attribute.isObjectClassAttribute() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                    BrowserCommonConstants.PREFERENCE_OBJECTCLASS_COLOR );
+                return BrowserCommonActivator.getDefault().getColor( rgb );
+            }
+            else if ( attribute.isMustAttribute() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                    BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_COLOR );
+                return BrowserCommonActivator.getDefault().getColor( rgb );
+            }
+            else if ( attribute.isOperationalAttribute() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                    BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_COLOR );
+                return BrowserCommonActivator.getDefault().getColor( rgb );
+            }
+            else
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                    BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_COLOR );
+                return BrowserCommonActivator.getDefault().getColor( rgb );
+            }
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Color getBackground( Object element )
+    {
+        return null;
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,213 @@
+/*
+ *  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.entryeditor;
+
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * This class is a wrapper for the preferences of the entry editor widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetPreferences implements IPropertyChangeListener
+{
+
+    /** The viewer. */
+    protected Viewer viewer;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetPreferences.
+     */
+    public EntryEditorWidgetPreferences()
+    {
+        BrowserCommonActivator.getDefault().getPreferenceStore().addPropertyChangeListener( this );
+    }
+
+
+    /**
+     * Connects this preferences with the given viewer.
+     * 
+     * @param viewer the viewer
+     */
+    public void connect( TreeViewer viewer )
+    {
+        this.viewer = viewer;
+    }
+
+
+    /**
+     * Disposes this preferences.
+     */
+    public void dispose()
+    {
+        BrowserCommonActivator.getDefault().getPreferenceStore().removePropertyChangeListener( this );
+        viewer = null;
+    }
+
+
+    /**
+     * Checks if folding is enabled.
+     * 
+     * @return true, if folding is enabled
+     */
+    public boolean isUseFolding()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING );
+    }
+
+
+    /**
+     * Gets the folding threshold.
+     * 
+     * @return the folding threshold
+     */
+    public int getFoldingThreshold()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD );
+    }
+
+
+    /**
+     * Checks if may attributes should be shown.
+     * 
+     * @return true, if may attributes should be shown
+     */
+    public boolean isShowMayAttributes()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES );
+    }
+
+
+    /**
+     * Checks if must attributes should be shown.
+     * 
+     * @return true, if must attributes should be shown
+     */
+    public boolean isShowMustAttributes()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES );
+    }
+
+
+    /**
+     * Checks if object class attribute should be shown.
+     * 
+     * @return true, if object class attribute should be shown
+     */
+    public boolean isShowObjectClassAttribute()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES );
+    }
+
+
+    /**
+     * Checks if operational attributes should be shown.
+     * 
+     * @return true, if operational attributes should be shown
+     */
+    public boolean isShowOperationalAttributes()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES );
+    }
+
+
+    /**
+     * Checks if object class and must attributes should be 
+     * grouped before may attributes.
+     * 
+     * @return true, if object class and must attributes first
+     */
+    public boolean isObjectClassAndMustAttributesFirst()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST );
+    }
+
+
+    /**
+     * Checks if operational attributes should be grouped after may attributes.
+     * 
+     * @return true, if operational attributes last
+     */
+    public boolean isOperationalAttributesLast()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST );
+    }
+
+
+    /**
+     * Gets the default sort property, one of 
+     * {@link BrowserCoreConstants#SORT_BY_ATTRIBUTE_DESCRIPTION} or
+     * {@link BrowserCoreConstants#SORT_BY_VALUE}.
+     * 
+     * @return the default sort property
+     */
+    public int getDefaultSortBy()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY );
+    }
+
+
+    /**
+     * Gets the default sort property, one of 
+     * {@link BrowserCoreConstants#SORT_ORDER_NONE},
+     * {@link BrowserCoreConstants#SORT_ORDER_ASCENDING} or
+     * {@link BrowserCoreConstants#SORT_ORDER_DESCENDING}.
+     * 
+     * @return the default sort property
+     */
+    public int getDefaultSortOrder()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void propertyChange( PropertyChangeEvent event )
+    {
+        if ( this.viewer != null )
+        {
+            this.viewer.refresh();
+        }
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,287 @@
+/*
+ *  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.entryeditor;
+
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.eclipse.jface.preference.PreferenceConverter;
+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.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * The EntryEditorWidgetQuickFilterWidget implements an instant search 
+ * for the entry editor widget. It contains separate search fields for
+ * attribute type and/or value.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetQuickFilterWidget
+{
+
+    /** The filter to propagate the entered filter phrases. */
+    private EntryEditorWidgetFilter filter;
+
+    /** The entry editor widget. */
+    private EntryEditorWidget entryEditorWidget;
+
+    /** The parent, used to create the composite. */
+    private Composite parent;
+
+    /** The outer composite. */
+    private Composite composite;
+
+    /** The inner composite, it is created/destroyed when showing/hiding the quick filter. */
+    private Composite innerComposite;
+
+    /** The quick filter attribute text. */
+    private Text quickFilterAttributeText;
+
+    /** The quick filter value text. */
+    private Text quickFilterValueText;
+
+    /** The clear quick filter button. */
+    private Button clearQuickFilterButton;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetQuickFilterWidget.
+     * 
+     * @param filter the filter
+     * @param entryEditorWidget the entry editor widget
+     */
+    public EntryEditorWidgetQuickFilterWidget( EntryEditorWidgetFilter filter, EntryEditorWidget entryEditorWidget )
+    {
+        this.filter = filter;
+        this.entryEditorWidget = entryEditorWidget;
+    }
+
+
+    /**
+     * Creates the outer composite.
+     * 
+     * @param parent the parent
+     */
+    public void createComposite( Composite parent )
+    {
+        this.parent = parent;
+
+        composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+        GridLayout gl = new GridLayout();
+        gl.marginHeight = 2;
+        gl.marginWidth = 2;
+        composite.setLayout( gl );
+
+        innerComposite = null;
+    }
+
+
+    /**
+     * Creates the inner composite with its input fields.
+     */
+    private void create()
+    {
+        innerComposite = BaseWidgetUtils.createColumnContainer( composite, 3, 1 );
+
+        quickFilterAttributeText = new Text( innerComposite, SWT.BORDER );
+        quickFilterAttributeText.setLayoutData( new GridData( 200 - 14, SWT.DEFAULT ) );
+        quickFilterAttributeText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                filter.setQuickFilterAttribute( quickFilterAttributeText.getText() );
+                clearQuickFilterButton.setEnabled( !"".equals( quickFilterAttributeText.getText() )
+                    || !"".equals( quickFilterValueText.getText() ) );
+                if ( !"".equals( quickFilterAttributeText.getText() ) )
+                {
+                    RGB fgRgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                        BrowserCommonConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR );
+                    RGB bgRgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                        BrowserCommonConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR );
+                    Color fgColor = BrowserCommonActivator.getDefault().getColor( fgRgb );
+                    Color bgColor = BrowserCommonActivator.getDefault().getColor( bgRgb );
+                    quickFilterAttributeText.setForeground( fgColor );
+                    quickFilterAttributeText.setBackground( bgColor );
+                    FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+                        .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_QUICKFILTER_FONT );
+                    Font font = BrowserCommonActivator.getDefault().getFont( fontData );
+                    quickFilterAttributeText.setFont( font );
+                }
+                else
+                {
+                    quickFilterAttributeText.setBackground( null );
+                }
+            }
+        } );
+
+        quickFilterValueText = new Text( innerComposite, SWT.BORDER );
+        quickFilterValueText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        quickFilterValueText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                filter.setQuickFilterValue( quickFilterValueText.getText() );
+                clearQuickFilterButton.setEnabled( !"".equals( quickFilterAttributeText.getText() )
+                    || !"".equals( quickFilterValueText.getText() ) );
+                if ( !"".equals( quickFilterValueText.getText() ) )
+                {
+                    RGB fgRgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                        BrowserCommonConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR );
+                    RGB bgRgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                        BrowserCommonConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR );
+                    Color fgColor = BrowserCommonActivator.getDefault().getColor( fgRgb );
+                    Color bgColor = BrowserCommonActivator.getDefault().getColor( bgRgb );
+                    quickFilterValueText.setForeground( fgColor );
+                    quickFilterValueText.setBackground( bgColor );
+                    FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+                        .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_QUICKFILTER_FONT );
+                    Font font = BrowserCommonActivator.getDefault().getFont( fontData );
+                    quickFilterValueText.setFont( font );
+                }
+                else
+                {
+                    quickFilterValueText.setBackground( null );
+                }
+            }
+        } );
+
+        clearQuickFilterButton = new Button( innerComposite, SWT.PUSH );
+        clearQuickFilterButton.setToolTipText( "Clear Quick Filter" );
+        clearQuickFilterButton.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_CLEAR ) );
+        clearQuickFilterButton.setEnabled( false );
+        clearQuickFilterButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                if ( !"".equals( quickFilterAttributeText.getText() ) )
+                {
+                    quickFilterAttributeText.setText( "" );
+                }
+                if ( !"".equals( quickFilterValueText.getText() ) )
+                {
+                    quickFilterValueText.setText( "" );
+                }
+            }
+        } );
+
+        setEnabled( composite.isEnabled() );
+
+        composite.layout( true, true );
+        parent.layout( true, true );
+    }
+
+
+    /**
+     * Destroys the inner widget.
+     */
+    private void destroy()
+    {
+        if ( !"".equals( quickFilterAttributeText.getText() ) )
+        {
+            quickFilterAttributeText.setText( "" );
+        }
+        if ( !"".equals( quickFilterValueText.getText() ) )
+        {
+            quickFilterValueText.setText( "" );
+        }
+        innerComposite.dispose();
+        innerComposite = null;
+
+        composite.layout( true, true );
+        parent.layout( true, true );
+    }
+
+
+    /**
+     * Disposes this widget.
+     */
+    public void dispose()
+    {
+        if ( filter != null )
+        {
+            quickFilterAttributeText = null;
+            quickFilterValueText = null;
+            clearQuickFilterButton = null;
+            innerComposite = null;
+            composite.dispose();
+            composite = null;
+            parent = null;
+            filter = null;
+        }
+    }
+
+
+    /**
+     * Enables or disables this quick filter widget.
+     * 
+     * @param enabled true to enable this quick filter widget, false to disable it
+     */
+    public void setEnabled( boolean enabled )
+    {
+        if ( composite != null && !composite.isDisposed() )
+        {
+            composite.setEnabled( enabled );
+        }
+        if ( innerComposite != null && !innerComposite.isDisposed() )
+        {
+            innerComposite.setEnabled( enabled );
+            quickFilterAttributeText.setEnabled( enabled );
+            quickFilterValueText.setEnabled( enabled );
+            clearQuickFilterButton.setEnabled( enabled );
+        }
+    }
+
+
+    /**
+     * Activates or deactivates this quick filter widget.
+     *
+     * @param visible true to crate this quick filter widget, false to destroy it
+     */
+    public void setActive( boolean visible )
+    {
+        if ( visible && innerComposite == null && composite != null )
+        {
+            create();
+            quickFilterAttributeText.setFocus();
+        }
+        else if ( !visible && innerComposite != null && composite != null )
+        {
+            destroy();
+            entryEditorWidget.getViewer().getTree().setFocus();
+        }
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorter.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorter.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorter.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,434 @@
+/*
+ *  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.entryeditor;
+
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.TreeColumn;
+
+
+/**
+ * The EntryEditorWidgetSorter implements the Sorter for the entry editor widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetSorter extends ViewerSorter implements SelectionListener
+{
+
+    /** The tree viewer. */
+    private TreeViewer viewer;
+
+    /** The sort property. */
+    private int sortBy;
+
+    /** The sort order. */
+    private int sortOrder;
+
+    /** The preferences. */
+    private EntryEditorWidgetPreferences preferences;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetSorter.
+     * 
+     * @param preferences the preferences
+     */
+    public EntryEditorWidgetSorter( EntryEditorWidgetPreferences preferences )
+    {
+        this.sortBy = BrowserCoreConstants.SORT_BY_NONE;
+        this.sortOrder = BrowserCoreConstants.SORT_ORDER_NONE;
+        this.preferences = preferences;
+    }
+
+
+    /**
+     * Connects this sorter to the given tree viewer.
+     * 
+     * @param viewer the viewer
+     */
+    public void connect( TreeViewer viewer )
+    {
+        this.viewer = viewer;
+        viewer.setSorter( this );
+
+        TreeColumn[] columns = ( ( TreeViewer ) viewer ).getTree().getColumns();
+        for ( int i = 0; i < columns.length; i++ )
+        {
+            columns[i].addSelectionListener( this );
+        }
+    }
+
+
+    /**
+     * Disposes this sorter.
+     */
+    public void dispose()
+    {
+        viewer = null;
+        preferences = null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void widgetDefaultSelected( SelectionEvent e )
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * Switches the sort property and sort order when clicking the table headers.
+     */
+    public void widgetSelected( SelectionEvent e )
+    {
+        if ( e.widget instanceof TreeColumn && viewer != null )
+        {
+            int index = viewer.getTree().indexOf( ( ( TreeColumn ) e.widget ) );
+            switch ( index )
+            {
+                case EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX:
+                    if ( sortBy == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION )
+                    {
+                        // toggle sort order
+                        sortOrder = sortOrder == BrowserCoreConstants.SORT_ORDER_NONE ? BrowserCoreConstants.SORT_ORDER_ASCENDING
+                            : sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING ? BrowserCoreConstants.SORT_ORDER_DESCENDING
+                                : BrowserCoreConstants.SORT_ORDER_NONE;
+                    }
+                    else
+                    {
+                        // set new sort by
+                        sortBy = BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION;
+                        sortOrder = BrowserCoreConstants.SORT_ORDER_ASCENDING;
+                    }
+                    break;
+                case EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX:
+                    if ( sortBy == BrowserCoreConstants.SORT_BY_VALUE )
+                    {
+                        // toggle sort order
+                        sortOrder = sortOrder == BrowserCoreConstants.SORT_ORDER_NONE ? BrowserCoreConstants.SORT_ORDER_ASCENDING
+                            : sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING ? BrowserCoreConstants.SORT_ORDER_DESCENDING
+                                : BrowserCoreConstants.SORT_ORDER_NONE;
+                    }
+                    else
+                    {
+                        // set new sort by
+                        sortBy = BrowserCoreConstants.SORT_BY_VALUE;
+                        sortOrder = BrowserCoreConstants.SORT_ORDER_ASCENDING;
+                    }
+                    break;
+                default:
+                    ;
+            }
+            if ( sortOrder == BrowserCoreConstants.SORT_ORDER_NONE )
+            {
+                sortBy = BrowserCoreConstants.SORT_BY_NONE;
+            }
+
+            TreeColumn[] columns = viewer.getTree().getColumns();
+            for ( int i = 0; i < columns.length; i++ )
+            {
+                columns[i].setImage( null );
+            }
+
+            if ( sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING )
+            {
+                ( ( TreeColumn ) e.widget ).setImage( BrowserCommonActivator.getDefault().getImage(
+                    BrowserCommonConstants.IMG_SORT_ASCENDING ) );
+            }
+            else if ( sortOrder == BrowserCoreConstants.SORT_ORDER_DESCENDING )
+            {
+                ( ( TreeColumn ) e.widget ).setImage( BrowserCommonActivator.getDefault().getImage(
+                    BrowserCommonConstants.IMG_SORT_DESCENDING ) );
+            }
+
+            viewer.refresh();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void sort( final Viewer viewer, Object[] elements )
+    {
+        Arrays.sort( elements, new Comparator<Object>()
+        {
+            public int compare( Object a, Object b )
+            {
+                return EntryEditorWidgetSorter.this.compare( viewer, a, b );
+            }
+        } );
+
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int compare( Viewer viewer, Object o1, Object o2 )
+    {
+        // check o1
+        IAttribute attribute1 = null;
+        IValue value1 = null;
+        if ( o1 instanceof IAttribute )
+        {
+            attribute1 = ( IAttribute ) o1;
+        }
+        else if ( o1 instanceof IValue )
+        {
+            value1 = ( IValue ) o1;
+            attribute1 = value1.getAttribute();
+        }
+
+        // check o2
+        IAttribute attribute2 = null;
+        IValue value2 = null;
+        if ( o2 instanceof IAttribute )
+        {
+            attribute2 = ( IAttribute ) o2;
+        }
+        else if ( o2 instanceof IValue )
+        {
+            value2 = ( IValue ) o2;
+            attribute2 = value2.getAttribute();
+        }
+
+        // compare
+        if ( value1 != null && value2 != null )
+        {
+            if ( getSortByOrDefault() == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION )
+            {
+                if ( value1.getAttribute() != value2.getAttribute() )
+                {
+                    return compareAttributes( value1.getAttribute(), value2.getAttribute() );
+                }
+                else
+                {
+                    return compareValues( value1, value2 );
+                }
+            }
+            else if ( getSortByOrDefault() == BrowserCoreConstants.SORT_BY_VALUE )
+            {
+                return compareValues( value1, value2 );
+            }
+            else
+            {
+                return equal();
+            }
+        }
+        else if ( attribute1 != null && attribute2 != null )
+        {
+            return compareAttributes( attribute1, attribute2 );
+        }
+        else
+        {
+            return equal();
+        }
+    }
+
+
+    /**
+     * Compares attribute kind or description.
+     * 
+     * @param attribute1 the attribute1
+     * @param attribute2 the attribute2
+     * 
+     * @return the compare result
+     */
+    private int compareAttributes( IAttribute attribute1, IAttribute attribute2 )
+    {
+        if ( this.sortOrder == BrowserCoreConstants.SORT_ORDER_NONE )
+        {
+            if ( preferences == null || preferences.isObjectClassAndMustAttributesFirst() )
+            {
+                if ( attribute1.isObjectClassAttribute() )
+                {
+                    return lessThan();
+                }
+                else if ( attribute2.isObjectClassAttribute() )
+                {
+                    return greaterThan();
+                }
+
+                if ( attribute1.isMustAttribute() && !attribute2.isMustAttribute() )
+                {
+                    return lessThan();
+                }
+                else if ( attribute2.isMustAttribute() && !attribute1.isMustAttribute() )
+                {
+                    return greaterThan();
+                }
+            }
+            if ( preferences == null || preferences.isOperationalAttributesLast() )
+            {
+                if ( attribute1.isOperationalAttribute() && !attribute2.isOperationalAttribute() )
+                {
+                    return greaterThan();
+                }
+                else if ( attribute2.isOperationalAttribute() && !attribute1.isOperationalAttribute() )
+                {
+                    return lessThan();
+                }
+            }
+        }
+
+        return compare( attribute1.getDescription(), attribute2.getDescription() );
+    }
+
+
+    /**
+     * Compares values.
+     * 
+     * @param value1 the value1
+     * @param value2 the value2
+     * 
+     * @return the compare result
+     */
+    private int compareValues( IValue value1, IValue value2 )
+    {
+        if ( value1.isEmpty() && value2.isEmpty() )
+        {
+            return equal();
+        }
+        else if ( value1.isEmpty() && !value2.isEmpty() )
+        {
+            return greaterThan();
+        }
+        else if ( !value1.isEmpty() && value2.isEmpty() )
+        {
+            return lessThan();
+        }
+        else
+        {
+            return compare( value1.getStringValue(), value2.getStringValue() );
+        }
+    }
+
+
+    /**
+     * Gets the current sort order or the default sort order from the preferences .
+     * 
+     * @return the current sort order or default sort order
+     */
+    private int getSortOrderOrDefault()
+    {
+        if ( preferences == null )
+        {
+            return BrowserCoreConstants.SORT_ORDER_ASCENDING;
+        }
+        else if ( sortOrder == BrowserCoreConstants.SORT_ORDER_NONE )
+        {
+            return preferences.getDefaultSortOrder();
+        }
+        else
+        {
+            return sortOrder;
+        }
+    }
+
+
+    /**
+     * Gets the current sort property or the default sort property from the preferences .
+     * 
+     * @return the current sort property or default sort property
+     */
+    private int getSortByOrDefault()
+    {
+        if ( preferences == null )
+        {
+            return BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION;
+        }
+        else if ( sortBy == BrowserCoreConstants.SORT_BY_NONE )
+        {
+            return preferences.getDefaultSortBy();
+        }
+        else
+        {
+            return sortBy;
+        }
+    }
+
+
+    /**
+     * Returns +1 or -1, depending on the sort order.
+     *
+     * @return +1 or -1, depending on the sort order
+     */
+    private int lessThan()
+    {
+        return this.getSortOrderOrDefault() == 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 this.getSortOrderOrDefault() == 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 this.getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? s1.compareToIgnoreCase( s2 )
+            : s2.compareToIgnoreCase( s1 );
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorterDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorterDialog.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorterDialog.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorterDialog.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,189 @@
+/*
+ *  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.entryeditor;
+
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.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.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.Shell;
+
+
+/**
+ * This class represents the dialog used to change the entry editors's  default sort preferences.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetSorterDialog extends Dialog
+{
+
+    /** The Constant DIALOG_TITLE. */
+    public static final String DIALOG_TITLE = "Entry Editor Sorting";
+
+    /** The Constant SORT_BY_NONE. */
+    public static final String SORT_BY_NONE = "No Default Sorting";
+
+    /** The Constant SORT_BY_ATTRIBUTE. */
+    public static final String SORT_BY_ATTRIBUTE = "Attribute Description";
+
+    /** The Constant SORT_BY_VALUE. */
+    public static final String SORT_BY_VALUE = "Value";
+
+    /** The preferences. */
+    private EntryEditorWidgetPreferences preferences;
+
+    /** The object class and must attributes first button. */
+    private Button objectClassAndMustAttributesFirstButton;
+
+    /** The operational attributes last button. */
+    private Button operationalAttributesLastButton;
+
+    /** The sort by combo. */
+    private Combo sortByCombo;
+
+    /** The sort acending button. */
+    private Button sortAcendingButton;
+
+    /** The sort descending button. */
+    private Button sortDescendingButton;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetSorterDialog.
+     * 
+     * @param parentShell the parent shell
+     * @param preferences the preferences
+     */
+    public EntryEditorWidgetSorterDialog( Shell parentShell, EntryEditorWidgetPreferences preferences )
+    {
+        super( parentShell );
+        this.preferences = preferences;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation calls its super implementation and sets the dialog's title.
+     */
+    protected void configureShell( Shell newShell )
+    {
+        super.configureShell( newShell );
+        newShell.setText( DIALOG_TITLE );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation saves the changed settings when OK is pressed.
+     */
+    protected void buttonPressed( int buttonId )
+    {
+        if ( buttonId == IDialogConstants.OK_ID )
+        {
+            IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
+            store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST,
+                objectClassAndMustAttributesFirstButton.getSelection() );
+            store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST,
+                operationalAttributesLastButton.getSelection() );
+            store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER, sortDescendingButton
+                .getSelection() ? BrowserCoreConstants.SORT_ORDER_DESCENDING
+                : BrowserCoreConstants.SORT_ORDER_ASCENDING );
+            store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY,
+                sortByCombo.getSelectionIndex() == 2 ? BrowserCoreConstants.SORT_BY_VALUE : sortByCombo
+                    .getSelectionIndex() == 1 ? BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION
+                    : BrowserCoreConstants.SORT_BY_NONE );
+        }
+
+        super.buttonPressed( buttonId );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+
+        Group group = BaseWidgetUtils.createGroup( composite, "Group attributes", 1 );
+        GridData gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL );
+        gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
+        group.setLayoutData( gd );
+
+        objectClassAndMustAttributesFirstButton = BaseWidgetUtils.createCheckbox( group,
+            "ObjectClass and must attributes first", 1 );
+        objectClassAndMustAttributesFirstButton.setSelection( preferences.isObjectClassAndMustAttributesFirst() );
+
+        operationalAttributesLastButton = BaseWidgetUtils.createCheckbox( group, "Operational attributes last", 1 );
+        operationalAttributesLastButton.setSelection( preferences.isOperationalAttributesLast() );
+
+        Group sortingGroup = BaseWidgetUtils.createGroup( composite, "Sort attributes", 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_ATTRIBUTE, SORT_BY_VALUE }, 0, 1 );
+        sortByCombo.select( preferences.getDefaultSortBy() == BrowserCoreConstants.SORT_BY_VALUE ? 2 : preferences
+            .getDefaultSortBy() == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION ? 1 : 0 );
+        sortByCombo.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+                sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+            }
+        } );
+
+        sortAcendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, "Ascending", 1 );
+        sortAcendingButton
+            .setSelection( preferences.getDefaultSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING );
+        sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+
+        sortDescendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, "Descending", 1 );
+        sortDescendingButton
+            .setSelection( preferences.getDefaultSortOrder() == BrowserCoreConstants.SORT_ORDER_DESCENDING );
+        sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+
+        BaseWidgetUtils.createSpacer( composite, 2 );
+
+        BaseWidgetUtils.createLabel( composite,
+            "Please click to table headers to sort by attribute description or value.", 1 );
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetTableMetadata.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetTableMetadata.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetTableMetadata.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetTableMetadata.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor;
+
+
+/**
+ * The EntryEditorWidgetTableMetadata interface contains some constants used
+ * by the entry editor widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface EntryEditorWidgetTableMetadata
+{
+
+    /** The Constant KEY_COLUMN_INDEX. */
+    public static final int KEY_COLUMN_INDEX = 0;
+
+    /** The Constant VALUE_COLUMN_INDEX. */
+    public static final int VALUE_COLUMN_INDEX = 1;
+
+    /** The Constant KEY_COLUMN_NAME. */
+    public static final String KEY_COLUMN_NAME = "Attribute Description";
+
+    /** The Constant VALUE_COLUMN_NAME. */
+    public static final String VALUE_COLUMN_NAME = "Value";
+
+    /** The Constant COLUM_NAMES. */
+    public static final String[] COLUM_NAMES =
+        { KEY_COLUMN_NAME, VALUE_COLUMN_NAME };
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetUniversalListener.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetUniversalListener.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetUniversalListener.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,238 @@
+/*
+ *  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.entryeditor;
+
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.actions.BrowserSelectionUtils;
+import org.apache.directory.studio.ldapbrowser.core.events.BulkModificationEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueAddedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueDeletedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.EntryUpdateListener;
+import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.events.ValueAddedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.ValueDeletedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.ValueModifiedEvent;
+import org.apache.directory.studio.ldapbrowser.core.events.ValueRenamedEvent;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+
+
+/**
+ * The EntryEditorWidgetUniversalListener manages all events for the entry editor widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetUniversalListener implements EntryUpdateListener
+{
+
+    /** The tree viewer */
+    protected TreeViewer viewer;
+
+    /** The action used to start the default value editor */
+    protected OpenDefaultEditorAction startEditAction;
+
+    /** This listener starts the value editor when pressing enter */
+    protected SelectionListener viewerSelectionListener = new SelectionAdapter()
+    {
+        /**
+         * {@inheritDoc}
+         */
+        public void widgetSelected( SelectionEvent e )
+        {
+        }
+
+
+        /**
+         * {@inheritDoc}
+         *
+         * This implementation starts the value editor.
+         */
+        public void widgetDefaultSelected( SelectionEvent e )
+        {
+            if ( startEditAction.isEnabled() )
+            {
+                startEditAction.run();
+            }
+        }
+    };
+
+    /** This listener starts the value editor or expands/collapses the selected attribute */
+    protected MouseListener viewerMouseListener = new MouseAdapter()
+    {
+        /**
+         * {@inheritDoc}
+         *
+         * This implementation starts the value editor or expands/collapses the selected attribute.
+         */
+        public void mouseDoubleClick( MouseEvent e )
+        {
+            IAttribute[] attributes = BrowserSelectionUtils.getAttributes( viewer.getSelection() );
+            IValue[] values = BrowserSelectionUtils.getValues( viewer.getSelection() );
+            if ( attributes.length == 1 && values.length == 0 )
+            {
+                if ( viewer.getExpandedState( attributes[0] ) )
+                {
+                    viewer.collapseToLevel( attributes[0], 1 );
+                }
+                else
+                {
+                    viewer.expandToLevel( attributes[0], 1 );
+                }
+            }
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void mouseDown( MouseEvent e )
+        {
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void mouseUp( MouseEvent e )
+        {
+        }
+    };
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetUniversalListener.
+     *
+     * @param treeViewer the tree viewer
+     * @param startEditAction the action used to start the default value editor
+     */
+    public EntryEditorWidgetUniversalListener( TreeViewer treeViewer, OpenDefaultEditorAction startEditAction )
+    {
+        this.startEditAction = startEditAction;
+        this.viewer = treeViewer;
+
+        // register listeners
+        viewer.getTree().addSelectionListener( viewerSelectionListener  );
+        viewer.getTree().addMouseListener( viewerMouseListener  );
+        EventRegistry.addEntryUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() );
+    }
+
+
+    /**
+     * Disposes this universal listener.
+     */
+    public void dispose()
+    {
+        if ( viewer != null )
+        {
+            EventRegistry.removeEntryUpdateListener( this );
+
+            startEditAction = null;
+            viewer = null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     *
+     * This implementation refreshes the viewer and selects a value depending
+     * on the event.
+     */
+    public void entryUpdated( EntryModificationEvent event )
+    {
+
+        if ( viewer == null || viewer.getTree() == null || viewer.getTree().isDisposed() || viewer.getInput() == null
+            || ( event.getModifiedEntry() != viewer.getInput() && !( event instanceof BulkModificationEvent ) ) )
+        {
+            return;
+        }
+
+        // force closing of cell editors
+        if ( viewer.isCellEditorActive() )
+        {
+            viewer.cancelEditing();
+        }
+
+        // refresh
+        viewer.refresh();
+
+        // selection value
+        if ( event instanceof ValueAddedEvent )
+        {
+            // select the vadded value
+            ValueAddedEvent vaEvent = ( ValueAddedEvent ) event;
+            viewer.setSelection( new StructuredSelection( vaEvent.getAddedValue() ), true );
+            viewer.refresh();
+        }
+        else if ( event instanceof ValueDeletedEvent )
+        {
+            // select another value of the deleted attribute
+            ValueDeletedEvent vdEvent = ( ValueDeletedEvent ) event;
+            if ( viewer.getSelection().isEmpty() && vdEvent.getDeletedValue().getAttribute().getValueSize() > 0 )
+            {
+                viewer.setSelection(
+                    new StructuredSelection( vdEvent.getDeletedValue().getAttribute().getValues()[0] ), true );
+            }
+        }
+        else if ( event instanceof EmptyValueAddedEvent )
+        {
+            // select the added value and start editing
+            EmptyValueAddedEvent evaEvent = ( EmptyValueAddedEvent ) event;
+            viewer.setSelection( new StructuredSelection( evaEvent.getAddedValue() ), true );
+            if ( startEditAction.isEnabled() )
+            {
+                startEditAction.run();
+            }
+        }
+        else if ( event instanceof EmptyValueDeletedEvent )
+        {
+            // select another value of the deleted attribute
+            EmptyValueDeletedEvent evdEvent = ( EmptyValueDeletedEvent ) event;
+            if ( viewer.getSelection().isEmpty() && evdEvent.getDeletedValue().getAttribute().getValueSize() > 0 )
+            {
+                viewer.setSelection(
+                    new StructuredSelection( evdEvent.getDeletedValue().getAttribute().getValues()[0] ), true );
+            }
+        }
+        else if ( event instanceof ValueModifiedEvent )
+        {
+            // select the modified value
+            ValueModifiedEvent vmEvent = ( ValueModifiedEvent ) event;
+            viewer.setSelection( new StructuredSelection( vmEvent.getNewValue() ), true );
+        }
+        else if ( event instanceof ValueRenamedEvent )
+        {
+            // select the renamed value
+            ValueRenamedEvent vrEvent = ( ValueRenamedEvent ) event;
+            viewer.setSelection( new StructuredSelection( vrEvent.getNewValue() ), true );
+        }
+    }
+
+}

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



Mime
View raw message