directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r488368 [15/23] - in /directory/sandbox/pamarcelot/ldapstudio: ldapstudio-browser-ui/ ldapstudio-browser-ui/META-INF/ ldapstudio-browser-ui/about_files/ ldapstudio-browser-ui/icons/ ldapstudio-browser-ui/icons/ovr16/ ldapstudio-browser-ui/s...
Date Mon, 18 Dec 2006 17:53:22 GMT
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifEditor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifEditor.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifEditor.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifEditor.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,702 @@
+/*
+ *  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.editors.ldif;
+
+
+import java.io.File;
+import java.util.ResourceBundle;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateListener;
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.actions.ExecuteLdifAction;
+import org.apache.directory.ldapstudio.browser.ui.actions.ValueEditorPreferencesAction;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.actions.EditLdifAttributeAction;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.actions.EditLdifRecordAction;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.actions.FormatLdifDocumentAction;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.actions.FormatLdifRecordAction;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.actions.OpenBestValueEditorAction;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.actions.OpenDefaultValueEditorAction;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.actions.OpenValueEditorAction;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.text.LdifPartitionScanner;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.AbstractDialogCellEditor;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProviderManager;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+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.action.ToolBarManager;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.projection.ProjectionSupport;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ViewForm;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.contexts.IContextActivation;
+import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.part.IShowInTargetList;
+import org.eclipse.ui.texteditor.ChainedPreferenceStore;
+import org.eclipse.ui.texteditor.ContentAssistAction;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+
+
+public class LdifEditor extends TextEditor implements ILdifEditor, ConnectionUpdateListener, IPartListener2
+{
+
+    protected ViewForm control;
+
+    protected Combo connectionCombo;
+
+    protected ToolBar actionToolBar;
+
+    protected IToolBarManager actionToolBarManager;
+
+    private IConnection connection;
+
+    private ProjectionSupport projectionSupport;
+
+    private LdifOutlinePage outlinePage;
+
+    private ValueProviderManager valueProviderManager;
+
+    private OpenBestValueEditorAction openBestValueEditorAction;
+
+    private OpenValueEditorAction[] openValueEditorActions;
+
+    private ValueEditorPreferencesAction valueEditorPreferencesAction;
+
+
+    public LdifEditor()
+    {
+        super();
+
+        setSourceViewerConfiguration( new LdifSourceViewerConfiguration( this, true ) );
+        setDocumentProvider( new LdifDocumentProvider() );
+
+        IPreferenceStore editorStore = EditorsUI.getPreferenceStore();
+        IPreferenceStore browserStore = BrowserUIPlugin.getDefault().getPreferenceStore();
+        IPreferenceStore combinedStore = new ChainedPreferenceStore( new IPreferenceStore[]
+            { browserStore, editorStore } );
+        setPreferenceStore( combinedStore );
+
+        setHelpContextId( BrowserUIPlugin.PLUGIN_ID + "." + "tools_ldif_editor" );
+    }
+
+
+    protected void handlePreferenceStoreChanged( PropertyChangeEvent event )
+    {
+        try
+        {
+
+            ISourceViewer sourceViewer = getSourceViewer();
+            if ( sourceViewer == null )
+                return;
+
+            // ((LdifSourceViewerConfiguration)
+            // getSourceViewerConfiguration()).handlePropertyChangeEvent(event);
+
+            int topIndex = getSourceViewer().getTopIndex();
+            getSourceViewer().getDocument().set( getSourceViewer().getDocument().get() );
+            getSourceViewer().setTopIndex( topIndex );
+
+        }
+        finally
+        {
+            super.handlePreferenceStoreChanged( event );
+        }
+    }
+
+
+    protected String[] collectContextMenuPreferencePages()
+    {
+        String[] ids = super.collectContextMenuPreferencePages();
+        String[] more = new String[ids.length + 4];
+        more[0] = BrowserUIConstants.PREFERENCEPAGEID_LDIFEDITOR;
+        more[1] = BrowserUIConstants.PREFERENCEPAGEID_LDIFEDITOR_CONTENTASSIST;
+        more[2] = BrowserUIConstants.PREFERENCEPAGEID_LDIFEDITOR_SYNTAXCOLORING;
+        more[3] = BrowserUIConstants.PREFERENCEPAGEID_LDIFEDITOR_TEMPLATES;
+        System.arraycopy( ids, 0, more, 4, ids.length );
+        return more;
+    }
+
+
+    public static String getId()
+    {
+        return LdifEditor.class.getName();
+    }
+
+
+    public void init( IEditorSite site, IEditorInput input ) throws PartInitException
+    {
+
+        if ( input instanceof FileEditorInput )
+        {
+            FileEditorInput fei = ( FileEditorInput ) input;
+            IFile file = fei.getFile();
+            IPath path = file.getLocation();
+            File javaIoFile = path.toFile();
+            long fileLength = javaIoFile.length();
+            if ( fileLength > ( 1 * 1024 * 1024 ) )
+            {
+                MessageDialog.openError( site.getShell(), "LDIF file is too big",
+                    "The selected LDIF file is too big. Perhaps it is possilbe to open it in a further version..." );
+                super.init( site, new NonExistingLdifEditorInput() );
+                return;
+            }
+        }
+
+        super.init( site, input );
+
+        EventRegistry.addConnectionUpdateListener( this );
+        getSite().getPage().addPartListener( this );
+
+        this.valueProviderManager = new ValueProviderManager( getSite().getShell() );
+    }
+
+
+    public void dispose()
+    {
+
+        this.valueProviderManager.dispose();
+
+        deactivateGlobalActionHandlers();
+
+        EventRegistry.removeConnectionUpdateListener( this );
+        getSite().getPage().removePartListener( this );
+
+        super.dispose();
+    }
+
+
+    public Object getAdapter( Class required )
+    {
+        if ( IShowInTargetList.class.equals( required ) )
+        {
+            return new IShowInTargetList()
+            {
+                public String[] getShowInTargetIds()
+                {
+                    return new String[]
+                        { IPageLayout.ID_RES_NAV };
+                }
+            };
+        }
+        if ( IContentOutlinePage.class.equals( required ) )
+        {
+            if ( outlinePage == null || outlinePage.getControl() == null || outlinePage.getControl().isDisposed() )
+            {
+                outlinePage = new LdifOutlinePage( this );
+            }
+            return outlinePage;
+        }
+        if ( ISourceViewer.class.equals( required ) )
+        {
+            return getSourceViewer();
+        }
+        if ( IAnnotationHover.class.equals( required ) )
+        {
+            if ( getSourceViewerConfiguration() != null && getSourceViewer() != null )
+                return getSourceViewerConfiguration().getAnnotationHover( getSourceViewer() );
+        }
+        if ( ITextHover.class.equals( required ) )
+        {
+            if ( getSourceViewerConfiguration() != null && getSourceViewer() != null )
+                return getSourceViewerConfiguration().getTextHover( getSourceViewer(), null );
+        }
+        if ( IContentAssistProcessor.class.equals( required ) )
+        {
+            if ( getSourceViewerConfiguration() != null && getSourceViewer() != null )
+                return getSourceViewerConfiguration().getContentAssistant( getSourceViewer() )
+                    .getContentAssistProcessor( LdifPartitionScanner.LDIF_RECORD );
+        }
+        if ( projectionSupport != null )
+        {
+            Object adapter = projectionSupport.getAdapter( getSourceViewer(), required );
+            if ( adapter != null )
+                return adapter;
+        }
+        return super.getAdapter( required );
+    }
+
+
+    protected void editorContextMenuAboutToShow( IMenuManager menu )
+    {
+        super.editorContextMenuAboutToShow( menu );
+
+        IContributionItem[] items = menu.getItems();
+        for ( int i = 0; i < items.length; i++ )
+        {
+
+            if ( items[i] instanceof ActionContributionItem )
+            {
+                ActionContributionItem aci = ( ActionContributionItem ) items[i];
+                if ( aci.getAction() == getAction( ITextEditorActionConstants.SHIFT_LEFT ) )
+                {
+                    menu.remove( items[i] );
+                }
+                if ( aci.getAction() == getAction( ITextEditorActionConstants.SHIFT_RIGHT ) )
+                {
+                    menu.remove( items[i] );
+                }
+                // if(aci.getAction() instanceof TextOperationAction) {
+                // TextOperationAction toa =
+                // (TextOperationAction)aci.getAction();
+                // String id = toa.getActionDefinitionId();
+                // IAction referenceAction =
+                // getAction(ITextEditorActionConstants.CUT);
+                // boolean equal = toa==referenceAction;
+                // System.out.println(equal);
+                // }
+            }
+        }
+
+        // add Edit actions
+        addAction( menu, ITextEditorActionConstants.GROUP_EDIT, EditLdifAttributeAction.class.getName() );
+        addAction( menu, ITextEditorActionConstants.GROUP_EDIT, OpenDefaultValueEditorAction.class.getName() );
+
+        MenuManager valueEditorMenuManager = new MenuManager( "Edit Value With" );
+        if ( this.openBestValueEditorAction.isEnabled() )
+        {
+            valueEditorMenuManager.add( this.openBestValueEditorAction );
+            valueEditorMenuManager.add( new Separator() );
+        }
+        for ( int i = 0; i < this.openValueEditorActions.length; i++ )
+        {
+            this.openValueEditorActions[i].update();
+            if ( this.openValueEditorActions[i].isEnabled()
+                && this.openValueEditorActions[i].getValueProvider().getClass() != this.openBestValueEditorAction
+                    .getValueProvider().getClass()
+                && this.openValueEditorActions[i].getValueProvider() instanceof AbstractDialogCellEditor )
+            {
+                valueEditorMenuManager.add( this.openValueEditorActions[i] );
+            }
+        }
+        valueEditorMenuManager.add( new Separator() );
+        valueEditorMenuManager.add( this.valueEditorPreferencesAction );
+        menu.appendToGroup( ITextEditorActionConstants.GROUP_EDIT, valueEditorMenuManager );
+
+        addAction( menu, ITextEditorActionConstants.GROUP_EDIT, EditLdifRecordAction.class.getName() );
+
+        // add Format actions
+        MenuManager formatMenuManager = new MenuManager( "Format" );
+        addAction( formatMenuManager, FormatLdifDocumentAction.class.getName() );
+        addAction( formatMenuManager, FormatLdifRecordAction.class.getName() );
+        menu.appendToGroup( ITextEditorActionConstants.GROUP_EDIT, formatMenuManager );
+
+    }
+
+
+    protected void createActions()
+    {
+        super.createActions();
+
+        // add content assistant
+        ResourceBundle bundle = BrowserUIPlugin.getDefault().getResourceBundle();
+        IAction action = new ContentAssistAction( bundle, "ldifeditor__contentassistproposal_", this ); //$NON-NLS-1$
+        action.setActionDefinitionId( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS );
+        setAction( "ContentAssistProposal", action ); //$NON-NLS-1$
+
+        // add execute action (for tool bar)
+        ExecuteLdifAction executeLdifAction = new ExecuteLdifAction( this );
+        this.actionToolBarManager.add( executeLdifAction );
+        setAction( ExecuteLdifAction.class.getName(), executeLdifAction );
+        this.actionToolBarManager.update( true );
+
+        // add context menu edit actions
+        EditLdifAttributeAction editLdifAttributeAction = new EditLdifAttributeAction( this );
+        setAction( EditLdifAttributeAction.class.getName(), editLdifAttributeAction );
+
+        this.openBestValueEditorAction = new OpenBestValueEditorAction( this );
+        ValueProvider[] valueProviders = valueProviderManager.getAllValueProviders();
+        this.openValueEditorActions = new OpenValueEditorAction[valueProviders.length];
+        for ( int i = 0; i < this.openValueEditorActions.length; i++ )
+        {
+            this.openValueEditorActions[i] = new OpenValueEditorAction( this, valueProviders[i] );
+        }
+        this.valueEditorPreferencesAction = new ValueEditorPreferencesAction();
+
+        OpenDefaultValueEditorAction openDefaultValueEditorAction = new OpenDefaultValueEditorAction( this,
+            openBestValueEditorAction );
+        setAction( OpenDefaultValueEditorAction.class.getName(), openDefaultValueEditorAction );
+
+        EditLdifRecordAction editRecordAction = new EditLdifRecordAction( this );
+        setAction( EditLdifRecordAction.class.getName(), editRecordAction );
+
+        // add context menu format actions
+        FormatLdifDocumentAction formatDocumentAction = new FormatLdifDocumentAction( this );
+        setAction( FormatLdifDocumentAction.class.getName(), formatDocumentAction );
+        FormatLdifRecordAction formatRecordAction = new FormatLdifRecordAction( this );
+        setAction( FormatLdifRecordAction.class.getName(), formatRecordAction );
+
+        // update cut, copy, paste
+        IAction cutAction = getAction( ITextEditorActionConstants.CUT );
+        if ( cutAction != null )
+        {
+            cutAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
+                ISharedImages.IMG_TOOL_CUT ) );
+        }
+        IAction copyAction = getAction( ITextEditorActionConstants.COPY );
+        if ( copyAction != null )
+        {
+            copyAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
+                ISharedImages.IMG_TOOL_COPY ) );
+        }
+        IAction pasteAction = getAction( ITextEditorActionConstants.PASTE );
+        if ( pasteAction != null )
+        {
+            pasteAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
+                ISharedImages.IMG_TOOL_PASTE ) );
+        }
+
+        activateGlobalActionHandlers();
+
+    }
+
+
+    public void createPartControl( Composite parent )
+    {
+
+        setHelpContextId( BrowserUIPlugin.PLUGIN_ID + "." + "tools_ldif_editor" );
+
+        Composite composite = new Composite( parent, SWT.NONE );
+        composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+        GridLayout layout = new GridLayout();
+        layout.marginWidth = 0;
+        layout.marginHeight = 0;
+        // layout.horizontalSpacing = 0;
+        layout.verticalSpacing = 0;
+        composite.setLayout( layout );
+
+        control = new ViewForm( composite, SWT.NONE );
+        control.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+
+        // infoText = BaseWidgetUtils.createLabeledText(control, "", 1);
+        Composite connectionComboControl = BaseWidgetUtils.createColumnContainer( control, 1, 1 );
+        // connectionComboControl.setLayoutData(new
+        // GridData(GridData.GRAB_HORIZONTAL));
+        connectionCombo = BaseWidgetUtils.createReadonlyCombo( connectionComboControl, new String[0], 0, 1 );
+        connectionCombo.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, true ) );
+        connectionUpdated( new ConnectionUpdateEvent( null, 0 ) );
+        connectionCombo.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
+                    connectionCombo.getText() );
+                setConnection( connection );
+                IAction action = getAction( ExecuteLdifAction.class.getName() );
+                if ( action != null )
+                {
+                    action.setEnabled( connection == null );
+                    action.setEnabled( connection != null );
+                    // actionToolBarManager.update(true);
+                }
+            }
+        } );
+        control.setTopLeft( connectionComboControl );
+
+        // tool bar
+        actionToolBar = new ToolBar( control, SWT.FLAT | SWT.RIGHT );
+        actionToolBar.setLayoutData( new GridData( SWT.END, SWT.NONE, true, false ) );
+        actionToolBarManager = new ToolBarManager( actionToolBar );
+        control.setTopCenter( actionToolBar );
+
+        // local menu
+        control.setTopRight( null );
+
+        // content
+        Composite editorComposite = new Composite( control, SWT.NONE );
+        editorComposite.setLayout( new FillLayout() );
+        GridData data = new GridData( GridData.FILL_BOTH );
+        data.widthHint = 450;
+        data.heightHint = 250;
+        editorComposite.setLayoutData( data );
+        super.createPartControl( editorComposite );
+        control.setContent( editorComposite );
+
+        ProjectionViewer projectionViewer = ( ProjectionViewer ) getSourceViewer();
+        projectionSupport = new ProjectionSupport( projectionViewer, getAnnotationAccess(), getSharedColors() );
+        projectionSupport.install();
+        projectionViewer.doOperation( ProjectionViewer.TOGGLE );
+
+    }
+
+
+    protected ISourceViewer createSourceViewer( Composite parent, IVerticalRuler ruler, int styles )
+    {
+        getAnnotationAccess();
+        getOverviewRuler();
+        ISourceViewer viewer = new ProjectionViewer( parent, ruler, getOverviewRuler(), true, styles );
+        getSourceViewerDecorationSupport( viewer );
+
+        return viewer;
+    }
+
+
+    protected void configureSourceViewerDecorationSupport( SourceViewerDecorationSupport support )
+    {
+        super.configureSourceViewerDecorationSupport( support );
+    }
+
+
+    protected void configureSourceViewerDecorationSupport()
+    {
+
+        // Iterator e=
+        // fAnnotationPreferences.getAnnotationPreferences().iterator();
+        // while (e.hasNext())
+        // fSourceViewerDecorationSupport.setAnnotationPreference((AnnotationPreference)
+        // e.next());
+        // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(DefaultMarkerAnnotationAccess.UNKNOWN,
+        // UNKNOWN_INDICATION_COLOR, UNKNOWN_INDICATION,
+        // UNKNOWN_INDICATION_IN_OVERVIEW_RULER, 0);
+        //			
+        // fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE,
+        // CURRENT_LINE_COLOR);
+        // fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN,
+        // PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
+        // fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
+    }
+
+
+    protected void doSetInput( IEditorInput input ) throws CoreException
+    {
+        // this.ldifModel = null;
+        super.doSetInput( input );
+
+        // setOutlinePageInput();
+        // if (fFoldingStructureProvider != null) {
+        // fFoldingStructureProvider.setDocument(getDocumentProvider().getDocument(input));
+        // }
+    }
+
+
+    public LdifFile getLdifModel()
+    {
+        IDocumentProvider provider = getDocumentProvider();
+        if ( provider instanceof LdifDocumentProvider )
+        {
+            return ( ( LdifDocumentProvider ) provider ).getLdifModel();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    public void outlinePageClosed()
+    {
+        projectionSupport.dispose();
+        outlinePage = null;
+    }
+
+
+    public IConnection getConnection()
+    {
+        return this.connection;
+    }
+
+
+    private void setConnection( IConnection connection )
+    {
+        this.connection = connection;
+        getEditorSite().getActionBars().getStatusLineManager().setMessage(
+            "Used Connection: " + ( this.connection == null ? "-" : this.connection.getName() ) );
+        // getStatusField("ldapconnection").setText();
+    }
+
+
+    public void connectionUpdated( ConnectionUpdateEvent connectionUpdateEvent )
+    {
+        IConnection[] connections = BrowserCorePlugin.getDefault().getConnectionManager().getConnections();
+        String[] names = new String[connections.length + 1];
+        names[0] = "";
+        for ( int i = 0; i < connections.length; i++ )
+        {
+            names[i + 1] = connections[i].getName();
+        }
+        String old = this.connectionCombo.getText();
+        this.connectionCombo.setItems( names );
+        this.connectionCombo.setText( old );
+        connectionCombo.setVisibleItemCount( Math.max( names.length, 20 ) );
+
+    }
+
+
+    protected void performSaveAs( IProgressMonitor progressMonitor )
+    {
+
+        IPreferenceStore store = EditorsUI.getPreferenceStore();
+        String key = getEditorSite().getId() + ".internal.delegateSaveAs"; // $NON-NLS-1$
+        store.setValue( key, true );
+        super.performSaveAs( progressMonitor );
+    }
+
+    private IContextActivation contextActivation;
+
+
+    public void partDeactivated( IWorkbenchPartReference partRef )
+    {
+        if ( partRef.getPart( false ) == this && contextActivation != null )
+        {
+
+            this.deactivateGlobalActionHandlers();
+
+            IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
+                IContextService.class );
+            contextService.deactivateContext( contextActivation );
+            contextActivation = null;
+        }
+    }
+
+
+    public void partActivated( IWorkbenchPartReference partRef )
+    {
+        if ( partRef.getPart( false ) == this )
+        {
+
+            IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
+                IContextService.class );
+            contextActivation = contextService
+                .activateContext( "org.apache.directory.ldapstudio.browser.action.context" );
+
+            this.activateGlobalActionHandlers();
+        }
+    }
+
+
+    public void partBroughtToTop( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partClosed( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partHidden( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partInputChanged( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partOpened( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partVisible( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void activateGlobalActionHandlers()
+    {
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+        if ( commandService != null )
+        {
+            IAction elaa = getAction( EditLdifAttributeAction.class.getName() );
+            commandService.getCommand( elaa.getActionDefinitionId() ).setHandler( new ActionHandler( elaa ) );
+            IAction elva = getAction( OpenDefaultValueEditorAction.class.getName() );
+            commandService.getCommand( elva.getActionDefinitionId() ).setHandler( new ActionHandler( elva ) );
+            IAction elra = getAction( EditLdifRecordAction.class.getName() );
+            commandService.getCommand( elra.getActionDefinitionId() ).setHandler( new ActionHandler( elra ) );
+        }
+    }
+
+
+    public void deactivateGlobalActionHandlers()
+    {
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+        if ( commandService != null )
+        {
+            IAction elaa = getAction( EditLdifAttributeAction.class.getName() );
+            commandService.getCommand( elaa.getActionDefinitionId() ).setHandler( null );
+            IAction elva = getAction( OpenDefaultValueEditorAction.class.getName() );
+            commandService.getCommand( elva.getActionDefinitionId() ).setHandler( null );
+            IAction elra = getAction( EditLdifRecordAction.class.getName() );
+            commandService.getCommand( elra.getActionDefinitionId() ).setHandler( null );
+        }
+    }
+
+
+    public ValueProviderManager getValueProviderManager()
+    {
+        return valueProviderManager;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifEditorContributor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifEditorContributor.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifEditorContributor.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifEditorContributor.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,73 @@
+/*
+ *  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.editors.ldif;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+import org.eclipse.ui.texteditor.RetargetTextEditorAction;
+
+
+public class LdifEditorContributor extends BasicTextEditorActionContributor
+{
+
+    private static final String CONTENTASSIST_ACTION = "org.apache.directory.ldapstudio.browser.ContentAssist";
+
+    private RetargetTextEditorAction contentAssist;
+
+
+    public LdifEditorContributor()
+    {
+        super();
+
+        contentAssist = new RetargetTextEditorAction( BrowserUIPlugin.getDefault().getResourceBundle(),
+            "ContentAssistProposal." );
+        contentAssist.setActionDefinitionId( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS );
+    }
+
+
+    public void setActiveEditor( IEditorPart part )
+    {
+        super.setActiveEditor( part );
+        ITextEditor editor = ( part instanceof ITextEditor ) ? ( ITextEditor ) part : null;
+        contentAssist.setAction( getAction( editor, CONTENTASSIST_ACTION ) );
+    }
+
+
+    public void init( IActionBars bars, IWorkbenchPage page )
+    {
+        super.init( bars, page );
+        bars.setGlobalActionHandler( CONTENTASSIST_ACTION, contentAssist );
+    }
+
+
+    public void dispose()
+    {
+        setActiveEditor( null );
+        super.dispose();
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifOutlinePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifOutlinePage.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifOutlinePage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifOutlinePage.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,480 @@
+/*
+ *  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.editors.ldif;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+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.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeDeleteRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModDnRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.parser.LdifParser;
+import org.apache.directory.ldapstudio.browser.core.utils.Utils;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.actions.CopyEntryAsLdifAction;
+import org.apache.directory.ldapstudio.browser.ui.editors.entry.EntryEditor;
+
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
+
+
+public class LdifOutlinePage extends ContentOutlinePage
+{
+
+    private IEditorPart editorPart;
+
+
+    public LdifOutlinePage( IEditorPart editorPart )
+    {
+        this.editorPart = editorPart;
+    }
+
+
+    public void createControl( Composite parent )
+    {
+        super.createControl( parent );
+
+        final TreeViewer treeViewer = getTreeViewer();
+        treeViewer.setLabelProvider( new LdifLabelProvider() );
+        treeViewer.setContentProvider( new LdifContentProvider() );
+        // treeViewer.setAutoExpandLevel(1);
+
+        treeViewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                if ( editorPart instanceof LdifEditor )
+                {
+                    LdifEditor ldifEditor = ( LdifEditor ) editorPart;
+                    if ( !event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection )
+                    {
+                        Object element = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+
+                        if ( element instanceof LdifRecord )
+                        {
+                            LdifRecord ldifRecord = ( LdifRecord ) element;
+                            ldifEditor.selectAndReveal( ldifRecord.getDnLine().getOffset(), ldifRecord.getDnLine()
+                                .getLength() );
+                        }
+                        else if ( element instanceof List )
+                        {
+                            List list = ( List ) element;
+                            if ( !list.isEmpty() && list.get( 0 ) instanceof LdifAttrValLine )
+                            {
+                                LdifAttrValLine line = ( LdifAttrValLine ) list.get( 0 );
+                                ldifEditor.selectAndReveal( line.getOffset(), line.getRawAttributeDescription()
+                                    .length() );
+                            }
+                        }
+                        else if ( element instanceof LdifAttrValLine )
+                        {
+                            LdifAttrValLine line = ( LdifAttrValLine ) element;
+                            ldifEditor.selectAndReveal( line.getOffset() + line.getRawAttributeDescription().length()
+                                + line.getRawValueType().length(), line.getRawValue().length() );
+                        }
+                        else if ( element instanceof LdifModSpec )
+                        {
+                            LdifModSpec modSpec = ( LdifModSpec ) element;
+                            ldifEditor.selectAndReveal( modSpec.getOffset(), modSpec.getModSpecType().getLength() );
+                        }
+                    }
+                }
+                else if ( editorPart instanceof EntryEditor )
+                {
+                    EntryEditor entryEditor = ( EntryEditor ) editorPart;
+                    if ( !event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection )
+                    {
+
+                        Object o = entryEditor.getMainWidget().getViewer().getInput();
+                        if ( o != null && o instanceof IEntry )
+                        {
+                            IEntry entry = ( IEntry ) o;
+                            IAttribute[] attributes = entry.getAttributes();
+
+                            List selectionList = new ArrayList();
+
+                            Iterator it = ( ( IStructuredSelection ) event.getSelection() ).iterator();
+                            while ( it.hasNext() )
+                            {
+                                Object element = it.next();
+
+                                if ( element instanceof LdifAttrValLine )
+                                {
+                                    // select the value
+                                    LdifAttrValLine line = ( LdifAttrValLine ) element;
+                                    for ( int a = 0; a < attributes.length; a++ )
+                                    {
+                                        IAttribute attribute = attributes[a];
+                                        if ( attribute.getDescription().equals( line.getUnfoldedAttributeDescription() ) )
+                                        {
+                                            IValue[] values = attribute.getValues();
+                                            for ( int v = 0; v < values.length; v++ )
+                                            {
+                                                IValue value = values[v];
+                                                if ( value.getStringValue().equals( line.getValueAsString() ) )
+                                                {
+                                                    selectionList.add( value );
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                                else if ( element instanceof List )
+                                {
+                                    // select attribute and all values
+                                    List list = ( List ) element;
+                                    if ( !list.isEmpty() && list.get( 0 ) instanceof LdifAttrValLine )
+                                    {
+                                        LdifAttrValLine line = ( LdifAttrValLine ) list.get( 0 );
+                                        for ( int a = 0; a < attributes.length; a++ )
+                                        {
+                                            IAttribute attribute = attributes[a];
+                                            if ( attribute.getDescription().equals(
+                                                line.getUnfoldedAttributeDescription() ) )
+                                            {
+                                                selectionList.add( attribute );
+                                                selectionList.addAll( Arrays.asList( attribute.getValues() ) );
+                                            }
+                                        }
+                                    }
+                                }
+                                else if ( element instanceof LdifRecord )
+                                {
+                                    for ( int a = 0; a < attributes.length; a++ )
+                                    {
+                                        IAttribute attribute = attributes[a];
+                                        selectionList.add( attribute );
+                                        selectionList.addAll( Arrays.asList( attribute.getValues() ) );
+                                    }
+                                }
+                            }
+
+                            IStructuredSelection selection = new StructuredSelection( selectionList );
+                            entryEditor.getMainWidget().getViewer().setSelection( selection );
+                        }
+                    }
+                }
+            }
+        } );
+
+        treeViewer.addDoubleClickListener( new IDoubleClickListener()
+        {
+            public void doubleClick( DoubleClickEvent event )
+            {
+                if ( event.getSelection() instanceof IStructuredSelection )
+                {
+                    Object obj = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
+                    if ( treeViewer.getExpandedState( obj ) )
+                        treeViewer.collapseToLevel( obj, 1 );
+                    else if ( ( ( ITreeContentProvider ) treeViewer.getContentProvider() ).hasChildren( obj ) )
+                        treeViewer.expandToLevel( obj, 1 );
+                }
+            }
+        } );
+
+        this.refresh();
+    }
+
+
+    public void refresh( Object element )
+    {
+        final TreeViewer treeViewer = getTreeViewer();
+        if ( treeViewer != null )
+        {
+            treeViewer.refresh( element );
+        }
+    }
+
+
+    public void refresh()
+    {
+
+        final TreeViewer treeViewer = getTreeViewer();
+
+        if ( treeViewer != null )
+        {
+
+            // ISelection selection = treeViewer.getSelection();
+            // Object[] expandedElements = treeViewer.getExpandedElements();
+
+            if ( this.editorPart != null && this.editorPart instanceof LdifEditor )
+            {
+                if ( treeViewer.getInput() != ( ( LdifEditor ) this.editorPart ).getLdifModel() )
+                {
+                    treeViewer.setInput( ( ( LdifEditor ) this.editorPart ).getLdifModel() );
+                }
+            }
+            else if ( this.editorPart != null && this.editorPart instanceof EntryEditor )
+            {
+                Object o = ( ( EntryEditor ) this.editorPart ).getMainWidget().getViewer().getInput();
+                if ( o != null && o instanceof IEntry )
+                {
+                    StringBuffer sb = new StringBuffer();
+                    new CopyEntryAsLdifAction( CopyEntryAsLdifAction.MODE_INCLUDE_OPERATIONAL_ATTRIBUTES )
+                        .serialializeEntries( new IEntry[]
+                            { ( IEntry ) o }, sb );
+                    LdifFile model = new LdifParser().parse( sb.toString() );
+                    treeViewer.setInput( model );
+                    treeViewer.expandToLevel( 2 );
+                }
+            }
+
+            treeViewer.refresh();
+
+            // treeViewer.setSelection(selection);
+            // treeViewer.setExpandedElements(expandedElements);
+        }
+    }
+
+
+    public void dispose()
+    {
+        super.dispose();
+        if ( this.editorPart != null && this.editorPart instanceof LdifEditor )
+        {
+            ( ( LdifEditor ) this.editorPart ).outlinePageClosed();
+            this.editorPart = null;
+        }
+    }
+
+    private static class LdifContentProvider implements ITreeContentProvider
+    {
+        public Object[] getChildren( Object element )
+        {
+
+            // file --> records
+            if ( element instanceof LdifFile )
+            {
+                LdifFile ldifFile = ( LdifFile ) element;
+                return ldifFile.getRecords();
+            }
+
+            // record --> Array of List of AttrValLine
+            else if ( element instanceof LdifContentRecord )
+            {
+                LdifContentRecord record = ( LdifContentRecord ) element;
+                return getUniqueAttrValLineArray( record.getAttrVals() );
+            }
+            else if ( element instanceof LdifChangeAddRecord )
+            {
+                LdifChangeAddRecord record = ( LdifChangeAddRecord ) element;
+                return getUniqueAttrValLineArray( record.getAttrVals() );
+            }
+            else if ( element instanceof LdifChangeModifyRecord )
+            {
+                LdifChangeModifyRecord record = ( LdifChangeModifyRecord ) element;
+                return record.getModSpecs();
+            }
+            else if ( element instanceof LdifChangeModDnRecord )
+            {
+                return new Object[0];
+            }
+            else if ( element instanceof LdifChangeDeleteRecord )
+            {
+                return new Object[0];
+            }
+
+            // List of AttrValLine --> Array of AttrValLine
+            else if ( element instanceof List && ( ( List ) element ).get( 0 ) instanceof LdifAttrValLine )
+            {
+                List list = ( List ) element;
+                return list.toArray();
+            }
+            else if ( element instanceof LdifModSpec )
+            {
+                LdifModSpec modSpec = ( LdifModSpec ) element;
+                return modSpec.getAttrVals();
+            }
+
+            else
+            {
+                return new Object[0];
+            }
+        }
+
+
+        private Object[] getUniqueAttrValLineArray( LdifAttrValLine[] lines )
+        {
+            Map uniqueAttrMap = new LinkedHashMap();
+            for ( int i = 0; i < lines.length; i++ )
+            {
+                if ( !uniqueAttrMap.containsKey( lines[i].getUnfoldedAttributeDescription() ) )
+                {
+                    uniqueAttrMap.put( lines[i].getUnfoldedAttributeDescription(), new ArrayList() );
+                }
+                ( ( List ) uniqueAttrMap.get( lines[i].getUnfoldedAttributeDescription() ) ).add( lines[i] );
+            }
+            return uniqueAttrMap.values().toArray();
+        }
+
+
+        public Object getParent( Object element )
+        {
+            return null;
+        }
+
+
+        public boolean hasChildren( Object element )
+        {
+            return getChildren( element ) != null && getChildren( element ).length > 0;
+        }
+
+
+        public Object[] getElements( Object inputElement )
+        {
+            return getChildren( inputElement );
+        }
+
+
+        public void dispose()
+        {
+        }
+
+
+        public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+        {
+        }
+    }
+
+    private static class LdifLabelProvider extends LabelProvider
+    {
+        public String getText( Object element )
+        {
+
+            // Record
+            if ( element instanceof LdifRecord )
+            {
+                LdifRecord ldifRecord = ( LdifRecord ) element;
+                return ldifRecord.getDnLine().getValueAsString();
+            }
+
+            // List of AttrValLine
+            else if ( element instanceof List && ( ( List ) element ).get( 0 ) instanceof LdifAttrValLine )
+            {
+                List list = ( List ) element;
+                return ( ( LdifAttrValLine ) list.get( 0 ) ).getUnfoldedAttributeDescription() + " (" + list.size()
+                    + ")";
+            }
+            else if ( element instanceof LdifModSpec )
+            {
+                LdifModSpec modSpec = ( LdifModSpec ) element;
+                return modSpec.getModSpecType().getUnfoldedAttributeDescription() + " (" + modSpec.getAttrVals().length
+                    + ")";
+            }
+
+            // AttrValLine
+            else if ( element instanceof LdifAttrValLine )
+            {
+                LdifAttrValLine line = ( LdifAttrValLine ) element;
+                return Utils.getShortenedString( line.getValueAsString(), 20 );
+            }
+
+            else
+            {
+                return "";
+            }
+        }
+
+
+        public Image getImage( Object element )
+        {
+
+            // Record
+            if ( element instanceof LdifContentRecord )
+            {
+                return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_ENTRY );
+            }
+            else if ( element instanceof LdifChangeAddRecord )
+            {
+                return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_ADD );
+            }
+            else if ( element instanceof LdifChangeModifyRecord )
+            {
+                return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_MODIFY );
+            }
+            else if ( element instanceof LdifChangeDeleteRecord )
+            {
+                return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_DELETE );
+            }
+            else if ( element instanceof LdifChangeModDnRecord )
+            {
+                return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_RENAME );
+            }
+
+            // List of AttrValLine
+            else if ( element instanceof List && ( ( List ) element ).get( 0 ) instanceof LdifAttrValLine )
+            {
+                return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_ATTRIBUTE );
+            }
+            else if ( element instanceof LdifModSpec )
+            {
+                LdifModSpec modSpec = ( LdifModSpec ) element;
+                if ( modSpec.isAdd() )
+                    return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_MOD_ADD );
+                else if ( modSpec.isReplace() )
+                    return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_MOD_REPLACE );
+                else if ( modSpec.isDelete() )
+                    return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_MOD_DELETE );
+                else
+                    return null;
+            }
+
+            // AttrValLine
+            else if ( element instanceof LdifAttrValLine )
+            {
+                return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LDIF_VALUE );
+            }
+
+            else
+            {
+                return null;
+            }
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifSourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifSourceViewerConfiguration.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifSourceViewerConfiguration.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifSourceViewerConfiguration.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,243 @@
+/*
+ *  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.editors.ldif;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.reconciler.LdifReconcilingStrategy;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.text.LdifAnnotationHover;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.text.LdifAutoEditStrategy;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.text.LdifCompletionProcessor;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.text.LdifDamagerRepairer;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.text.LdifDoubleClickStrategy;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.text.LdifPartitionScanner;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.text.LdifTextHover;
+import org.apache.directory.ldapstudio.browser.ui.widgets.DialogContentAssistant;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.reconciler.MonoReconciler;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.graphics.RGB;
+
+
+public class LdifSourceViewerConfiguration extends SourceViewerConfiguration
+{
+
+    private ILdifEditor editor;
+
+    // Error hover and annotations
+    private LdifAnnotationHover annotationHover;
+
+    private LdifTextHover textHover;
+
+    // Presentation Reconciler (syntax highlight)
+    private PresentationReconciler presentationReconciler;
+
+    private LdifDamagerRepairer damagerRepairer;
+
+    // Content Assistent
+    private boolean contentAssistEnabled;
+
+    private ContentAssistant contentAssistant;
+
+    private IContentAssistProcessor contentAssistProcessor;
+
+    private LdifDoubleClickStrategy doubleClickStrategy;
+
+    // Asynchronous Reconciler (annotations)
+    private MonoReconciler reconciler;
+
+    private LdifReconcilingStrategy reconcilingStrategy;
+
+    private IAutoEditStrategy[] autoEditStrategies;
+
+
+    public LdifSourceViewerConfiguration( ILdifEditor editor, boolean contentAssistEnabled )
+    {
+        super();
+        this.editor = editor;
+
+        this.contentAssistEnabled = contentAssistEnabled;
+
+    }
+
+
+    public void setTextAttribute( String key, RGB rgb, int style )
+    {
+        damagerRepairer.setTextAttribute( key, rgb, style );
+    }
+
+
+    public String getConfiguredDocumentPartitioning( ISourceViewer sourceViewer )
+    {
+        return LdifDocumentSetupParticipant.LDIF_PARTITIONING;
+    }
+
+
+    public String[] getConfiguredContentTypes( ISourceViewer sourceViewer )
+    {
+        return new String[]
+            { IDocument.DEFAULT_CONTENT_TYPE, LdifPartitionScanner.LDIF_RECORD };
+    }
+
+
+    public ITextDoubleClickStrategy getDoubleClickStrategy( ISourceViewer sourceViewer, String contentType )
+    {
+        if ( this.doubleClickStrategy == null )
+        {
+            this.doubleClickStrategy = new LdifDoubleClickStrategy();
+        }
+        return this.doubleClickStrategy;
+    }
+
+
+    public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer )
+    {
+
+        if ( this.presentationReconciler == null )
+        {
+            this.presentationReconciler = new PresentationReconciler();
+            this.presentationReconciler.setDocumentPartitioning( getConfiguredDocumentPartitioning( sourceViewer ) );
+
+            damagerRepairer = new LdifDamagerRepairer( this.editor );
+
+            this.presentationReconciler.setDamager( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+            this.presentationReconciler.setRepairer( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+
+            this.presentationReconciler.setDamager( damagerRepairer, LdifPartitionScanner.LDIF_RECORD );
+            this.presentationReconciler.setRepairer( damagerRepairer, LdifPartitionScanner.LDIF_RECORD );
+        }
+
+        return this.presentationReconciler;
+    }
+
+
+    public IReconciler getReconciler( ISourceViewer sourceViewer )
+    {
+        if ( this.reconciler == null )
+        {
+            this.reconcilingStrategy = new LdifReconcilingStrategy( editor );
+
+            // Reconciler reconciler = new Reconciler();
+            // reconciler.setIsIncrementalReconciler(true);
+            // reconciler.setReconcilingStrategy(strategy,
+            // LdifPartitionScanner.LDIF_RECORD);
+            // reconciler.setReconcilingStrategy(strategy,
+            // IDocument.DEFAULT_CONTENT_TYPE);
+            // reconciler.setProgressMonitor(new NullProgressMonitor());
+            // reconciler.setDelay(500);
+            // return reconciler;
+
+            this.reconciler = new MonoReconciler( this.reconcilingStrategy, true );
+            this.reconciler.setProgressMonitor( new NullProgressMonitor() );
+            this.reconciler.setDelay( 500 );
+        }
+
+        return this.reconciler;
+    }
+
+
+    public IContentAssistant getContentAssistant( ISourceViewer sourceViewer )
+    {
+        if ( this.contentAssistEnabled )
+        {
+            if ( this.contentAssistant == null )
+            {
+                // this.contentAssistant = new ContentAssistant();
+                this.contentAssistant = new DialogContentAssistant();
+
+                this.contentAssistProcessor = new LdifCompletionProcessor( editor, contentAssistant );
+                this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor,
+                    LdifPartitionScanner.LDIF_RECORD );
+                this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor,
+                    IDocument.DEFAULT_CONTENT_TYPE );
+                this.contentAssistant.setDocumentPartitioning( LdifDocumentSetupParticipant.LDIF_PARTITIONING );
+
+                this.contentAssistant.setContextInformationPopupOrientation( IContentAssistant.CONTEXT_INFO_ABOVE );
+                this.contentAssistant.setInformationControlCreator( getInformationControlCreator( sourceViewer ) );
+
+                IPreferenceStore store = BrowserUIPlugin.getDefault().getPreferenceStore();
+                this.contentAssistant.enableAutoInsert( store
+                    .getBoolean( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO ) );
+                this.contentAssistant.enableAutoActivation( store
+                    .getBoolean( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION ) );
+                this.contentAssistant.setAutoActivationDelay( store
+                    .getInt( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY ) );
+                // this.contentAssistant.enableAutoInsert(true);
+                // this.contentAssistant.enableAutoActivation(true);
+                // this.contentAssistant.setAutoActivationDelay(100);
+            }
+            return this.contentAssistant;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    public IAnnotationHover getAnnotationHover( ISourceViewer sourceViewer )
+    {
+        if ( this.annotationHover == null )
+        {
+            this.annotationHover = new LdifAnnotationHover( this.editor );
+        }
+        return this.annotationHover;
+    }
+
+
+    public ITextHover getTextHover( ISourceViewer sourceViewer, String contentType )
+    {
+        if ( this.textHover == null )
+        {
+            this.textHover = new LdifTextHover( this.editor );
+        }
+        return this.textHover;
+    }
+
+
+    public IAutoEditStrategy[] getAutoEditStrategies( ISourceViewer sourceViewer, String contentType )
+    {
+        if ( autoEditStrategies == null )
+        {
+            this.autoEditStrategies = new IAutoEditStrategy[2];
+            this.autoEditStrategies[0] = new DefaultIndentLineAutoEditStrategy();
+            this.autoEditStrategies[1] = new LdifAutoEditStrategy( this.editor );
+        }
+
+        return autoEditStrategies;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/NonExistingLdifEditorInput.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/NonExistingLdifEditorInput.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/NonExistingLdifEditorInput.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/NonExistingLdifEditorInput.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,111 @@
+/*
+ *  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.editors.ldif;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.editors.text.ILocationProvider;
+
+
+public class NonExistingLdifEditorInput implements IEditorInput, ILocationProvider
+{
+
+    private static int counter = 0;
+
+    private String name;
+
+
+    public NonExistingLdifEditorInput()
+    {
+        ++counter;
+        name = "LDIF " + counter; //$NON-NLS-1$
+    }
+
+
+    public boolean exists()
+    {
+        return false;
+    }
+
+
+    public ImageDescriptor getImageDescriptor()
+    {
+        return null;
+    }
+
+
+    public String getName()
+    {
+        return name;
+    }
+
+
+    public IPersistableElement getPersistable()
+    {
+        return null;
+    }
+
+
+    public String getToolTipText()
+    {
+        return name;
+    }
+
+
+    public Object getAdapter( Class adapter )
+    {
+        if ( ILocationProvider.class.equals( adapter ) )
+            return this;
+        return Platform.getAdapterManager().getAdapter( this, adapter );
+    }
+
+
+    public IPath getPath( Object element )
+    {
+        return BrowserUIPlugin.getDefault().getStateLocation().append( name + ".ldif" );
+    }
+
+
+    public boolean equals( Object o )
+    {
+        if ( o == this )
+            return true;
+
+        if ( o instanceof NonExistingLdifEditorInput )
+        {
+            NonExistingLdifEditorInput input = ( NonExistingLdifEditorInput ) o;
+            return name.equals( input.name );
+        }
+
+        return false;
+    }
+
+
+    public int hashCode()
+    {
+        return name.hashCode();
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/AbstractLdifAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/AbstractLdifAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/AbstractLdifAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/AbstractLdifAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,132 @@
+/*
+ *  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.editors.ldif.actions;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifEditor;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.texteditor.IUpdate;
+
+
+public abstract class AbstractLdifAction extends Action implements IUpdate
+{
+
+    protected LdifEditor editor;
+
+
+    public AbstractLdifAction( String text, LdifEditor editor )
+    {
+        super( text );
+        this.editor = editor;
+    }
+
+
+    public final void run()
+    {
+        if ( this.isEnabled() )
+        {
+            doRun();
+        }
+    }
+
+
+    protected abstract void doRun();
+
+
+    public boolean isEnabled()
+    {
+        update();
+        return super.isEnabled();
+    }
+
+
+    protected LdifFile getLdifModel()
+    {
+        LdifFile model = editor.getLdifModel();
+        return model;
+    }
+
+
+    protected LdifContainer[] getSelectedLdifContainers()
+    {
+
+        LdifContainer[] containers = null;
+
+        ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+        if ( sourceViewer != null )
+        {
+            LdifFile model = editor.getLdifModel();
+            Point selection = sourceViewer.getSelectedRange();
+            containers = LdifFile.getContainers( model, selection.x, selection.y );
+        }
+
+        return containers != null ? containers : new LdifContainer[0];
+
+    }
+
+
+    protected LdifPart[] getSelectedLdifParts()
+    {
+
+        LdifPart[] parts = null;
+
+        ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+        if ( sourceViewer != null )
+        {
+            LdifFile model = editor.getLdifModel();
+            Point selection = sourceViewer.getSelectedRange();
+            parts = LdifFile.getParts( model, selection.x, selection.y );
+
+        }
+
+        return parts != null ? parts : new LdifPart[0];
+
+    }
+
+
+    protected LdifModSpec getSelectedLdifModSpec()
+    {
+
+        LdifModSpec modSpec = null;
+
+        LdifContainer[] containers = getSelectedLdifContainers();
+        if ( containers.length == 1 )
+        {
+            ISourceViewer sourceViewer = ( ISourceViewer ) editor.getAdapter( ISourceViewer.class );
+            if ( sourceViewer != null )
+            {
+                Point selection = sourceViewer.getSelectedRange();
+                modSpec = LdifFile.getInnerContainer( containers[0], selection.x );
+            }
+        }
+
+        return modSpec;
+
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/AbstractOpenValueEditorAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/AbstractOpenValueEditorAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/AbstractOpenValueEditorAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/actions/AbstractOpenValueEditorAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,197 @@
+/*
+ *  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.editors.ldif.actions;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifControlLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDeloldrdnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifNewrdnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifNewsuperiorLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifValueLineBase;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifEditor;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.AbstractDialogCellEditor;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProviderManager;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+
+public abstract class AbstractOpenValueEditorAction extends AbstractLdifAction
+{
+
+    protected ValueProviderManager manager;
+
+    protected ValueProvider valueProvider;
+
+
+    public AbstractOpenValueEditorAction( LdifEditor editor )
+    {
+        super( "Edit Value", editor );
+        manager = editor.getValueProviderManager();
+    }
+
+
+    public Object getValueProvider()
+    {
+        return valueProvider;
+    }
+
+
+    protected void doRun()
+    {
+
+        LdifPart[] parts = getSelectedLdifParts();
+        if ( parts.length == 1 && ( parts[0] instanceof LdifValueLineBase ) )
+        {
+            LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
+
+            String attributeDescription = getAttributeDescription();
+            Object rawValue = getValueProviderRawValue();
+
+            if ( valueProvider instanceof AbstractDialogCellEditor )
+            {
+                AbstractDialogCellEditor cellEditor = ( AbstractDialogCellEditor ) valueProvider;
+                cellEditor.setValue( rawValue );
+                cellEditor.activate();
+                Object newValue = cellEditor.getValue();
+
+                if ( newValue != null && newValue instanceof String || newValue instanceof byte[] )
+                {
+                    IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );
+
+                    LdifValueLineBase newLine;
+                    if ( line instanceof LdifControlLine )
+                    {
+                        LdifControlLine oldControlLine = ( LdifControlLine ) line;
+                        if ( newValue instanceof String )
+                        {
+                            newLine = LdifControlLine.create( oldControlLine.getUnfoldedOid(), oldControlLine
+                                .getUnfoldedCriticality(), ( String ) newValue );
+                        }
+                        else
+                        {
+                            newLine = LdifControlLine.create( oldControlLine.getUnfoldedOid(), oldControlLine
+                                .getUnfoldedCriticality(), ( byte[] ) newValue );
+                        }
+                    }
+                    else
+                    {
+                        if ( newValue instanceof String )
+                        {
+                            newLine = LdifAttrValLine.create( attributeDescription, ( String ) newValue );
+                        }
+                        else
+                        {
+                            newLine = LdifAttrValLine.create( attributeDescription, ( byte[] ) newValue );
+                        }
+                    }
+
+                    try
+                    {
+                        document.replace( line.getOffset(), line.getLength(), newLine.toFormattedString() );
+                    }
+                    catch ( BadLocationException e )
+                    {
+                        e.printStackTrace();
+                    }
+
+                }
+            }
+        }
+    }
+
+
+    protected Schema getSchema()
+    {
+        return editor.getConnection() != null ? editor.getConnection().getSchema() : Schema.DEFAULT_SCHEMA;
+    }
+
+
+    protected Object getValueProviderRawValue()
+    {
+        Object rawValue = null;
+        Object value = getValue();
+        if ( value != null )
+        {
+            Schema schema = getSchema();
+            rawValue = valueProvider.getRawValue( null, schema, value );
+        }
+
+        return rawValue;
+    }
+
+
+    protected Object getValue()
+    {
+        LdifPart[] parts = getSelectedLdifParts();
+        Object oldValue = null;
+        if ( parts.length == 1 && ( parts[0] instanceof LdifValueLineBase ) )
+        {
+            LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
+            oldValue = line.getValueAsObject();
+
+            if ( line instanceof LdifControlLine )
+            {
+                oldValue = ( ( LdifControlLine ) line ).getUnfoldedControlValue();
+            }
+
+        }
+        return oldValue;
+    }
+
+
+    protected String getAttributeDescription()
+    {
+        String attributeDescription = null;
+        LdifPart[] parts = getSelectedLdifParts();
+        if ( parts.length == 1 && ( parts[0] instanceof LdifValueLineBase ) )
+        {
+            LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
+
+            if ( line instanceof LdifControlLine )
+            {
+                attributeDescription = "";
+            }
+            else
+            {
+                attributeDescription = line.getUnfoldedLineStart();
+            }
+        }
+        return attributeDescription;
+    }
+
+
+    protected boolean isEditableLineSelected()
+    {
+        LdifPart[] parts = getSelectedLdifParts();
+        boolean b = parts.length == 1
+            && ( parts[0] instanceof LdifAttrValLine || parts[0] instanceof LdifDnLine
+                || parts[0] instanceof LdifControlLine || parts[0] instanceof LdifNewrdnLine
+                || parts[0] instanceof LdifDeloldrdnLine || parts[0] instanceof LdifNewsuperiorLine );
+        return b;
+    }
+
+}



Mime
View raw message