directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r526693 [13/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/entryeditor/EntryEditorWidgetActionGroupWithAttribute.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetActionGroupWithAttribute.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetActionGroupWithAttribute.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetActionGroupWithAttribute.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,162 @@
+/*
+ *  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.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.common.actions.DeleteAllValuesAction;
+import org.apache.directory.ldapstudio.browser.common.actions.NewAttributeAction;
+import org.apache.directory.ldapstudio.browser.common.actions.proxy.EntryEditorActionProxy;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+
+
+/**
+ * This class manages all the actions of the attribute page of the new entry wizard.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetActionGroupWithAttribute extends EntryEditorWidgetActionGroup
+{
+
+    /** The Constant editAttributeDescriptionAction. */
+    private static final String editAttributeDescriptionAction = "editAttributeDescriptionAction";
+
+    /** The Constant newAttributeAction. */
+    private static final String newAttributeAction = "newAttributeAction";
+
+    /** The Constant deleteAllValuesAction. */
+    private static final String deleteAllValuesAction = "deleteAllValuesAction";
+
+
+    /**
+     * 
+     * Creates a new instance of NewEntryAttributesWizardPageActionGroup.
+     *
+     * @param mainWidget
+     * @param configuration
+     */
+    public EntryEditorWidgetActionGroupWithAttribute( EntryEditorWidget mainWidget,
+        EntryEditorWidgetConfiguration configuration )
+    {
+        super( mainWidget, configuration );
+        TreeViewer viewer = mainWidget.getViewer();
+
+        entryEditorActionMap.put( editAttributeDescriptionAction, new EntryEditorActionProxy( viewer,
+            new EditAttributeDescriptionAction( viewer ) ) );
+        entryEditorActionMap.put( newAttributeAction, new EntryEditorActionProxy( viewer, new NewAttributeAction() ) );
+        entryEditorActionMap.put( deleteAllValuesAction, new EntryEditorActionProxy( viewer,
+            new DeleteAllValuesAction() ) );
+
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void fillToolBar( IToolBarManager toolBarManager )
+    {
+        toolBarManager.add( ( IAction ) entryEditorActionMap.get( newValueAction ) );
+        toolBarManager.add( ( IAction ) entryEditorActionMap.get( newAttributeAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( ( IAction ) this.entryEditorActionMap.get( deleteAction ) );
+        toolBarManager.add( ( IAction ) this.entryEditorActionMap.get( deleteAllValuesAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( this.showQuickFilterAction );
+        toolBarManager.update( true );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void contextMenuAboutToShow( IMenuManager menuManager )
+    {
+        // new
+        menuManager.add( ( IAction ) entryEditorActionMap.get( newAttributeAction ) );
+        menuManager.add( ( IAction ) entryEditorActionMap.get( newValueAction ) );
+        menuManager.add( new Separator() );
+
+        // copy, paste, delete
+        menuManager.add( ( IAction ) entryEditorActionMap.get( copyAction ) );
+        menuManager.add( ( IAction ) entryEditorActionMap.get( pasteAction ) );
+        menuManager.add( ( IAction ) entryEditorActionMap.get( deleteAction ) );
+        menuManager.add( ( IAction ) entryEditorActionMap.get( selectAllAction ) );
+        MenuManager copyMenuManager = new MenuManager( "Advanced" );
+        copyMenuManager.add( ( IAction ) entryEditorActionMap.get( deleteAllValuesAction ) );
+        menuManager.add( copyMenuManager );
+        menuManager.add( new Separator() );
+
+        // edit
+        menuManager.add( ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction ) );
+        super.addEditMenu( menuManager );
+        menuManager.add( new Separator() );
+
+        // properties
+        menuManager.add( ( IAction ) entryEditorActionMap.get( propertyDialogAction ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void activateGlobalActionHandlers()
+    {
+        super.activateGlobalActionHandlers();
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+        if ( commandService != null )
+        {
+            IAction naa = ( IAction ) entryEditorActionMap.get( newAttributeAction );
+            commandService.getCommand( naa.getActionDefinitionId() ).setHandler( new ActionHandler( naa ) );
+            IAction eada = ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction );
+            commandService.getCommand( eada.getActionDefinitionId() ).setHandler( new ActionHandler( eada ) );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void deactivateGlobalActionHandlers()
+    {
+        super.deactivateGlobalActionHandlers();
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+        if ( commandService != null )
+        {
+            IAction naa = ( IAction ) entryEditorActionMap.get( newAttributeAction );
+            commandService.getCommand( naa.getActionDefinitionId() ).setHandler( null );
+            IAction eada = ( IAction ) entryEditorActionMap.get( editAttributeDescriptionAction );
+            commandService.getCommand( eada.getActionDefinitionId() ).setHandler( null );
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetCellModifier.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetCellModifier.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetCellModifier.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetCellModifier.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,162 @@
+/*
+ *  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.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Item;
+
+
+/**
+ * The EntryEditorWidgetCellModifier implements the {@link ICellModifier} interface
+ * for the entry editor widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetCellModifier implements ICellModifier
+{
+
+    /** The value editor manager. */
+    private ValueEditorManager valueEditorManager;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetCellModifier.
+     *
+     * @param valueEditorManager
+     */
+    public EntryEditorWidgetCellModifier( ValueEditorManager valueEditorManager )
+    {
+        this.valueEditorManager = valueEditorManager;
+    }
+
+
+    /**
+     * Disposes this object.
+     */
+    public void dispose()
+    {
+        valueEditorManager = null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean canModify( Object element, String property )
+    {
+        if ( element != null && element instanceof IValue && valueEditorManager != null )
+        {
+            IValue attributeValue = ( IValue ) element;
+
+            if ( !SchemaUtils.isModifyable( attributeValue.getAttribute().getAttributeTypeDescription() ) )
+            {
+                return false;
+            }
+            if ( attributeValue.isRdnPart() )
+            {
+                return false;
+            }
+            if ( EntryEditorWidgetTableMetadata.KEY_COLUMN_NAME.equals( property ) )
+            {
+                return false;
+            }
+            if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) )
+            {
+                return this.valueEditorManager.getCurrentValueEditor( attributeValue ).getRawValue( attributeValue ) != null;
+            }
+        }
+
+        return false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object getValue( Object element, String property )
+    {
+        if ( element != null && element instanceof IValue && valueEditorManager != null )
+        {
+            IValue attributeValue = ( IValue ) element;
+            Object returnValue;
+            if ( EntryEditorWidgetTableMetadata.KEY_COLUMN_NAME.equals( property ) )
+            {
+                returnValue = attributeValue.getAttribute().getDescription();
+            }
+            else if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) )
+            {
+                returnValue = this.valueEditorManager.getCurrentValueEditor( attributeValue ).getRawValue(
+                    attributeValue );
+            }
+            else
+            {
+                returnValue = "";
+            }
+            return returnValue;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * TODO: Remove value modification from value editors 
+     */
+    public void modify( Object element, String property, Object newRawValue )
+    {
+        if ( element != null && element instanceof Item )
+        {
+            element = ( ( Item ) element ).getData();
+        }
+
+        if ( element != null && element instanceof IValue && valueEditorManager != null )
+        {
+            IValue attributeValue = ( IValue ) element;
+
+            if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) )
+            {
+                try
+                {
+                    this.valueEditorManager.getCurrentValueEditor( attributeValue ).modifyValue( attributeValue,
+                        newRawValue );
+                }
+                catch ( ModelModificationException mme )
+                {
+                    MessageDialog.openError( Display.getDefault().getActiveShell(), "Error While Modifying Value", mme
+                        .getMessage() );
+                }
+            }
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetConfiguration.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetConfiguration.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetConfiguration.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetConfiguration.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,245 @@
+/*
+ *  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.entryeditor;
+
+
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
+import org.eclipse.jface.viewers.TreeViewer;
+
+
+/**
+ * The BrowserConfiguration contains the content provider, 
+ * label provider, sorter, filter the context menu manager and the
+ * preferences for the entry editor widget. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryEditorWidgetConfiguration
+{
+
+    /** The disposed flag */
+    private boolean disposed = false;
+
+    /** The sorter. */
+    protected EntryEditorWidgetSorter sorter;
+
+    /** The filter. */
+    protected EntryEditorWidgetFilter filter;
+
+    /** The preferences. */
+    protected EntryEditorWidgetPreferences preferences;
+
+    /** The content provider. */
+    protected EntryEditorWidgetContentProvider contentProvider;
+
+    /** The label provider. */
+    protected EntryEditorWidgetLabelProvider labelProvider;
+
+    /** The cell modifier. */
+    protected EntryEditorWidgetCellModifier cellModifier;
+
+    /** The value editor manager. */
+    protected ValueEditorManager valueEditorManager;
+
+
+    /**
+     * Creates a new instance of EntryEditorWidgetConfiguration.
+     */
+    public EntryEditorWidgetConfiguration()
+    {
+    }
+
+
+    /**
+     * Disposes this configuration.
+     */
+    public void dispose()
+    {
+        if ( !disposed )
+        {
+            if ( sorter != null )
+            {
+                sorter.dispose();
+                sorter = null;
+            }
+
+            if ( filter != null )
+            {
+                filter.dispose();
+                filter = null;
+            }
+
+            if ( preferences != null )
+            {
+                preferences.dispose();
+                preferences = null;
+            }
+
+            if ( contentProvider != null )
+            {
+                contentProvider.dispose();
+                contentProvider = null;
+            }
+
+            if ( labelProvider != null )
+            {
+                labelProvider.dispose();
+                labelProvider = null;
+            }
+
+            if ( cellModifier != null )
+            {
+                cellModifier.dispose();
+                cellModifier = null;
+            }
+
+            if ( valueEditorManager != null )
+            {
+                valueEditorManager.dispose();
+                valueEditorManager = null;
+            }
+
+            disposed = true;
+        }
+    }
+
+
+    /**
+     * Gets the content provider.
+     * 
+     * @param mainWidget the main widget
+     * 
+     * @return the content provider
+     */
+    public EntryEditorWidgetContentProvider getContentProvider( EntryEditorWidget mainWidget )
+    {
+        if ( contentProvider == null )
+        {
+            contentProvider = new EntryEditorWidgetContentProvider( getPreferences(), mainWidget );
+        }
+
+        return contentProvider;
+    }
+
+
+    /**
+     * Gets the label provider.
+     * 
+     * @param viewer the viewer
+     * 
+     * @return the label provider
+     */
+    public EntryEditorWidgetLabelProvider getLabelProvider( TreeViewer viewer )
+    {
+        if ( labelProvider == null )
+        {
+            labelProvider = new EntryEditorWidgetLabelProvider( getValueEditorManager( viewer ) );
+        }
+
+        return labelProvider;
+    }
+
+
+    /**
+     * Gets the cell modifier.
+     * 
+     * @param viewer the viewer
+     * 
+     * @return the cell modifier
+     */
+    public EntryEditorWidgetCellModifier getCellModifier( TreeViewer viewer )
+    {
+        if ( cellModifier == null )
+        {
+            cellModifier = new EntryEditorWidgetCellModifier( getValueEditorManager( viewer ) );
+        }
+
+        return cellModifier;
+    }
+
+
+    /**
+     * Gets the value editor manager.
+     * 
+     * @param viewer the viewer
+     * 
+     * @return the value editor manager
+     */
+    public ValueEditorManager getValueEditorManager( TreeViewer viewer )
+    {
+        if ( valueEditorManager == null )
+        {
+            valueEditorManager = new ValueEditorManager( viewer.getTree() );
+        }
+
+        return valueEditorManager;
+    }
+
+
+    /**
+     * Gets the sorter.
+     * 
+     * @return the sorter
+     */
+    public EntryEditorWidgetSorter getSorter()
+    {
+        if ( sorter == null )
+        {
+            sorter = new EntryEditorWidgetSorter( getPreferences() );
+        }
+
+        return sorter;
+    }
+
+
+    /**
+     * Gets the filter.
+     * 
+     * @return the filter
+     */
+    public EntryEditorWidgetFilter getFilter()
+    {
+        if ( filter == null )
+        {
+            filter = new EntryEditorWidgetFilter();
+        }
+
+        return filter;
+    }
+
+
+    /**
+     * Gets the preferences.
+     * 
+     * @return the preferences
+     */
+    public EntryEditorWidgetPreferences getPreferences()
+    {
+        if ( preferences == null )
+        {
+            preferences = new EntryEditorWidgetPreferences();
+        }
+
+        return preferences;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetContentProvider.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetContentProvider.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetContentProvider.java Mon Apr  9 02:49:48 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.ldapstudio.browser.common.widgets.entryeditor;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.jobs.InitializeAttributesJob;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.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().toString();
+            }
+            else if ( newInput != null && newInput instanceof AttributeHierarchy )
+            {
+                AttributeHierarchy ah = ( AttributeHierarchy ) newInput;
+                dn = "DN: " + ah.getAttribute().getEntry().getDn().toString();
+            }
+            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

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetFilter.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetFilter.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetFilter.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetFilter.java Mon Apr  9 02:49:48 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.ldapstudio.browser.common.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.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;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java Mon Apr  9 02:49:48 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.ldapstudio.browser.common.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.valueeditors.IValueEditor;
+import org.apache.directory.ldapstudio.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;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java Mon Apr  9 02:49:48 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.ldapstudio.browser.common.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.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();
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java Mon Apr  9 02:49:48 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.ldapstudio.browser.common.widgets.entryeditor;
+
+
+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.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();
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetSorter.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetSorter.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetSorter.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/entryeditor/EntryEditorWidgetSorter.java Mon Apr  9 02:49:48 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.ldapstudio.browser.common.widgets.entryeditor;
+
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.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 );
+    }
+
+}



Mime
View raw message