directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r504202 - in /directory/ldapstudio/trunk/ldapstudio-schemas-plugin: META-INF/ src/main/java/org/apache/directory/ldapstudio/schemas/ src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/ src/main/java/org/apache/directory/ldap...
Date Tue, 06 Feb 2007 17:14:18 GMT
Author: pamarcelot
Date: Tue Feb  6 09:14:17 2007
New Revision: 504202

URL: http://svn.apache.org/viewvc?view=rev&rev=504202
Log:
Fixed DIRSTUDIO-33 (Add syntax coloring to the Source Code view of AT, OC & Schema editors).

Added:
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaCodeScanner.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewer.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewerConfiguration.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaTextAttributeProvider.java
Modified:
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/META-INF/MANIFEST.MF
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/AttributeTypeFormEditorSourceCodePage.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/ObjectClassFormEditorSourceCodePage.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/SchemaFormEditorSourceCodePage.java

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/META-INF/MANIFEST.MF?view=diff&rev=504202&r1=504201&r2=504202
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/META-INF/MANIFEST.MF (original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/META-INF/MANIFEST.MF Tue Feb  6 09:14:17
2007
@@ -8,7 +8,8 @@
 Bundle-Localization: plugin
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime,
- org.apache.directory.ldapstudio.jars
+ org.apache.directory.ldapstudio.jars,
+ org.eclipse.jface.text
 Eclipse-LazyStart: true
 Bundle-ClassPath: .,
  lib/commons-collections-3.1.jar,

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java?view=diff&rev=504202&r1=504201&r2=504202
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/Activator.java
Tue Feb  6 09:14:17 2007
@@ -24,8 +24,11 @@
 import org.apache.directory.ldapstudio.schemas.controller.Application;
 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
 import org.apache.directory.ldapstudio.schemas.view.preferences.SchemaPreferencePage;
+import org.apache.directory.ldapstudio.schemas.view.viewers.SchemaCodeScanner;
+import org.apache.directory.ldapstudio.schemas.view.viewers.SchemaTextAttributeProvider;
 import org.eclipse.core.runtime.preferences.ConfigurationScope;
 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.text.rules.ITokenScanner;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 
@@ -42,6 +45,10 @@
     // The shared instance
     private static Activator plugin;
 
+    private static ITokenScanner schemaCodeScanner;
+
+    private static SchemaTextAttributeProvider schemaTextAttributeProvider;
+
 
     /**
      * The constructor
@@ -88,4 +95,37 @@
         return plugin;
     }
 
+
+    /**
+     * Returns the Schema Code Scanner.
+     *
+     * @return
+     *      the Schema Code Scanner
+     */
+    public static ITokenScanner getSchemaCodeScanner()
+    {
+        if ( schemaCodeScanner == null )
+        {
+            schemaCodeScanner = new SchemaCodeScanner( getSchemaTextAttributeProvider() );
+        }
+        
+        return schemaCodeScanner;
+    }
+
+
+    /**
+     * Returns the Schema Text Attribute Provider.
+     *
+     * @return
+     *     the Schema Text Attribute Provider 
+     */
+    private static SchemaTextAttributeProvider getSchemaTextAttributeProvider()
+    {
+        if ( schemaTextAttributeProvider == null )
+        {
+            schemaTextAttributeProvider = new SchemaTextAttributeProvider();
+        }
+        
+        return schemaTextAttributeProvider;
+    }
 }

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/AttributeTypeFormEditorSourceCodePage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/AttributeTypeFormEditorSourceCodePage.java?view=diff&rev=504202&r1=504201&r2=504202
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/AttributeTypeFormEditorSourceCodePage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/AttributeTypeFormEditorSourceCodePage.java
Tue Feb  6 09:14:17 2007
@@ -22,10 +22,14 @@
 
 
 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
+import org.apache.directory.ldapstudio.schemas.view.viewers.SchemaSourceViewer;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.IManagedForm;
 import org.eclipse.ui.forms.editor.FormEditor;
 import org.eclipse.ui.forms.editor.FormPage;
