directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r488368 [14/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/entry/EntryEditorUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorUniversalListener.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorUniversalListener.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorUniversalListener.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,150 @@
+/*
+ *  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.entry;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifOutlinePage;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetUniversalListener;
+
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.contexts.IContextActivation;
+import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+
+
+public class EntryEditorUniversalListener extends EntryEditorWidgetUniversalListener implements IPartListener2
+{
+
+    private EntryEditor entryEditor;
+
+    private IContextActivation contextActivation;
+
+
+    public EntryEditorUniversalListener( EntryEditor entryEditor )
+    {
+        super( entryEditor.getMainWidget().getViewer(), entryEditor.getActionGroup().getOpenDefaultEditorAction() );
+        this.entryEditor = entryEditor;
+        entryEditor.getSite().getPage().addPartListener( this );
+    }
+
+
+    public void dispose()
+    {
+        if ( this.entryEditor != null )
+        {
+            entryEditor.getSite().getPage().removePartListener( this );
+            this.entryEditor = null;
+        }
+
+        super.dispose();
+    }
+
+
+    void setInput( IEntry entry )
+    {
+        if ( entry != this.viewer.getInput() )
+        {
+            this.viewer.setInput( entry );
+            this.entryEditor.getActionGroup().setInput( entry );
+        }
+
+    }
+
+
+    public void partDeactivated( IWorkbenchPartReference partRef )
+    {
+        if ( partRef.getPart( false ) == this.entryEditor && contextActivation != null )
+        {
+
+            this.entryEditor.getActionGroup().deactivateGlobalActionHandlers();
+
+            IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
+                IContextService.class );
+            contextService.deactivateContext( contextActivation );
+            contextActivation = null;
+        }
+    }
+
+
+    public void partActivated( IWorkbenchPartReference partRef )
+    {
+        if ( partRef.getPart( false ) == this.entryEditor )
+        {
+
+            IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter(
+                IContextService.class );
+            contextActivation = contextService
+                .activateContext( "org.apache.directory.ldapstudio.browser.action.context" );
+            // org.eclipse.ui.contexts.dialogAndWindow
+            // org.eclipse.ui.contexts.window
+            // org.eclipse.ui.text_editor_context
+
+            this.entryEditor.getActionGroup().activateGlobalActionHandlers();
+        }
+    }
+
+
+    public void partBroughtToTop( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partClosed( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partOpened( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partHidden( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partVisible( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void partInputChanged( IWorkbenchPartReference partRef )
+    {
+    }
+
+
+    public void entryUpdated( EntryModificationEvent event )
+    {
+        super.entryUpdated( event );
+
+        LdifOutlinePage outlinePage = ( LdifOutlinePage ) this.entryEditor.getAdapter( IContentOutlinePage.class );
+        if ( outlinePage != null )
+        {
+            outlinePage.refresh();
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/OpenEntryEditorPreferencePageAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/OpenEntryEditorPreferencePageAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/OpenEntryEditorPreferencePageAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/OpenEntryEditorPreferencePageAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,56 @@
+/*
+ *  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.entry;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.eclipse.jface.action.Action;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+
+
+public class OpenEntryEditorPreferencePageAction extends Action
+{
+
+    public OpenEntryEditorPreferencePageAction()
+    {
+        super.setText( "Preferences..." );
+        super.setToolTipText( "Preferences..." );
+        super.setEnabled( true );
+    }
+
+
+    public void run()
+    {
+        Shell shell = Display.getCurrent().getActiveShell();
+        String eePageId = BrowserUIConstants.PREFERENCEPAGEID_ENTRYEDITOR;
+        String attPageId = BrowserUIConstants.PREFERENCEPAGEID_ATTRIBUTES;
+        PreferencesUtil.createPreferenceDialogOn( shell, eePageId, new String[]
+            { eePageId, attPageId }, null ).open();
+    }
+
+
+    public void dispose()
+    {
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/ShowOperationalAttributesAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/ShowOperationalAttributesAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/ShowOperationalAttributesAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/ShowOperationalAttributesAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,66 @@
+/*
+ *  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.entry;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.eclipse.jface.action.Action;
+
+
+public class ShowOperationalAttributesAction extends Action
+{
+
+    public ShowOperationalAttributesAction()
+    {
+        super( "Show Operational Attributes", AS_CHECK_BOX );
+        super.setToolTipText( getText() );
+        super.setEnabled( true );
+
+        super.setChecked( BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES ) );
+    }
+
+
+    public void run()
+    {
+        BrowserUIPlugin.getDefault().getPreferenceStore().setValue(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES, super.isChecked() );
+    }
+
+
+    public void setChecked( boolean checked )
+    {
+        super.setChecked( checked );
+    }
+
+
+    public boolean isChecked()
+    {
+        return super.isChecked();
+    }
+
+
+    public void dispose()
+    {
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/ShowQuickFilterAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/ShowQuickFilterAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/ShowQuickFilterAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/entry/ShowQuickFilterAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,92 @@
+/*
+ *  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.entry;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetQuickFilterWidget;
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+
+
+public class ShowQuickFilterAction extends Action
+{
+
+    public static final String SHOW_QUICKFILTER_DIALOGSETTING_KEY = ShowQuickFilterAction.class.getName()
+        + ".showQuickFilter";
+
+    private EntryEditorWidgetQuickFilterWidget quickFilterWidget;
+
+
+    public ShowQuickFilterAction( EntryEditorWidgetQuickFilterWidget quickFilterWidget )
+    {
+        super( "Show Quick Filter", AS_CHECK_BOX );
+        super.setToolTipText( "Show Quick Filter" );
+        super.setImageDescriptor( BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_FILTER ) );
+        super.setActionDefinitionId( IWorkbenchActionDefinitionIds.FIND_REPLACE );
+        super.setEnabled( true );
+
+        this.quickFilterWidget = quickFilterWidget;
+
+        if ( BrowserUIPlugin.getDefault().getDialogSettings().get( SHOW_QUICKFILTER_DIALOGSETTING_KEY ) == null )
+        {
+            BrowserUIPlugin.getDefault().getDialogSettings().put( SHOW_QUICKFILTER_DIALOGSETTING_KEY, false );
+        }
+        super.setChecked( BrowserUIPlugin.getDefault().getDialogSettings().getBoolean(
+            SHOW_QUICKFILTER_DIALOGSETTING_KEY ) );
+        this.quickFilterWidget.setActive( super.isChecked() );
+    }
+
+
+    public void run()
+    {
+
+        boolean checked = super.isChecked();
+        super.setChecked( !checked );
+
+        BrowserUIPlugin.getDefault().getDialogSettings().put( SHOW_QUICKFILTER_DIALOGSETTING_KEY, super.isChecked() );
+
+        if ( this.quickFilterWidget != null )
+        {
+            this.quickFilterWidget.setActive( super.isChecked() );
+        }
+    }
+
+
+    public void setChecked( boolean checked )
+    {
+        // super.setChecked(checked);
+    }
+
+
+    public boolean isChecked()
+    {
+        return super.isChecked();
+    }
+
+
+    public void dispose()
+    {
+        this.quickFilterWidget = null;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterAutoEditStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterAutoEditStrategy.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterAutoEditStrategy.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterAutoEditStrategy.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,172 @@
+/*
+ *  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.filter;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
+
+import org.eclipse.jface.text.DefaultAutoIndentStrategy;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.source.SourceViewer;
+
+
+// TODO: Refactor Filter Editor
+public class FilterAutoEditStrategy extends DefaultAutoIndentStrategy implements IAutoEditStrategy
+{
+
+    public static final String INDENT_STRING = "    ";
+
+    private LdapFilterParser parser;
+
+    private SourceViewer sourceViewer;
+
+    private int autoRightParenthesisFilterOffset;
+
+
+    public FilterAutoEditStrategy( SourceViewer sourceViewer, LdapFilterParser parser )
+    {
+        super();
+        this.sourceViewer = sourceViewer;
+        this.parser = parser;
+        this.autoRightParenthesisFilterOffset = -1;
+    }
+
+
+    public void customizeDocumentCommand( IDocument d, DocumentCommand c )
+    {
+
+        LdapFilter filter = this.parser.getModel().getFilter( c.offset );
+
+        // this.dumpDocumentCommand(c);
+
+        if ( c.length == 0 && c.text != null )
+        {
+            // new line
+            if ( TextUtilities.endsWith( d.getLegalLineDelimiters(), c.text ) != -1 )
+            {
+                super.customizeDocumentCommand( d, c );
+                if ( filter != null && filter.getFilterComponent() != null )
+                {
+                    LdapFilterToken startToken = filter.getFilterComponent().getStartToken();
+                    if ( startToken != null
+                        && ( startToken.getType() == LdapFilterToken.AND || startToken.getType() == LdapFilterToken.OR ) )
+                    {
+
+                        if ( startToken.getOffset() == c.offset - 1 )
+                        {
+                            c.text += INDENT_STRING;
+                            if ( filter.getStopToken() != null && filter.getStopToken().getOffset() == c.offset )
+                            {
+                                c.caretOffset = c.offset + c.text.length();
+                                c.shiftsCaret = false;
+                                c.text += "\n";
+                                super.customizeDocumentCommand( d, c );
+                            }
+                        }
+                    }
+                }
+            }
+
+            // filter start/stop
+            if ( c.text.equals( "(" ) )
+            {
+                c.text = "()";
+                c.caretOffset = c.offset + 1;
+                c.shiftsCaret = false;
+                this.autoRightParenthesisFilterOffset = c.offset;
+            }
+            else if ( c.text.equals( ")" ) )
+            {
+                LdapFilter filter2 = this.parser.getModel().getFilter( this.autoRightParenthesisFilterOffset );
+                if ( filter2 != null && filter2.getStopToken() != null
+                    && filter2.getStopToken().getOffset() == c.offset )
+                {
+                    c.text = "";
+                    c.caretOffset = c.offset + 1;
+                    c.shiftsCaret = false;
+                }
+                this.autoRightParenthesisFilterOffset = -1;
+            }
+
+            // tab to IDENT_STRING
+            if ( c.text.equals( "\t" ) )
+            {
+                c.text = INDENT_STRING;
+            }
+
+            // smart formatting
+            if ( filter != null && filter.getStartToken() != null && filter.getFilterComponent() == null )
+            {
+                if ( c.text.equals( "&" ) || c.text.equals( "|" ) )
+                {
+                    if ( filter.getStartToken().getOffset() == c.offset - 1 )
+                    {
+                        c.text += "\n";
+                        super.customizeDocumentCommand( d, c );
+                        c.text += INDENT_STRING + "()";
+                        c.caretOffset = c.offset + c.text.length() - 1;
+                        c.shiftsCaret = false;
+                        if ( filter.getStopToken() != null && filter.getStopToken().getOffset() == c.offset )
+                        {
+                            c.text += "\n";
+                            super.customizeDocumentCommand( d, c );
+                        }
+
+                    }
+                }
+                else if ( c.text.equals( "!" ) )
+                {
+                    if ( filter.getStartToken().getOffset() == c.offset - 1 )
+                    {
+                        c.text += "()";
+                        c.caretOffset = c.offset + c.text.length() - 1;
+                        c.shiftsCaret = false;
+                    }
+                }
+            }
+
+        }
+    }
+
+
+    private void autoIndentAfterNewLine()
+    {
+
+    }
+
+
+    private void dumpDocumentCommand( DocumentCommand command )
+    {
+        System.out.println( "----------------------------------" );
+        System.out.println( "  offset     : " + command.offset );
+        System.out.println( "  length     : " + command.length );
+        System.out.println( "  text       : " + command.text );
+        System.out.println( "  caretoffset: " + command.caretOffset );
+        System.out.println( "  shiftsCaret: " + command.shiftsCaret );
+        System.out.println( "  doit       : " + command.doit );
+
+    }
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterCharacterPairMatcher.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterCharacterPairMatcher.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterCharacterPairMatcher.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterCharacterPairMatcher.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,103 @@
+/*
+ *  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.filter;
+
+
+// TODO: Refactor Filter Editor
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
+import org.apache.directory.ldapstudio.browser.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;
+
+
+public class FilterCharacterPairMatcher implements ICharacterPairMatcher
+{
+
+    private ISourceViewer sourceViewer;
+
+    private LdapFilterParser parser;
+
+    private int anchor;
+
+
+    public FilterCharacterPairMatcher( ISourceViewer sourceViewer, LdapFilterParser parser )
+    {
+        super();
+        this.sourceViewer = sourceViewer;
+        this.parser = parser;
+        this.clear();
+    }
+
+
+    public void dispose()
+    {
+    }
+
+
+    public void clear()
+    {
+        this.anchor = LEFT;
+    }
+
+
+    public IRegion match( IDocument document, int offset )
+    {
+
+        LdapFilter model = this.parser.getModel();
+        if ( model != null )
+        {
+            LdapFilter filter = this.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 )
+                {
+                    this.anchor = LEFT;
+                    IRegion region = new Region( left, right - left + 1 );
+                    return region;
+                }
+                if ( right == offset - 1 )
+                {
+                    this.anchor = RIGHT;
+                    IRegion region = new Region( left, right - left + 1 );
+                    return region;
+                }
+            }
+        }
+
+        return null;
+    }
+
+
+    public int getAnchor()
+    {
+        return this.anchor;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterContentAssistProcessor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterContentAssistProcessor.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterContentAssistProcessor.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterContentAssistProcessor.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.filter;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilterItemComponent;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+
+import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
+import org.eclipse.jface.contentassist.ISubjectControlContentAssistProcessor;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateCompletionProcessor;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.swt.graphics.Image;
+
+
+// TODO: Refactor Filter Editor
+public class FilterContentAssistProcessor extends TemplateCompletionProcessor implements
+    ISubjectControlContentAssistProcessor
+{
+
+    private LdapFilterParser parser;
+
+    private ISourceViewer sourceViewer;
+
+    private char[] autoActivationCharacters;
+
+    private String[] possibleAttributeTypes;
+
+
+    public FilterContentAssistProcessor( LdapFilterParser parser )
+    {
+        this( null, parser );
+    }
+
+
+    public FilterContentAssistProcessor( ISourceViewer sourceViewer, LdapFilterParser parser )
+    {
+        super();
+        this.parser = parser;
+        this.sourceViewer = sourceViewer;
+
+        this.autoActivationCharacters = new char[1 + 26 + 26];
+        this.autoActivationCharacters[0] = '(';
+        int i = 1;
+        for ( char c = 'a'; c <= 'z'; c++, i++ )
+        {
+            this.autoActivationCharacters[i] = c;
+        }
+        for ( char c = 'A'; c <= 'Z'; c++, i++ )
+        {
+            this.autoActivationCharacters[i] = c;
+        }
+    }
+
+
+    public void setPossibleAttributeTypes( String[] possibleAttributeTypes )
+    {
+        Arrays.sort( possibleAttributeTypes );
+        this.possibleAttributeTypes = possibleAttributeTypes;
+    }
+
+
+    public char[] getCompletionProposalAutoActivationCharacters()
+    {
+        return this.autoActivationCharacters;
+    }
+
+
+    public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset )
+    {
+        return this.computeCompletionProposals( offset );
+    }
+
+
+    public ICompletionProposal[] computeCompletionProposals( IContentAssistSubjectControl contentAssistSubjectControl,
+        int documentOffset )
+    {
+        String filter = contentAssistSubjectControl.getDocument().get();
+        this.parser.parse( filter );
+        return this.computeCompletionProposals( documentOffset );
+    }
+
+
+    public IContextInformation[] computeContextInformation( IContentAssistSubjectControl contentAssistSubjectControl,
+        int documentOffset )
+    {
+        return null;
+    }
+
+
+    private ICompletionProposal[] computeCompletionProposals( int offset )
+    {
+        List proposalList = new ArrayList();
+        LdapFilter filter = this.parser.getModel().getFilter( offset );
+        if ( filter != null )
+        {
+            if ( filter.getStartToken() != null && filter.getFilterComponent() == null )
+            {
+
+                if ( sourceViewer != null )
+                {
+                    ICompletionProposal[] templateProposals = super.computeCompletionProposals( sourceViewer, offset );
+                    if ( templateProposals != null )
+                    {
+                        proposalList.addAll( Arrays.asList( templateProposals ) );
+                    }
+                }
+
+                for ( int k = 0; k < this.possibleAttributeTypes.length; k++ )
+                {
+                    ICompletionProposal proposal = new CompletionProposal( this.possibleAttributeTypes[k], offset, 0,
+                        this.possibleAttributeTypes[k].length() );
+                    proposalList.add( proposal );
+                }
+            }
+            else if ( filter.getFilterComponent() instanceof LdapFilterItemComponent
+                && filter.getFilterComponent().getStartToken().getOffset() <= offset
+                && offset <= filter.getFilterComponent().getStartToken().getOffset()
+                    + filter.getFilterComponent().getStartToken().getLength() )
+            {
+                // show matching attribute types
+                LdapFilterItemComponent fc = ( LdapFilterItemComponent ) filter.getFilterComponent();
+                for ( int k = 0; k < this.possibleAttributeTypes.length; k++ )
+                {
+                    if ( this.possibleAttributeTypes[k].startsWith( fc.getAttributeToken().getValue() ) )
+                    {
+                        ICompletionProposal proposal = new CompletionProposal( this.possibleAttributeTypes[k], fc
+                            .getAttributeToken().getOffset(), fc.getAttributeToken().getLength(),
+                            this.possibleAttributeTypes[k].length() );
+                        proposalList.add( proposal );
+                    }
+                }
+            }
+            else
+            {
+                // no proposals
+            }
+        }
+        return ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[0] );
+
+    }
+
+
+    protected Template[] getTemplates( String contextTypeId )
+    {
+        Template[] templates = BrowserUIPlugin.getDefault().getFilterTemplateStore().getTemplates(
+            BrowserUIConstants.FILTER_TEMPLATE_ID );
+        return templates;
+    }
+
+
+    protected TemplateContextType getContextType( ITextViewer viewer, IRegion region )
+    {
+        TemplateContextType contextType = BrowserUIPlugin.getDefault().getFilterTemplateContextTypeRegistry()
+            .getContextType( BrowserUIConstants.FILTER_TEMPLATE_ID );
+        return contextType;
+    }
+
+
+    protected Image getImage( Template template )
+    {
+        return BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_TEMPLATE );
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterDamagerRepairer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterDamagerRepairer.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterDamagerRepairer.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterDamagerRepairer.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,142 @@
+/*
+ *  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.filter;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.presentation.IPresentationDamager;
+import org.eclipse.jface.text.presentation.IPresentationRepairer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.graphics.RGB;
+
+
+public class FilterDamagerRepairer implements IPresentationDamager, IPresentationRepairer
+{
+
+    private static final TextAttribute DEFAULT_TEXT_ATTRIBUTE = new TextAttribute( BrowserUIPlugin.getDefault()
+        .getColor( new RGB( 0, 0, 0 ) ) );
+
+    private static final TextAttribute AND_OR_NOT_TEXT_ATTRIBUTE = new TextAttribute( BrowserUIPlugin.getDefault()
+        .getColor( new RGB( 0, 127, 0 ) ), null, SWT.BOLD );
+
+    private static final TextAttribute ATTRIBUTE_TEXT_ATTRIBUTE = new TextAttribute( BrowserUIPlugin.getDefault()
+        .getColor( new RGB( 127, 0, 85 ) ) );
+
+    private static final TextAttribute FILTER_TYPE_TEXT_ATTRIBUTE = new TextAttribute( BrowserUIPlugin.getDefault()
+        .getColor( new RGB( 255, 0, 0 ) ), null, SWT.BOLD );
+
+    private static final TextAttribute VALUE_TEXT_ATTRIBUTE = new TextAttribute( BrowserUIPlugin.getDefault().getColor(
+        new RGB( 0, 0, 127 ) ) );
+
+    private static final TextAttribute PARENTHESIS_TEXT_ATTRIBUTE = new TextAttribute( BrowserUIPlugin.getDefault()
+        .getColor( new RGB( 0, 0, 0 ) ), null, SWT.BOLD );
+
+    private SourceViewer sourceViewer;
+
+    private LdapFilterParser parser;
+
+    private IDocument document;
+
+
+    public FilterDamagerRepairer( SourceViewer sourceViewer, LdapFilterParser parser )
+    {
+        super();
+        this.sourceViewer = sourceViewer;
+        this.parser = parser;
+        this.document = null;
+    }
+
+
+    public void setDocument( IDocument document )
+    {
+        this.document = document;
+    }
+
+
+    public IRegion getDamageRegion( ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged )
+    {
+        return partition;
+    }
+
+
+    public void createPresentation( TextPresentation presentation, ITypedRegion damage )
+    {
+
+        // parse the filter
+        this.parser.parse( this.document.get() );
+
+        // get tokens
+        LdapFilterToken[] tokens = this.parser.getModel().getTokens();
+
+        // syntax highlighting
+        for ( int i = 0; i < tokens.length; i++ )
+        {
+            switch ( tokens[i].getType() )
+            {
+                case LdapFilterToken.LPAR:
+                case LdapFilterToken.RPAR:
+                    this.addStyleRange( presentation, tokens[i], PARENTHESIS_TEXT_ATTRIBUTE );
+                    break;
+                case LdapFilterToken.AND:
+                case LdapFilterToken.OR:
+                case LdapFilterToken.NOT:
+                    this.addStyleRange( presentation, tokens[i], AND_OR_NOT_TEXT_ATTRIBUTE );
+                    break;
+                case LdapFilterToken.EQUAL:
+                case LdapFilterToken.GREATER:
+                case LdapFilterToken.LESS:
+                case LdapFilterToken.APROX:
+                case LdapFilterToken.PRESENT:
+                    this.addStyleRange( presentation, tokens[i], FILTER_TYPE_TEXT_ATTRIBUTE );
+                    break;
+                case LdapFilterToken.ATTRIBUTE:
+                    this.addStyleRange( presentation, tokens[i], ATTRIBUTE_TEXT_ATTRIBUTE );
+                    break;
+                case LdapFilterToken.VALUE:
+                    this.addStyleRange( presentation, tokens[i], VALUE_TEXT_ATTRIBUTE );
+                    break;
+                default:
+                    this.addStyleRange( presentation, tokens[i], DEFAULT_TEXT_ATTRIBUTE );
+            }
+        }
+
+    }
+
+
+    private void addStyleRange( TextPresentation presentation, LdapFilterToken token, TextAttribute textAttribute )
+    {
+        StyleRange range = new StyleRange( token.getOffset(), token.getLength(), textAttribute.getForeground(),
+            textAttribute.getBackground(), textAttribute.getStyle() );
+        presentation.addStyleRange( range );
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterFormattingStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterFormattingStrategy.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterFormattingStrategy.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterFormattingStrategy.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,138 @@
+/*
+ *  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.filter;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapAndFilterComponent;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilterComponent;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilterItemComponent;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapNotFilterComponent;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapOrFilterComponent;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+
+import org.eclipse.jface.text.formatter.IFormattingStrategy;
+import org.eclipse.jface.text.source.SourceViewer;
+
+
+public class FilterFormattingStrategy implements IFormattingStrategy
+{
+
+    private LdapFilterParser parser;
+
+    private SourceViewer sourceViewer;
+
+
+    public FilterFormattingStrategy( SourceViewer sourceViewer, LdapFilterParser parser )
+    {
+        super();
+        this.parser = parser;
+        this.sourceViewer = sourceViewer;
+    }
+
+
+    public void formatterStarts( String initialIndentation )
+    {
+    }
+
+
+    public String format( String content, boolean isLineStart, String indentation, int[] positions )
+    {
+        // this.parser.parse(content);
+        LdapFilter model = this.parser.getModel();
+        if ( model != null && model.isValid() )
+        {
+            this.sourceViewer.getDocument().set( get( model, 0 ) );
+        }
+
+        return null;
+    }
+
+
+    private String get( LdapFilter filter, int indent )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        for ( int i = 0; i < indent; i++ )
+            sb.append( FilterAutoEditStrategy.INDENT_STRING );
+
+        LdapFilterComponent fc = filter.getFilterComponent();
+        if ( fc instanceof LdapFilterItemComponent )
+        {
+            sb.append( '(' ).append( ( ( LdapFilterItemComponent ) fc ).toString() ).append( ')' );
+        }
+        else if ( fc instanceof LdapNotFilterComponent )
+        {
+            sb.append( "(!" );
+            LdapNotFilterComponent lnfc = ( LdapNotFilterComponent ) fc;
+            if ( lnfc.getFilters().length > 0
+                && lnfc.getFilters()[0].getFilterComponent() instanceof LdapFilterItemComponent )
+            {
+                sb.append( get( ( lnfc ).getFilters()[0], 0 ) );
+            }
+            else
+            {
+                sb.append( '\n' );
+                sb.append( get( ( lnfc ).getFilters()[0], indent + 1 ) );
+                sb.append( '\n' );
+                for ( int i = 0; i < indent; i++ )
+                    sb.append( FilterAutoEditStrategy.INDENT_STRING );
+            }
+            sb.append( ')' );
+        }
+        else if ( fc instanceof LdapAndFilterComponent )
+        {
+            sb.append( "(&" );
+            sb.append( '\n' );
+            LdapFilter[] filters = ( ( LdapAndFilterComponent ) fc ).getFilters();
+            for ( int i = 0; i < filters.length; i++ )
+            {
+                sb.append( get( filters[i], indent + 1 ) );
+                sb.append( '\n' );
+            }
+            for ( int i = 0; i < indent; i++ )
+                sb.append( FilterAutoEditStrategy.INDENT_STRING );
+            sb.append( ')' );
+        }
+        else if ( fc instanceof LdapOrFilterComponent )
+        {
+            sb.append( "(|" );
+            sb.append( '\n' );
+            LdapFilter[] filters = ( ( LdapOrFilterComponent ) fc ).getFilters();
+            for ( int i = 0; i < filters.length; i++ )
+            {
+                sb.append( get( filters[i], indent + 1 ) );
+                sb.append( '\n' );
+            }
+            for ( int i = 0; i < indent; i++ )
+                sb.append( FilterAutoEditStrategy.INDENT_STRING );
+            sb.append( ')' );
+        }
+
+        return sb.toString();
+    }
+
+
+    public void formatterStops()
+    {
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterReconcilingStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterReconcilingStrategy.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterReconcilingStrategy.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterReconcilingStrategy.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,168 @@
+/*
+ *  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.filter;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.PaintManager;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.AnnotationModel;
+import org.eclipse.jface.text.source.AnnotationPainter;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.IAnnotationModelExtension;
+import org.eclipse.jface.text.source.MatchingCharacterPainter;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.swt.graphics.RGB;
+
+
+public class FilterReconcilingStrategy implements IReconcilingStrategy
+{
+
+    private SourceViewer sourceViewer;
+
+    private LdapFilterParser parser;
+
+    private IDocument document;
+
+    private PaintManager paintManager;
+
+
+    public FilterReconcilingStrategy( SourceViewer sourceViewer, LdapFilterParser parser )
+    {
+        super();
+        this.sourceViewer = sourceViewer;
+        this.parser = parser;
+        this.document = null;
+        this.paintManager = null;
+    }
+
+
+    public void setDocument( IDocument document )
+    {
+        this.document = document;
+
+        if ( this.sourceViewer.getAnnotationModel() == null )
+        {
+            IAnnotationModel model = new AnnotationModel();
+            this.sourceViewer.setDocument( this.sourceViewer.getDocument(), model );
+        }
+
+        // add annotation painter
+        if ( this.paintManager == null && this.sourceViewer.getAnnotationModel() instanceof IAnnotationModelExtension )
+        {
+            AnnotationPainter ap = new AnnotationPainter( this.sourceViewer, null );
+            ap.addAnnotationType( "DEFAULT" );
+            ap.setAnnotationTypeColor( "DEFAULT", BrowserUIPlugin.getDefault().getColor( new RGB( 255, 0, 0 ) ) );
+            this.sourceViewer.getAnnotationModel().addAnnotationModelListener( ap );
+
+            FilterCharacterPairMatcher cpm = new FilterCharacterPairMatcher( this.sourceViewer, this.parser );
+            MatchingCharacterPainter mcp = new MatchingCharacterPainter( this.sourceViewer, cpm );
+            mcp.setColor( BrowserUIPlugin.getDefault().getColor( new RGB( 159, 159, 159 ) ) );
+
+            this.paintManager = new PaintManager( this.sourceViewer );
+            this.paintManager.addPainter( ap );
+            this.paintManager.addPainter( mcp );
+        }
+
+    }
+
+
+    public void reconcile( DirtyRegion dirtyRegion, IRegion subRegion )
+    {
+        this.reconcile( dirtyRegion );
+    }
+
+
+    public void reconcile( IRegion partition )
+    {
+
+        /*
+         * Display.getDefault().syncExec(new Runnable(){ public void run() {
+         * if(sourceViewer.canDoOperation(SourceViewer.FORMAT)) {
+         * sourceViewer.doOperation(SourceViewer.FORMAT); } } });
+         */
+
+        LdapFilterToken[] tokens = this.parser.getModel().getTokens();
+
+        // annotations
+        if ( this.sourceViewer.getAnnotationModel() instanceof IAnnotationModelExtension )
+        {
+            ( ( IAnnotationModelExtension ) this.sourceViewer.getAnnotationModel() ).removeAllAnnotations();
+
+            List positionList = new ArrayList();
+
+            LdapFilter[] invalidFilters = this.parser.getModel().getInvalidFilters();
+            for ( int i = 0; i < invalidFilters.length; i++ )
+            {
+                if ( invalidFilters[i].getStartToken() != null )
+                {
+                    int start = invalidFilters[i].getStartToken().getOffset();
+                    int stop = invalidFilters[i].getStopToken() != null ? invalidFilters[i].getStopToken().getOffset()
+                        + invalidFilters[i].getStopToken().getLength() : start
+                        + invalidFilters[i].getStartToken().getLength();
+
+                    Annotation annotation = new Annotation( "DEFAULT", true, invalidFilters[i].toString() );
+                    Position position = new Position( start, stop - start );
+                    positionList.add( position );
+                    this.sourceViewer.getAnnotationModel().addAnnotation( annotation, position );
+                }
+            }
+
+            for ( int i = 0; i < tokens.length; i++ )
+            {
+                if ( tokens[i].getType() == LdapFilterToken.ERROR )
+                {
+
+                    boolean overlaps = false;
+                    for ( int k = 0; k < positionList.size(); k++ )
+                    {
+                        Position pos = ( Position ) positionList.get( k );
+                        if ( pos.overlapsWith( tokens[i].getOffset(), tokens[i].getLength() ) )
+                        {
+                            overlaps = true;
+                            break;
+                        }
+                    }
+                    if ( !overlaps )
+                    {
+                        Annotation annotation = new Annotation( "DEFAULT", true, tokens[i].getValue() );
+                        Position position = new Position( tokens[i].getOffset(), tokens[i].getLength() );
+                        this.sourceViewer.getAnnotationModel().addAnnotation( annotation, position );
+                    }
+                }
+            }
+        }
+
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterSourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterSourceViewerConfiguration.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterSourceViewerConfiguration.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterSourceViewerConfiguration.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,184 @@
+/*
+ *  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.filter;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+import org.apache.directory.ldapstudio.browser.ui.widgets.DialogContentAssistant;
+
+import org.eclipse.jface.text.IAutoIndentStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.formatter.ContentFormatter;
+import org.eclipse.jface.text.formatter.IContentFormatter;
+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.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+
+
+// TODO: Refactor Filter Editor
+public class FilterSourceViewerConfiguration extends SourceViewerConfiguration
+{
+
+    private IConnection connection;
+
+    private LdapFilterParser parser;
+
+    private SourceViewer sourceViewer;
+
+    // Presentation Reconciler (syntax highlight)
+    private PresentationReconciler presentationReconciler;
+
+    private FilterDamagerRepairer damagerRepairer;
+
+    // Asynchronous Reconciler (annotations)
+    private MonoReconciler reconciler;
+
+    private FilterReconcilingStrategy reconcilingStrategy;
+
+    // Hover
+    private FilterTextHover textHover;
+
+    // Auto Edit Strategy
+    private FilterAutoEditStrategy autoEditStrategy;
+
+    private ContentFormatter formatter;
+
+    private FilterFormattingStrategy formattingStrategy;
+
+    // Content Assistent
+    private DialogContentAssistant contentAssistant;
+
+    private FilterContentAssistProcessor contentAssistProcessor;
+
+
+    public FilterSourceViewerConfiguration( SourceViewer sourceViewer, LdapFilterParser parser, IConnection connection )
+    {
+        super();
+        this.sourceViewer = sourceViewer;
+        this.parser = parser;
+        this.connection = connection;
+    }
+
+
+    public void setConnection( IConnection connection )
+    {
+        this.connection = connection;
+        this.contentAssistProcessor.setPossibleAttributeTypes( this.connection == null ? new String[0]
+            : this.connection.getSchema().getAttributeTypeDescriptionNames() );
+    }
+
+
+    public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer )
+    {
+        if ( this.damagerRepairer == null )
+        {
+            this.damagerRepairer = new FilterDamagerRepairer( this.sourceViewer, this.parser );
+        }
+        if ( this.presentationReconciler == null )
+        {
+            this.presentationReconciler = new PresentationReconciler();
+            this.presentationReconciler.setDamager( this.damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+            this.presentationReconciler.setRepairer( this.damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+        }
+        return this.presentationReconciler;
+    }
+
+
+    public ITextHover getTextHover( ISourceViewer sourceViewer, String contentType )
+    {
+        if ( this.textHover == null )
+        {
+            this.textHover = new FilterTextHover( this.sourceViewer, this.parser );
+        }
+        return this.textHover;
+    }
+
+
+    public IReconciler getReconciler( ISourceViewer sourceViewer )
+    {
+        if ( this.reconcilingStrategy == null )
+        {
+            this.reconcilingStrategy = new FilterReconcilingStrategy( this.sourceViewer, this.parser );
+        }
+        if ( this.reconciler == null )
+        {
+            this.reconciler = new MonoReconciler( this.reconcilingStrategy, false );
+        }
+        return this.reconciler;
+    }
+
+
+    public IAutoIndentStrategy getAutoIndentStrategy( ISourceViewer sourceViewer, String contentType )
+    {
+        if ( this.autoEditStrategy == null )
+        {
+            this.autoEditStrategy = new FilterAutoEditStrategy( this.sourceViewer, this.parser );
+        }
+        return this.autoEditStrategy;
+    }
+
+
+    public IContentFormatter getContentFormatter( ISourceViewer sourceViewer )
+    {
+        if ( this.formattingStrategy == null )
+        {
+            this.formattingStrategy = new FilterFormattingStrategy( this.sourceViewer, this.parser );
+        }
+        if ( this.formatter == null )
+        {
+            this.formatter = new ContentFormatter();
+            this.formatter.enablePartitionAwareFormatting( false );
+            this.formatter.setFormattingStrategy( this.formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE );
+        }
+        return formatter;
+    }
+
+
+    public IContentAssistant getContentAssistant( ISourceViewer sourceViewer )
+    {
+
+        if ( this.contentAssistProcessor == null )
+        {
+            this.contentAssistProcessor = new FilterContentAssistProcessor( this.sourceViewer, this.parser );
+            this.contentAssistProcessor.setPossibleAttributeTypes( this.connection == null ? new String[0]
+                : this.connection.getSchema().getAttributeTypeDescriptionNames() );
+        }
+        if ( this.contentAssistant == null )
+        {
+            this.contentAssistant = new DialogContentAssistant();
+            this.contentAssistant.enableAutoInsert( true );
+            this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor,
+                IDocument.DEFAULT_CONTENT_TYPE );
+            this.contentAssistant.enableAutoActivation( true );
+            this.contentAssistant.setAutoActivationDelay( 100 );
+        }
+        return this.contentAssistant;
+
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterTextHover.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterTextHover.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterTextHover.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/FilterTextHover.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,92 @@
+/*
+ *  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.filter;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+
+public class FilterTextHover implements ITextHover
+{
+
+    private ISourceViewer sourceViewer;
+
+    private LdapFilterParser parser;
+
+
+    public FilterTextHover( ISourceViewer sourceViewer, LdapFilterParser parser )
+    {
+        super();
+        this.sourceViewer = sourceViewer;
+        this.parser = parser;
+    }
+
+
+    public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion )
+    {
+        LdapFilter[] invalidFilters = this.parser.getModel().getInvalidFilters();
+        for ( int i = 0; i < invalidFilters.length; i++ )
+        {
+            if ( invalidFilters[i].getStartToken() != null )
+            {
+                int start = invalidFilters[i].getStartToken().getOffset();
+                int stop = invalidFilters[i].getStopToken() != null ? invalidFilters[i].getStopToken().getOffset()
+                    + invalidFilters[i].getStopToken().getLength() : start
+                    + invalidFilters[i].getStartToken().getLength();
+                if ( start <= hoverRegion.getOffset() && hoverRegion.getOffset() < stop )
+                {
+                    return invalidFilters[i].getInvalidCause();
+                }
+            }
+        }
+
+        LdapFilterToken[] tokens = this.parser.getModel().getTokens();
+        for ( int i = 0; i < tokens.length; i++ )
+        {
+            if ( tokens[i].getType() == LdapFilterToken.ERROR )
+            {
+
+                int start = tokens[i].getOffset();
+                int stop = start + tokens[i].getLength();
+                if ( start <= hoverRegion.getOffset() && hoverRegion.getOffset() < stop )
+                {
+                    return "Invalid characters";
+                }
+            }
+        }
+        return null;
+    }
+
+
+    public IRegion getHoverRegion( ITextViewer textViewer, int offset )
+    {
+        return new Region( offset, 1 );
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/StyledTextContentAssistSubjectAdapter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/StyledTextContentAssistSubjectAdapter.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/StyledTextContentAssistSubjectAdapter.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/filter/StyledTextContentAssistSubjectAdapter.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,141 @@
+/*
+ *  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.filter;
+
+
+import java.util.HashMap;
+
+import org.eclipse.jface.contentassist.AbstractControlContentAssistSubjectAdapter;
+import org.eclipse.jface.text.Assert;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+
+
+public class StyledTextContentAssistSubjectAdapter extends AbstractControlContentAssistSubjectAdapter
+{
+
+    private StyledText styledText;
+
+    private ITextViewer viewer;
+
+    private HashMap modifyListeners;
+
+
+    public StyledTextContentAssistSubjectAdapter( ITextViewer viewer )
+    {
+        Assert.isNotNull( viewer );
+        this.styledText = viewer.getTextWidget();
+        this.viewer = viewer;
+        this.modifyListeners = new HashMap();
+    }
+
+
+    public Control getControl()
+    {
+        return styledText;
+    }
+
+
+    public int getLineHeight()
+    {
+        return styledText.getLineHeight();
+    }
+
+
+    public int getCaretOffset()
+    {
+        return styledText.getCaretOffset();
+    }
+
+
+    public Point getLocationAtOffset( int offset )
+    {
+        return styledText.getLocationAtOffset( offset );
+    }
+
+
+    public Point getWidgetSelectionRange()
+    {
+        return new Point( styledText.getSelection().x, Math.abs( styledText.getSelection().y
+            - styledText.getSelection().x ) );
+    }
+
+
+    public Point getSelectedRange()
+    {
+        return new Point( styledText.getSelection().x, Math.abs( styledText.getSelection().y
+            - styledText.getSelection().x ) );
+    }
+
+
+    public void setSelectedRange( int i, int j )
+    {
+        styledText.setSelection( new Point( i, i + j ) );
+    }
+
+
+    public void revealRange( int i, int j )
+    {
+        styledText.setSelection( new Point( i, i + j ) );
+    }
+
+
+    public IDocument getDocument()
+    {
+        return viewer.getDocument();
+    }
+
+
+    public boolean addSelectionListener( final SelectionListener selectionListener )
+    {
+        styledText.addSelectionListener( selectionListener );
+        Listener listener = new Listener()
+        {
+            public void handleEvent( Event e )
+            {
+                selectionListener.widgetSelected( new SelectionEvent( e ) );
+            }
+        };
+        styledText.addListener( SWT.Modify, listener );
+        modifyListeners.put( selectionListener, listener );
+        return true;
+    }
+
+
+    public void removeSelectionListener( SelectionListener selectionListener )
+    {
+        styledText.removeSelectionListener( selectionListener );
+        Object listener = modifyListeners.get( selectionListener );
+        if ( listener instanceof Listener )
+        {
+            styledText.removeListener( SWT.Modify, ( Listener ) listener );
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/ILdifEditor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/ILdifEditor.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/ILdifEditor.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/ILdifEditor.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,38 @@
+/*
+ *  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.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+
+public interface ILdifEditor extends IAdaptable
+{
+
+    public LdifFile getLdifModel();
+
+
+    public IConnection getConnection();
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifDocumentProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifDocumentProvider.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifDocumentProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifDocumentProvider.java Mon Dec 18 09:52:58 2006
@@ -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.ldapstudio.browser.ui.editors.ldif;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.parser.LdifParser;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.text.LdifExternalAnnotationModel;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.ui.editors.text.TextFileDocumentProvider;
+
+
+public class LdifDocumentProvider extends TextFileDocumentProvider implements IDocumentListener
+{
+
+    private final LdifParser ldifParser;
+
+    private final LdifDocumentSetupParticipant ldifDocumentSetupParticipant;
+
+    private LdifFile ldifModel;
+
+
+    public LdifDocumentProvider()
+    {
+        super();
+        this.ldifParser = new LdifParser();
+        this.ldifDocumentSetupParticipant = new LdifDocumentSetupParticipant();
+    }
+
+
+    public IDocument getDocument( Object element )
+    {
+        IDocument document = super.getDocument( element );
+        return document;
+    }
+
+
+    protected FileInfo createFileInfo( Object element ) throws CoreException
+    {
+        FileInfo info = super.createFileInfo( element );
+
+        if ( info != null )
+        {
+            // setup document partitioning
+            IDocument document = info.fTextFileBuffer.getDocument();
+            ldifDocumentSetupParticipant.setup( document );
+
+            // initial parsing of whole document
+            this.ldifModel = this.ldifParser.parse( document.get() );
+
+            // add listener for incremental parsing
+            document.addDocumentListener( this );
+
+            IAnnotationModel annotationModel = info.fTextFileBuffer.getAnnotationModel();
+            if ( annotationModel == null )
+            {
+                annotationModel = new LdifExternalAnnotationModel();
+                info.fModel = annotationModel;
+            }
+        }
+
+        return info;
+    }
+
+
+    protected void disposeFileInfo( Object element, FileInfo info )
+    {
+        IDocument document = info.fTextFileBuffer.getDocument();
+        document.removeDocumentListener( this );
+
+        super.disposeFileInfo( element, info );
+    }
+
+
+    public LdifFile getLdifModel()
+    {
+        return ldifModel;
+    }
+
+
+    public void documentAboutToBeChanged( DocumentEvent event )
+    {
+    }
+
+
+    /**
+     * Update the LDIF Model.
+     */
+    public void documentChanged( DocumentEvent event )
+    {
+
+        try
+        {
+
+            int changeOffset = event.getOffset();
+            int replacedTextLength = event.getLength();
+            int insertedTextLength = event.getText() != null ? event.getText().length() : 0;
+            IDocument document = event.getDocument();
+            // Region changeRegion = new Region(changeOffset,
+            // replacedTextLength);
+            Region changeRegion = new Region( changeOffset - BrowserCoreConstants.LINE_SEPARATOR.length(),
+                replacedTextLength + ( 2 * BrowserCoreConstants.LINE_SEPARATOR.length() ) );
+
+            // get containers to replace (from changeOffset till
+            // changeOffset+replacedTextLength, check end of record)
+            List oldContainerList = new ArrayList();
+            LdifContainer[] containers = this.ldifModel.getContainers();
+            for ( int i = 0; i < containers.length; i++ )
+            {
+
+                Region containerRegion = new Region( containers[i].getOffset(), containers[i].getLength() );
+
+                boolean changeOffsetAtEOF = i == containers.length - 1
+                    && changeOffset >= containerRegion.getOffset() + containerRegion.getLength();
+
+                if ( TextUtilities.overlaps( containerRegion, changeRegion ) || changeOffsetAtEOF )
+                {
+
+                    // remember index
+                    int index = i;
+
+                    // add invalid containers and non-records before overlap
+                    i--;
+                    for ( ; i >= 0; i-- )
+                    {
+                        if ( !containers[i].isValid() || !( containers[i] instanceof LdifRecord ) )
+                        {
+                            oldContainerList.add( 0, containers[i] );
+                        }
+                        else
+                        {
+                            break;
+                        }
+                    }
+
+                    // add all overlapping containers
+                    i = index;
+                    for ( ; i < containers.length; i++ )
+                    {
+                        containerRegion = new Region( containers[i].getOffset(), containers[i].getLength() );
+                        if ( TextUtilities.overlaps( containerRegion, changeRegion ) || changeOffsetAtEOF )
+                        {
+                            oldContainerList.add( containers[i] );
+                        }
+                        else
+                        {
+                            break;
+                        }
+                    }
+
+                    // add invalid containers and non-records after overlap
+                    for ( ; i < containers.length; i++ )
+                    {
+                        if ( !containers[i].isValid() || !( containers[i] instanceof LdifRecord )
+                            || !( oldContainerList.get( oldContainerList.size() - 1 ) instanceof LdifRecord ) )
+                        {
+                            oldContainerList.add( containers[i] );
+                        }
+                        else
+                        {
+                            break;
+                        }
+                    }
+                }
+            }
+            LdifContainer[] oldContainers = ( LdifContainer[] ) oldContainerList
+                .toArray( new LdifContainer[oldContainerList.size()] );
+            int oldCount = oldContainers.length;
+            int oldOffset = oldCount > 0 ? oldContainers[0].getOffset() : 0;
+            int oldLength = oldCount > 0 ? ( oldContainers[oldContainers.length - 1].getOffset()
+                + oldContainers[oldContainers.length - 1].getLength() - oldContainers[0].getOffset() ) : 0;
+
+            // get new content
+            int newOffset = oldOffset;
+            int newLength = oldLength - replacedTextLength + insertedTextLength;
+            String textToParse = document.get( newOffset, newLength );
+
+            // parse partion content to containers (offset=0)
+            LdifFile newModel = this.ldifParser.parse( textToParse );
+            LdifContainer[] newContainers = newModel.getContainers();
+
+            // replace old containers with new containers
+            // must adjust offsets of all following containers in model
+            this.ldifModel.replace( oldContainers, newContainers );
+
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+
+    }
+
+}
\ No newline at end of file

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifDocumentSetupParticipant.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifDocumentSetupParticipant.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifDocumentSetupParticipant.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/LdifDocumentSetupParticipant.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,66 @@
+/*
+ *  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.editors.ldif.text.LdifPartitionScanner;
+import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentExtension3;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.FastPartitioner;
+
+
+public class LdifDocumentSetupParticipant implements IDocumentSetupParticipant
+{
+
+    public final static String LDIF_PARTITIONING = "new.sf.browser.ui.editors.ldif.LdifPartitioning"; //$NON-NLS-1$
+
+
+    public LdifDocumentSetupParticipant()
+    {
+    }
+
+
+    public void setup( IDocument document )
+    {
+
+        if ( document instanceof IDocumentExtension3 )
+        {
+            IDocumentExtension3 extension3 = ( IDocumentExtension3 ) document;
+            if ( extension3.getDocumentPartitioner( LdifDocumentSetupParticipant.LDIF_PARTITIONING ) == null )
+            {
+                IDocumentPartitioner partitioner = createDocumentPartitioner();
+                extension3.setDocumentPartitioner( LDIF_PARTITIONING, partitioner );
+                partitioner.connect( document );
+            }
+        }
+    }
+
+
+    private IDocumentPartitioner createDocumentPartitioner()
+    {
+        IDocumentPartitioner partitioner = new FastPartitioner( new LdifPartitionScanner(), new String[]
+            { LdifPartitionScanner.LDIF_RECORD } );
+        return partitioner;
+    }
+
+}



Mime
View raw message