directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r558698 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor: ./ controller/ view/views/
Date Mon, 23 Jul 2007 12:26:15 GMT
Author: pamarcelot
Date: Mon Jul 23 05:26:09 2007
New Revision: 558698

URL: http://svn.apache.org/viewvc?view=rev&rev=558698
Log:
Added a ProjectsHandlerListener in the controller of the SchemaView to be notified of Add/Modify/Remove
of Schemas/ATs/OCs.

Added:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsHandlerAdapter.java
Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandlerAdapter.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaViewController.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaView.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaViewContentProvider.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java?view=diff&rev=558698&r1=558697&r2=558698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java
Mon Jul 23 05:26:09 2007
@@ -94,11 +94,11 @@
                     schemaChecker.enableModificationsListening();
 
                     // Reloading views
-                    schemaView = ( SchemaView ) getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(
-                        SchemaView.ID );
+//                    schemaView = ( SchemaView ) getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(
+//                        SchemaView.ID );
                     problemsView = ( ProblemsView ) getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(
                         ProblemsView.ID );
-                    schemaView.reloadViewer();
+//                    schemaView.reloadViewer();
                     problemsView.reloadViewer();
                 }
             }

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsHandlerAdapter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsHandlerAdapter.java?view=auto&rev=558698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsHandlerAdapter.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsHandlerAdapter.java
Mon Jul 23 05:26:09 2007
@@ -0,0 +1,60 @@
+/*
+ *  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.studio.apacheds.schemaeditor.controller;
+
+
+import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
+
+
+/**
+ * This adapter class provides default implementations for the methods 
+ * described by the ProjectsHandlerListener interface.
+ * <p>
+ * Classes that wish to deal with Project events can extend this class 
+ * and override only the methods which they are interested in. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ProjectsHandlerAdapter implements ProjectsHandlerListener
+{
+    /* (non-Javadoc)
+     * @see org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandlerListener#projectAdded(org.apache.directory.studio.apacheds.schemaeditor.model.Project)
+     */
+    public void projectAdded( Project project )
+    {
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandlerListener#projectRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.Project)
+     */
+    public void projectRemoved( Project project )
+    {
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandlerListener#openProjectChanged(org.apache.directory.studio.apacheds.schemaeditor.model.Project,
org.apache.directory.studio.apacheds.schemaeditor.model.Project)
+     */
+    public void openProjectChanged( Project oldProject, Project newProject )
+    {
+    }
+}

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandlerAdapter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandlerAdapter.java?view=diff&rev=558698&r1=558697&r2=558698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandlerAdapter.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandlerAdapter.java
Mon Jul 23 05:26:09 2007
@@ -1,12 +1,32 @@
-
+/*
+ *  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.studio.apacheds.schemaeditor.controller;
 
+
 import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
 import org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl;
 import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
 import org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl;
 
+
 /**
  * This adapter class provides default implementations for the methods 
  * described by the SchemaHandlerListener interface.
@@ -103,7 +123,7 @@
      * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#schemaRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.Schema)
      */
     public void schemaRemoved( Schema schema )
