directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r488371 [8/14] - in /directory/sandbox/pamarcelot/ldapstudio: ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/jobs/ ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/perspective/ ldapstudio-browser-ui...
Date Mon, 18 Dec 2006 17:57:49 GMT
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetActionGroup.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetActionGroup.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetActionGroup.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetActionGroup.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,378 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.actions.CopyAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.DeleteAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.NewValueAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.PasteAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.PropertiesAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.SelectAllAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.ShowRawValuesAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.ValueEditorPreferencesAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.proxy.BrowserActionProxy;
+import org.apache.directory.ldapstudio.browser.ui.actions.proxy.EntryEditorActionProxy;
+import org.apache.directory.ldapstudio.browser.ui.editors.entry.ShowQuickFilterAction;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProvider;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.commands.ICommandService;
+
+
+public class EntryEditorWidgetActionGroup implements IMenuListener
+{
+
+    protected OpenSortDialogAction openSortDialogAction;
+
+    protected ShowRawValuesAction showRawValuesAction;
+
+    protected ShowQuickFilterAction showQuickFilterAction;
+
+    protected OpenDefaultEditorAction openDefaultEditorAction;
+
+    protected OpenBestEditorAction openBestEditorAction;
+
+    protected OpenEditorAction[] openEditorActions;
+
+    protected ValueEditorPreferencesAction openValueEditorPreferencesAction;
+
+    protected final static String newValueAction = "newValueAction";
+
+    protected final static String copyAction = "copyAction";
+
+    protected final static String pasteAction = "pasteAction";
+
+    protected final static String deleteAction = "deleteAction";
+
+    protected final static String selectAllAction = "selectAllAction";
+
+    protected final static String propertyDialogAction = "propertyDialogAction";
+
+    protected Map entryEditorActionMap;
+
+    protected IActionBars actionBars;
+
+    private EntryEditorWidget mainWidget;
+
+
+    public EntryEditorWidgetActionGroup( EntryEditorWidget mainWidget, EntryEditorWidgetConfiguration configuration )
+    {
+
+        this.mainWidget = mainWidget;
+        this.entryEditorActionMap = new HashMap();
+        TreeViewer viewer = mainWidget.getViewer();
+
+        this.openSortDialogAction = new OpenSortDialogAction( configuration.getPreferences() );
+        this.showRawValuesAction = new ShowRawValuesAction();
+        this.showQuickFilterAction = new ShowQuickFilterAction( mainWidget.getQuickFilterWidget() );
+
+        this.openBestEditorAction = new OpenBestEditorAction( viewer, this, configuration
+            .getValueProviderManager( viewer ) );
+        this.openDefaultEditorAction = new OpenDefaultEditorAction( viewer, this.openBestEditorAction );
+        ValueProvider[] valueProviders = configuration.getValueProviderManager( viewer ).getAllValueProviders();
+        this.openEditorActions = new OpenEditorAction[valueProviders.length];
+        for ( int i = 0; i < this.openEditorActions.length; i++ )
+        {
+            this.openEditorActions[i] = new OpenEditorAction( viewer, this, configuration
+                .getValueProviderManager( viewer ), valueProviders[i] );
+        }
+        this.openValueEditorPreferencesAction = new ValueEditorPreferencesAction();
+
+        this.entryEditorActionMap.put( newValueAction, new EntryEditorActionProxy( viewer, new NewValueAction() ) );
+
+        this.entryEditorActionMap.put( pasteAction, new EntryEditorActionProxy( viewer, new PasteAction() ) );
+        this.entryEditorActionMap.put( copyAction, new EntryEditorActionProxy( viewer, new CopyAction(
+            ( BrowserActionProxy ) this.entryEditorActionMap.get( pasteAction ) ) ) );
+        this.entryEditorActionMap.put( deleteAction, new EntryEditorActionProxy( viewer, new DeleteAction() ) );
+        this.entryEditorActionMap.put( selectAllAction, new EntryEditorActionProxy( viewer,
+            new SelectAllAction( viewer ) ) );
+
+        this.entryEditorActionMap.put( propertyDialogAction,
+            new EntryEditorActionProxy( viewer, new PropertiesAction() ) );
+
+    }
+
+
+    public void dispose()
+    {
+        if ( this.mainWidget != null )
+        {
+
+            this.openSortDialogAction = null;
+            this.showQuickFilterAction.dispose();
+            this.showQuickFilterAction = null;
+            this.showRawValuesAction.dispose();
+            this.showRawValuesAction = null;
+
+            this.openDefaultEditorAction.dispose();
+            this.openDefaultEditorAction = null;
+            this.openBestEditorAction.dispose();
+            this.openBestEditorAction = null;
+            for ( int i = 0; i < this.openEditorActions.length; i++ )
+            {
+                this.openEditorActions[i].dispose();
+                this.openEditorActions[i] = null;
+            }
+            this.openValueEditorPreferencesAction.dispose();
+            this.openValueEditorPreferencesAction = null;
+
+            for ( Iterator it = this.entryEditorActionMap.keySet().iterator(); it.hasNext(); )
+            {
+                String key = ( String ) it.next();
+                EntryEditorActionProxy action = ( EntryEditorActionProxy ) this.entryEditorActionMap.get( key );
+                action.dispose();
+                action = null;
+                it.remove();
+            }
+            this.entryEditorActionMap.clear();
+            this.entryEditorActionMap = null;
+
+            this.actionBars = null;
+            this.mainWidget = null;
+        }
+
+    }
+
+
+    public void enableGlobalActionHandlers( IActionBars actionBars )
+    {
+        this.actionBars = actionBars;
+        this.activateGlobalActionHandlers();
+    }
+
+
+    public void fillToolBar( IToolBarManager toolBarManager )
+    {
+
+        toolBarManager.add( ( IAction ) this.entryEditorActionMap.get( newValueAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( ( IAction ) this.entryEditorActionMap.get( deleteAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( this.showQuickFilterAction );
+        toolBarManager.update( true );
+
+    }
+
+
+    public void fillMenu( IMenuManager menuManager )
+    {
+        menuManager.add( this.openSortDialogAction );
+        menuManager.add( this.showRawValuesAction );
+        menuManager.addMenuListener( new IMenuListener()
+        {
+            public void menuAboutToShow( IMenuManager manager )
+            {
+                showRawValuesAction.setChecked( BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+                    BrowserUIConstants.PREFERENCE_SHOW_RAW_VALUES ) );
+            }
+        } );
+    }
+
+
+    public void fillContextMenu( IMenuManager menuManager )
+    {
+        menuManager.setRemoveAllWhenShown( true );
+        menuManager.addMenuListener( this );
+    }
+
+
+    public void menuAboutToShow( IMenuManager menuManager )
+    {
+
+        // new
+        menuManager.add( ( IAction ) this.entryEditorActionMap.get( newValueAction ) );
+        menuManager.add( new Separator() );
+
+        // copy, paste, delete
+        menuManager.add( ( IAction ) this.entryEditorActionMap.get( copyAction ) );
+        menuManager.add( ( IAction ) this.entryEditorActionMap.get( pasteAction ) );
+        menuManager.add( ( IAction ) this.entryEditorActionMap.get( deleteAction ) );
+        menuManager.add( ( IAction ) this.entryEditorActionMap.get( selectAllAction ) );
+        menuManager.add( new Separator() );
+
+        // edit
+        addEditMenu( menuManager );
+        menuManager.add( new Separator() );
+
+        // properties
+        menuManager.add( ( IAction ) this.entryEditorActionMap.get( propertyDialogAction ) );
+    }
+
+
+    protected void addEditMenu( IMenuManager menuManager )
+    {
+        // edit
+        menuManager.add( this.openDefaultEditorAction );
+        MenuManager editorMenuManager = new MenuManager( "Edit Value With" );
+        if ( this.openBestEditorAction.isEnabled() )
+        {
+            editorMenuManager.add( this.openBestEditorAction );
+            editorMenuManager.add( new Separator() );
+        }
+        for ( int i = 0; i < this.openEditorActions.length; i++ )
+        {
+            if ( this.openEditorActions[i].isEnabled()
+                && this.openEditorActions[i].getValueProvider().getClass() != this.openBestEditorAction
+                    .getBestValueProvider().getClass() )
+            {
+                editorMenuManager.add( this.openEditorActions[i] );
+            }
+        }
+        editorMenuManager.add( new Separator() );
+        editorMenuManager.add( this.openValueEditorPreferencesAction );
+        menuManager.add( editorMenuManager );
+    }
+
+
+    public void activateGlobalActionHandlers()
+    {
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( this.actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), ( IAction ) this.entryEditorActionMap
+                .get( copyAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), ( IAction ) this.entryEditorActionMap
+                .get( pasteAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), ( IAction ) this.entryEditorActionMap
+                .get( deleteAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.SELECT_ALL.getId(), ( IAction ) this.entryEditorActionMap
+                .get( selectAllAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), ( IAction ) this.entryEditorActionMap
+                .get( propertyDialogAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.FIND.getId(), this.showQuickFilterAction ); // IWorkbenchActionDefinitionIds.FIND_REPLACE
+
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction da = ( IAction ) this.entryEditorActionMap.get( deleteAction );
+                da.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.delete" );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( new ActionHandler( da ) );
+
+                IAction ca = ( IAction ) this.entryEditorActionMap.get( copyAction );
+                ca.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.copy" );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( new ActionHandler( ca ) );
+
+                IAction pa = ( IAction ) this.entryEditorActionMap.get( pasteAction );
+                pa.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.paste" );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( new ActionHandler( pa ) );
+
+                showQuickFilterAction.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.find" );
+                commandService.getCommand( showQuickFilterAction.getActionDefinitionId() ).setHandler(
+                    new ActionHandler( showQuickFilterAction ) );
+
+                IAction pda = ( IAction ) this.entryEditorActionMap.get( propertyDialogAction );
+                pda.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.properties" );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( new ActionHandler( pda ) );
+            }
+        }
+
+        if ( commandService != null )
+        {
+            IAction nva = ( IAction ) this.entryEditorActionMap.get( newValueAction );
+            commandService.getCommand( nva.getActionDefinitionId() ).setHandler( new ActionHandler( nva ) );
+            commandService.getCommand( openDefaultEditorAction.getActionDefinitionId() ).setHandler(
+                new ActionHandler( openDefaultEditorAction ) );
+        }
+
+    }
+
+
+    public void deactivateGlobalActionHandlers()
+    {
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( this.actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.SELECT_ALL.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.FIND.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), null );
+
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction da = ( IAction ) this.entryEditorActionMap.get( deleteAction );
+                commandService.getCommand( da.getActionDefinitionId() ).setHandler( null );
+
+                IAction ca = ( IAction ) this.entryEditorActionMap.get( copyAction );
+                commandService.getCommand( ca.getActionDefinitionId() ).setHandler( null );
+
+                IAction pa = ( IAction ) this.entryEditorActionMap.get( pasteAction );
+                commandService.getCommand( pa.getActionDefinitionId() ).setHandler( null );
+
+                commandService.getCommand( showQuickFilterAction.getActionDefinitionId() ).setHandler( null );
+
+                IAction pda = ( IAction ) this.entryEditorActionMap.get( propertyDialogAction );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( null );
+            }
+        }
+
+        if ( commandService != null )
+        {
+            IAction nva = ( IAction ) this.entryEditorActionMap.get( newValueAction );
+            commandService.getCommand( nva.getActionDefinitionId() ).setHandler( null );
+            commandService.getCommand( openDefaultEditorAction.getActionDefinitionId() ).setHandler( null );
+        }
+
+    }
+
+
+    public OpenBestEditorAction getOpenBestEditorAction()
+    {
+        return openBestEditorAction;
+    }
+
+
+    public OpenDefaultEditorAction getOpenDefaultEditorAction()
+    {
+        return openDefaultEditorAction;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetCellModifier.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetCellModifier.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetCellModifier.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetCellModifier.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,149 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.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.browser.ui.valueproviders.ValueProviderManager;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Item;
+
+
+public class EntryEditorWidgetCellModifier implements ICellModifier
+{
+
+    private ValueProviderManager valueProviderManager;
+
+
+    public EntryEditorWidgetCellModifier( ValueProviderManager valueProviderManager )
+    {
+        this.valueProviderManager = valueProviderManager;
+    }
+
+
+    public void dispose()
+    {
+        this.valueProviderManager = null;
+    }
+
+
+    public boolean canModify( Object element, String property )
+    {
+        if ( element != null && element instanceof IValue )
+        {
+            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.valueProviderManager.getCurrentValueProvider( attributeValue ).getRawValue( attributeValue ) != null;
+            }
+        }
+
+        return false;
+    }
+
+
+    public Object getValue( Object element, String property )
+    {
+        if ( element != null && element instanceof IValue )
+        {
+            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.valueProviderManager.getCurrentValueProvider( attributeValue ).getRawValue(
+                    attributeValue );
+            }
+            else
+            {
+                returnValue = "";
+            }
+            return returnValue;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    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 )
+        {
+            IValue attributeValue = ( IValue ) element;
+
+            if ( EntryEditorWidgetTableMetadata.KEY_COLUMN_NAME.equals( property ) )
+            {
+                // no modification
+            }
+            else if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) )
+            {
+                try
+                {
+                    this.valueProviderManager.getCurrentValueProvider( attributeValue ).modify( attributeValue,
+                        newRawValue );
+                }
+                catch ( ModelModificationException mme )
+                {
+                    MessageDialog.openError( Display.getDefault().getActiveShell(), "Error While Modifying Value", mme
+                        .getMessage() );
+                }
+            }
+            else
+            {
+                // no modification
+            }
+        }
+        else
+        {
+            ;
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetConfiguration.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetConfiguration.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetConfiguration.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,153 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProviderManager;
+import org.eclipse.jface.viewers.TreeViewer;
+
+
+public class EntryEditorWidgetConfiguration
+{
+
+    private boolean disposed = false;
+
+    protected EntryEditorWidgetSorter sorter;
+
+    protected EntryEditorWidgetFilter filter;
+
+    protected EntryEditorWidgetPreferences preferences;
+
+    protected EntryEditorWidgetContentProvider contentProvider;
+
+    protected EntryEditorWidgetLabelProvider labelProvider;
+
+    protected EntryEditorWidgetCellModifier cellModifier;
+
+    protected ValueProviderManager valueProviderManager;
+
+
+    public EntryEditorWidgetConfiguration()
+    {
+    }
+
+
+    public void dispose()
+    {
+        if ( !this.disposed )
+        {
+
+            if ( this.sorter != null )
+                this.sorter.dispose();
+            this.sorter = null;
+
+            if ( this.filter != null )
+                this.filter.dispose();
+            this.filter = null;
+
+            if ( this.preferences != null )
+                this.preferences.dispose();
+            this.preferences = null;
+
+            if ( this.contentProvider != null )
+                this.contentProvider.dispose();
+            this.contentProvider = null;
+
+            if ( this.labelProvider != null )
+                this.labelProvider.dispose();
+            this.labelProvider = null;
+
+            if ( this.cellModifier != null )
+                this.cellModifier.dispose();
+            this.cellModifier = null;
+
+            if ( this.valueProviderManager != null )
+                this.valueProviderManager.dispose();
+            this.valueProviderManager = null;
+
+            this.disposed = true;
+        }
+    }
+
+
+    public EntryEditorWidgetContentProvider getContentProvider( EntryEditorWidget mainWidget )
+    {
+        if ( this.contentProvider == null )
+            this.contentProvider = new EntryEditorWidgetContentProvider( this.getPreferences(), mainWidget );
+
+        return contentProvider;
+    }
+
+
+    public EntryEditorWidgetLabelProvider getLabelProvider( TreeViewer viewer )
+    {
+        if ( this.labelProvider == null )
+            this.labelProvider = new EntryEditorWidgetLabelProvider( this.getValueProviderManager( viewer ) );
+
+        return labelProvider;
+    }
+
+
+    public EntryEditorWidgetCellModifier getCellModifier( TreeViewer viewer )
+    {
+        if ( this.cellModifier == null )
+            this.cellModifier = new EntryEditorWidgetCellModifier( this.getValueProviderManager( viewer ) );
+
+        return cellModifier;
+    }
+
+
+    public ValueProviderManager getValueProviderManager( TreeViewer viewer )
+    {
+        if ( this.valueProviderManager == null )
+            this.valueProviderManager = new ValueProviderManager( viewer.getTree() );
+
+        return valueProviderManager;
+    }
+
+
+    public EntryEditorWidgetSorter getSorter()
+    {
+        if ( this.sorter == null )
+            this.sorter = new EntryEditorWidgetSorter( getPreferences() );
+
+        return sorter;
+    }
+
+
+    public EntryEditorWidgetFilter getFilter()
+    {
+        if ( this.filter == null )
+            this.filter = new EntryEditorWidgetFilter();
+
+        return filter;
+    }
+
+
+    public EntryEditorWidgetPreferences getPreferences()
+    {
+        if ( this.preferences == null )
+            this.preferences = new EntryEditorWidgetPreferences();
+
+        return preferences;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetContentProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetContentProvider.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetContentProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetContentProvider.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,185 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.jobs.InitializeAttributesJob;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierachie;
+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.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+public class EntryEditorWidgetContentProvider implements ITreeContentProvider
+{
+
+    protected EntryEditorWidgetPreferences preferences;
+
+    protected EntryEditorWidget mainWidget;
+
+
+    public EntryEditorWidgetContentProvider( EntryEditorWidgetPreferences preferences, EntryEditorWidget mainWidget )
+    {
+        this.preferences = preferences;
+        this.mainWidget = mainWidget;
+    }
+
+
+    public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+    {
+
+        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 AttributeHierachie )
+        {
+            AttributeHierachie ah = ( AttributeHierachie ) newInput;
+            dn = "DN: " + ah.getAttribute().getEntry().getDn().toString();
+        }
+        else
+        {
+            dn = "No entry selected";
+            enabled = false;
+        }
+
+        if ( this.mainWidget.getInfoText() != null && !this.mainWidget.getInfoText().isDisposed() )
+        {
+            this.mainWidget.getInfoText().setText( dn );
+        }
+        if ( this.mainWidget.getQuickFilterWidget() != null )
+        {
+            this.mainWidget.getQuickFilterWidget().setEnabled( enabled );
+        }
+        if ( this.mainWidget.getViewer() != null && !this.mainWidget.getViewer().getTree().isDisposed() )
+        {
+            this.mainWidget.getViewer().getTree().setEnabled( enabled );
+        }
+    }
+
+
+    public void dispose()
+    {
+    }
+
+
+    public Object[] getElements( Object inputElement )
+    {
+
+        if ( inputElement != null && inputElement instanceof IEntry )
+        {
+            IEntry entry = ( IEntry ) inputElement;
+
+            if ( !entry.isAttributesInitialized() && entry.isDirectoryEntry() )
+            {
+                boolean soa = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+                    BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES );
+                InitializeAttributesJob job = new InitializeAttributesJob( new IEntry[]
+                    { entry }, soa );
+                job.execute();
+                return new Object[]
+                    {};
+            }
+            else
+            {
+                IAttribute[] attributes = entry.getAttributes();
+                Object[] values = getValues( attributes );
+                return values;
+            }
+        }
+        else if ( inputElement != null && inputElement instanceof AttributeHierachie )
+        {
+            AttributeHierachie ah = ( AttributeHierachie ) inputElement;
+            IAttribute[] attributes = ah.getAttributes();
+            Object[] values = getValues( attributes );
+            return values;
+        }
+        else
+        {
+            return new Object[]
+                {};
+        }
+    }
+
+
+    private Object[] getValues( IAttribute[] attributes )
+    {
+        List valueList = new ArrayList();
+        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
+            {
+                valueList.add( attributes[i] );
+            }
+        }
+        return valueList.toArray();
+    }
+
+
+    public Object[] getChildren( Object parentElement )
+    {
+        if ( parentElement instanceof IAttribute )
+        {
+            IAttribute attribute = ( IAttribute ) parentElement;
+            IValue[] values = attribute.getValues();
+            return values;
+        }
+        return null;
+    }
+
+
+    public Object getParent( Object element )
+    {
+        if ( element instanceof IValue )
+        {
+            return ( ( IValue ) element ).getAttribute();
+        }
+        return null;
+    }
+
+
+    public boolean hasChildren( Object element )
+    {
+        return ( element instanceof IAttribute );
+    }
+
+}
\ No newline at end of file

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetFilter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetFilter.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetFilter.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetFilter.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,220 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import java.util.ArrayList;
+
+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;
+
+
+public class EntryEditorWidgetFilter extends ViewerFilter
+{
+
+    protected TreeViewer viewer;
+
+    protected String quickFilterAttribute;
+
+    protected String quickFilterValue;
+
+
+    public EntryEditorWidgetFilter()
+    {
+        this.quickFilterAttribute = "";
+        this.quickFilterValue = "";
+    }
+
+
+    public void connect( TreeViewer viewer )
+    {
+        this.viewer = viewer;
+        this.viewer.addFilter( this );
+    }
+
+
+    public Object[] filter( Viewer viewer, Object parent, Object[] elements )
+    {
+
+        int size = elements.length;
+        ArrayList out = new ArrayList( size );
+        for ( int i = 0; i < size; ++i )
+        {
+            Object element = elements[i];
+            if ( select( viewer, parent, element ) )
+                out.add( element );
+        }
+
+        return out.toArray();
+    }
+
+
+    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 ( this.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 ( !this.goesThroughQuickFilter( value ) )
+            {
+                return false;
+            }
+
+            // filter attribute types
+            if ( value.getAttribute().isObjectClassAttribute() )
+                return this.isShowObjectClassAttribute();
+            else if ( value.getAttribute().isMustAttribute() )
+                return this.isShowMustAttributes();
+            else if ( value.getAttribute().isMayAttribute() )
+                return this.isShowMayAttributes();
+            else if ( value.getAttribute().isOperationalAttribute() )
+                return this.isShowOperationalAttributes();
+            else
+                return true;
+        }
+        else
+        {
+            return true;
+        }
+    }
+
+
+    private boolean goesThroughQuickFilter( IValue value )
+    {
+        // filter attribute description
+        if ( this.quickFilterAttribute != null && !"".equals( this.quickFilterAttribute ) )
+        {
+            if ( value.getAttribute().getDescription().toUpperCase().indexOf( this.quickFilterAttribute.toUpperCase() ) == -1 )
+            {
+                return false;
+            }
+        }
+
+        // fitler value
+        if ( this.quickFilterValue != null && !"".equals( this.quickFilterValue ) )
+        {
+            if ( value.isString()
+                && value.getStringValue().toUpperCase().indexOf( this.quickFilterValue.toUpperCase() ) == -1 )
+            {
+                return false;
+            }
+            else if ( value.isBinary() )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+
+    public void dispose()
+    {
+        this.viewer = null;
+    }
+
+
+    public String getQuickFilterAttribute()
+    {
+        return quickFilterAttribute;
+    }
+
+
+    public void setQuickFilterAttribute( String quickFilterAttribute )
+    {
+        if ( !this.quickFilterAttribute.equals( quickFilterAttribute ) )
+        {
+            this.quickFilterAttribute = quickFilterAttribute;
+            if ( this.viewer != null )
+                this.viewer.refresh();
+        }
+    }
+
+
+    public String getQuickFilterValue()
+    {
+        return quickFilterValue;
+    }
+
+
+    public void setQuickFilterValue( String quickFilterValue )
+    {
+        if ( !this.quickFilterValue.equals( quickFilterValue ) )
+        {
+            this.quickFilterValue = quickFilterValue;
+            if ( this.viewer != null )
+                this.viewer.refresh();
+        }
+    }
+
+
+    public boolean isShowMayAttributes()
+    {
+        return true;
+    }
+
+
+    public boolean isShowMustAttributes()
+    {
+        return true;
+    }
+
+
+    public boolean isShowObjectClassAttribute()
+    {
+        return true;
+    }
+
+
+    public boolean isShowOperationalAttributes()
+    {
+        return true;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetLabelProvider.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetLabelProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetLabelProvider.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,251 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProviderManager;
+
+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;
+
+
+public class EntryEditorWidgetLabelProvider extends LabelProvider implements ITableLabelProvider, IFontProvider,
+    IColorProvider
+{
+
+    private ValueProviderManager valueProviderManager;
+
+
+    public EntryEditorWidgetLabelProvider( ValueProviderManager valueProviderManager )
+    {
+        this.valueProviderManager = valueProviderManager;
+    }
+
+
+    public void dispose()
+    {
+        super.dispose();
+        this.valueProviderManager = null;
+    }
+
+
+    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:
+                    ValueProvider vp = this.valueProviderManager.getCurrentValueProvider( 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 "";
+        }
+    }
+
+
+    public final Image getColumnImage( Object element, int index )
+    {
+        return null;
+    }
+
+
+    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( BrowserUIPlugin.getDefault()
+                    .getPreferenceStore(), BrowserUIConstants.PREFERENCE_ERROR_FONT );
+                return BrowserUIPlugin.getDefault().getFont( fontData );
+            }
+        }
+        if ( attribute != null && value == null )
+        {
+            if ( !attribute.isConsistent() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+                    .getPreferenceStore(), BrowserUIConstants.PREFERENCE_ERROR_FONT );
+                return BrowserUIPlugin.getDefault().getFont( fontData );
+            }
+        }
+
+        // attribute type
+        if ( attribute != null )
+        {
+            if ( attribute.isObjectClassAttribute() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+                    .getPreferenceStore(), BrowserUIConstants.PREFERENCE_OBJECTCLASS_FONT );
+                return BrowserUIPlugin.getDefault().getFont( fontData );
+            }
+            else if ( attribute.isMustAttribute() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+                    .getPreferenceStore(), BrowserUIConstants.PREFERENCE_MUSTATTRIBUTE_FONT );
+                return BrowserUIPlugin.getDefault().getFont( fontData );
+            }
+            else if ( attribute.isOperationalAttribute() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+                    .getPreferenceStore(), BrowserUIConstants.PREFERENCE_OPERATIONALATTRIBUTE_FONT );
+                return BrowserUIPlugin.getDefault().getFont( fontData );
+            }
+            else
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+                    .getPreferenceStore(), BrowserUIConstants.PREFERENCE_MAYATTRIBUTE_FONT );
+                return BrowserUIPlugin.getDefault().getFont( fontData );
+            }
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    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( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                    BrowserUIConstants.PREFERENCE_ERROR_COLOR );
+                return BrowserUIPlugin.getDefault().getColor( rgb );
+            }
+        }
+        if ( attribute != null && value == null )
+        {
+            if ( !attribute.isConsistent() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                    BrowserUIConstants.PREFERENCE_ERROR_COLOR );
+                return BrowserUIPlugin.getDefault().getColor( rgb );
+            }
+        }
+
+        // attribute type
+        if ( attribute != null )
+        {
+            if ( attribute.isObjectClassAttribute() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                    BrowserUIConstants.PREFERENCE_OBJECTCLASS_COLOR );
+                return BrowserUIPlugin.getDefault().getColor( rgb );
+            }
+            else if ( attribute.isMustAttribute() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                    BrowserUIConstants.PREFERENCE_MUSTATTRIBUTE_COLOR );
+                return BrowserUIPlugin.getDefault().getColor( rgb );
+            }
+            else if ( attribute.isOperationalAttribute() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                    BrowserUIConstants.PREFERENCE_OPERATIONALATTRIBUTE_COLOR );
+                return BrowserUIPlugin.getDefault().getColor( rgb );
+            }
+            else
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                    BrowserUIConstants.PREFERENCE_MAYATTRIBUTE_COLOR );
+                return BrowserUIPlugin.getDefault().getColor( rgb );
+            }
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    public Color getBackground( Object element )
+    {
+        return null;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetPreferences.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetPreferences.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetPreferences.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetPreferences.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,135 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+
+
+public class EntryEditorWidgetPreferences implements IPropertyChangeListener
+{
+
+    protected Viewer viewer;
+
+
+    public EntryEditorWidgetPreferences()
+    {
+        BrowserUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( this );
+    }
+
+
+    public void connect( TreeViewer viewer )
+    {
+        this.viewer = viewer;
+    }
+
+
+    public void dispose()
+    {
+        BrowserUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( this );
+        this.viewer = null;
+    }
+
+
+    public boolean isUseFolding()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING );
+    }
+
+
+    public int getFoldingThreshold()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getInt(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD );
+    }
+
+
+    public boolean isShowMayAttributes()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES );
+    }
+
+
+    public boolean isShowMustAttributes()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES );
+    }
+
+
+    public boolean isShowObjectClassAttribute()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES );
+    }
+
+
+    public boolean isShowOperationalAttributes()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES );
+    }
+
+
+    public boolean isObjectClassAndMustAttributesFirst()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST );
+    }
+
+
+    public boolean isOperationalAttributesLast()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST );
+    }
+
+
+    public int getDefaultSortBy()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getInt(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY );
+    }
+
+
+    public int getDefaultSortOrder()
+    {
+        return BrowserUIPlugin.getDefault().getPreferenceStore().getInt(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER );
+    }
+
+
+    public void propertyChange( PropertyChangeEvent event )
+    {
+        if ( this.viewer != null )
+        {
+            this.viewer.refresh();
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,233 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.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;
+
+
+public class EntryEditorWidgetQuickFilterWidget
+{
+
+    private EntryEditorWidgetFilter filter;
+
+    private EntryEditorWidget entryEditorWidget;
+
+    private Composite parent;
+
+    private Composite composite;
+
+    private Composite innerComposite;
+
+    private Text quickFilterAttributeText;
+
+    private Text quickFilterValueText;
+
+    private Button clearQuickFilterButton;
+
+
+    public EntryEditorWidgetQuickFilterWidget( EntryEditorWidgetFilter filter, EntryEditorWidget entryEditorWidget )
+    {
+        this.filter = filter;
+        this.entryEditorWidget = entryEditorWidget;
+    }
+
+
+    public void createComposite( Composite parent )
+    {
+        this.parent = parent;
+
+        this.composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+        GridLayout gl = new GridLayout();
+        gl.marginHeight = 2;
+        gl.marginWidth = 2;
+        composite.setLayout( gl );
+
+        this.innerComposite = null;
+    }
+
+
+    private void create()
+    {
+        innerComposite = BaseWidgetUtils.createColumnContainer( this.composite, 3, 1 );
+
+        this.quickFilterAttributeText = new Text( innerComposite, SWT.BORDER );
+        this.quickFilterAttributeText.setLayoutData( new GridData( 200 - 14, SWT.DEFAULT ) );
+        this.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( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                        BrowserUIConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR );
+                    RGB bgRgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                        BrowserUIConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR );
+                    Color fgColor = BrowserUIPlugin.getDefault().getColor( fgRgb );
+                    Color bgColor = BrowserUIPlugin.getDefault().getColor( bgRgb );
+                    quickFilterAttributeText.setForeground( fgColor );
+                    quickFilterAttributeText.setBackground( bgColor );
+                    FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+                        .getPreferenceStore(), BrowserUIConstants.PREFERENCE_QUICKFILTER_FONT );
+                    Font font = BrowserUIPlugin.getDefault().getFont( fontData );
+                    quickFilterAttributeText.setFont( font );
+                }
+                else
+                {
+                    quickFilterAttributeText.setBackground( null );
+                }
+            }
+        } );
+
+        this.quickFilterValueText = new Text( innerComposite, SWT.BORDER );
+        this.quickFilterValueText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        this.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( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                        BrowserUIConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR );
+                    RGB bgRgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+                        BrowserUIConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR );
+                    Color fgColor = BrowserUIPlugin.getDefault().getColor( fgRgb );
+                    Color bgColor = BrowserUIPlugin.getDefault().getColor( bgRgb );
+                    quickFilterValueText.setForeground( fgColor );
+                    quickFilterValueText.setBackground( bgColor );
+                    FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+                        .getPreferenceStore(), BrowserUIConstants.PREFERENCE_QUICKFILTER_FONT );
+                    Font font = BrowserUIPlugin.getDefault().getFont( fontData );
+                    quickFilterValueText.setFont( font );
+                }
+                else
+                {
+                    quickFilterValueText.setBackground( null );
+                }
+            }
+        } );
+
+        this.clearQuickFilterButton = new Button( innerComposite, SWT.PUSH );
+        this.clearQuickFilterButton.setToolTipText( "Clear Quick Filter" );
+        this.clearQuickFilterButton.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_CLEAR ) );
+        this.clearQuickFilterButton.setEnabled( false );
+        this.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 );
+    }
+
+
+    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 );
+    }
+
+
+    public void dispose()
+    {
+        if ( this.filter != null )
+        {
+            this.quickFilterAttributeText = null;
+            this.quickFilterValueText = null;
+            this.clearQuickFilterButton = null;
+            this.innerComposite = null;
+            this.composite.dispose();
+            this.composite = null;
+            this.parent = null;
+            this.filter = null;
+        }
+    }
+
+
+    public void setEnabled( boolean enabled )
+    {
+        if ( this.composite != null && !this.composite.isDisposed() )
+        {
+            this.composite.setEnabled( enabled );
+        }
+        if ( this.innerComposite != null && !this.innerComposite.isDisposed() )
+        {
+            this.innerComposite.setEnabled( enabled );
+            this.quickFilterAttributeText.setEnabled( enabled );
+            this.quickFilterValueText.setEnabled( enabled );
+            this.clearQuickFilterButton.setEnabled( enabled );
+        }
+    }
+
+
+    public void setActive( boolean visible )
+    {
+        if ( visible && this.innerComposite == null && composite != null )
+        {
+            create();
+            this.quickFilterAttributeText.setFocus();
+        }
+        else if ( !visible && this.innerComposite != null && composite != null )
+        {
+            destroy();
+            this.entryEditorWidget.getViewer().getTree().setFocus();
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetSorter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetSorter.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetSorter.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetSorter.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,378 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+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.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+
+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;
+
+
+public class EntryEditorWidgetSorter extends ViewerSorter implements SelectionListener
+{
+
+    private TreeViewer viewer;
+
+    private int sortBy;
+
+    private int sortOrder;
+
+    private EntryEditorWidgetPreferences preferences;
+
+
+    public EntryEditorWidgetSorter( EntryEditorWidgetPreferences preferences )
+    {
+        this.sortBy = BrowserCoreConstants.SORT_BY_NONE;
+        this.sortOrder = BrowserCoreConstants.SORT_ORDER_NONE;
+        this.preferences = preferences;
+    }
+
+
+    public void connect( TreeViewer viewer )
+    {
+        this.viewer = viewer;
+        this.viewer.setSorter( this );
+
+        TreeColumn[] columns = ( ( TreeViewer ) viewer ).getTree().getColumns();
+        for ( int i = 0; i < columns.length; i++ )
+        {
+            columns[i].addSelectionListener( this );
+        }
+    }
+
+
+    public void dispose()
+    {
+        /*
+         * TableColumn[] columns = this.viewer.getTable().getColumns(); for(int
+         * i=0; i <columns.length; i++) {
+         * columns[i].removeSelectionListener(this); }
+         */
+        this.viewer = null;
+    }
+
+
+    public void widgetDefaultSelected( SelectionEvent e )
+    {
+    }
+
+
+    public void widgetSelected( SelectionEvent e )
+    {
+        if ( e.widget instanceof TreeColumn && this.viewer != null )
+        {
+
+            int index = this.viewer.getTree().indexOf( ( ( TreeColumn ) e.widget ) );
+            switch ( index )
+            {
+                case EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX:
+                    if ( this.sortBy == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION )
+                    {
+                        // toggle sort order
+                        this.sortOrder = this.sortOrder == BrowserCoreConstants.SORT_ORDER_NONE ? BrowserCoreConstants.SORT_ORDER_ASCENDING
+                            : this.sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING ? BrowserCoreConstants.SORT_ORDER_DESCENDING
+                                : BrowserCoreConstants.SORT_ORDER_NONE;
+                    }
+                    else
+                    {
+                        // set new sort by
+                        this.sortBy = BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION;
+                        this.sortOrder = BrowserCoreConstants.SORT_ORDER_ASCENDING;
+                    }
+                    break;
+                case EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX:
+                    if ( this.sortBy == BrowserCoreConstants.SORT_BY_VALUE )
+                    {
+                        // toggle sort order
+                        this.sortOrder = this.sortOrder == BrowserCoreConstants.SORT_ORDER_NONE ? BrowserCoreConstants.SORT_ORDER_ASCENDING
+                            : this.sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING ? BrowserCoreConstants.SORT_ORDER_DESCENDING
+                                : BrowserCoreConstants.SORT_ORDER_NONE;
+                    }
+                    else
+                    {
+                        // set new sort by
+                        this.sortBy = BrowserCoreConstants.SORT_BY_VALUE;
+                        this.sortOrder = BrowserCoreConstants.SORT_ORDER_ASCENDING;
+                    }
+                    break;
+                default:
+                    ;
+            }
+            if ( this.sortOrder == BrowserCoreConstants.SORT_ORDER_NONE )
+            {
+                this.sortBy = BrowserCoreConstants.SORT_BY_NONE;
+            }
+
+            TreeColumn[] columns = this.viewer.getTree().getColumns();
+            for ( int i = 0; i < columns.length; i++ )
+            {
+                columns[i].setImage( null );
+            }
+
+            if ( this.sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING )
+            {
+                ( ( TreeColumn ) e.widget ).setImage( BrowserUIPlugin.getDefault().getImage(
+                    BrowserUIConstants.IMG_SORT_ASCENDING ) );
+            }
+            else if ( this.sortOrder == BrowserCoreConstants.SORT_ORDER_DESCENDING )
+            {
+                ( ( TreeColumn ) e.widget ).setImage( BrowserUIPlugin.getDefault().getImage(
+                    BrowserUIConstants.IMG_SORT_DESCENDING ) );
+            }
+
+            this.viewer.refresh();
+        }
+    }
+
+
+    public void sort( final Viewer viewer, Object[] elements )
+    {
+
+        Arrays.sort( elements, new Comparator()
+        {
+            public int compare( Object a, Object b )
+            {
+                return EntryEditorWidgetSorter.this.compare( viewer, a, b );
+            }
+        } );
+
+    }
+
+
+    public int compare( Viewer viewer, Object o1, Object o2 )
+    {
+
+        // System.out.println("compare() " + o1 + " - " + o2);
+
+        // if (o1 == null && o2 == null) {
+        // return this.equal();
+        // }
+        // else if (o1 == null && o2 != null) {
+        // return this.lessThan();
+        // }
+        // else if (o1 != null && o2 == null) {
+        // return this.greaterThan();
+        // }
+        // else {
+        IAttribute attribute1 = null;
+        IValue value1 = null;
+        if ( o1 instanceof IAttribute )
+        {
+            attribute1 = ( IAttribute ) o1;
+        }
+        else if ( o1 instanceof IValue )
+        {
+            value1 = ( IValue ) o1;
+            attribute1 = value1.getAttribute();
+        }
+
+        IAttribute attribute2 = null;
+        IValue value2 = null;
+        if ( o2 instanceof IAttribute )
+        {
+            attribute2 = ( IAttribute ) o2;
+        }
+        else if ( o2 instanceof IValue )
+        {
+            value2 = ( IValue ) o2;
+            attribute2 = value2.getAttribute();
+        }
+
+        if ( value1 != null && value2 != null )
+        {
+            if ( this.getSortByOrDefault() == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION )
+            {
+                if ( value1.getAttribute() != value2.getAttribute() )
+                {
+                    return this.compareAttributeNames( value1.getAttribute(), value2.getAttribute() );
+                }
+                else
+                {
+                    return this.compareValues( value1, value2 );
+                }
+            }
+            else if ( this.getSortByOrDefault() == BrowserCoreConstants.SORT_BY_VALUE )
+            {
+                return this.compareValues( value1, value2 );
+            }
+            else
+            {
+                return this.equal();
+            }
+        }
+        else if ( attribute1 != null && attribute2 != null )
+        {
+            return this.compareAttributeNames( attribute1, attribute2 );
+        }
+        else
+        {
+            return this.equal();
+        }
+
+        // }
+    }
+
+
+    private int compareAttributeNames( 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() );
+    }
+
+
+    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 if ((value1.isString()) && !(value2.isString())) {
+        // return lessThan();
+        // }
+        // else if ((value2.isString()) && !(value1.isString())) {
+        // return greaterThan();
+        // }
+        // else if ((value1.isString()) && (value2.isString())) {
+        // return compare(value1.getStringValue(), value2.getStringValue());
+        // }
+        // else {
+        // return equal();
+        // }
+        else
+        {
+            return compare( value1.getStringValue(), value2.getStringValue() );
+        }
+    }
+
+
+    private int getSortOrderOrDefault()
+    {
+        if ( preferences == null )
+        {
+            return BrowserCoreConstants.SORT_ORDER_ASCENDING;
+        }
+        else if ( this.sortOrder == BrowserCoreConstants.SORT_ORDER_NONE )
+        {
+            return preferences.getDefaultSortOrder();
+        }
+        else
+        {
+            return this.sortOrder;
+        }
+    }
+
+
+    private int getSortByOrDefault()
+    {
+        if ( preferences == null )
+        {
+            return BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION;
+        }
+        else if ( this.sortBy == BrowserCoreConstants.SORT_BY_NONE )
+        {
+            return preferences.getDefaultSortBy();
+        }
+        else
+        {
+            return this.sortBy;
+        }
+    }
+
+
+    private int lessThan()
+    {
+        return this.getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? -1 : 1;
+    }
+
+
+    private int equal()
+    {
+        return 0;
+    }
+
+
+    private int greaterThan()
+    {
+        return this.getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? 1 : -1;
+    }
+
+
+    private int compare( String s1, String s2 )
+    {
+        return this.getSortOrderOrDefault() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? s1.compareToIgnoreCase( s2 )
+            : s2.compareToIgnoreCase( s1 );
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetSorterDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetSorterDialog.java?view=auto&rev=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetSorterDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/widgets/entryeditor/EntryEditorWidgetSorterDialog.java Mon Dec 18 09:57:38 2006
@@ -0,0 +1,159 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+import org.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;
+
+
+public class EntryEditorWidgetSorterDialog extends Dialog
+{
+
+    public static final String DIALOG_TITLE = "Entry Editor Sorting";
+
+    public static final String SORT_BY_NONE = "No Default Sorting";
+
+    public static final String SORT_BY_ATTRIBUTE = "Attribute Description";
+
+    public static final String SORT_BY_VALUE = "Value";
+
+    private EntryEditorWidgetPreferences preferences;
+
+    private Button objectClassAndMustAttributesFirstButton;
+
+    private Button operationalAttributesLastButton;
+
+    private Combo sortByCombo;
+
+    private Button sortAcendingButton;
+
+    private Button sortDescendingButton;
+
+
+    public EntryEditorWidgetSorterDialog( Shell parentShell, EntryEditorWidgetPreferences preferences )
+    {
+        super( parentShell );
+        this.preferences = preferences;
+    }
+
+
+    protected void configureShell( Shell newShell )
+    {
+        super.configureShell( newShell );
+        newShell.setText( DIALOG_TITLE );
+    }
+
+
+    protected void buttonPressed( int buttonId )
+    {
+        if ( buttonId == IDialogConstants.OK_ID )
+        {
+            IPreferenceStore store = BrowserUIPlugin.getDefault().getPreferenceStore();
+            store.setValue( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST,
+                this.objectClassAndMustAttributesFirstButton.getSelection() );
+            store.setValue( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST,
+                this.operationalAttributesLastButton.getSelection() );
+            store.setValue( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER, this.sortDescendingButton
+                .getSelection() ? BrowserCoreConstants.SORT_ORDER_DESCENDING
+                : BrowserCoreConstants.SORT_ORDER_ASCENDING );
+            store.setValue( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY, this.sortByCombo
+                .getSelectionIndex() == 2 ? BrowserCoreConstants.SORT_BY_VALUE
+                : this.sortByCombo.getSelectionIndex() == 1 ? BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION
+                    : BrowserCoreConstants.SORT_BY_NONE );
+        }
+        else
+        {
+            // no changes
+        }
+
+        super.buttonPressed( buttonId );
+    }
+
+
+    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( this.preferences.isObjectClassAndMustAttributesFirst() );
+
+        operationalAttributesLastButton = BaseWidgetUtils.createCheckbox( group, "Operational attributes last", 1 );
+        operationalAttributesLastButton.setSelection( this.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( this.preferences.getDefaultSortBy() == BrowserCoreConstants.SORT_BY_VALUE ? 2
+            : this.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( this.preferences.getDefaultSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING );
+        sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 );
+
+        sortDescendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, "Descending", 1 );
+        sortDescendingButton
+            .setSelection( this.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;
+    }
+
+}



Mime
View raw message