directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r520474 - in /directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas: model/ view/viewers/
Date Tue, 20 Mar 2007 16:47:08 GMT
Author: pamarcelot
Date: Tue Mar 20 09:47:07 2007
New Revision: 520474

URL: http://svn.apache.org/viewvc?view=rev&rev=520474
Log:
Updated LDAP Model Event for better handling of Schema notifications.
Updated SchemasView to match those modifications.
Implemented listener for pool modifications in the SchemaElementsView.

Modified:
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsView.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsViewContentProvider.java
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemasViewContentProvider.java

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java?view=diff&rev=520474&r1=520473&r2=520474
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/model/LDAPModelEvent.java
Tue Mar 20 09:47:07 2007
@@ -135,9 +135,15 @@
     {
         this( reason );
 
-        if ( ( reason == Reason.SchemaAdded ) || ( reason == Reason.SchemaRemoved ) )
+        if ( reason == Reason.SchemaAdded )
         {
+            oldValue = null;
             newValue = schema;
+        }
+        else if ( reason == Reason.SchemaRemoved )
+        {
+            oldValue = schema;
+            newValue = null;
         }
         else
         {

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsView.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsView.java?view=diff&rev=520474&r1=520473&r2=520474
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsView.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsView.java
Tue Mar 20 09:47:07 2007
@@ -74,7 +74,7 @@
     private void initViewer( Composite parent )
     {
         viewer = new TreeViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER
);
-        contentProvider = new SchemaElementsViewContentProvider();
+        contentProvider = new SchemaElementsViewContentProvider( viewer );
         viewer.setContentProvider( contentProvider );
         viewer.setLabelProvider( new DecoratingLabelProvider( new SchemaElementsViewLabelProvider(),
Activator
             .getDefault().getWorkbench().getDecoratorManager().getLabelDecorator() ) );

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsViewContentProvider.java?view=diff&rev=520474&r1=520473&r2=520474
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsViewContentProvider.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemaElementsViewContentProvider.java
Tue Mar 20 09:47:07 2007
@@ -33,6 +33,8 @@
 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent;
 import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
 import org.apache.directory.ldapstudio.schemas.model.PoolListener;
+import org.apache.directory.ldapstudio.schemas.model.Schema;
+import org.apache.directory.ldapstudio.schemas.model.SchemaElement;
 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
 import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.AttributeTypeWrapper;
 import org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.FirstNameSorter;
@@ -43,6 +45,7 @@
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
 
 
@@ -52,11 +55,15 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class SchemaElementsViewContentProvider implements IStructuredContentProvider, ITreeContentProvider,
PoolListener
+public class SchemaElementsViewContentProvider implements IStructuredContentProvider, ITreeContentProvider,
+    PoolListener
 {
     /** The Schema Pool holding all schemas */
     private SchemaPool schemaPool;
 
+    /** The associated viewer */
+    private TreeViewer viewer;
+
     /** The preferences store */
     IPreferenceStore store;
 
@@ -73,8 +80,9 @@
      * @param schemaPool
      *      the associated Schema Pool
      */
-    public SchemaElementsViewContentProvider()
+    public SchemaElementsViewContentProvider( TreeViewer viewer )
     {
+        this.viewer = viewer;
         schemaPool = SchemaPool.getInstance();
         schemaPool.addListener( this );
         store = Activator.getDefault().getPreferenceStore();
@@ -254,8 +262,205 @@
      */
     public void poolChanged( SchemaPool p, LDAPModelEvent e )
     {
-        // TODO Auto-generated method stub
+        switch ( e.getReason() )
+        {
+            case SchemaAdded:
+                schemaAdded( p, e );
+                break;
+
+            case SchemaRemoved:
+                schemaRemoved( p, e );
+                break;
+
+            case ATAdded:
+            case OCAdded:
+                aTOrOCAdded( p, e );
+                break;
+
+            case ATModified:
+            case OCModified:
+                aTOrOCModified( p, e );
+                break;
+
+            case ATRemoved:
+            case OCRemoved:
+                aTOrOCRemoved( p, e );
+                break;
+
+            default:
+                break;
+        }
+    }
+
+
+    /**
+     * Refreshes the viewer when a SchemaAdded event is fired.
+     *
+     * @param p
+     *      the schema pool
+     * @param e
+     *      the event
+     */
+    private void schemaAdded( SchemaPool p, LDAPModelEvent e )
+    {
+        SchemaElementsViewRoot root = ( SchemaElementsViewRoot ) viewer.getInput();
+        Schema schema = ( Schema ) e.getNewValue();
+
+        // ATTRIBUTE TYPES
+        AttributeType[] attributeTypes = schema.getAttributeTypesAsArray();
+        for ( AttributeType attributeType : attributeTypes )
+        {
+            root.addChild( new AttributeTypeWrapper( attributeType, root ) );
+        }
+
+        // OBJECT CLASSES
+        ObjectClass[] objectClasses = schema.getObjectClassesAsArray();
+        for ( ObjectClass objectClass : objectClasses )
+        {
+            root.addChild( new ObjectClassWrapper( objectClass, root ) );
+        }
+
+        viewer.refresh();
+    }
+
+
+    /**
+     * Refreshes the viewer when a SchemaRemoved event is fired.
+     *
+     * @param p
+     *      the schema pool
+     * @param e
+     *      the event
+     */
+    private void schemaRemoved( SchemaPool p, LDAPModelEvent e )
+    {
+        Schema schema = ( Schema ) e.getOldValue();
+
+        // ATTRIBUTE TYPES
+        AttributeType[] attributeTypes = schema.getAttributeTypesAsArray();
+        for ( AttributeType attributeType : attributeTypes )
+        {
+            ITreeNode wrapper = getWrapper( attributeType );
+            if ( wrapper != null )
+            {
+                wrapper.getParent().removeChild( wrapper );
+            }
+        }
+
+        // OBJECT CLASSES
+        ObjectClass[] objectClasses = schema.getObjectClassesAsArray();
+        for ( ObjectClass objectClass : objectClasses )
+        {
+            ITreeNode wrapper = getWrapper( objectClass );
+            if ( wrapper != null )
+            {
+                wrapper.getParent().removeChild( wrapper );
+            }
+        }
+
+        viewer.refresh();
+    }
+
+
+    /**
+     * Refreshes the viewer when a ATAdded or OCAdded event is fired.
+     *
+     * @param p
+     *      the schema pool
+     * @param e
+     *      the event
+     */
+    private void aTOrOCAdded( SchemaPool p, LDAPModelEvent e )
+    {
+        SchemaElementsViewRoot root = ( SchemaElementsViewRoot ) viewer.getInput();
+        Object element = e.getNewValue();
+
+        if ( element instanceof AttributeType )
+        {
+            root.addChild( new AttributeTypeWrapper( ( AttributeType ) element, root ) );
+        }
+        else if ( element instanceof ObjectClass )
+        {
+            root.addChild( new ObjectClassWrapper( ( ObjectClass ) element, root ) );
+        }
+
+        viewer.refresh();
+    }
+
+
+    /**
+     * Refreshes the viewer when a ATModified or OCModified event is fired.
+     *
+     * @param p
+     *      the schema pool
+     * @param e
+     *      the event
+     */
+    private void aTOrOCModified( SchemaPool p, LDAPModelEvent e )
+    {
+        ITreeNode wrapper = getWrapper( ( SchemaElement ) e.getNewValue() );
+        if ( wrapper != null )
+        {
+            viewer.update( wrapper, null );
+        }
+    }
+
+
+    /**
+     * Refreshes the viewer when a ATRemoved or OCRemoved event is fired.
+     *
+     * @param p
+     *      the schema pool
+     * @param e
+     *      the event
+     */
+    private void aTOrOCRemoved( SchemaPool p, LDAPModelEvent e )
+    {
+        ITreeNode wrapper = getWrapper( ( SchemaElement ) e.getOldValue() );
+        if ( wrapper != null )
+        {
+            wrapper.getParent().removeChild( wrapper );
+            viewer.refresh();
+        }
+    }
+
+
+    /**
+     * Gets the Wrapper associated with the given Schema Element.
+     *
+     * @param schemaElement
+     *      the Schema Element to search from
+     * @return
+     *      the associated wrapper, null if no wrapper is found
+     */
+    private ITreeNode getWrapper( SchemaElement schemaElement )
+    {
+        SchemaElementsViewRoot root = ( SchemaElementsViewRoot ) viewer.getInput();
+
+        if ( schemaElement instanceof AttributeType )
+        {
+            List<AttributeTypeWrapper> atws = root.getAttributeTypes();
+            for ( AttributeTypeWrapper atw : atws )
+            {
+                if ( atw.getMyAttributeType().equals( schemaElement ) )
+                {
+                    return atw;
+                }
+            }
+        }
+        else if ( schemaElement instanceof ObjectClass )
+        {
+            List<ObjectClassWrapper> ocws = root.getObjectClasses();
+            for ( ObjectClassWrapper ocw : ocws )
+            {
+                if ( ocw.getMyObjectClass().equals( schemaElement ) )
+                {
+                    return ocw;
+                }
+            }
+        }
 
+        return null;
     }
 
 

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemasViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemasViewContentProvider.java?view=diff&rev=520474&r1=520473&r2=520474
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemasViewContentProvider.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SchemasViewContentProvider.java
Tue Mar 20 09:47:07 2007
@@ -353,7 +353,7 @@
         for ( Iterator iter = schemaWrapperList.iterator(); iter.hasNext(); )
         {
             SchemaWrapper schemaWrapper = ( SchemaWrapper ) iter.next();
-            if ( schemaWrapper.getMySchema().equals( ( Schema ) e.getNewValue() ) )
+            if ( schemaWrapper.getMySchema().equals( ( Schema ) e.getOldValue() ) )
             {
                 rootNode.removeChild( schemaWrapper );
                 viewer.refresh( rootNode );
@@ -383,7 +383,7 @@
 
         // Forcing the load of the children
         getChildren( parentNode );
-        
+
         // Creating and adding the new element
         ITreeNode newElement = null;
         if ( element instanceof AttributeType )



Mime
View raw message