-    {   
+    {
     }
 
 

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaViewController.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaViewController.java?view=diff&rev=558698&r1=558697&r2=558698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaViewController.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaViewController.java
Mon Jul 23 05:26:09 2007
@@ -23,6 +23,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.directory.shared.ldap.schema.SchemaObject;
 import org.apache.directory.studio.apacheds.schemaeditor.Activator;
 import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants;
 import org.apache.directory.studio.apacheds.schemaeditor.controller.actions.CollapseAllAction;
@@ -38,6 +39,10 @@
 import org.apache.directory.studio.apacheds.schemaeditor.controller.actions.OpenElementAction;
 import org.apache.directory.studio.apacheds.schemaeditor.controller.actions.OpenSchemaViewPreferenceAction;
 import org.apache.directory.studio.apacheds.schemaeditor.controller.actions.OpenSchemaViewSortingDialogAction;
+import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
 import org.apache.directory.studio.apacheds.schemaeditor.view.editors.attributetype.AttributeTypeEditor;
 import org.apache.directory.studio.apacheds.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput;
 import org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass.ObjectClassEditor;
@@ -47,6 +52,8 @@
 import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.Folder;
 import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.ObjectClassWrapper;
 import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.SchemaWrapper;
+import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.TreeNode;
+import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.Folder.FolderType;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuListener;
 import org.eclipse.jface.action.IMenuManager;
@@ -57,6 +64,7 @@
 import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.ui.IEditorInput;
@@ -86,6 +94,230 @@
     /** The TreeViewer */
     private TreeViewer viewer;
 
+    /** The SchemaHandlerListener */
+    private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter()
+    {
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#attributeTypeAdded(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl)
+         */
+        public void attributeTypeAdded( AttributeTypeImpl at )
+        {
+            TreeNode schemaWrapper = findSchemaWrapperInTree( at.getSchema() );
+
+            if ( schemaWrapper != null )
+            {
+                int group = Activator.getDefault().getPreferenceStore().getInt(
+                    PluginConstants.PREFS_SCHEMA_VIEW_GROUPING );
+                if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS )
+                {
+                    List<TreeNode> children = schemaWrapper.getChildren();
+                    for ( TreeNode child : children )
+                    {
+                        Folder folder = ( Folder ) child;
+                        if ( folder.getType() == FolderType.ATTRIBUTE_TYPE )
+                        {
+                            folder.addChild( new AttributeTypeWrapper( at, folder ) );
+                            break;
+                        }
+                    }
+                }
+                else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED )
+                {
+                    schemaWrapper.addChild( new AttributeTypeWrapper( at, schemaWrapper )
);
+                }
+
+                viewer.refresh( schemaWrapper );
+            }
+            else
+            {
+                // An error has occurred we need to reload the view.
+                view.reloadViewer();
+            }
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#attributeTypeModified(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl)
+         */
+        public void attributeTypeModified( AttributeTypeImpl at )
+        {
+            AttributeTypeWrapper atw = findAttributeTypeWrapperInTree( at );
+
+            if ( atw != null )
+            {
+                viewer.update( atw, null );
+            }
+            else
+            {
+                // An error has occurred we need to reload the view.
+                view.reloadViewer();
+            }
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#attributeTypeRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl)
+         */
+        public void attributeTypeRemoved( AttributeTypeImpl at )
+        {
+            AttributeTypeWrapper atw = findAttributeTypeWrapperInTree( at );
+
+            if ( atw != null )
+            {
+                atw.getParent().removeChild( atw );
+                viewer.refresh( atw.getParent() );
+            }
+            else
+            {
+                // An error has occurred we need to reload the view.
+                view.reloadViewer();
+            }
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#objectClassAdded(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl)
+         */
+        public void objectClassAdded( ObjectClassImpl oc )
+        {
+            TreeNode schemaWrapper = findSchemaWrapperInTree( oc.getSchema() );
+
+            if ( schemaWrapper != null )
+            {
+                int group = Activator.getDefault().getPreferenceStore().getInt(
+                    PluginConstants.PREFS_SCHEMA_VIEW_GROUPING );
+                if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS )
+                {
+                    List<TreeNode> children = schemaWrapper.getChildren();
+                    for ( TreeNode child : children )
+                    {
+                        Folder folder = ( Folder ) child;
+                        if ( folder.getType() == FolderType.OBJECT_CLASS )
+                        {
+                            folder.addChild( new ObjectClassWrapper( oc, folder ) );
+                            break;
+                        }
+                    }
+                }
+                else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED )
+                {
+                    schemaWrapper.addChild( new ObjectClassWrapper( oc, schemaWrapper ) );
+                }
+
+                viewer.refresh( schemaWrapper );
+            }
+            else
+            {
+                // An error has occurred we need to reload the view.
+                view.reloadViewer();
+            }
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#objectClassModified(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl)
+         */
+        public void objectClassModified( ObjectClassImpl oc )
+        {
+            ObjectClassWrapper ocw = findObjectClassWrapperInTree( oc );
+
+            if ( ocw != null )
+            {
+                viewer.update( ocw, null );
+            }
+            else
+            {
+                // An error has occurred we need to reload the view.
+                view.reloadViewer();
+            }
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#objectClassRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl)
+         */
+        public void objectClassRemoved( ObjectClassImpl oc )
+        {
+            ObjectClassWrapper ocw = findObjectClassWrapperInTree( oc );
+
+            if ( ocw != null )
+            {
+                ocw.getParent().removeChild( ocw );
+                viewer.refresh( ocw.getParent() );
+            }
+            else
+            {
+                // An error has occurred we need to reload the view.
+                view.reloadViewer();
+            }
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#schemaAdded(org.apache.directory.studio.apacheds.schemaeditor.model.Schema)
+         */
+        public void schemaAdded( Schema schema )
+        {
+            TreeNode rootNode = ( TreeNode ) viewer.getInput();
+            SchemaWrapper schemaWrapper = new SchemaWrapper( schema, rootNode );
+            rootNode.addChild( schemaWrapper );
+
+            int group = Activator.getDefault().getPreferenceStore().getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING
);
+            if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS )
+            {
+                Folder atFolder = new Folder( FolderType.ATTRIBUTE_TYPE, schemaWrapper );
+                schemaWrapper.addChild( atFolder );
+
+                for ( AttributeTypeImpl attributeType : schema.getAttributeTypes() )
+                {
+                    atFolder.addChild( new AttributeTypeWrapper( attributeType, atFolder
) );
+                }
+
+                Folder ocFolder = new Folder( FolderType.OBJECT_CLASS, schemaWrapper );
+                schemaWrapper.addChild( ocFolder );
+
+                for ( ObjectClassImpl objectClass : schema.getObjectClasses() )
+                {
+                    ocFolder.addChild( new ObjectClassWrapper( objectClass, ocFolder ) );
+                }
+            }
+            else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED )
+            {
+                for ( AttributeTypeImpl attributeType : schema.getAttributeTypes() )
+                {
+                    schemaWrapper.addChild( new AttributeTypeWrapper( attributeType, schemaWrapper
) );
+                }
+
+                for ( ObjectClassImpl objectClass : schema.getObjectClasses() )
+                {
+                    schemaWrapper.addChild( new ObjectClassWrapper( objectClass, schemaWrapper
) );
+                }
+            }
+
+            viewer.refresh( rootNode );
+            viewer.setSelection( new StructuredSelection( schemaWrapper ) );
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#schemaRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.Schema)
+         */
+        public void schemaRemoved( Schema schema )
+        {
+            TreeNode schemaWrapper = findSchemaWrapperInTree( schema.getName() );
+            if ( schemaWrapper != null )
+            {
+                schemaWrapper.getParent().removeChild( schemaWrapper );
+                viewer.refresh( viewer.getInput() );
+            }
+            else
+            {
+                // An error has occurred we need to reload the view.
+                view.reloadViewer();
+            }
+        }
+    };
+
     // The Actions
     private Action connect;
     private NewSchemaAction newSchema;
@@ -117,6 +349,7 @@
         initToolbar();
         initMenu();
         initContextMenu();
+        initProjectsHandlerListener();
         initDoubleClickListener();
         initAuthorizedPrefs();
         initPreferencesListener();
@@ -216,11 +449,71 @@
 
 
     /**
+     * Initializes the ProjectsHandlerListener.
+     */
+    private void initProjectsHandlerListener()
+    {
+        Activator.getDefault().getProjectsHandler().addListener( new ProjectsHandlerAdapter()
+        {
+            public void openProjectChanged( Project oldProject, Project newProject )
+            {
+                if ( oldProject != null )
+                {
+                    removeSchemaHandlerListener( oldProject );
+                }
+
+                if ( newProject != null )
+                {
+                    addSchemaHandlerListener( newProject );
+                    view.reloadViewer();
+                }
+                else
+                {
+                    viewer.setInput( null );
+                }
+            }
+        } );
+    }
+
+
+    /**
+     * Adds the SchemaHandlerListener.
+     *
+     * @param project
+     *      the project
+     */
+    private void addSchemaHandlerListener( Project project )
+    {
+        SchemaHandler schemaHandler = project.getSchemaHandler();
+        if ( schemaHandler != null )
+        {
+            schemaHandler.addListener( schemaHandlerListener );
+        }
+    }
+
+
+    /**
+     * Removes the SchemaHandlerListener.
+     *
+     * @param project
+     *      the project
+     */
+    private void removeSchemaHandlerListener( Project project )
+    {
+        SchemaHandler schemaHandler = project.getSchemaHandler();
+        if ( schemaHandler != null )
+        {
+            schemaHandler.removeListener( schemaHandlerListener );
+        }
+    }
+
+
+    /**
      * Initializes the DoubleClickListener.
      */
     private void initDoubleClickListener()
     {
-        view.getViewer().addDoubleClickListener( new IDoubleClickListener()
+        viewer.addDoubleClickListener( new IDoubleClickListener()
         {
             public void doubleClick( DoubleClickEvent event )
             {
@@ -264,7 +557,7 @@
                     catch ( PartInitException e )
                     {
                         //                        logger.debug( "error when opening the editor"
); //$NON-NLS-1$
-                        e.printStackTrace();
+                        e.printStackTrace(); // TODO
                     }
                 }
             }
@@ -316,5 +609,192 @@
                 }
             }
         } );
