directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r488368 [17/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/text/LdifDamagerRepairer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifDamagerRepairer.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifDamagerRepairer.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifDamagerRepairer.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,420 @@
+/*
+ *  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.text;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEOFPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifInvalidPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
+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.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifChangeTypeLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifCommentLine;
+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.LdifLineBase;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecSepLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecTypeLine;
+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.LdifVersionLine;
+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.ILdifEditor;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+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.Region;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.presentation.IPresentationDamager;
+import org.eclipse.jface.text.presentation.IPresentationRepairer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+
+public class LdifDamagerRepairer implements IPresentationDamager, IPresentationRepairer
+{
+
+    private ILdifEditor editor;
+
+
+    // private IDocument document;
+
+    public LdifDamagerRepairer( ILdifEditor editor )
+    {
+        super();
+        this.editor = editor;
+        // 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 )
+    {
+
+        LdifFile ldifModel = this.editor.getLdifModel();
+        LdifContainer[] allContainers = ldifModel.getContainers();
+        List containerList = new ArrayList();
+        for ( int i = 0; i < allContainers.length; i++ )
+        {
+            LdifContainer container = allContainers[i];
+            Region containerRegion = new Region( container.getOffset(), container.getLength() );
+            if ( TextUtilities.overlaps( containerRegion, damage ) )
+            {
+                containerList.add( container );
+            }
+        }
+        LdifContainer[] containers = ( LdifContainer[] ) containerList
+            .toArray( new LdifContainer[containerList.size()] );
+        this.highlight( containers, presentation, damage );
+
+        // LdifFile ldifModel = this.editor.getLdifModel();
+        // System.out.println(ldifModel.toRawString());
+        // LdifContainer[] allContainers = ldifModel.getContainers();
+        // this.highlight(allContainers, presentation, null);
+
+    }
+
+    private Map textAttributeKeyToValueMap;
+
+
+    private TextAttribute geTextAttribute( String key )
+    {
+        IPreferenceStore store = BrowserUIPlugin.getDefault().getPreferenceStore();
+
+        RGB rgb = PreferenceConverter
+            .getColor( store, key + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX );
+        int style = store.getInt( key + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX );
+
+        if ( textAttributeKeyToValueMap != null )
+        {
+            if ( textAttributeKeyToValueMap.containsKey( key
+                + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX ) )
+            {
+                rgb = ( RGB ) textAttributeKeyToValueMap.get( key
+                    + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX );
+            }
+            if ( textAttributeKeyToValueMap.containsKey( key
+                + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX ) )
+            {
+                style = ( ( Integer ) textAttributeKeyToValueMap.get( key
+                    + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX ) ).intValue();
+            }
+        }
+
+        Color color = BrowserUIPlugin.getDefault().getColor( rgb );
+        TextAttribute textAttribute = new TextAttribute( color, null, style );
+        return textAttribute;
+    }
+
+
+    /**
+     * Overwrites the style set in preference store
+     * 
+     * @param key
+     *                the key
+     *                BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_xxx +
+     *                BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX
+     *                ore
+     *                BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX
+     * @param newValue
+     *                RGB object or Integer object
+     */
+    public void setTextAttribute( String key, RGB rgb, int style )
+    {
+        if ( textAttributeKeyToValueMap == null )
+        {
+            textAttributeKeyToValueMap = new HashMap();
+        }
+        textAttributeKeyToValueMap.put( key + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, rgb );
+        textAttributeKeyToValueMap.put( key + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX,
+            new Integer( style ) );
+    }
+
+
+    private void highlight( LdifContainer[] containers, TextPresentation presentation, ITypedRegion damage )
+    {
+
+        // TextAttribute DEFAULT_TEXT_ATTRIBUTE = new
+        // TextAttribute(BrowserUIPlugin.getDefault().getColor(new RGB(0, 0,
+        // 0)));
+
+        TextAttribute COMMENT_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_COMMENT );
+        TextAttribute KEYWORD_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_KEYWORD );
+        TextAttribute DN_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_DN );
+        TextAttribute ATTRIBUTE_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_ATTRIBUTE );
+        TextAttribute VALUETYPE_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUETYPE );
+        TextAttribute VALUE_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUE );
+        TextAttribute ADD_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEADD );
+        TextAttribute MODIFY_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODIFY );
+        TextAttribute DELETE_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEDELETE );
+        TextAttribute MODDN_TEXT_ATTRIBUTE = geTextAttribute( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODDN );
+
+        for ( int z = 0; z < containers.length; z++ )
+        {
+
+            LdifContainer container = containers[z];
+
+            LdifPart[] parts = container.getParts();
+
+            for ( int i = 0; i < parts.length; i++ )
+            {
+
+                // int offset = damage.getOffset() + parts[i].getOffset();
+                int offset = parts[i].getOffset();
+
+                if ( parts[i] instanceof LdifLineBase )
+                {
+                    LdifLineBase line = ( LdifLineBase ) parts[i];
+
+                    // String debug = line.getClass().getName() +
+                    // "("+line.getOffset()+","+line.getLength()+"):
+                    // "+line.toString();
+                    // debug = debug.replaceAll("\n", "\\\\n");
+                    // debug = debug.replaceAll("\r", "\\\\r");
+                    // System.out.println(debug);
+
+                    if ( line instanceof LdifVersionLine )
+                    {
+                        this.addStyleRange( presentation, offset, line.getLength(), KEYWORD_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifCommentLine )
+                    {
+                        this.addStyleRange( presentation, offset, line.getLength(), COMMENT_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifDnLine )
+                    {
+                        LdifDnLine dnLine = ( LdifDnLine ) line;
+                        int dnSpecLength = dnLine.getRawDnSpec().length();
+                        int valueTypeLength = dnLine.getRawValueType().length();
+                        int dnLength = dnLine.getRawDn().length();
+                        this.addStyleRange( presentation, offset, dnSpecLength, DN_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + dnSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + dnSpecLength + valueTypeLength, dnLength,
+                            DN_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifAttrValLine )
+                    {
+                        LdifAttrValLine attrValLine = ( LdifAttrValLine ) line;
+                        int attributeNameLength = attrValLine.getRawAttributeDescription().length();
+                        int valueTypeLength = attrValLine.getRawValueType().length();
+                        int valueLength = attrValLine.getRawValue().length();
+                        this.addStyleRange( presentation, offset, attributeNameLength, ATTRIBUTE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + attributeNameLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + attributeNameLength + valueTypeLength, valueLength,
+                            VALUE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifChangeTypeLine )
+                    {
+                        LdifChangeTypeLine changeTypeLine = ( LdifChangeTypeLine ) line;
+                        int changeTypeSpecLength = changeTypeLine.getRawChangeTypeSpec().length();
+                        int valueTypeLength = changeTypeLine.getRawValueType().length();
+                        int changeTypeLength = changeTypeLine.getRawChangeType().length();
+                        this.addStyleRange( presentation, offset, changeTypeSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + changeTypeSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+
+                        if ( container instanceof LdifChangeAddRecord )
+                        {
+                            this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
+                                changeTypeLength, ADD_TEXT_ATTRIBUTE );
+                        }
+                        else if ( container instanceof LdifChangeModifyRecord )
+                        {
+                            this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
+                                changeTypeLength, MODIFY_TEXT_ATTRIBUTE );
+                        }
+                        else if ( container instanceof LdifChangeModDnRecord )
+                        {
+                            this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
+                                changeTypeLength, MODDN_TEXT_ATTRIBUTE );
+                        }
+                        else if ( container instanceof LdifChangeDeleteRecord )
+                        {
+                            this.addStyleRange( presentation, offset + changeTypeSpecLength + valueTypeLength,
+                                changeTypeLength, DELETE_TEXT_ATTRIBUTE );
+                        }
+                    }
+                    else if ( line instanceof LdifNewrdnLine )
+                    {
+                        LdifNewrdnLine newrdnLine = ( LdifNewrdnLine ) line;
+                        int newrdnSpecLength = newrdnLine.getRawNewrdnSpec().length();
+                        int valueTypeLength = newrdnLine.getRawValueType().length();
+                        int newrdnLength = newrdnLine.getRawNewrdn().length();
+                        this.addStyleRange( presentation, offset, newrdnSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + newrdnSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + newrdnSpecLength + valueTypeLength, newrdnLength,
+                            VALUE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifDeloldrdnLine )
+                    {
+                        LdifDeloldrdnLine deleteoldrdnLine = ( LdifDeloldrdnLine ) line;
+                        int deleteoldrdnSpecLength = deleteoldrdnLine.getRawDeleteOldrdnSpec().length();
+                        int valueTypeLength = deleteoldrdnLine.getRawValueType().length();
+                        int deleteoldrdnLength = deleteoldrdnLine.getRawDeleteOldrdn().length();
+                        this.addStyleRange( presentation, offset, deleteoldrdnSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + deleteoldrdnSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + deleteoldrdnSpecLength + valueTypeLength,
+                            deleteoldrdnLength, VALUE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifNewsuperiorLine )
+                    {
+                        LdifNewsuperiorLine newsuperiorLine = ( LdifNewsuperiorLine ) line;
+                        int newsuperiorSpecLength = newsuperiorLine.getRawNewSuperiorSpec().length();
+                        int valueTypeLength = newsuperiorLine.getRawValueType().length();
+                        int newsuperiorLength = newsuperiorLine.getRawNewSuperiorDn().length();
+                        this.addStyleRange( presentation, offset, newsuperiorSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + newsuperiorSpecLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + newsuperiorSpecLength + valueTypeLength,
+                            newsuperiorLength, VALUE_TEXT_ATTRIBUTE );
+                    }
+                    // else if(line instanceof LdifDeloldrdnLine) {
+                    // this.addStyleRange(presentation, offset,
+                    // line.getLength(), MODTYPE_TEXT_ATTRIBUTE);
+                    // }
+                    // else if(line instanceof LdifNewsuperiorLine) {
+                    // this.addStyleRange(presentation, offset,
+                    // line.getLength(), MODTYPE_TEXT_ATTRIBUTE);
+                    // }
+                    else if ( line instanceof LdifModSpecTypeLine )
+                    {
+                        LdifModSpecTypeLine modSpecTypeLine = ( LdifModSpecTypeLine ) line;
+                        int modTypeLength = modSpecTypeLine.getRawModType().length();
+                        int valueTypeLength = modSpecTypeLine.getRawValueType().length();
+                        int attributeDescriptionLength = modSpecTypeLine.getRawAttributeDescription().length();
+                        this.addStyleRange( presentation, offset, modTypeLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + modTypeLength, valueTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + modTypeLength + valueTypeLength,
+                            attributeDescriptionLength, ATTRIBUTE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifModSpecSepLine )
+                    {
+                        this.addStyleRange( presentation, offset, line.getLength(), VALUETYPE_TEXT_ATTRIBUTE );
+                    }
+                    else if ( line instanceof LdifControlLine )
+                    {
+                        LdifControlLine controlLine = ( LdifControlLine ) line;
+                        int controlSpecLength = controlLine.getRawControlSpec().length();
+                        int controlTypeLength = controlLine.getRawControlType().length();
+                        int oidLength = controlLine.getRawOid().length();
+                        int critLength = controlLine.getRawCriticality().length();
+                        int valueTypeLength = controlLine.getRawControlValueType().length();
+                        int valueLength = controlLine.getRawControlValue().length();
+                        this.addStyleRange( presentation, offset, controlSpecLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength, controlTypeLength,
+                            VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength, oidLength,
+                            ATTRIBUTE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength + oidLength,
+                            critLength, KEYWORD_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength + oidLength
+                            + critLength, valueTypeLength, VALUETYPE_TEXT_ATTRIBUTE );
+                        this.addStyleRange( presentation, offset + controlSpecLength + controlTypeLength + oidLength
+                            + critLength + valueTypeLength, valueLength, VALUE_TEXT_ATTRIBUTE );
+                    }
+                    else
+                    {
+                        // this.addStyleRange(presentation, offset,
+                        // line.getLength(), DEFAULT_TEXT_ATTRIBUTE);
+                    }
+                }
+                else if ( parts[i] instanceof LdifModSpec )
+                {
+                    LdifModSpec modSpec = ( LdifModSpec ) parts[i];
+                    this.highlight( new LdifContainer[]
+                        { modSpec }, presentation, damage );
+
+                }
+                else if ( parts[i] instanceof LdifInvalidPart )
+                {
+                    // LdifUnknownPart unknownPart =
+                    // (LdifUnknownPart)parts[i];
+                    // this.addStyleRange(presentation, offset,
+                    // unknownPart.getLength(), UNKNOWN_TEXT_ATTRIBUTE);
+                    // this.addStyleRange(presentation, offset,
+                    // parts[i].getLength(), DEFAULT_TEXT_ATTRIBUTE);
+                }
+                else if ( parts[i] instanceof LdifEOFPart )
+                {
+                    // ignore
+                }
+                else
+                {
+                    // TODO
+                    System.out.println( "LdifDamagerRepairer: Unspecified Token: " + parts[i].getClass() );
+                }
+
+            }
+        }
+
+    }
+
+
+    private void addStyleRange( TextPresentation presentation, int offset, int length, TextAttribute textAttribute )
+    {
+        if ( offset >= 0 && length > 0 )
+        {
+            StyleRange range = new StyleRange( offset, length, textAttribute.getForeground(), textAttribute
+                .getBackground(), textAttribute.getStyle() & ( SWT.BOLD | SWT.ITALIC ) );
+            range.underline = ( textAttribute.getStyle() & TextAttribute.UNDERLINE ) != 0;
+            range.strikeout = ( textAttribute.getStyle() & TextAttribute.STRIKETHROUGH ) != 0;
+            presentation.addStyleRange( range );
+        }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifDoubleClickStrategy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifDoubleClickStrategy.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifDoubleClickStrategy.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifDoubleClickStrategy.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,157 @@
+/*
+ *  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.text;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEOFPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifInvalidPart;
+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.lines.LdifLineBase;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifSepLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifValueLineBase;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.parser.LdifParser;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultTextDoubleClickStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.ITypedRegion;
+
+
+public class LdifDoubleClickStrategy implements ITextDoubleClickStrategy
+{
+
+    private static final int OFFSET = 0;
+
+    private static final int LENGTH = 1;
+
+    /**
+     * Default double click strategy
+     */
+    private DefaultTextDoubleClickStrategy delegateDoubleClickStrategy;
+
+
+    public LdifDoubleClickStrategy()
+    {
+        this.delegateDoubleClickStrategy = new DefaultTextDoubleClickStrategy();
+    }
+
+
+    public void doubleClicked( ITextViewer viewer )
+    {
+
+        if ( !BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK ) )
+        {
+            delegateDoubleClickStrategy.doubleClicked( viewer );
+        }
+        else
+        {
+
+            int cursorPos = viewer.getSelectedRange().x;
+            if ( cursorPos < 0 )
+            {
+                return;
+            }
+
+            try
+            {
+                LdifParser parser = new LdifParser();
+                IDocument document = viewer.getDocument();
+                ITypedRegion partition = document.getPartition( cursorPos );
+
+                // now use position relative to partition
+                int offset = partition.getOffset();
+                int relativePos = cursorPos - offset;
+
+                // parse partition
+                String s = document.get( partition.getOffset(), partition.getLength() );
+                LdifFile model = parser.parse( s );
+                LdifContainer container = LdifFile.getContainer( model, relativePos );
+                if ( container != null )
+                {
+                    LdifPart part = LdifFile.getContainerContent( container, relativePos );
+
+                    if ( part != null && !( part instanceof LdifSepLine ) && !( part instanceof LdifInvalidPart )
+                        && !( part instanceof LdifEOFPart ) )
+                    {
+
+                        // calculate selected range
+                        int[] range = null;
+                        if ( part instanceof LdifValueLineBase )
+                        {
+                            LdifValueLineBase line = ( LdifValueLineBase ) part;
+                            range = getRange( relativePos, part.getOffset(), new String[]
+                                { line.getRawLineStart(), line.getRawValueType(), line.getRawValue() } );
+                        }
+                        else if ( part instanceof LdifLineBase )
+                        {
+                            LdifLineBase line = ( LdifLineBase ) part;
+                            range = new int[]
+                                { part.getOffset(), part.getLength() - line.getRawNewLine().length() };
+                        }
+
+                        // set range on viewer, add global offset
+                        int start = range != null ? range[OFFSET] : part.getOffset();
+                        start += offset;
+                        int length = range != null ? range[LENGTH] : part.getLength();
+                        viewer.setSelectedRange( start, length );
+                    }
+                    else
+                    {
+                        // use default double click strategy
+                        delegateDoubleClickStrategy.doubleClicked( viewer );
+                    }
+                }
+
+            }
+            catch ( BadLocationException e )
+            {
+                e.printStackTrace();
+            }
+        }
+    }
+
+
+    private int[] getRange( int pos, int offset, String[] parts )
+    {
+
+        for ( int i = 0; i < parts.length; i++ )
+        {
+            if ( parts[i] != null )
+            {
+                if ( pos < offset + parts[i].length() )
+                {
+                    return new int[]
+                        { offset, parts[i].length() };
+                }
+                offset += parts[i].length();
+            }
+        }
+        return null;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifExternalAnnotationModel.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifExternalAnnotationModel.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifExternalAnnotationModel.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifExternalAnnotationModel.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,30 @@
+/*
+ *  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.text;
+
+
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+
+
+public class LdifExternalAnnotationModel extends ProjectionAnnotationModel
+{
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifPartitionScanner.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifPartitionScanner.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifPartitionScanner.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifPartitionScanner.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,57 @@
+/*
+ *  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.text;
+
+
+import org.eclipse.jface.text.rules.IPredicateRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
+import org.eclipse.jface.text.rules.Token;
+
+
+public class LdifPartitionScanner extends RuleBasedPartitionScanner
+{
+
+    public final static String LDIF_RECORD = "__ldif_record";
+
+
+    public LdifPartitionScanner()
+    {
+        IToken record = new Token( LDIF_RECORD );
+
+        IPredicateRule[] rules = new IPredicateRule[1];
+        rules[0] = new LdifRecordRule( record );
+
+        setPredicateRules( rules );
+    }
+
+
+    public int read()
+    {
+        return super.read();
+        // try {
+        // return super.read();
+        // } finally {
+        // fColumn = UNDEFINED;
+        // }
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifRecordRule.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifRecordRule.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifRecordRule.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifRecordRule.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,222 @@
+/*
+ *  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.text;
+
+
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IPredicateRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+
+
+/**
+ * Rule to detect LDIF records. A LDIF record must start with "dn:" at column 0
+ * and end with new line at column 0.
+ * 
+ * 
+ */
+public class LdifRecordRule implements IPredicateRule
+{
+
+    private static char[] DN_SEQUENCE = new char[]
+        { 'd', 'n', ':' };
+
+    private IToken recordToken;
+
+
+    public LdifRecordRule( IToken recordToken )
+    {
+        this.recordToken = recordToken;
+    }
+
+
+    public IToken getSuccessToken()
+    {
+        return this.recordToken;
+    }
+
+
+    /**
+     * Checks for new line "\n", "\r" or "\r\n".
+     * 
+     * @param scanner
+     * @return
+     */
+    private int matchNewline( ICharacterScanner scanner )
+    {
+
+        int c = scanner.read();
+
+        if ( c == '\r' )
+        {
+            c = scanner.read();
+            if ( c == '\n' )
+            {
+                return 2;
+            }
+            else
+            {
+                scanner.unread();
+                return 1;
+            }
+        }
+        else if ( c == '\n' )
+        {
+            c = scanner.read();
+            if ( c == '\r' )
+            {
+                return 2;
+            }
+            else
+            {
+                scanner.unread();
+                return 1;
+            }
+        }
+        else
+        {
+            scanner.unread();
+            return 0;
+        }
+    }
+
+
+    /**
+     * Checks for "dn:".
+     * 
+     * @param scanner
+     * @return
+     */
+    private int matchDnAndColon( ICharacterScanner scanner )
+    {
+
+        for ( int i = 0; i < DN_SEQUENCE.length; i++ )
+        {
+
+            int c = scanner.read();
+
+            if ( c != DN_SEQUENCE[i] )
+            {
+                while ( i >= 0 )
+                {
+                    scanner.unread();
+                    i--;
+                }
+                return 0;
+            }
+
+        }
+
+        return DN_SEQUENCE.length;
+    }
+
+
+    private boolean matchEOF( ICharacterScanner scanner )
+    {
+        int c = scanner.read();
+        if ( c == ICharacterScanner.EOF )
+        {
+            return true;
+        }
+        else
+        {
+            scanner.unread();
+            return false;
+        }
+    }
+
+
+    public IToken evaluate( ICharacterScanner scanner, boolean resume )
+    {
+
+        if ( scanner.getColumn() != 0 )
+        {
+            return Token.UNDEFINED;
+        }
+
+        int c;
+
+        do
+        {
+            c = scanner.read();
+
+            if ( c == '\r' || c == '\n' )
+            {
+
+                // check end of record
+                scanner.unread();
+
+                if ( this.matchNewline( scanner ) > 0 )
+                {
+
+                    int nlCount = this.matchNewline( scanner );
+                    if ( nlCount > 0 )
+                    {
+                        int dnCount = this.matchDnAndColon( scanner );
+                        if ( dnCount > 0 )
+                        {
+                            while ( dnCount > 0 )
+                            {
+                                scanner.unread();
+                                dnCount--;
+                            }
+                            return this.recordToken;
+                        }
+                        else if ( this.matchEOF( scanner ) )
+                        {
+                            return this.recordToken;
+                        }
+                        else
+                        {
+                            while ( nlCount > 0 )
+                            {
+                                scanner.unread();
+                                nlCount--;
+                            }
+                        }
+                    }
+                    else if ( this.matchEOF( scanner ) )
+                    {
+                        return this.recordToken;
+                    }
+                }
+                else if ( this.matchEOF( scanner ) )
+                {
+                    return this.recordToken;
+                }
+
+            }
+            else if ( c == ICharacterScanner.EOF )
+            {
+                return this.recordToken;
+            }
+        }
+        while ( true );
+
+    }
+
+
+    public IToken evaluate( ICharacterScanner scanner )
+    {
+        return this.evaluate( scanner, false );
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifTextHover.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifTextHover.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifTextHover.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifTextHover.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,87 @@
+/*
+ *  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.text;
+
+
+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.lines.LdifValueLineBase;
+import org.apache.directory.ldapstudio.browser.ui.editors.ldif.ILdifEditor;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
+
+
+public class LdifTextHover implements ITextHover
+{
+
+    private ILdifEditor editor;
+
+
+    public LdifTextHover( ILdifEditor editor )
+    {
+        this.editor = editor;
+    }
+
+
+    public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion )
+    {
+
+        if ( this.editor != null )
+        {
+
+            LdifContainer container = LdifFile.getContainer( this.editor.getLdifModel(), hoverRegion.getOffset() );
+            if ( container != null )
+            {
+                LdifPart part = LdifFile.getContainerContent( container, hoverRegion.getOffset() );
+                if ( part != null )
+                {
+                    if ( part instanceof LdifValueLineBase )
+                    {
+                        LdifValueLineBase line = ( LdifValueLineBase ) part;
+                        if ( line.isValueTypeBase64() )
+                        {
+                            return line.getValueAsString();
+                        }
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+
+    public IRegion getHoverRegion( ITextViewer textViewer, int offset )
+    {
+
+        if ( this.editor != null )
+        {
+            return new Region( offset, 0 );
+        }
+
+        return null;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifValueRule.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifValueRule.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifValueRule.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/ldif/text/LdifValueRule.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,121 @@
+/*
+ *  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.text;
+
+
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+
+
+public class LdifValueRule implements IRule
+{
+
+    private IToken token;
+
+
+    public LdifValueRule( IToken token )
+    {
+        this.token = token;
+    }
+
+
+    public IToken evaluate( ICharacterScanner scanner )
+    {
+
+        if ( matchContent( scanner ) )
+        {
+            return this.token;
+        }
+        else
+        {
+            return Token.UNDEFINED;
+        }
+
+    }
+
+
+    protected boolean matchContent( ICharacterScanner scanner )
+    {
+
+        int count = 0;
+
+        int c = scanner.read();
+        while ( c != ICharacterScanner.EOF )
+        {
+
+            // check for folding
+            if ( c == '\n' || c == '\r' )
+            {
+                StringBuffer temp = new StringBuffer( 3 );
+                if ( c == '\r' )
+                {
+                    c = scanner.read();
+                    if ( c == '\n' )
+                    {
+                        temp.append( c );
+                    }
+                    else
+                    {
+                        scanner.unread();
+                    }
+                }
+                else if ( c == '\n' )
+                {
+                    c = scanner.read();
+                    if ( c == '\r' )
+                    {
+                        temp.append( c );
+                    }
+                    else
+                    {
+                        scanner.unread();
+                    }
+                }
+
+                c = scanner.read();
+                if ( c == ' ' && c != ICharacterScanner.EOF )
+                {
+                    // space after newline, continue
+                    temp.append( c );
+                    count += temp.length();
+                    c = scanner.read();
+                }
+                else
+                {
+                    for ( int i = 0; i < temp.length(); i++ )
+                        scanner.unread();
+                    break;
+                }
+            }
+            else
+            {
+                count++;
+                c = scanner.read();
+            }
+        }
+        scanner.unread();
+
+        return count > 0;
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/AttributeTypeDescriptionDetailsPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/AttributeTypeDescriptionDetailsPage.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/AttributeTypeDescriptionDetailsPage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/AttributeTypeDescriptionDetailsPage.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,731 @@
+/*
+ *  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.schemabrowser;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.events.ExpansionAdapter;
+import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Hyperlink;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
+
+
+public class AttributeTypeDescriptionDetailsPage extends SchemaDetailsPage
+{
+
+    private Section mainSection;
+
+    private Text numericOidText;
+
+    private Text nameText;
+
+    private Text descText;
+
+    private Text usageText;
+
+    private Section flagSection;
+
+    private Label singleValuedText;
+
+    private Label isObsoleteText;
+
+    private Label collectiveText;
+
+    private Label noUserModificationText;
+
+    private Section syntaxSection;
+
+    private Text syntaxText;
+
+    private Text lengthText;
+
+    private Hyperlink syntaxLink;
+
+    private Section matchSection;
+
+    private Hyperlink equalityLink;
+
+    private Hyperlink substringLink;
+
+    private Hyperlink orderingLink;
+
+    private Section otherMatchSection;
+
+    private Hyperlink[] otherMatchLinks;
+
+    private Section mustSection;
+
+    private Hyperlink[] usedAsMustLinks;
+
+    private Section maySection;
+
+    private Hyperlink[] usedAsMayLinks;
+
+    private Section superSection;
+
+    private Hyperlink superLink;
+
+    private Section subSection;
+
+    private Hyperlink[] subAttributeTypeLinks;
+
+
+    public AttributeTypeDescriptionDetailsPage( SchemaBrowser schemaBrowser, FormToolkit toolkit )
+    {
+        super( schemaBrowser, toolkit );
+    }
+
+
+    public void createContents( final ScrolledForm detailForm )
+    {
+
+        this.detailForm = detailForm;
+        detailForm.getBody().setLayout( new GridLayout() );
+
+        mainSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
+        mainSection.setText( "Details" );
+        mainSection.marginWidth = 0;
+        mainSection.marginHeight = 0;
+        mainSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        toolkit.createCompositeSeparator( mainSection );
+
+        flagSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
+        flagSection.setText( "Flags" );
+        flagSection.marginWidth = 0;
+        flagSection.marginHeight = 0;
+        flagSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        toolkit.createCompositeSeparator( flagSection );
+
+        Composite flagClient = toolkit.createComposite( flagSection, SWT.WRAP );
+        GridLayout flagLayout = new GridLayout();
+        flagLayout.numColumns = 4;
+        flagLayout.marginWidth = 0;
+        flagLayout.marginHeight = 0;
+        flagClient.setLayout( flagLayout );
+        flagSection.setClient( flagClient );
+
+        singleValuedText = toolkit.createLabel( flagClient, "Single valued", SWT.CHECK );
+        singleValuedText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        singleValuedText.setEnabled( false );
+
+        noUserModificationText = toolkit.createLabel( flagClient, "Read only", SWT.CHECK );
+        noUserModificationText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        noUserModificationText.setEnabled( false );
+
+        collectiveText = toolkit.createLabel( flagClient, "Collective", SWT.CHECK );
+        collectiveText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        collectiveText.setEnabled( false );
+
+        isObsoleteText = toolkit.createLabel( flagClient, "Obsolete", SWT.CHECK );
+        isObsoleteText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        isObsoleteText.setEnabled( false );
+
+        syntaxSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
+        syntaxSection.setText( "Syntax" );
+        syntaxSection.marginWidth = 0;
+        syntaxSection.marginHeight = 0;
+        syntaxSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        toolkit.createCompositeSeparator( syntaxSection );
+
+        Composite syntaxClient = toolkit.createComposite( syntaxSection, SWT.WRAP );
+        GridLayout syntaxLayout = new GridLayout();
+        syntaxLayout.numColumns = 2;
+        syntaxLayout.marginWidth = 0;
+        syntaxLayout.marginHeight = 0;
+        syntaxClient.setLayout( syntaxLayout );
+        syntaxSection.setClient( syntaxClient );
+
+        toolkit.createLabel( syntaxClient, "Syntax OID:", SWT.NONE );
+        syntaxLink = toolkit.createHyperlink( syntaxClient, "", SWT.WRAP );
+        syntaxLink.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        syntaxLink.addHyperlinkListener( new HyperlinkAdapter()
+        {
+            public void linkActivated( HyperlinkEvent e )
+            {
+                SchemaBrowser.select( e.getHref() );
+            }
+        } );
+
+        toolkit.createLabel( syntaxClient, "Syntax Description:", SWT.NONE );
+        syntaxText = toolkit.createText( syntaxClient, "", SWT.NONE );
+        syntaxText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        syntaxText.setEditable( false );
+
+        toolkit.createLabel( syntaxClient, "Length:", SWT.NONE );
+        lengthText = toolkit.createText( syntaxClient, "", SWT.NONE );
+        lengthText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        lengthText.setEditable( false );
+
+        matchSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
+        matchSection.setText( "Matching Rules" );
+        matchSection.marginWidth = 0;
+        matchSection.marginHeight = 0;
+        matchSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        toolkit.createCompositeSeparator( matchSection );
+
+        Composite matchClient = toolkit.createComposite( matchSection, SWT.WRAP );
+        GridLayout matchLayout = new GridLayout();
+        matchLayout.numColumns = 2;
+        matchLayout.marginWidth = 0;
+        matchLayout.marginHeight = 0;
+        matchClient.setLayout( matchLayout );
+        matchSection.setClient( matchClient );
+
+        toolkit.createLabel( matchClient, "Equality match:", SWT.NONE );
+        equalityLink = toolkit.createHyperlink( matchClient, "", SWT.WRAP );
+        equalityLink.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        equalityLink.addHyperlinkListener( new HyperlinkAdapter()
+        {
+            public void linkActivated( HyperlinkEvent e )
+            {
+                SchemaBrowser.select( e.getHref() );
+            }
+        } );
+
+        toolkit.createLabel( matchClient, "Substring match:", SWT.NONE );
+        substringLink = toolkit.createHyperlink( matchClient, "", SWT.WRAP );
+        substringLink.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        substringLink.addHyperlinkListener( new HyperlinkAdapter()
+        {
+            public void linkActivated( HyperlinkEvent e )
+            {
+                SchemaBrowser.select( e.getHref() );
+            }
+        } );
+
+        toolkit.createLabel( matchClient, "Ordering match:", SWT.NONE );
+        orderingLink = toolkit.createHyperlink( matchClient, "", SWT.WRAP );
+        orderingLink.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        orderingLink.addHyperlinkListener( new HyperlinkAdapter()
+        {
+            public void linkActivated( HyperlinkEvent e )
+            {
+                SchemaBrowser.select( e.getHref() );
+            }
+        } );
+
+        otherMatchSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
+        otherMatchSection.setText( "Other Matching Rules" );
+        otherMatchSection.marginWidth = 0;
+        otherMatchSection.marginHeight = 0;
+        otherMatchSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        toolkit.createCompositeSeparator( otherMatchSection );
+        otherMatchSection.addExpansionListener( new ExpansionAdapter()
+        {
+            public void expansionStateChanged( ExpansionEvent e )
+            {
+                detailForm.reflow( true );
+            }
+        } );
+
+        mustSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
+        mustSection.setText( "Used as MUST" );
+        mustSection.marginWidth = 0;
+        mustSection.marginHeight = 0;
+        mustSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        toolkit.createCompositeSeparator( mustSection );
+        mustSection.addExpansionListener( new ExpansionAdapter()
+        {
+            public void expansionStateChanged( ExpansionEvent e )
+            {
+                detailForm.reflow( true );
+            }
+        } );
+
+        maySection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
+        maySection.setText( "Used as MAY" );
+        maySection.marginWidth = 0;
+        maySection.marginHeight = 0;
+        maySection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        toolkit.createCompositeSeparator( maySection );
+        maySection.addExpansionListener( new ExpansionAdapter()
+        {
+            public void expansionStateChanged( ExpansionEvent e )
+            {
+                detailForm.reflow( true );
+            }
+        } );
+
+        superSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
+        superSection.setText( "Supertypes" );
+        superSection.marginWidth = 0;
+        superSection.marginHeight = 0;
+        superSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        toolkit.createCompositeSeparator( superSection );
+        superSection.addExpansionListener( new ExpansionAdapter()
+        {
+            public void expansionStateChanged( ExpansionEvent e )
+            {
+                detailForm.reflow( true );
+            }
+        } );
+
+        subSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
+        subSection.setText( "Subtypes" );
+        subSection.marginWidth = 0;
+        subSection.marginHeight = 0;
+        subSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        toolkit.createCompositeSeparator( subSection );
+        subSection.addExpansionListener( new ExpansionAdapter()
+        {
+            public void expansionStateChanged( ExpansionEvent e )
+            {
+                detailForm.reflow( true );
+            }
+        } );
+
+        super.createRawSection();
+    }
+
+
+    public void attributeTypeDescriptionSelected( AttributeTypeDescription atd )
+    {
+        this.createMainContent( atd );
+
+        singleValuedText.setEnabled( atd != null && atd.isSingleValued() );
+        isObsoleteText.setEnabled( atd != null && atd.isObsolete() );
+        collectiveText.setEnabled( atd != null && atd.isCollective() );
+        noUserModificationText.setEnabled( atd != null && atd.isNoUserModification() );
+        flagSection.layout();
+
+        String lsdOid = null;
+        LdapSyntaxDescription lsd = null;
+        String lsdLength = null;
+        if ( atd != null )
+        {
+            lsdOid = atd.getSyntaxDescriptionNumericOIDTransitive();
+            if ( lsdOid != null && atd.getSchema().hasLdapSyntaxDescription( lsdOid ) )
+            {
+                lsd = atd.getSchema().getLdapSyntaxDescription( lsdOid );
+            }
+            lsdLength = atd.getSyntaxDescriptionLengthTransitive();
+        }
+        syntaxLink.setText( getNonNullString( lsd != null ? lsd.getNumericOID() : lsdOid ) );
+        syntaxLink.setHref( lsd );
+        syntaxLink.setUnderlined( lsd != null );
+        syntaxLink.setEnabled( lsd != null );
+        syntaxText.setText( getNonNullString( lsd != null ? lsd.getDesc() : null ) );
+        lengthText.setText( getNonNullString( lsdLength ) );
+        syntaxSection.layout();
+
+        String emrOid = null;
+        MatchingRuleDescription emr = null;
+        if ( atd != null )
+        {
+            emrOid = atd.getEqualityMatchingRuleDescriptionOIDTransitive();
+            if ( emrOid != null && atd.getSchema().hasMatchingRuleDescription( emrOid ) )
+            {
+                emr = atd.getSchema().getMatchingRuleDescription( emrOid );
+            }
+        }
+        equalityLink.setText( getNonNullString( emr != null ? emr.toString() : emrOid ) );
+        equalityLink.setHref( emr );
+        equalityLink.setUnderlined( emr != null );
+        equalityLink.setEnabled( emr != null );
+
+        String smrOid = null;
+        MatchingRuleDescription smr = null;
+        if ( atd != null )
+        {
+            smrOid = atd.getSubstringMatchingRuleDescriptionOIDTransitive();
+            if ( smrOid != null && atd.getSchema().hasMatchingRuleDescription( smrOid ) )
+            {
+                smr = atd.getSchema().getMatchingRuleDescription( smrOid );
+            }
+        }
+        substringLink.setText( getNonNullString( smr != null ? smr.toString() : smrOid ) );
+        substringLink.setHref( smr );
+        substringLink.setUnderlined( smr != null );
+        substringLink.setEnabled( smr != null );
+
+        String omrOid = null;
+        MatchingRuleDescription omr = null;
+        if ( atd != null )
+        {
+            omrOid = atd.getOrderingMatchingRuleDescriptionOIDTransitive();
+            if ( omrOid != null && atd.getSchema().hasMatchingRuleDescription( omrOid ) )
+            {
+                omr = atd.getSchema().getMatchingRuleDescription( omrOid );
+            }
+        }
+        orderingLink.setText( getNonNullString( omr != null ? omr.toString() : omrOid ) );
+        orderingLink.setHref( omr );
+        orderingLink.setUnderlined( omr != null );
+        orderingLink.setEnabled( omr != null );
+        matchSection.layout();
+
+        this.createOtherMatchContent( atd );
+        this.createMustContent( atd );
+        this.createMayContent( atd );
+        this.createSuperContent( atd );
+        this.createSubContent( atd );
+
+        super.createRawContents( atd );
+
+        detailForm.reflow( true );
+    }
+
+
+    private void createMainContent( AttributeTypeDescription atd )
+    {
+
+        if ( mainSection.getClient() != null )
+        {
+            mainSection.getClient().dispose();
+        }
+
+        Composite mainClient = toolkit.createComposite( mainSection, SWT.WRAP );
+        GridLayout mainLayout = new GridLayout( 2, false );
+        mainClient.setLayout( mainLayout );
+        mainSection.setClient( mainClient );
+
+        if ( atd != null )
+        {
+
+            toolkit.createLabel( mainClient, "Numeric OID:", SWT.NONE );
+            numericOidText = toolkit.createText( mainClient, getNonNullString( atd.getNumericOID() ), SWT.NONE );
+            numericOidText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+            numericOidText.setEditable( false );
+
+            toolkit.createLabel( mainClient, "Attribute names:", SWT.NONE );
+            nameText = toolkit.createText( mainClient, getNonNullString( atd.toString() ), SWT.NONE );
+            nameText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+            nameText.setEditable( false );
+
+            toolkit.createLabel( mainClient, "Descripton:", SWT.WRAP );
+            descText = toolkit.createText( mainClient, getNonNullString( atd.getDesc() ), SWT.WRAP | SWT.MULTI );
+            GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+            gd.widthHint = detailForm.getForm().getSize().x - 100 - 60;
+            descText.setLayoutData( gd );
+            descText.setEditable( false );
+
+            toolkit.createLabel( mainClient, "Usage:", SWT.NONE );
+            usageText = toolkit.createText( mainClient, getNonNullString( atd.getUsage() ), SWT.NONE );
+            usageText.setLayoutData( new GridData( GridData.GRAB_HORIZONTAL ) );
+            usageText.setEditable( false );
+
+        }
+
+        mainSection.layout();
+    }
+
+
+    private void createOtherMatchContent( AttributeTypeDescription atd )
+    {
+
+        if ( otherMatchSection.getClient() != null )
+        {
+            otherMatchSection.getClient().dispose();
+        }
+
+        Composite otherMatchClient = toolkit.createComposite( otherMatchSection, SWT.WRAP );
+        otherMatchClient.setLayout( new GridLayout() );
+        otherMatchSection.setClient( otherMatchClient );
+
+        if ( atd != null )
+        {
+            String[] names = atd.getOtherMatchingRuleDescriptionNames();
+            if ( names != null && names.length > 0 )
+            {
+                otherMatchSection.setText( "Other Matching Rules (" + names.length + ")" );
+                otherMatchLinks = new Hyperlink[names.length];
+                for ( int i = 0; i < names.length; i++ )
+                {
+                    if ( atd.getSchema().hasMatchingRuleDescription( names[i] ) )
+                    {
+                        MatchingRuleDescription mrd = atd.getSchema().getMatchingRuleDescription( names[i] );
+                        otherMatchLinks[i] = toolkit.createHyperlink( otherMatchClient, mrd.toString(), SWT.WRAP );
+                        otherMatchLinks[i].setHref( mrd );
+                        otherMatchLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                        otherMatchLinks[i].setUnderlined( true );
+                        otherMatchLinks[i].setEnabled( true );
+                        otherMatchLinks[i].addHyperlinkListener( new HyperlinkAdapter()
+                        {
+                            public void linkActivated( HyperlinkEvent e )
+                            {
+                                SchemaBrowser.select( e.getHref() );
+                            }
+                        } );
+                    }
+                    else
+                    {
+                        otherMatchLinks[i] = toolkit.createHyperlink( otherMatchClient, names[i], SWT.WRAP );
+                        otherMatchLinks[i].setHref( null );
+                        otherMatchLinks[i].setUnderlined( false );
+                        otherMatchLinks[i].setEnabled( false );
+                    }
+                }
+            }
+            else
+            {
+                otherMatchSection.setText( "Other Matching Rules (0)" );
+                otherMatchLinks = new Hyperlink[0];
+                Text otherText = toolkit.createText( otherMatchClient, getNonNullString( null ), SWT.NONE );
+                otherText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                otherText.setEditable( false );
+            }
+        }
+        else
+        {
+            otherMatchSection.setText( "Other Matching Rules" );
+        }
+
+        otherMatchSection.layout();
+
+    }
+
+
+    private void createSuperContent( AttributeTypeDescription atd )
+    {
+
+        if ( superSection.getClient() != null )
+        {
+            superSection.getClient().dispose();
+        }
+
+        Composite superClient = toolkit.createComposite( superSection, SWT.WRAP );
+        superClient.setLayout( new GridLayout() );
+        superSection.setClient( superClient );
+
+        if ( atd != null )
+        {
+            String superName = atd.getSuperiorAttributeTypeDescriptionName();
+            if ( superName != null )
+            {
+                superSection.setText( "Supertype (" + "1" + ")" );
+                if ( atd.getSchema().hasAttributeTypeDescription( superName ) )
+                {
+                    AttributeTypeDescription supAtd = atd.getSchema().getAttributeTypeDescription( superName );
+                    superLink = toolkit.createHyperlink( superClient, supAtd.toString(), SWT.WRAP );
+                    superLink.setHref( supAtd );
+                    superLink.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                    superLink.setUnderlined( true );
+                    superLink.setEnabled( true );
+                    superLink.addHyperlinkListener( new HyperlinkAdapter()
+                    {
+                        public void linkActivated( HyperlinkEvent e )
+                        {
+                            SchemaBrowser.select( e.getHref() );
+                        }
+                    } );
+                }
+                else
+                {
+                    superLink = toolkit.createHyperlink( superClient, superName, SWT.WRAP );
+                    superLink.setHref( null );
+                    superLink.setUnderlined( false );
+                    superLink.setEnabled( false );
+                }
+            }
+            else
+            {
+                superSection.setText( "Supertype (0)" );
+                superLink = null;
+                Text supText = toolkit.createText( superClient, getNonNullString( null ), SWT.NONE );
+                supText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                supText.setEditable( false );
+            }
+        }
+        else
+        {
+            superSection.setText( "Supertype" );
+        }
+
+        superSection.layout();
+
+    }
+
+
+    private void createSubContent( AttributeTypeDescription atd )
+    {
+
+        if ( subSection.getClient() != null )
+        {
+            subSection.getClient().dispose();
+        }
+
+        Composite subClient = toolkit.createComposite( subSection, SWT.WRAP );
+        subClient.setLayout( new GridLayout() );
+        subSection.setClient( subClient );
+
+        if ( atd != null )
+        {
+            AttributeTypeDescription[] subATDs = atd.getDerivedAttributeTypeDescriptions();
+            if ( subATDs != null && subATDs.length > 0 )
+            {
+                subSection.setText( "Subtypes (" + subATDs.length + ")" );
+                subAttributeTypeLinks = new Hyperlink[subATDs.length];
+                for ( int i = 0; i < subATDs.length; i++ )
+                {
+                    subAttributeTypeLinks[i] = toolkit.createHyperlink( subClient, subATDs[i].toString(), SWT.WRAP );
+                    subAttributeTypeLinks[i].setHref( subATDs[i] );
+                    subAttributeTypeLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                    subAttributeTypeLinks[i].setUnderlined( true );
+                    subAttributeTypeLinks[i].setEnabled( true );
+                    subAttributeTypeLinks[i].addHyperlinkListener( new HyperlinkAdapter()
+                    {
+                        public void linkActivated( HyperlinkEvent e )
+                        {
+                            SchemaBrowser.select( e.getHref() );
+                        }
+                    } );
+                }
+            }
+            else
+            {
+                subSection.setText( "Subtypes (0)" );
+                subAttributeTypeLinks = new Hyperlink[0];
+                Text subText = toolkit.createText( subClient, getNonNullString( null ), SWT.NONE );
+                subText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                subText.setEditable( false );
+            }
+        }
+        else
+        {
+            subSection.setText( "Subtypes" );
+        }
+
+        subSection.layout();
+
+    }
+
+
+    private void createMustContent( AttributeTypeDescription atd )
+    {
+
+        if ( mustSection.getClient() != null )
+        {
+            mustSection.getClient().dispose();
+        }
+
+        Composite mustClient = toolkit.createComposite( mustSection, SWT.WRAP );
+        mustClient.setLayout( new GridLayout() );
+        mustSection.setClient( mustClient );
+
+        if ( atd != null )
+        {
+            ObjectClassDescription[] usedAsMusts = atd.getUsedAsMust();
+            if ( usedAsMusts != null && usedAsMusts.length > 0 )
+            {
+                mustSection.setText( "Used as MUST (" + usedAsMusts.length + ")" );
+                usedAsMustLinks = new Hyperlink[usedAsMusts.length];
+                for ( int i = 0; i < usedAsMusts.length; i++ )
+                {
+                    usedAsMustLinks[i] = toolkit.createHyperlink( mustClient, usedAsMusts[i].toString(), SWT.WRAP );
+                    usedAsMustLinks[i].setHref( usedAsMusts[i] );
+                    usedAsMustLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                    usedAsMustLinks[i].setUnderlined( true );
+                    usedAsMustLinks[i].setEnabled( true );
+                    usedAsMustLinks[i].addHyperlinkListener( new HyperlinkAdapter()
+                    {
+                        public void linkActivated( HyperlinkEvent e )
+                        {
+                            SchemaBrowser.select( e.getHref() );
+                        }
+                    } );
+                }
+            }
+            else
+            {
+                mustSection.setText( "Used as MUST (0)" );
+                usedAsMustLinks = new Hyperlink[0];
+                Text mustText = toolkit.createText( mustClient, getNonNullString( null ), SWT.NONE );
+                mustText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                mustText.setEditable( false );
+            }
+        }
+        else
+        {
+            mustSection.setText( "Used as MUST" );
+        }
+
+        mustSection.layout();
+
+    }
+
+
+    private void createMayContent( AttributeTypeDescription atd )
+    {
+
+        if ( maySection.getClient() != null )
+        {
+            maySection.getClient().dispose();
+        }
+
+        Composite mayClient = toolkit.createComposite( maySection, SWT.WRAP );
+        mayClient.setLayout( new GridLayout() );
+        maySection.setClient( mayClient );
+
+        if ( atd != null )
+        {
+            ObjectClassDescription[] usedAsMays = atd.getUsedAsMay();
+            if ( usedAsMays != null && usedAsMays.length > 0 )
+            {
+                maySection.setText( "Used as MAY (" + usedAsMays.length + ")" );
+                usedAsMayLinks = new Hyperlink[usedAsMays.length];
+                for ( int i = 0; i < usedAsMays.length; i++ )
+                {
+                    usedAsMayLinks[i] = toolkit.createHyperlink( mayClient, usedAsMays[i].toString(), SWT.WRAP );
+                    usedAsMayLinks[i].setHref( usedAsMays[i] );
+                    usedAsMayLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                    usedAsMayLinks[i].setUnderlined( true );
+                    usedAsMayLinks[i].setEnabled( true );
+                    usedAsMayLinks[i].addHyperlinkListener( new HyperlinkAdapter()
+                    {
+                        public void linkActivated( HyperlinkEvent e )
+                        {
+                            SchemaBrowser.select( e.getHref() );
+                        }
+                    } );
+                }
+            }
+            else
+            {
+                maySection.setText( "Used as MAY (0)" );
+                usedAsMayLinks = new Hyperlink[0];
+                Text mayText = toolkit.createText( mayClient, getNonNullString( null ), SWT.NONE );
+                mayText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+                mayText.setEditable( false );
+            }
+        }
+        else
+        {
+            maySection.setText( "Used as MAY" );
+        }
+
+        maySection.layout();
+    }
+
+}

Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/AttributeTypeDescriptionPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/AttributeTypeDescriptionPage.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/AttributeTypeDescriptionPage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/AttributeTypeDescriptionPage.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,239 @@
+/*
+ *  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.schemabrowser;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+
+
+public class AttributeTypeDescriptionPage extends SchemaPage implements ISelectionChangedListener
+{
+
+    private Section section;
+
+    private Text filterText;
+
+    private TableViewer viewer;
+
+
+    public AttributeTypeDescriptionPage( SchemaBrowser schemaBrowser )
+    {
+        super( schemaBrowser );
+    }
+
+
+    protected void refresh()
+    {
+        if ( this.schemaBrowser.isShowDefaultSchema() )
+        {
+            this.form.setText( "Attribute Types of default schema" );
+            this.viewer.setInput( Schema.DEFAULT_SCHEMA );
+        }
+        else if ( this.selectedConnection != null )
+        {
+            this.form.setText( "Attribute Types of connection '" + this.selectedConnection.getName() + "'" );
+            this.viewer.setInput( this.selectedConnection.getSchema() );
+        }
+        else
+        {
+            this.form.setText( "Attribute Types" );
+            this.viewer.setInput( null );
+        }
+        this.viewer.refresh();
+    }
+
+
+    protected void createMaster( Composite parent )
+    {
+
+        section = toolkit.createSection( parent, Section.DESCRIPTION );
+        section.marginWidth = 10;
+        section.marginHeight = 12;
+        section.setText( "Attribute Types" );
+        section.setDescription( "Please select a attribute type. Enter a filter to restrict the list." );
+        toolkit.createCompositeSeparator( section );
+
+        Composite client = toolkit.createComposite( section, SWT.WRAP );
+        GridLayout layout = new GridLayout( 2, false );
+        layout.marginWidth = 5;
+        layout.marginHeight = 5;
+        client.setLayout( layout );
+        section.setClient( client );
+
+        toolkit.createLabel( client, "Filter:" );
+        this.filterText = toolkit.createText( client, "", SWT.NONE );
+        this.filterText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        this.filterText.setData( FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER );
+        this.filterText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                viewer.refresh();
+            }
+        } );
+
+        Table t = toolkit.createTable( client, SWT.NONE );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.horizontalSpan = 2;
+        gd.heightHint = 20;
+        gd.widthHint = 100;
+        t.setLayoutData( gd );
+        toolkit.paintBordersFor( client );
+
+        viewer = new TableViewer( t );
+        viewer.setContentProvider( new ATDContentProvider() );
+        viewer.setLabelProvider( new ATDLabelProvider() );
+        viewer.setSorter( new ATDViewerSorter() );
+        viewer.addFilter( new ATDViewerFilter() );
+    }
+
+
+    protected void createDetail( Composite body )
+    {
+        this.detailsPage = new AttributeTypeDescriptionDetailsPage( this.schemaBrowser, this.toolkit );
+        this.detailsPage.createContents( this.detailForm );
+        this.viewer.addSelectionChangedListener( this );
+    }
+
+
+    public void selectionChanged( SelectionChangedEvent event )
+    {
+        ISelection selection = event.getSelection();
+        if ( selection.isEmpty() )
+        {
+            EventRegistry.fireAttributeTypeDescriptionSelected( null, this );
+        }
+        else
+        {
+            Object obj = ( ( StructuredSelection ) selection ).getFirstElement();
+            if ( obj instanceof AttributeTypeDescription )
+            {
+                AttributeTypeDescription atd = ( AttributeTypeDescription ) obj;
+                EventRegistry.fireAttributeTypeDescriptionSelected( atd, this );
+            }
+        }
+    }
+
+
+    public void select( Object obj )
+    {
+        this.viewer.setSelection( new StructuredSelection( obj ), true );
+        if ( this.viewer.getSelection().isEmpty() )
+        {
+            this.filterText.setText( "" );
+            this.viewer.setSelection( new StructuredSelection( obj ), true );
+        }
+    }
+
+    class ATDContentProvider implements IStructuredContentProvider
+    {
+        public Object[] getElements( Object inputElement )
+        {
+            if ( inputElement instanceof Schema )
+            {
+                Schema schema = ( Schema ) inputElement;
+                if ( schema != null )
+                {
+                    return schema.getAttributeTypeDescriptions();
+                }
+            }
+            return new Object[0];
+        }
+
+
+        public void dispose()
+        {
+        }
+
+
+        public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+        {
+        }
+    }
+
+    class ATDLabelProvider extends LabelProvider implements ITableLabelProvider
+    {
+        public String getColumnText( Object obj, int index )
+        {
+            return obj.toString();
+        }
+
+
+        public Image getColumnImage( Object obj, int index )
+        {
+            return null;
+        }
+    }
+
+    class ATDViewerSorter extends ViewerSorter
+    {
+        public int compare( Viewer viewer, Object e1, Object e2 )
+        {
+            return e1.toString().compareTo( e2.toString() );
+        }
+    }
+
+    class ATDViewerFilter extends ViewerFilter
+    {
+        public boolean select( Viewer viewer, Object parentElement, Object element )
+        {
+            if ( element instanceof AttributeTypeDescription )
+            {
+                AttributeTypeDescription atd = ( AttributeTypeDescription ) element;
+                boolean matched = false;
+
+                if ( !matched )
+                    matched = atd.toString().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1;
+                if ( !matched )
+                    matched = atd.getNumericOID().toLowerCase().indexOf( filterText.getText().toLowerCase() ) != -1;
+
+                return matched;
+            }
+            return false;
+        }
+    }
+
+}



Mime
View raw message