directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r592079 [7/17] - in /directory/sandbox/felixk/studio-ldapbrowser-common: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ ...
Date Mon, 05 Nov 2007 16:48:54 GMT
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/preferences/ValueEditorsPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/preferences/ValueEditorsPreferencePage.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/preferences/ValueEditorsPreferencePage.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/preferences/ValueEditorsPreferencePage.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,598 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.dialogs.preferences;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
+import org.apache.directory.studio.ldapbrowser.core.BrowserConnectionManager;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeTypeDescription;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeValueProviderRelation;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.LdapSyntaxDescription;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.SyntaxValueProviderRelation;
+import org.apache.directory.studio.valueeditors.ValueEditorManager;
+import org.apache.directory.studio.valueeditors.ValueEditorManager.ValueEditorExtension;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+public class ValueEditorsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
+{
+
+    private SortedMap<String, ValueEditorExtension> class2ValueEditorProxyMap;
+
+    private SortedMap attributeOid2AtdMap;
+
+    private SortedMap attributeTypes2AtdMap;
+
+    private String[] attributeTypesAndOids;
+
+    private SortedMap syntaxOid2LsdMap;
+
+    private SortedMap syntaxDesc2LsdMap;
+
+    private String[] syntaxDescsAndOids;
+
+    private List attributeList;
+
+    private TableViewer attributeViewer;
+
+    private Button attributeAddButton;
+
+    private Button attributeEditButton;
+
+    private Button attributeRemoveButton;
+
+    private List syntaxList;
+
+    private TableViewer syntaxViewer;
+
+    private Button syntaxAddButton;
+
+    private Button syntaxEditButton;
+
+    private Button syntaxRemoveButton;
+
+
+    public ValueEditorsPreferencePage()
+    {
+        super();
+        super.setDescription( "Specify value editors:" );
+    }
+
+
+    public void init( IWorkbench workbench )
+    {
+    }
+
+
+    protected Control createContents( Composite parent )
+    {
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+        composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+
+        // init available value providers
+        this.class2ValueEditorProxyMap = new TreeMap<String, ValueEditorExtension>();
+        Composite dummyComposite = new Composite( composite, SWT.NONE );
+        dummyComposite.setLayoutData( new GridData( 1, 1 ) );
+        
+        Collection<ValueEditorExtension> valueEditorProxys = ValueEditorManager.getValueEditorProxys();
+        for ( ValueEditorExtension proxy : valueEditorProxys )
+        {
+            this.class2ValueEditorProxyMap.put( proxy.className, proxy );
+        }
+
+        // init available attribute types
+        this.attributeTypes2AtdMap = new TreeMap();
+        this.attributeOid2AtdMap = new TreeMap();
+        BrowserConnectionManager cm = BrowserCorePlugin.getDefault().getConnectionManager();
+        IBrowserConnection[] connections = cm.getBrowserConnections();
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            Schema schema = connections[i].getSchema();
+            if ( schema != null )
+            {
+                createAttributeMaps( schema );
+            }
+        }
+        createAttributeMaps( Schema.DEFAULT_SCHEMA );
+        this.attributeTypesAndOids = new String[this.attributeTypes2AtdMap.size() + this.attributeOid2AtdMap.size()];
+        System.arraycopy( this.attributeTypes2AtdMap.keySet().toArray(), 0, this.attributeTypesAndOids, 0,
+            this.attributeTypes2AtdMap.size() );
+        System.arraycopy( this.attributeOid2AtdMap.keySet().toArray(), 0, this.attributeTypesAndOids,
+            this.attributeTypes2AtdMap.size(), this.attributeOid2AtdMap.size() );
+
+        // init available syntaxes
+        this.syntaxOid2LsdMap = new TreeMap();
+        this.syntaxDesc2LsdMap = new TreeMap();
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            Schema schema = connections[i].getSchema();
+            if ( schema != null )
+            {
+                createSyntaxMaps( schema );
+            }
+        }
+        createSyntaxMaps( Schema.DEFAULT_SCHEMA );
+        this.syntaxDescsAndOids = new String[this.syntaxOid2LsdMap.size()];
+        System.arraycopy( this.syntaxOid2LsdMap.keySet().toArray(), 0, this.syntaxDescsAndOids, 0,
+            this.syntaxOid2LsdMap.size() );
+
+        // create attribute contents
+        // BaseWidgetUtils.createSpacer(composite, 1);
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        this.createAttributeContents( composite );
+        this.attributeList = new ArrayList( Arrays.asList( BrowserCommonActivator.getDefault().getValueEditorsPreferences()
+            .getAttributeValueProviderRelations() ) );
+        attributeViewer.setInput( this.attributeList );
+        attributeViewer.getTable().getColumn( 0 ).pack();
+        // attributeViewer.getTable().getColumn(1).pack();
+        attributeViewer.getTable().getColumn( 2 ).pack();
+        attributeViewer.getTable().pack();
+
+        // create syntax contents
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        BaseWidgetUtils.createSpacer( composite, 1 );
+        this.createSyntaxContents( composite );
+        this.syntaxList = new ArrayList( Arrays.asList( BrowserCommonActivator.getDefault().getValueEditorsPreferences()
+            .getSyntaxValueProviderRelations() ) );
+        syntaxViewer.setInput( this.syntaxList );
+        syntaxViewer.getTable().getColumn( 0 ).pack();
+        // syntaxViewer.getTable().getColumn(1).pack();
+        syntaxViewer.getTable().getColumn( 2 ).pack();
+        syntaxViewer.getTable().pack();
+
+        return composite;
+    }
+
+
+    private void createAttributeMaps( Schema schema )
+    {
+        AttributeTypeDescription[] atds = schema.getAttributeTypeDescriptions();
+        for ( int i = 0; i < atds.length; i++ )
+        {
+
+            attributeOid2AtdMap.put( atds[i].getNumericOID(), atds[i] );
+
+            String[] names = atds[i].getNames();
+            for ( int j = 0; j < names.length; j++ )
+            {
+                attributeTypes2AtdMap.put( names[j], atds[i] );
+            }
+
+        }
+    }
+
+
+    private void createSyntaxMaps( Schema schema )
+    {
+        LdapSyntaxDescription[] lsds = schema.getLdapSyntaxDescriptions();
+        for ( int i = 0; i < lsds.length; i++ )
+        {
+
+            syntaxOid2LsdMap.put( lsds[i].getNumericOID(), lsds[i] );
+
+            if ( lsds[i].getDesc() != null )
+            {
+                syntaxDesc2LsdMap.put( lsds[i].getDesc(), lsds[i] );
+            }
+
+        }
+    }
+
+
+    private void createAttributeContents( Composite parent )
+    {
+
+        BaseWidgetUtils.createLabel( parent, "Value Editors by Attribute Types", 1 );
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 );
+        composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+        Composite listComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 );
+        listComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+        Composite buttonComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 );
+        buttonComposite.setLayoutData( new GridData( GridData.VERTICAL_ALIGN_BEGINNING ) );
+
+        Table table = new Table( listComposite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION );
+        GridData data = new GridData( GridData.FILL_BOTH );
+        data.widthHint = 360;
+        data.heightHint = convertHeightInCharsToPixels( 10 );
+        table.setLayoutData( data );
+        table.setHeaderVisible( true );
+        table.setLinesVisible( true );
+        attributeViewer = new TableViewer( table );
+
+        TableColumn c1 = new TableColumn( table, SWT.NONE );
+        c1.setText( "Attribute" );
+        c1.setWidth( 80 );
+        TableColumn c2 = new TableColumn( table, SWT.NONE );
+        c2.setText( "Alias" );
+        c2.setWidth( 80 );
+        TableColumn c3 = new TableColumn( table, SWT.NONE );
+        c3.setText( "Value Editor" );
+        c3.setWidth( 200 );
+
+        attributeViewer.setColumnProperties( new String[]
+            { "Attribute", "Value Editor" } );
+        attributeViewer.setContentProvider( new ArrayContentProvider() );
+        attributeViewer.setLabelProvider( new AttributeLabelProvider() );
+
+        attributeViewer.addDoubleClickListener( new IDoubleClickListener()
+        {
+            public void doubleClick( DoubleClickEvent event )
+            {
+                editAttribute();
+            }
+        } );
+
+        attributeAddButton = BaseWidgetUtils.createButton( buttonComposite, "Add...", 1 );
+        attributeAddButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                addAttribute();
+            }
+        } );
+        attributeEditButton = BaseWidgetUtils.createButton( buttonComposite, "Edit...", 1 );
+        attributeEditButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                editAttribute();
+            }
+        } );
+        attributeRemoveButton = BaseWidgetUtils.createButton( buttonComposite, "Remove", 1 );
+        attributeRemoveButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                removeAttribute();
+            }
+        } );
+
+        // c1.pack();
+        // c2.pack();
+        // table.pack();
+    }
+
+
+    private void createSyntaxContents( Composite parent )
+    {
+
+        BaseWidgetUtils.createLabel( parent, "Value Editors by Syntax", 1 );
+
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 );
+        composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+        Composite listComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 );
+        listComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+        Composite buttonComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 );
+        buttonComposite.setLayoutData( new GridData( GridData.VERTICAL_ALIGN_BEGINNING ) );
+
+        Table table = new Table( listComposite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION );
+        GridData data = new GridData( GridData.FILL_BOTH );
+        data.widthHint = 360;
+        data.heightHint = convertHeightInCharsToPixels( 10 );
+        table.setLayoutData( data );
+        table.setHeaderVisible( true );
+        table.setLinesVisible( true );
+        syntaxViewer = new TableViewer( table );
+
+        TableColumn c1 = new TableColumn( table, SWT.NONE );
+        c1.setText( "Syntax" );
+        c1.setWidth( 80 );
+        TableColumn c2 = new TableColumn( table, SWT.NONE );
+        c2.setText( "Desc" );
+        c2.setWidth( 80 );
+        TableColumn c3 = new TableColumn( table, SWT.NONE );
+        c3.setText( "Value Editor" );
+        c3.setWidth( 200 );
+
+        syntaxViewer.setColumnProperties( new String[]
+            { "Syntax", "Value Editor" } );
+        syntaxViewer.setContentProvider( new ArrayContentProvider() );
+        syntaxViewer.setLabelProvider( new SyntaxLabelProvider() );
+
+        syntaxViewer.addDoubleClickListener( new IDoubleClickListener()
+        {
+            public void doubleClick( DoubleClickEvent event )
+            {
+                editSyntax();
+            }
+        } );
+
+        syntaxAddButton = BaseWidgetUtils.createButton( buttonComposite, "Add...", 1 );
+        syntaxAddButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                addSyntax();
+            }
+        } );
+        syntaxEditButton = BaseWidgetUtils.createButton( buttonComposite, "Edit...", 1 );
+        syntaxEditButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                editSyntax();
+            }
+        } );
+        syntaxRemoveButton = BaseWidgetUtils.createButton( buttonComposite, "Remove", 1 );
+        syntaxRemoveButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                removeSyntax();
+            }
+        } );
+
+        // c1.pack();
+        // c2.pack();
+        // table.pack();
+    }
+
+
+    protected void addAttribute()
+    {
+        AttributeValueEditorDialog dialog = new AttributeValueEditorDialog( getShell(), null,
+            this.class2ValueEditorProxyMap, this.attributeTypesAndOids );
+        if ( dialog.open() == AttributeValueEditorDialog.OK )
+        {
+            this.attributeList.add( dialog.getRelation() );
+            this.attributeViewer.refresh();
+        }
+    }
+
+
+    protected void removeAttribute()
+    {
+        Object o = ( ( StructuredSelection ) this.attributeViewer.getSelection() ).getFirstElement();
+        this.attributeList.remove( o );
+        this.attributeViewer.refresh();
+    }
+
+
+    protected void editAttribute()
+    {
+        StructuredSelection sel = ( StructuredSelection ) this.attributeViewer.getSelection();
+        if ( !sel.isEmpty() )
+        {
+            AttributeValueProviderRelation relation = ( AttributeValueProviderRelation ) sel.getFirstElement();
+            AttributeValueEditorDialog dialog = new AttributeValueEditorDialog( getShell(), relation,
+                this.class2ValueEditorProxyMap, this.attributeTypesAndOids );
+            if ( dialog.open() == AttributeValueEditorDialog.OK )
+            {
+                int index = this.attributeList.indexOf( relation );
+                this.attributeList.set( index, dialog.getRelation() );
+                this.attributeViewer.refresh();
+            }
+        }
+    }
+
+
+    protected void addSyntax()
+    {
+        SyntaxValueEditorDialog dialog = new SyntaxValueEditorDialog( getShell(), null,
+            this.class2ValueEditorProxyMap, this.syntaxDescsAndOids );
+        if ( dialog.open() == SyntaxValueEditorDialog.OK )
+        {
+            this.syntaxList.add( dialog.getRelation() );
+            this.syntaxViewer.refresh();
+        }
+    }
+
+
+    protected void removeSyntax()
+    {
+        Object o = ( ( StructuredSelection ) this.syntaxViewer.getSelection() ).getFirstElement();
+        this.syntaxList.remove( o );
+        this.syntaxViewer.refresh();
+    }
+
+
+    protected void editSyntax()
+    {
+        StructuredSelection sel = ( StructuredSelection ) this.syntaxViewer.getSelection();
+        if ( !sel.isEmpty() )
+        {
+            SyntaxValueProviderRelation relation = ( SyntaxValueProviderRelation ) sel.getFirstElement();
+            SyntaxValueEditorDialog dialog = new SyntaxValueEditorDialog( getShell(), relation,
+                this.class2ValueEditorProxyMap, this.syntaxDescsAndOids );
+            if ( dialog.open() == SyntaxValueEditorDialog.OK )
+            {
+                int index = this.syntaxList.indexOf( relation );
+                this.syntaxList.set( index, dialog.getRelation() );
+                this.syntaxViewer.refresh();
+            }
+        }
+    }
+
+
+    public boolean performOk()
+    {
+        AttributeValueProviderRelation[] aRelations = ( AttributeValueProviderRelation[] ) this.attributeList
+            .toArray( new AttributeValueProviderRelation[this.attributeList.size()] );
+        BrowserCommonActivator.getDefault().getValueEditorsPreferences().setAttributeValueProviderRelations( aRelations );
+
+        SyntaxValueProviderRelation[] sRelations = ( SyntaxValueProviderRelation[] ) this.syntaxList
+            .toArray( new SyntaxValueProviderRelation[this.syntaxList.size()] );
+        BrowserCommonActivator.getDefault().getValueEditorsPreferences().setSyntaxValueProviderRelations( sRelations );
+
+        return true;
+    }
+
+
+    protected void performDefaults()
+    {
+        this.attributeList.clear();
+        this.attributeList.addAll( Arrays.asList( BrowserCommonActivator.getDefault().getValueEditorsPreferences()
+            .getDefaultAttributeValueProviderRelations() ) );
+        this.attributeViewer.refresh();
+
+        this.syntaxList.clear();
+        this.syntaxList.addAll( Arrays.asList( BrowserCommonActivator.getDefault().getValueEditorsPreferences()
+            .getDefaultSyntaxValueProviderRelations() ) );
+        this.syntaxViewer.refresh();
+
+        super.performDefaults();
+    }
+
+    class AttributeLabelProvider extends LabelProvider implements ITableLabelProvider
+    {
+        public String getColumnText( Object obj, int index )
+        {
+            if ( obj instanceof AttributeValueProviderRelation )
+            {
+                AttributeValueProviderRelation relation = ( AttributeValueProviderRelation ) obj;
+                if ( index == 0 )
+                {
+                    return relation.getAttributeNumericOidOrType();
+                }
+                else if ( index == 1 )
+                {
+                    if ( relation.getAttributeNumericOidOrType() != null )
+                    {
+                        if ( attributeTypes2AtdMap.containsKey( relation.getAttributeNumericOidOrType() ) )
+                        {
+                            AttributeTypeDescription atd = ( AttributeTypeDescription ) attributeTypes2AtdMap
+                                .get( relation.getAttributeNumericOidOrType() );
+                            String s = atd.getNumericOID();
+                            for ( int i = 0; i < atd.getNames().length; i++ )
+                            {
+                                if ( !relation.getAttributeNumericOidOrType().equals( atd.getNames()[i] ) )
+                                {
+                                    s += ", " + atd.getNames()[i];
+                                }
+                            }
+                            return s;
+                        }
+                        else if ( attributeOid2AtdMap.containsKey( relation.getAttributeNumericOidOrType() ) )
+                        {
+                            AttributeTypeDescription atd = ( AttributeTypeDescription ) attributeOid2AtdMap
+                                .get( relation.getAttributeNumericOidOrType() );
+                            return atd.toString();
+                        }
+                    }
+                }
+                else if ( index == 2 )
+                {
+                    ValueEditorExtension vp = class2ValueEditorProxyMap.get( relation.getValueProviderClassname() );
+                    return vp != null ? vp.name : null;
+                }
+            }
+            return null;
+        }
+
+
+        public Image getColumnImage( Object obj, int index )
+        {
+            if ( obj instanceof AttributeValueProviderRelation )
+            {
+                AttributeValueProviderRelation relation = ( AttributeValueProviderRelation ) obj;
+                if ( index == 2 )
+                {
+                    ValueEditorExtension vp = class2ValueEditorProxyMap.get( relation.getValueProviderClassname() );
+                    return vp != null ? vp.icon.createImage() : null;
+                }
+            }
+
+            return null;
+        }
+    }
+
+    class SyntaxLabelProvider extends LabelProvider implements ITableLabelProvider
+    {
+        public String getColumnText( Object obj, int index )
+        {
+            if ( obj instanceof SyntaxValueProviderRelation )
+            {
+                SyntaxValueProviderRelation relation = ( SyntaxValueProviderRelation ) obj;
+                if ( index == 0 )
+                {
+                    return relation.getSyntaxOID();
+                }
+                else if ( index == 1 )
+                {
+                    if ( relation.getSyntaxOID() != null )
+                    {
+                        if ( syntaxOid2LsdMap.containsKey( relation.getSyntaxOID() ) )
+                        {
+                            LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) syntaxOid2LsdMap.get( relation
+                                .getSyntaxOID() );
+                            return lsd.toString();
+                        }
+                    }
+                }
+                else if ( index == 2 )
+                {
+                    ValueEditorExtension vp = class2ValueEditorProxyMap.get( relation.getValueProviderClassname() );
+                    return vp != null ? vp.name : null;
+                }
+            }
+            return null;
+        }
+
+
+        public Image getColumnImage( Object obj, int index )
+        {
+            if ( obj instanceof SyntaxValueProviderRelation )
+            {
+                SyntaxValueProviderRelation relation = ( SyntaxValueProviderRelation ) obj;
+                if ( index == 2 )
+                {
+                    ValueEditorExtension vp = class2ValueEditorProxyMap.get( relation.getValueProviderClassname() );
+                    return vp != null ? vp.icon.createImage() : null;
+                }
+            }
+
+            return null;
+        }
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/EntryTransfer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/EntryTransfer.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/EntryTransfer.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/EntryTransfer.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,227 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.dnd;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
+import org.apache.directory.studio.ldapbrowser.core.BrowserConnectionManager;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+
+/**
+ * A {@link Transfer} that could be used to transfer {@link IEntry} objects.
+ * Note that only the connection id and entry's DN is converted to a platform specific 
+ * representation, not the complete object.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryTransfer extends ByteArrayTransfer
+{
+
+    /** The Constant TYPENAME. */
+    private static final String TYPENAME = "org.apache.directory.studio.ldapbrowser.entry";
+
+    /** The Constant TYPEID. */
+    private static final int TYPEID = registerType( TYPENAME );
+
+    /** The instance. */
+    private static EntryTransfer instance = new EntryTransfer();
+
+
+    /**
+     * Gets the instance.
+     * 
+     * @return the instance
+     */
+    public static EntryTransfer getInstance()
+    {
+        return instance;
+    }
+
+
+    /**
+     * Creates a new instance of EntryTransfer.
+     */
+    private EntryTransfer()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation only accepts {@link IEntry} objects. 
+     * It just converts the id of the connection and the entry's DN
+     * to the platform specific representation.
+     */
+    public void javaToNative( Object object, TransferData transferData )
+    {
+        if ( object == null || !( object instanceof IEntry[] ) )
+        {
+            return;
+        }
+
+        if ( isSupportedType( transferData ) )
+        {
+            IEntry[] entries = ( IEntry[] ) object;
+            try
+            {
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                DataOutputStream writeOut = new DataOutputStream( out );
+
+                for ( int i = 0; i < entries.length; i++ )
+                {
+                    byte[] connectionId = entries[i].getBrowserConnection().getConnection().getId().getBytes( "UTF-8" );
+                    writeOut.writeInt( connectionId.length );
+                    writeOut.write( connectionId );
+                    byte[] dn = entries[i].getDn().getUpName().getBytes( "UTF-8" );
+                    writeOut.writeInt( dn.length );
+                    writeOut.write( dn );
+                }
+
+                byte[] buffer = out.toByteArray();
+                writeOut.close();
+
+                super.javaToNative( buffer, transferData );
+
+            }
+            catch ( IOException e )
+            {
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation just converts the platform specific representation
+     * to the connection id and entry DN and invokes 
+     * {@link BrowserConnectionManager#getBrowserConnectionById(String)} to get the
+     * {@link IBrowserConnection} object and {@link IBrowserConnection#getEntryFromCache(DN)}
+     * to get the {@link IEntry} object.
+     */
+    public Object nativeToJava( TransferData transferData )
+    {
+        try
+        {
+            if ( isSupportedType( transferData ) )
+            {
+                byte[] buffer = ( byte[] ) super.nativeToJava( transferData );
+                if ( buffer == null )
+                {
+                    return null;
+                }
+
+                List<IEntry> entryList = new ArrayList<IEntry>();
+                try
+                {
+                    IBrowserConnection connection = null;
+                    ByteArrayInputStream in = new ByteArrayInputStream( buffer );
+                    DataInputStream readIn = new DataInputStream( in );
+
+                    do
+                    {
+                        if ( readIn.available() > 1 )
+                        {
+                            int size = readIn.readInt();
+                            byte[] connectionId = new byte[size];
+                            readIn.read( connectionId );
+                            connection = BrowserCorePlugin.getDefault().getConnectionManager().getBrowserConnectionById(
+                                new String( connectionId, "UTF-8" ) );
+                        }
+
+                        IEntry entry = null;
+                        if ( readIn.available() > 1 && connection != null )
+                        {
+                            int size = readIn.readInt();
+                            byte[] dn = new byte[size];
+                            readIn.read( dn );
+                            entry = connection.getEntryFromCache( new LdapDN( new String( dn, "UTF-8" ) ) );
+                        }
+                        else
+                        {
+                            return null;
+                        }
+
+                        if ( entry != null )
+                        {
+                            entryList.add( entry );
+                        }
+                    }
+                    while ( readIn.available() > 1 );
+
+                    readIn.close();
+                }
+                catch ( IOException ex )
+                {
+                    return null;
+                }
+
+                return entryList.isEmpty() ? null : entryList.toArray( new IEntry[0] );
+            }
+
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+
+        return null;
+
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected String[] getTypeNames()
+    {
+        return new String[]
+            { TYPENAME };
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected int[] getTypeIds()
+    {
+        return new int[]
+            { TYPEID };
+    }
+
+}
\ No newline at end of file

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/SearchTransfer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/SearchTransfer.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/SearchTransfer.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/SearchTransfer.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,225 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.dnd;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.ldapbrowser.core.BrowserConnectionManager;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+
+/**
+ * A {@link Transfer} that could be used to transfer {@link ISearch} objects.
+ * Note that only the connection id and search name is converted to a platform specific 
+ * representation, not the complete object.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SearchTransfer extends ByteArrayTransfer
+{
+
+    /** The Constant TYPENAME. */
+    private static final String TYPENAME = "org.apache.directory.studio.ldapbrowser.search";
+
+    /** The Constant TYPEID. */
+    private static final int TYPEID = registerType( TYPENAME );
+
+    /** The instance. */
+    private static SearchTransfer instance = new SearchTransfer();
+
+
+    /**
+     * Creates a new instance of SearchTransfer.
+     */
+    private SearchTransfer()
+    {
+    }
+
+
+    /**
+     * Gets the instance.
+     * 
+     * @return the instance
+     */
+    public static SearchTransfer getInstance()
+    {
+        return instance;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation only accepts {@link ISearch} objects. 
+     * It just converts the id of the connection and the name of the search
+     * to the platform specific representation.
+     */
+    public void javaToNative( Object object, TransferData transferData )
+    {
+        if ( object == null || !( object instanceof ISearch[] ) )
+        {
+            return;
+        }
+
+        if ( isSupportedType( transferData ) )
+        {
+            ISearch[] searches = ( ISearch[] ) object;
+            try
+            {
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                DataOutputStream writeOut = new DataOutputStream( out );
+
+                for ( int i = 0; i < searches.length; i++ )
+                {
+                    byte[] connectionId = searches[i].getBrowserConnection().getConnection().getId().getBytes( "UTF-8" );
+                    writeOut.writeInt( connectionId.length );
+                    writeOut.write( connectionId );
+                    byte[] searchName = searches[i].getName().getBytes( "UTF-8" );
+                    writeOut.writeInt( searchName.length );
+                    writeOut.write( searchName );
+                }
+
+                byte[] buffer = out.toByteArray();
+                writeOut.close();
+
+                super.javaToNative( buffer, transferData );
+
+            }
+            catch ( IOException e )
+            {
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation just converts the platform specific representation
+     * to the connection id and search name and invokes 
+     * {@link BrowserConnectionManager#getBrowserConnectionById(String)} to get the
+     * {@link IBrowserConnection} object and {@link IBrowserConnection#getSearchManager()}
+     * to get the {@link ISearch} object.
+     */
+    public Object nativeToJava( TransferData transferData )
+    {
+        try
+        {
+            if ( isSupportedType( transferData ) )
+            {
+                byte[] buffer = ( byte[] ) super.nativeToJava( transferData );
+                if ( buffer == null )
+                {
+                    return null;
+                }
+
+                List<ISearch> searchList = new ArrayList<ISearch>();
+                try
+                {
+                    IBrowserConnection connection = null;
+                    ByteArrayInputStream in = new ByteArrayInputStream( buffer );
+                    DataInputStream readIn = new DataInputStream( in );
+
+                    do
+                    {
+                        if ( readIn.available() > 1 )
+                        {
+                            int size = readIn.readInt();
+                            byte[] connectionId = new byte[size];
+                            readIn.read( connectionId );
+                            connection = BrowserCorePlugin.getDefault().getConnectionManager().getBrowserConnectionById(
+                                new String( connectionId, "UTF-8" ) );
+                        }
+
+                        ISearch search = null;
+                        if ( readIn.available() > 1 && connection != null )
+                        {
+                            int size = readIn.readInt();
+                            byte[] searchName = new byte[size];
+                            readIn.read( searchName );
+                            search = connection.getSearchManager().getSearch( new String( searchName, "UTF-8" ) );
+                        }
+                        else
+                        {
+                            return null;
+                        }
+
+                        if ( search != null )
+                        {
+                            searchList.add( search );
+                        }
+                    }
+                    while ( readIn.available() > 1 );
+
+                    readIn.close();
+                }
+                catch ( IOException ex )
+                {
+                    return null;
+                }
+
+                return searchList.isEmpty() ? null : searchList.toArray( new ISearch[0] );
+            }
+
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+
+        return null;
+
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected String[] getTypeNames()
+    {
+        return new String[]
+            { TYPENAME };
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected int[] getTypeIds()
+    {
+        return new int[]
+            { TYPEID };
+    }
+
+}
\ No newline at end of file

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/ValuesTransfer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/ValuesTransfer.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/ValuesTransfer.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/ValuesTransfer.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,285 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.dnd;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+
+/**
+ * A {@link Transfer} that could be used to transfer {@link IValue} objects.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ValuesTransfer extends ByteArrayTransfer
+{
+
+    /** The Constant TYPENAME. */
+    private static final String TYPENAME = "org.apache.directory.studio.ldapbrowser.value";
+
+    /** The Constant TYPEID. */
+    private static final int TYPEID = registerType( TYPENAME );
+
+    /** The instance. */
+    private static ValuesTransfer instance = new ValuesTransfer();
+
+
+    /**
+     * Gets the instance.
+     * 
+     * @return the instance
+     */
+    public static ValuesTransfer getInstance()
+    {
+        return instance;
+    }
+
+
+    /**
+     * Creates a new instance of ValuesTransfer.
+     */
+    private ValuesTransfer()
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation only accepts {@link IValue} objects. 
+     * It converts the id of the connection, the entry's DN, the 
+     * attribute description and the value to the platform specific 
+     * representation.
+     */
+    public void javaToNative( Object object, TransferData transferData )
+    {
+        if ( object == null || !( object instanceof IValue[] ) )
+        {
+            return;
+        }
+
+        if ( isSupportedType( transferData ) )
+        {
+            IValue[] values = ( IValue[] ) object;
+            try
+            {
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                DataOutputStream writeOut = new DataOutputStream( out );
+
+                for ( int i = 0; i < values.length; i++ )
+                {
+                    byte[] connectionId = values[i].getAttribute().getEntry().getBrowserConnection().getConnection()
+                        .getId().getBytes( "UTF-8" );
+                    writeOut.writeInt( connectionId.length );
+                    writeOut.write( connectionId );
+                    byte[] dn = values[i].getAttribute().getEntry().getDn().getUpName().getBytes( "UTF-8" );
+                    writeOut.writeInt( dn.length );
+                    writeOut.write( dn );
+                    byte[] attributeName = values[i].getAttribute().getDescription().getBytes( "UTF-8" );
+                    writeOut.writeInt( attributeName.length );
+                    writeOut.write( attributeName );
+                    if ( values[i].isString() )
+                    {
+                        byte[] value = values[i].getStringValue().getBytes( "UTF-8" );
+                        writeOut.writeBoolean( true );
+                        writeOut.writeInt( value.length );
+                        writeOut.write( value );
+                    }
+                    else if ( values[i].isBinary() )
+                    {
+                        byte[] value = values[i].getBinaryValue();
+                        writeOut.writeBoolean( false );
+                        writeOut.writeInt( value.length );
+                        writeOut.write( value );
+                    }
+                }
+
+                byte[] buffer = out.toByteArray();
+                writeOut.close();
+
+                super.javaToNative( buffer, transferData );
+
+            }
+            catch ( IOException e )
+            {
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation converts the platform specific representation
+     * to the connection name, entry DN, attribute description and value and
+     * restores the {@link IValue} object. 
+     */
+    public Object nativeToJava( TransferData transferData )
+    {
+        try
+        {
+            if ( isSupportedType( transferData ) )
+            {
+                byte[] buffer = ( byte[] ) super.nativeToJava( transferData );
+                if ( buffer == null )
+                {
+                    return null;
+                }
+
+                List<IValue> valueList = new ArrayList<IValue>();
+                try
+                {
+                    ByteArrayInputStream in = new ByteArrayInputStream( buffer );
+                    DataInputStream readIn = new DataInputStream( in );
+
+                    do
+                    {
+                        IBrowserConnection connection = null;
+                        if ( readIn.available() > 1 )
+                        {
+                            int size = readIn.readInt();
+                            byte[] connectionId = new byte[size];
+                            readIn.read( connectionId );
+                            connection = BrowserCorePlugin.getDefault().getConnectionManager().getBrowserConnectionById(
+                                new String( connectionId, "UTF-8" ) );
+                        }
+
+                        IEntry entry = null;
+                        if ( readIn.available() > 1 && connection != null )
+                        {
+                            int size = readIn.readInt();
+                            byte[] dn = new byte[size];
+                            readIn.read( dn );
+                            entry = connection.getEntryFromCache( new LdapDN( new String( dn, "UTF-8" ) ) );
+                        }
+                        else
+                        {
+                            return null;
+                        }
+
+                        IAttribute attribute = null;
+                        if ( readIn.available() > 1 && entry != null )
+                        {
+                            int size = readIn.readInt();
+                            byte[] attributeName = new byte[size];
+                            readIn.read( attributeName );
+                            attribute = entry.getAttribute( new String( attributeName, "UTF-8" ) );
+                        }
+                        else
+                        {
+                            return null;
+                        }
+
+                        IValue value = null;
+                        if ( readIn.available() > 1 && attribute != null )
+                        {
+                            boolean isString = readIn.readBoolean();
+                            int size = readIn.readInt();
+                            byte[] val = new byte[size];
+                            readIn.read( val );
+                            String test = new String( val, "UTF-8" );
+
+                            IValue[] values = attribute.getValues();
+                            for ( int i = 0; i < values.length; i++ )
+                            {
+                                if ( isString && values[i].isString() && test.equals( values[i].getStringValue() ) )
+                                {
+                                    value = values[i];
+                                    break;
+                                }
+                                else if ( !isString && values[i].isBinary()
+                                    && test.equals( new String( values[i].getBinaryValue() ) ) )
+                                {
+                                    value = values[i];
+                                    break;
+                                }
+                            }
+                        }
+                        else
+                        {
+                            return null;
+                        }
+
+                        if ( value != null )
+                        {
+                            valueList.add( value );
+                        }
+                    }
+                    while ( readIn.available() > 1 );
+
+                    readIn.close();
+                }
+                catch ( IOException ex )
+                {
+                    return null;
+                }
+
+                return valueList.isEmpty() ? null : valueList.toArray( new IValue[valueList.size()] );
+            }
+
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+
+        return null;
+
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected String[] getTypeNames()
+    {
+        return new String[]
+            { TYPENAME };
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected int[] getTypeIds()
+    {
+        return new int[]
+            { TYPEID };
+    }
+
+}
\ No newline at end of file

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterAutoEditStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterAutoEditStrategy.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterAutoEditStrategy.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterAutoEditStrategy.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,267 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.filtereditor;
+
+
+import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapAndFilterComponent;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilter;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilterComponent;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapNotFilterComponent;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapOrFilterComponent;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterParser;
+import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+
+
+/**
+ * The FilterAutoEditStrategy implements the IAutoEditStrategy for the filter editor widget.
+ * It provides smart parentesis handling when typing the filter.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class FilterAutoEditStrategy extends DefaultIndentLineAutoEditStrategy implements IAutoEditStrategy
+{
+
+    /** The Constant INDENT_STRING. */
+    public static final String INDENT_STRING = "    ";
+
+    /** The filter parser. */
+    private LdapFilterParser parser;
+
+
+    /**
+     * Creates a new instance of FilterAutoEditStrategy.
+     * 
+     * @param parser the filter parser
+     */
+    public FilterAutoEditStrategy( LdapFilterParser parser )
+    {
+        this.parser = parser;
+    }
+
+
+    /**
+     * @see org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy#customizeDocumentCommand(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.DocumentCommand)
+     */
+    public void customizeDocumentCommand( IDocument d, DocumentCommand c )
+    {
+        super.customizeDocumentCommand( d, c );
+        AutoEditParameters aep = new AutoEditParameters( c.text, c.offset, c.length, c.caretOffset, c.shiftsCaret );
+        customizeAutoEditParameters( d.get(), aep );
+        c.offset = aep.offset;
+        c.length = aep.length;
+        c.text = aep.text;
+        c.caretOffset = aep.caretOffset;
+        c.shiftsCaret = aep.shiftsCaret;
+    }
+
+
+    /**
+     * Customizes auto edit parameters.
+     * 
+     * @param currentFilter the current filter
+     * @param aep the auto edit parameters
+     */
+    public void customizeAutoEditParameters( String currentFilter, AutoEditParameters aep )
+    {
+        parser.parse( currentFilter );
+        LdapFilter filter = parser.getModel().getFilter( aep.offset );
+
+        // check balanced parenthesis
+        int balanced = 0;
+        for ( int i = 0; i < currentFilter.length(); i++ )
+        {
+            if ( currentFilter.charAt( i ) == '(' )
+            {
+                balanced++;
+            }
+            else if ( currentFilter.charAt( i ) == ')' )
+            {
+                balanced--;
+            }
+        }
+
+        if ( aep.length > 0 && ( aep.text == null || "".equals( aep.text ) ) )
+        {
+            // delete surrounding parenthesis after deleting the last character
+            if ( filter.toString().length() - aep.length == 2 && filter.getStartToken() != null
+                && filter.getStopToken() != null
+                && aep.offset >= filter.getStartToken().getOffset() + filter.getStartToken().getLength()
+                && aep.offset + aep.length <= filter.getStopToken().getOffset() )
+            {
+                aep.offset -= 1;
+                aep.length += 2;
+                aep.caretOffset = aep.offset;
+                aep.shiftsCaret = false;
+            }
+        }
+
+        if ( aep.length == 0 && aep.text != null && !"".equals( aep.text ) )
+        {
+            boolean isNewFilter = aep.text.equals( "(" );
+            boolean isNewNestedFilter = aep.text.equals( "&" ) || aep.text.equals( "|" ) || aep.text.equals( "!" );
+            boolean isSurroundNew = false;
+            boolean isSurroundNested = false;
+            boolean isSurroundBeforeOtherFilter = false;
+            boolean isSurroundAfterOtherFilter = false;
+            if ( aep.text.matches( "[a-zA-Z0-9-\\.&|!:]+" ) && filter != null )
+            {
+                isSurroundNew = filter.getStartToken() == null && aep.offset == 0 && !aep.text.startsWith( "(" )
+                    && !aep.text.endsWith( ")" );
+
+                if ( filter.getStartToken() != null
+                    && filter.getFilterComponent() != null
+                    && ( filter.getFilterComponent() instanceof LdapAndFilterComponent
+                        || filter.getFilterComponent() instanceof LdapOrFilterComponent || filter.getFilterComponent() instanceof LdapNotFilterComponent ) )
+                {
+                    LdapFilterComponent fc = filter.getFilterComponent();
+                    LdapFilter[] filters = fc.getFilters();
+
+                    if ( filters.length == 0 && aep.offset > fc.getStartToken().getOffset() )
+                    {
+                        // no nested filter yet
+                        isSurroundNested = true;
+                    }
+
+                    if ( filters.length > 0 && aep.offset > fc.getStartToken().getOffset()
+                        && aep.offset < filters[0].getStartToken().getOffset() )
+                    {
+                        // before first nested filter
+                        isSurroundNested = true;
+                    }
+
+                    if ( filters.length > 0 && aep.offset > filters[filters.length - 1].getStopToken().getOffset()
+                        && aep.offset <= filter.getStopToken().getOffset() )
+                    {
+                        // after last nested filter
+                        isSurroundNested = true;
+                    }
+
+                    for ( int i = 0; i < filters.length; i++ )
+                    {
+                        if ( filters.length > i + 1 )
+                        {
+                            if ( aep.offset > filters[i].getStopToken().getOffset()
+                                && aep.offset <= filters[i + 1].getStopToken().getOffset() )
+                            {
+                                // between nested filter
+                                isSurroundNested = true;
+                            }
+                        }
+                    }
+                }
+
+                isSurroundBeforeOtherFilter = filter.getStartToken() != null
+                    && aep.offset == filter.getStartToken().getOffset();
+
+                isSurroundAfterOtherFilter = filter.getStopToken() != null
+                    && aep.offset == filter.getStopToken().getOffset()
+                    && ( filter.getFilterComponent() instanceof LdapAndFilterComponent
+                        || filter.getFilterComponent() instanceof LdapOrFilterComponent || filter.getFilterComponent() instanceof LdapNotFilterComponent );
+            }
+
+            // add opening parenthesis '('
+            if ( isSurroundNew || isSurroundNested || isSurroundAfterOtherFilter || isSurroundBeforeOtherFilter )
+            {
+                aep.text = "(" + aep.text;
+                aep.caretOffset = aep.offset + aep.text.length();
+                aep.shiftsCaret = false;
+            }
+
+            // add parenthesis for nested filters
+            if ( isNewNestedFilter )
+            {
+                aep.text = aep.text + "()";
+                aep.caretOffset = aep.offset + aep.text.length() - 1;
+                aep.shiftsCaret = false;
+            }
+
+            // add closing parenthesis ')'
+            if ( isNewFilter || isSurroundNew || isSurroundNested || isSurroundAfterOtherFilter
+                || isSurroundBeforeOtherFilter )
+            {
+                if ( balanced == 0 )
+                {
+                    aep.text = aep.text + ")";
+                    if( aep.caretOffset == -1 )
+                    {
+                        aep.caretOffset = aep.offset + aep.text.length() - 1;
+                        aep.shiftsCaret = false;
+                    }
+                }
+            }
+
+            // translate tab to IDENT_STRING
+            if ( aep.text.equals( "\t" ) )
+            {
+                aep.text = INDENT_STRING;
+            }
+        }
+    }
+
+    /**
+     * Helper class.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    public static class AutoEditParameters
+    {
+
+        /** The text. */
+        public String text;
+
+        /** The offset. */
+        public int offset;
+
+        /** The length. */
+        public int length;
+
+        /** The caret offset. */
+        public int caretOffset;
+
+        /** The shifts caret flag. */
+        public boolean shiftsCaret;
+
+
+        /**
+         * Creates a new instance of AutoEditParameters.
+         * 
+         * @param text the text
+         * @param offset the offset
+         * @param length the length
+         * @param caretOffset the caret offset
+         * @param shiftsCaret the shifts caret flag
+         */
+        public AutoEditParameters( String text, int offset, int length, int caretOffset, boolean shiftsCaret )
+        {
+            this.text = text;
+            this.offset = offset;
+            this.length = length;
+            this.caretOffset = caretOffset;
+            this.shiftsCaret = shiftsCaret;
+        }
+    }
+
+}

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

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterCharacterPairMatcher.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterCharacterPairMatcher.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterCharacterPairMatcher.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/filtereditor/FilterCharacterPairMatcher.java Mon Nov  5 08:48:35 2007
@@ -0,0 +1,123 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.filtereditor;
+
+
+import org.apache.directory.studio.ldapbrowser.core.model.filter.LdapFilter;
+import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterParser;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.source.ICharacterPairMatcher;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+
+/**
+ * The FilterCharacterPairMatcher implements the ICharacterPairMatcher interface
+ * to match the peer opening and closing parentesis.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class FilterCharacterPairMatcher implements ICharacterPairMatcher
+{
+
+    /** The filter parser. */
+    private LdapFilterParser parser;
+
+    /** The anchor. */
+    private int anchor;
+
+
+    /**
+     * Creates a new instance of FilterCharacterPairMatcher.
+     * 
+     * @param sourceViewer the source viewer
+     * @param parser the filter parser
+     */
+    public FilterCharacterPairMatcher( ISourceViewer sourceViewer, LdapFilterParser parser )
+    {
+        this.parser = parser;
+        this.clear();
+    }
+
+
+    /**
+     * @see org.eclipse.jface.text.source.ICharacterPairMatcher#dispose()
+     */
+    public void dispose()
+    {
+    }
+
+
+    /**
+     * @see org.eclipse.jface.text.source.ICharacterPairMatcher#clear()
+     */
+    public void clear()
+    {
+        anchor = LEFT;
+    }
+
+
+    /**
+     * @see org.eclipse.jface.text.source.ICharacterPairMatcher#match(org.eclipse.jface.text.IDocument, int)
+     */
+    public IRegion match( IDocument document, int offset )
+    {
+        LdapFilter model = parser.getModel();
+        if ( model != null )
+        {
+            LdapFilter filter = parser.getModel().getFilter( offset - 1 );
+
+            if ( filter != null && filter.getStartToken() != null && filter.getStopToken() != null )
+            {
+
+                int left = filter.getStartToken().getOffset();
+                int right = filter.getStopToken().getOffset();
+
+                if ( left == offset - 1 )
+                {
+                    anchor = LEFT;
+                    IRegion region = new Region( left, right - left + 1 );
+                    return region;
+                }
+                if ( right == offset - 1 )
+                {
+                    anchor = RIGHT;
+                    IRegion region = new Region( left, right - left + 1 );
+                    return region;
+                }
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * @see org.eclipse.jface.text.source.ICharacterPairMatcher#getAnchor()
+     */
+    public int getAnchor()
+    {
+        return anchor;
+    }
+
+}

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



Mime
View raw message