@@ -39,7 +43,7 @@
 public class AttributeTypeFormEditorSourceCodePage extends FormPage
 {
     private AttributeType attributeType;
-    private Text sourceCode_text;
+    private SchemaSourceViewer schemaSourceViewer;
 
 
     /**
@@ -70,9 +74,16 @@
         attributeType = input.getAttributeType();
 
         // SOURCE CODE Field
-        sourceCode_text = toolkit.createText( form.getBody(), "", SWT.MULTI ); //$NON-NLS-1$
-        sourceCode_text.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
-        sourceCode_text.setEditable( false );
+        schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.MULTI
);
+        schemaSourceViewer.getTextWidget().setLayoutData( new GridData( SWT.FILL, SWT.FILL,
true, true ) );
+        schemaSourceViewer.getTextWidget().setEditable( false );
+        
+        // set text font
+        Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT );
+        schemaSourceViewer.getTextWidget().setFont( font );
+        
+        IDocument document = new Document();
+        schemaSourceViewer.setDocument( document );
 
         // Initialization from the "input" object class
         initFieldsContentFromInput();
@@ -82,7 +93,7 @@
     private void initFieldsContentFromInput()
     {
         // SOURCE CODE Field
-        sourceCode_text.setText( attributeType.write() );
+        schemaSourceViewer.getDocument().set( attributeType.write() );
     }
 
 
@@ -91,7 +102,7 @@
      */
     public void refresh()
     {
-        if ( sourceCode_text != null )
+        if ( schemaSourceViewer != null )
         {
             initFieldsContentFromInput();
         }

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/ObjectClassFormEditorSourceCodePage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/ObjectClassFormEditorSourceCodePage.java?view=diff&rev=504202&r1=504201&r2=504202
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/ObjectClassFormEditorSourceCodePage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/ObjectClassFormEditorSourceCodePage.java
Tue Feb  6 09:14:17 2007
@@ -22,10 +22,14 @@
 
 
 import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
+import org.apache.directory.ldapstudio.schemas.view.viewers.SchemaSourceViewer;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.IManagedForm;
 import org.eclipse.ui.forms.editor.FormEditor;
 import org.eclipse.ui.forms.editor.FormPage;
@@ -39,7 +43,7 @@
 public class ObjectClassFormEditorSourceCodePage extends FormPage
 {
     private ObjectClass objectClass;
-    private Text sourceCode_text;
+    private SchemaSourceViewer schemaSourceViewer;
 
 
     /**
@@ -70,9 +74,16 @@
         objectClass = input.getObjectClass();
 
         // SOURCE CODE Field
-        sourceCode_text = toolkit.createText( form.getBody(), "", SWT.MULTI ); //$NON-NLS-1$
-        sourceCode_text.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
-        sourceCode_text.setEditable( false );
+        schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.MULTI
);
+        schemaSourceViewer.getTextWidget().setLayoutData( new GridData( SWT.FILL, SWT.FILL,
true, true ) );
+        schemaSourceViewer.getTextWidget().setEditable( false );
+        
+        // set text font
+        Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT );
+        schemaSourceViewer.getTextWidget().setFont( font );
+        
+        IDocument document = new Document();
+        schemaSourceViewer.setDocument( document );
 
         // Initialization from the "input" object class
         initFieldsContentFromInput();
@@ -82,7 +93,7 @@
     private void initFieldsContentFromInput()
     {
         // SOURCE CODE Field
-        sourceCode_text.setText( objectClass.write() );
+        schemaSourceViewer.getDocument().set( objectClass.write() );
     }
 
 
@@ -91,7 +102,7 @@
      */
     public void refresh()
     {
-        if ( sourceCode_text != null )
+        if ( schemaSourceViewer != null )
         {
             initFieldsContentFromInput();
         }

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/SchemaFormEditorSourceCodePage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/SchemaFormEditorSourceCodePage.java?view=diff&rev=504202&r1=504201&r2=504202
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/SchemaFormEditorSourceCodePage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/editors/SchemaFormEditorSourceCodePage.java
Tue Feb  6 09:14:17 2007
@@ -24,10 +24,15 @@
 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
 import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
 import org.apache.directory.ldapstudio.schemas.model.Schema;
+import org.apache.directory.ldapstudio.schemas.view.viewers.SchemaSourceViewer;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.SourceViewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.IManagedForm;
 import org.eclipse.ui.forms.editor.FormEditor;
 import org.eclipse.ui.forms.editor.FormPage;
@@ -41,7 +46,7 @@
 public class SchemaFormEditorSourceCodePage extends FormPage
 {
     private Schema schema;
-    private Text sourceCode_text;
+    private SourceViewer schemaSourceViewer;
 
 
     /**
@@ -72,10 +77,17 @@
         schema = input.getSchema();
 
         // SOURCE CODE Field
-        sourceCode_text = toolkit.createText( form.getBody(), "", SWT.MULTI ); //$NON-NLS-1$
-        sourceCode_text.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
-        sourceCode_text.setEditable( false );
-
+        schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.MULTI
);
+        schemaSourceViewer.getTextWidget().setLayoutData( new GridData( SWT.FILL, SWT.FILL,
true, true ) );
+        schemaSourceViewer.getTextWidget().setEditable( false );
+        
+        // set text font
+        Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT );
+        schemaSourceViewer.getTextWidget().setFont( font );
+        
+        IDocument document = new Document();
+        schemaSourceViewer.setDocument( document );
+        
         // Initialization from the "input" object class
         initFieldsContentFromInput();
     }
@@ -107,6 +119,7 @@
                 sb.append( "\n" ); //$NON-NLS-1$
             }
         }
-        sourceCode_text.setText( sb.toString() );
+        
+        schemaSourceViewer.getDocument().set( sb.toString() );
     }
 }

Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaCodeScanner.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaCodeScanner.java?view=auto&rev=504202
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaCodeScanner.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaCodeScanner.java
Tue Feb  6 09:14:17 2007
@@ -0,0 +1,162 @@
+/*
+ *  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.schemas.view.viewers;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWhitespaceDetector;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+import org.eclipse.jface.text.rules.WordRule;
+
+
+/**
+ * Scanner used to analyse Schema code. Allows syntax coloring.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaCodeScanner extends RuleBasedScanner
+{
+    String attributype = "attributetype";
+
+    String objectclass = "objectclass";
+
+    String[] keywords = new String[]
+        { "NAME", "DESC", "OBSOLETE", "SUP", "EQUALITY", "ORDERING", "MUST", "MAY", "STRUCTURAL",
"SUBSTR", "SYNTAX",
+            "SINGLE-VALUE", "COLLECTIVE", "NO-USER-MODIFICATION", "USAGE", "userApplications",
"directoryOperation",
+            "distributedOperation", "dSAOperation", "ABSTRACT", "STRUCTURAL", "AUXILIARY",
"MUST", "MAY" };
+
+
+    public SchemaCodeScanner( SchemaTextAttributeProvider provider )
+    {
+        List<IRule> rules = new ArrayList<IRule>();
+
+        IToken keyword = new Token( provider.getAttribute( SchemaTextAttributeProvider.KEYWORD_ATTRIBUTE
) );
+        IToken string = new Token( provider.getAttribute( SchemaTextAttributeProvider.STRING_ATTRIBUTE
) );
+        IToken undefined = new Token( provider.getAttribute( SchemaTextAttributeProvider.DEFAULT_ATTRIBUTE
) );
+        IToken ATToken = new Token( provider.getAttribute( SchemaTextAttributeProvider.ATTRIBUTETYPE_ATTRIBUTE
) );
+        IToken OCToken = new Token( provider.getAttribute( SchemaTextAttributeProvider.OBJECTCLASS_ATTRIBUTE
) );
+        IToken oid = new Token( provider.getAttribute( SchemaTextAttributeProvider.OID_ATTRIBUTE
) );
+
+        // Rules for Strings
+        rules.add( new SingleLineRule( "\"", "\"", string, '\0', true ) );
+        rules.add( new SingleLineRule( "'", "'", string, '\0', true ) );
+        // Generic rule for whitespaces
+        rules.add( new WhitespaceRule( new IWhitespaceDetector()
+        {
+            /**
+             * Indicates if the given character is a whitespace
+             * @param c the character to analyse
+             * @return <code>true</code> if the character is to be considered
as a whitespace,  <code>false</code> if not.
+             * @see org.eclipse.jface.text.rules.IWhitespaceDetector#isWhitespace(char)
+             */
+            public boolean isWhitespace( char c )
+            {
+                return Character.isWhitespace( c );
+            }
+        } ) );
+
+        WordRule wrOID = new WordRule( new SchemaOIDDetector(), oid );
+
+        rules.add( wrOID );
+
+        // If the word isn't in the List, returns undefined
+        WordRule wr = new WordRule( new SchemaWordDetector(), undefined );
+
+        // 'attributetype' rule
+        wr.addWord( attributype, ATToken );
+
+        // 'objectclass' rule
+        wr.addWord( objectclass, OCToken );
+
+        // Adding Keywords
+        for ( int i = 0; i < keywords.length; ++i )
+        {
+            wr.addWord( keywords[i], keyword );
+        }
+
+        rules.add( wr );
+
+        IRule[] param = new IRule[rules.size()];
+        rules.toArray( param );
+        setRules( param );
+    }
+
+    /**
+     * This class implements a word detector for Schema
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    static class SchemaWordDetector implements IWordDetector
+    {
+        /* (non-Javadoc)
+         * @see org.eclipse.jface.text.rules.IWordDetector#isWordPart(char)
+         */
+        public boolean isWordPart( char c )
+        {
+            return ( Character.isLetterOrDigit( c ) || c == '_' || c == '-' || c == '$' ||
c == '#' || c == '@'
+                || c == '~' || c == '.' || c == '?' );
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.eclipse.jface.text.rules.IWordDetector#isWordStart(char)
+         */
+        public boolean isWordStart( char c )
+        {
+            return ( Character.isLetter( c ) || c == '.' || c == '_' || c == '?' || c ==
'$' );
+        }
+    }
+
+    /**
+     * This class implements an OID detector for Schema
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    static class SchemaOIDDetector implements IWordDetector
+    {
+        /* (non-Javadoc)
+         * @see org.eclipse.jface.text.rules.IWordDetector#isWordPart(char)
+         */
+        public boolean isWordPart( char c )
+        {
+            return ( Character.isDigit( c ) || c == '.' );
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.eclipse.jface.text.rules.IWordDetector#isWordStart(char)
+         */
+        public boolean isWordStart( char c )
+        {
+            return ( Character.isDigit( c ) );
+        }
+    }
+}

Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewer.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewer.java?view=auto&rev=504202
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewer.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewer.java
Tue Feb  6 09:14:17 2007
@@ -0,0 +1,74 @@
+/*
+ *  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.schemas.view.viewers;
+
+
+import org.eclipse.jface.text.source.IOverviewRuler;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * Implementation of a SourceViewer for displaying Schema files source code.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaSourceViewer extends SourceViewer
+{
+    /**
+     * Creates a new instance of SchemaSourceViewer.
+     *
+     * @param parent
+     *      the parent of the viewer's control
+     * @param verticalRuler
+     *      the vertical ruler used by this source viewer
+     * @param overviewRuler
+     *      the overview ruler
+     * @param showAnnotationsOverview
+     *      true if the overview ruler should be visible, false otherwise
+     * @param styles
+     *      the SWT style bits
+     */
+    public SchemaSourceViewer( Composite parent, IVerticalRuler verticalRuler, IOverviewRuler
overviewRuler,
+        boolean showAnnotationsOverview, int styles )
+    {
+        super( parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles );
+        this.configure( new SchemaSourceViewerConfiguration() );
+    }
+
+
+    /**
+     * Creates a new instance of SchemaSourceViewer.
+     *
+     * @param parent
+     *      the parent of the viewer's control
+     * @param ruler
+     *      the vertical ruler used by this source viewer
+     * @param styles
+     *      the SWT style bits
+     */
+    public SchemaSourceViewer( Composite parent, IVerticalRuler ruler, int styles )
+    {
+        super( parent, ruler, styles );
+        this.configure( new SchemaSourceViewerConfiguration() );
+    }
+}

Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewerConfiguration.java?view=auto&rev=504202
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewerConfiguration.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaSourceViewerConfiguration.java
Tue Feb  6 09:14:17 2007
@@ -0,0 +1,53 @@
+/*
+ *  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.schemas.view.viewers;
+
+import org.apache.directory.ldapstudio.schemas.Activator;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+
+/**
+ * This class is used to handle the display (syntax highlighting, etc.) of Schema files in
the SchemaSourceViewer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaSourceViewerConfiguration extends SourceViewerConfiguration
+{
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer)
+     */
+    public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer
)
+    {
+        PresentationReconciler reconciler = new PresentationReconciler();
+        reconciler.setDocumentPartitioning( getConfiguredDocumentPartitioning( sourceViewer
) );
+        
+        // Creating the damager/repairer for code
+        DefaultDamagerRepairer dr = new DefaultDamagerRepairer( Activator.getSchemaCodeScanner()
);
+        reconciler.setDamager( dr, IDocument.DEFAULT_CONTENT_TYPE );
+        reconciler.setRepairer( dr, IDocument.DEFAULT_CONTENT_TYPE );
+
+        return reconciler;
+    }
+}