+    }
+
+
+    /**
+     * Finds the parent node of a given element (AT or OT).
+     *
+     * @param element
+     *      the element
+     * @return
+     *      the parent node of a given element (AT or OT)
+     */
+    private TreeNode findParentElement( SchemaObject element )
+    {
+        // Finding the associated SchemaWrapper
+        TreeNode schemaWrapper = findSchemaWrapperInTree( element.getSchema() );
+        if ( schemaWrapper == null )
+        {
+            return null;
+        }
+
+        // Finding the correct node
+        TreeNode parentNode = null;
+        int group = Activator.getDefault().getPreferenceStore().getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING
);
+        if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS )
+        {
+            Object[] children = ( ( ITreeContentProvider ) viewer.getContentProvider() ).getChildren(
schemaWrapper );
+            for ( Object child : children )
+            {
+                Folder folder = ( Folder ) child;
+
+                if ( element instanceof AttributeTypeImpl )
+                {
+                    if ( folder.getType() == FolderType.ATTRIBUTE_TYPE )
+                    {
+                        parentNode = folder;
+                    }
+                }
+                else if ( element instanceof ObjectClassImpl )
+                {
+                    if ( folder.getType() == FolderType.OBJECT_CLASS )
+                    {
+                        parentNode = folder;
+                    }
+                }
+            }
+        }
+        else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED )
+        {
+            parentNode = schemaWrapper;
+        }
+
+        return parentNode;
+    }
+
+
+    /**
+     * Finds the corresponding SchemaWrapper in the Tree.
+     *
+     * @param name
+     *      the name of the SchemaWrapper to search
+     * @return
+     *      the corresponding SchemaWrapper in the Tree
+     */
+    private SchemaWrapper findSchemaWrapperInTree( String name )
+    {
+        List<TreeNode> schemaWrappers = ( ( TreeNode ) viewer.getInput() ).getChildren();
+        for ( TreeNode sw : schemaWrappers )
+        {
+            if ( ( ( SchemaWrapper ) sw ).getSchema().getName().toLowerCase().equals( name.toLowerCase()
) )
+            {
+                return ( SchemaWrapper ) sw;
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Finds the corresponding AttributeTypeWrapper in the Tree.
+     *
+     * @param at
+     *      the attribute type
+     * @return
+     *      the corresponding AttributeTypeWrapper in the Tree
+     */
+    private AttributeTypeWrapper findAttributeTypeWrapperInTree( AttributeTypeImpl at )
+    {
+        SchemaWrapper schemaWrapper = findSchemaWrapperInTree( at.getSchema() );
+        if ( schemaWrapper == null )
+        {
+            return null;
+        }
+
+        // Finding the correct node
+        int group = Activator.getDefault().getPreferenceStore().getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING
);
+        List<TreeNode> children = schemaWrapper.getChildren();
+        if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS )
+        {
+            for ( TreeNode child : children )
+            {
+                Folder folder = ( Folder ) child;
+                if ( folder.getType() == FolderType.ATTRIBUTE_TYPE )
+                {
+                    for ( TreeNode folderChild : folder.getChildren() )
+                    {
+                        AttributeTypeWrapper atw = ( AttributeTypeWrapper ) folderChild;
+                        if ( atw.getAttributeType().equals( at ) )
+                        {
+                            return atw;
+                        }
+                    }
+                }
+            }
+        }
+        else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED )
+        {
+            for ( Object child : children )
+            {
+                if ( child instanceof AttributeTypeImpl )
+                {
+                    AttributeTypeWrapper atw = ( AttributeTypeWrapper ) child;
+                    if ( atw.getAttributeType().equals( at ) )
+                    {
+                        return atw;
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Finds the corresponding ObjectClassWrapper in the Tree.
+     *
+     * @param oc
+     *      the attribute type
+     * @return
+     *      the corresponding ObjectClassWrapper in the Tree
+     */
+    private ObjectClassWrapper findObjectClassWrapperInTree( ObjectClassImpl oc )
+    {
+        SchemaWrapper schemaWrapper = findSchemaWrapperInTree( oc.getSchema() );
+        if ( schemaWrapper == null )
+        {
+            return null;
+        }
+
+        // Finding the correct node
+        int group = Activator.getDefault().getPreferenceStore().getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING
);
+        List<TreeNode> children = schemaWrapper.getChildren();
+        if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS )
+        {
+            for ( TreeNode child : children )
+            {
+                Folder folder = ( Folder ) child;
+                if ( folder.getType() == FolderType.OBJECT_CLASS )
+                {
+                    for ( TreeNode folderChild : folder.getChildren() )
+                    {
+                        ObjectClassWrapper ocw = ( ObjectClassWrapper ) folderChild;
+                        if ( ocw.getObjectClass().equals( oc ) )
+                        {
+                            return ocw;
+                        }
+                    }
+                }
+            }
+        }
+        else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED )
+        {
+            for ( Object child : children )
+            {
+                if ( child instanceof ObjectClassWrapper )
+                {
+                    ObjectClassWrapper ocw = ( ObjectClassWrapper ) child;
+                    if ( ocw.getObjectClass().equals( oc ) )
+                    {
+                        return ocw;
+                    }
+                }
+            }
+        }
+
+        return null;
     }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaView.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaView.java?view=diff&rev=558698&r1=558697&r2=558698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaView.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaView.java
Mon Jul 23 05:26:09 2007
@@ -46,9 +46,6 @@
     /** The viewer */
     private TreeViewer treeViewer;
 
-    /** The content provider of the viewer */
-    private SchemaViewContentProvider contentProvider;
-
 
     /* (non-Javadoc)
      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
@@ -62,47 +59,6 @@
 
         // Adding the controller
         new SchemaViewController( this );
-
-        //        DifferencesWidget differencesWidget = new DifferencesWidget();
-        //        differencesWidget.createWidget( parent );
-        //        
-        //        List<Difference> differences = new ArrayList<Difference>();
-        //        differences.add( new AddAliasDifference(null, null, "alias1") );
-        //        differences.add( new RemoveAliasDifference(null, null, "alias2") );
-        //        differences.add( new AddDescriptionDifference(null, null, "Description")
);
-        //        differences.add( new ModifyDescriptionDifference(null, null, "Old description",
"New Description") );
-        //        differences.add( new RemoveDescriptionDifference(null, null, "Description")
);
-        //        differences.add( new AddEqualityDifference(null, null, "equality") );
-        //        differences.add( new ModifyEqualityDifference(null, null, "old equality",
"new equality") );
-        //        differences.add( new RemoveEqualityDifference(null, null, "equality") );
-        //        differences.add( new AddMandatoryATDifference(null, null, "name") );
-        //        differences.add( new RemoveMandatoryATDifference(null, null, "name2") );
-        //        differences.add( new AddOptionalATDifference(null, null, "name") );
-        //        differences.add( new RemoveOptionalATDifference(null, null, "name2") );
-        //        differences.add( new AddOrderingDifference(null, null, "ordering") );
-        //        differences.add( new ModifyOrderingDifference(null, null, "old ordering",
"new ordering") );
-        //        differences.add( new RemoveOrderingDifference(null, null, "ordering") );
-        //        differences.add( new AddSubstringDifference(null, null, "substring") );
-        //        differences.add( new ModifySubstringDifference(null, null, "old substring",
"new substring") );
-        //        differences.add( new RemoveSubstringDifference(null, null, "substring")
);
-        //        differences.add( new AddSuperiorATDifference(null, null, "supAT") );
-        //        differences.add( new ModifySuperiorATDifference(null, null, "oldSupAT",
"newSupAT") );
-        //        differences.add( new RemoveSuperiorATDifference(null, null, "supAT") );
-        //        differences.add( new AddSuperiorOCDifference(null, null, "supOC") );
-        //        differences.add( new RemoveSuperiorOCDifference(null, null, "supOC") );
-        //        differences.add( new AddSyntaxDifference(null, null, "syntax") );
-        //        differences.add( new ModifySyntaxDifference(null, null, "syntax1", "syntax2")
);
-        //        differences.add( new RemoveSyntaxDifference(null, null, "syntax") );
-        //        differences.add( new AddSyntaxLengthDifference(null, null, 1234) );
-        //        differences.add( new ModifySyntaxLengthDifference(null, null, 1234, 12345)
);
-        //        differences.add( new RemoveSyntaxLengthDifference(null, null, 1234) );
-        //        differences.add( new ModifyClassTypeDifference(null, null, ObjectClassTypeEnum.AUXILIARY,
ObjectClassTypeEnum.ABSTRACT) );
-        //        differences.add( new ModifyCollectiveDifference(null, null, false, true)
);
-        //        differences.add( new ModifyNoUserModificationDifference(null, null, true,
false) );
-        //        differences.add( new ModifyObsoleteDifference(null, null, true, false)
);
-        //        differences.add( new ModifySingleValueDifference(null, null, true, false)
);
-        //        differences.add( new ModifyUsageDifference(null, null, UsageEnum.DISTRIBUTED_OPERATION,
UsageEnum.DSA_OPERATION) );
-        //        differencesWidget.setInput( differences );
     }
 
 
@@ -112,8 +68,7 @@
     private void initViewer( Composite parent )
     {
         treeViewer = new TreeViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER
);
-        contentProvider = new SchemaViewContentProvider();
-        treeViewer.setContentProvider( contentProvider );
+        treeViewer.setContentProvider( new SchemaViewContentProvider() );
         treeViewer.setLabelProvider( new DecoratingLabelProvider( new SchemaViewLabelProvider(),
Activator.getDefault()
             .getWorkbench().getDecoratorManager().getLabelDecorator() ) );
     }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaViewContentProvider.java?view=diff&rev=558698&r1=558697&r2=558698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaViewContentProvider.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SchemaViewContentProvider.java
Mon Jul 23 05:26:09 2007
@@ -137,31 +137,28 @@
                         {
                             Folder atFolder = new Folder( FolderType.ATTRIBUTE_TYPE, schemaWrapper
);
                             schemaWrapper.addChild( atFolder );
-                            Folder ocFolder = new Folder( FolderType.OBJECT_CLASS, schemaWrapper
);
-                            schemaWrapper.addChild( ocFolder );
 
-                            List<AttributeTypeImpl> attributeTypes = schema.getAttributeTypes();
-                            for ( AttributeTypeImpl attributeType : attributeTypes )
+                            for ( AttributeTypeImpl attributeType : schema.getAttributeTypes()
)
                             {
                                 atFolder.addChild( new AttributeTypeWrapper( attributeType,
atFolder ) );
                             }
 
-                            List<ObjectClassImpl> objectClasses = schema.getObjectClasses();
-                            for ( ObjectClassImpl objectClass : objectClasses )
+                            Folder ocFolder = new Folder( FolderType.OBJECT_CLASS, schemaWrapper
);
+                            schemaWrapper.addChild( ocFolder );
+
+                            for ( ObjectClassImpl objectClass : schema.getObjectClasses()
)
                             {
                                 ocFolder.addChild( new ObjectClassWrapper( objectClass, ocFolder
) );
                             }
                         }
                         else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED
)
                         {
-                            List<AttributeTypeImpl> attributeTypes = schema.getAttributeTypes();
-                            for ( AttributeTypeImpl attributeType : attributeTypes )
+                            for ( AttributeTypeImpl attributeType : schema.getAttributeTypes()
)
                             {
                                 schemaWrapper.addChild( new AttributeTypeWrapper( attributeType,
schemaWrapper ) );
                             }
 
-                            List<ObjectClassImpl> objectClasses = schema.getObjectClasses();
-                            for ( ObjectClassImpl objectClass : objectClasses )
+                            for ( ObjectClassImpl objectClass : schema.getObjectClasses()
)
                             {
                                 schemaWrapper.addChild( new ObjectClassWrapper( objectClass,
schemaWrapper ) );
                             }



Mime
View raw message