Added: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaTextAttributeProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaTextAttributeProvider.java?view=auto&rev=504202
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaTextAttributeProvider.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaTextAttributeProvider.java
Tue Feb  6 09:14:17 2007
@@ -0,0 +1,91 @@
+/*
+ *  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.schemas.view.viewers;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * This class provides the TextAttributes elements for each kind of attribute.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaTextAttributeProvider
+{
+    public static final String DEFAULT_ATTRIBUTE = "__pos_schema_default_attribute";
+    public static final String STRING_ATTRIBUTE = "__pos_schema_string_attribute";
+    public static final String KEYWORD_ATTRIBUTE = "__pos_schema_keyword_attribute";
+    public static final String ATTRIBUTETYPE_ATTRIBUTE = "__pos_schema_attributetype_attribute";
+    public static final String OBJECTCLASS_ATTRIBUTE = "__pos_schema_objectclass_attribute";
+    public static final String OID_ATTRIBUTE = "__pos_schema_oid_attribute";
+
+    private Map<String, TextAttribute> attributes = new HashMap<String, TextAttribute>();
+
+
+    /**
+     * Creates a new instance of SchemaTextAttributeProvider.
+     *
+     */
+    public SchemaTextAttributeProvider()
+    {
+        attributes.put( DEFAULT_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(),
new RGB( 0, 0, 0 ) ) ) );
+
+        attributes.put( KEYWORD_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(),
new RGB( 127, 0, 85 ) ),
+            null, SWT.BOLD ) );
+
+        attributes.put( STRING_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(),
new RGB( 0, 0, 255 ) ) ) );
+        
+        attributes.put( ATTRIBUTETYPE_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(),
new RGB( 89, 71, 158 ) ),
+            null, SWT.BOLD ) );
+        
+        attributes.put( OBJECTCLASS_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(),
new RGB( 45, 124, 68 ) ),
+            null, SWT.BOLD ) );
+        
+        attributes.put( OID_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(),
new RGB( 255, 0, 0 ) ) ) );
+    }
+
+
+    /**
+     * Gets the correct TextAttribute for the given type
+     *
+     * @param type
+     *      the type of element
+     * @return
+     *      the correct TextAttribute for the given type
+     */
+    public TextAttribute getAttribute( String type )
+    {
+        TextAttribute attr = ( TextAttribute ) attributes.get( type );
+        if ( attr == null )
+        {
+            attr = ( TextAttribute ) attributes.get( DEFAULT_ATTRIBUTE );
+        }
+        return attr;
+    }
+}



Mime
View raw message