directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r560890 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor: ./ controller/ view/editors/attributetype/
Date Mon, 30 Jul 2007 08:45:51 GMT
Author: pamarcelot
Date: Mon Jul 30 01:45:46 2007
New Revision: 560890

URL: http://svn.apache.org/viewvc?view=rev&rev=560890
Log:
Updated the AT Editor to automatically be closed when the AT or the parent Schema it belongs
to is closed. 

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/SchemaHandler.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditor.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorOverviewPage.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=560890&r1=560889&r2=560890
==============================================================================
--- 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 30 01:45:46 2007
@@ -26,7 +26,12 @@
 import org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandler;
 import org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandlerListener;
 import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerAdapter;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener;
+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.model.schemachecker.SchemaChecker;
 import org.apache.directory.studio.apacheds.schemaeditor.view.editors.attributetype.AttributeTypeEditor;
 import org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass.ObjectClassEditor;
@@ -35,6 +40,7 @@
 import org.apache.directory.studio.apacheds.schemaeditor.view.widget.SchemaTextAttributeProvider;
 import org.eclipse.jface.text.rules.ITokenScanner;
 import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 
@@ -68,6 +74,26 @@
     /** The ProjectsHandler */
     private ProjectsHandler projectsHandler;
 
+    private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter()
+    {
+        public void attributeTypeRemoved( AttributeTypeImpl at )
+        {
+//            closeOpenedEditor( at );
+        }
+
+
+        public void objectClassRemoved( ObjectClassImpl oc )
+        {
+//            closeOpenedEditor( oc );
+        }
+
+
+        public void schemaRemoved( Schema schema )
+        {
+//            closeOpenedEditor( schema );
+        }
+    };
+
 
     /**
      * Creates a new instance of Activator.
@@ -80,26 +106,11 @@
         {
             public void openProjectChanged( Project oldProject, Project newProject )
             {
-                // Listing all the editors from the Schema Editor Plugin.
-                List<IEditorReference> editors = new ArrayList<IEditorReference>();
-                for ( IEditorReference editorReference : getWorkbench().getActiveWorkbenchWindow().getActivePage()
-                    .getEditorReferences() )
-                {
-                    if ( ( editorReference.getId().equals( AttributeTypeEditor.ID ) )
-                        || ( editorReference.getId().equals( ObjectClassEditor.ID ) )
-                        || ( editorReference.getId().equals( SchemaEditor.ID ) ) )
-                    {
-                        editors.add( editorReference );
-                    }
-                }
-
-                // Closing the opened editors
-                if ( !getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditors(
-                    editors.toArray( new IEditorReference[0] ), true ) )
-                {
-                    // If all the editors have not been closed, we force them to be closed.
-                    getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditors(
-                        editors.toArray( new IEditorReference[0] ), false );
+                closeProjectEditors();
+
+                if ( oldProject != null )
+                {
+                    schemaHandler.removeListener( schemaHandlerListener );
                 }
 
                 if ( newProject == null )
@@ -112,6 +123,8 @@
                     // Registering the SchemaHandler and SchemaChecker
                     schemaHandler = newProject.getSchemaHandler();
                     schemaChecker = newProject.getSchemaChecker();
+
+                    schemaHandler.addListener( schemaHandlerListener );
                 }
 
                 PluginUtils.saveProjects();
@@ -129,6 +142,152 @@
                 PluginUtils.saveProjects();
             }
         } );
+    }
+
+
+    /**
+     * Closes the project editors.
+     */
+    private void closeProjectEditors()
+    {
+        // Listing all the editors from the Schema Editor Plugin.
+        List<IEditorReference> editors = new ArrayList<IEditorReference>();
+        for ( IEditorReference editorReference : getWorkbench().getActiveWorkbenchWindow().getActivePage()
+            .getEditorReferences() )
+        {
+            if ( ( editorReference.getId().equals( AttributeTypeEditor.ID ) )
+                || ( editorReference.getId().equals( ObjectClassEditor.ID ) )
+                || ( editorReference.getId().equals( SchemaEditor.ID ) ) )
+            {
+                editors.add( editorReference );
+            }
+        }
+
+        // Closing the opened editors
+        if ( !getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditors(
+            editors.toArray( new IEditorReference[0] ), true ) )
+        {
+            // If all the editors have not been closed, we force them to be closed.
+            getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditors(
+                editors.toArray( new IEditorReference[0] ), false );
+        }
+    }
+
+
+    /**
+     * Close the editor associated with the given object if it is opened.
+     *
+     * @param o
+     *      the object
+     */
+    private void closeOpenedEditor( Object o )
+    {
+        if ( o instanceof AttributeTypeImpl )
+        {
+            closeAttributeTypeEditor( ( AttributeTypeImpl ) o );
+        }
+        else if ( o instanceof ObjectClassImpl )
+        {
+            closeObjectClassEditor( ( ObjectClassImpl ) o );
+        }
+        else if ( o instanceof Schema )
+        {
+            Schema schema = ( Schema ) o;
+
+            // Closing the schema editor
+            closeObjectClassEditor( schema );
+
+            // Closing attribute type editors
+            for ( AttributeTypeImpl at : schema.getAttributeTypes() )
+            {
+                closeAttributeTypeEditor( at );
+            }
+
+            // Closing object class editors
+            for ( ObjectClassImpl oc : schema.getObjectClasses() )
+            {
+                closeObjectClassEditor( oc );
+            }
+        }
+    }
+
+
+    /**
+     * Closes the editor associated with the given attribute type.
+     *
+     * @param at
+     *      the attribute type
+     */
+    private void closeAttributeTypeEditor( AttributeTypeImpl at )
+    {
+        IWorkbenchPage activePage = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+
+        for ( IEditorReference editorReference : activePage.getEditorReferences() )
+        {
+            String editorID = editorReference.getId();
+
+            if ( editorID.equals( AttributeTypeEditor.ID ) )
+            {
+                if ( at.equals( ( ( AttributeTypeEditor ) editorReference.getEditor( false
) )
+                    .getOriginalAttributeType() ) )
+                {
+                    activePage.closeEditors( new IEditorReference[]
+                        { editorReference }, false );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Closes the editor associate with the given object class.
+     *
+     * @param oc
+     *      the object class
+     */
+    private void closeObjectClassEditor( ObjectClassImpl oc )
+    {
+        IWorkbenchPage activePage = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+
+        for ( IEditorReference editorReference : activePage.getEditorReferences() )
+        {
+            String editorID = editorReference.getId();
+
+            if ( editorID.equals( ObjectClassEditor.ID ) )
+            {
+                if ( oc.equals( ( ( ObjectClassEditor ) editorReference.getEditor( false
) ).getOriginalObjectClass() ) )
+                {
+                    activePage.closeEditors( new IEditorReference[]
+                        { editorReference }, false );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Closes the editor associated with the given schema.
+     *
+     * @param schema
+     *      the schema
+     */
+    private void closeObjectClassEditor( Schema schema )
+    {
+        IWorkbenchPage activePage = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+
+        for ( IEditorReference editorReference : activePage.getEditorReferences() )
+        {
+            String editorID = editorReference.getId();
+
+            if ( editorID.equals( SchemaEditor.ID ) )
+            {
+                if ( schema.equals( ( ( SchemaEditor ) editorReference.getEditor( false )
).getSchema() ) )
+                {
+                    activePage.closeEditors( new IEditorReference[]
+                        { editorReference }, false );
+                }
+            }
+        }
     }
 
 

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandler.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandler.java?view=diff&rev=560890&r1=560889&r2=560890
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandler.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/SchemaHandler.java
Mon Jul 30 01:45:46 2007
@@ -857,7 +857,7 @@
      */
     private void notifySchemaAdded( Schema schema )
     {
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.schemaAdded( schema );
         }
@@ -872,7 +872,7 @@
      */
     private void notifySchemaRemoved( Schema schema )
     {
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.schemaRemoved( schema );
         }
@@ -888,7 +888,7 @@
     private void notifyAttributeTypeAdded( AttributeTypeImpl at )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.attributeTypeAdded( at );
         }
@@ -897,7 +897,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( at.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).attributeTypeAdded( at );
             }
@@ -914,7 +914,7 @@
     private void notifyAttributeTypeModified( AttributeTypeImpl at )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.attributeTypeModified( at );
         }
@@ -923,7 +923,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( at.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).attributeTypeModified( at );
             }
@@ -940,7 +940,7 @@
     private void notifyAttributeTypeRemoved( AttributeTypeImpl at )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.attributeTypeRemoved( at );
         }
@@ -949,11 +949,21 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( at.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).attributeTypeRemoved( at );
             }
         }
+        
+        // Attribute Type Listeners
+        List<?> atListeners = ( List<?> ) attributeTypeListeners.get( at );
+        if ( atListeners != null )
+        {
+            for ( Object object : atListeners.toArray() )
+            {
+                ( ( AttributeTypeListener ) object ).attributeTypeRemoved();
+            }
+        }
     }
 
 
@@ -966,7 +976,7 @@
     private void notifyObjectClassAdded( ObjectClassImpl oc )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.objectClassAdded( oc );
         }
@@ -975,7 +985,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( oc.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).objectClassAdded( oc );
             }
@@ -992,7 +1002,7 @@
     private void notifyObjectClassModified( ObjectClassImpl oc )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.objectClassModified( oc );
         }
@@ -1001,7 +1011,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( oc.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).objectClassModified( oc );
             }
@@ -1018,7 +1028,7 @@
     private void notifyObjectClassRemoved( ObjectClassImpl oc )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.objectClassRemoved( oc );
         }
@@ -1027,7 +1037,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( oc.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).objectClassModified( oc );
             }
@@ -1044,7 +1054,7 @@
     private void notifyMatchingRuleAdded( MatchingRuleImpl mr )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.matchingRuleAdded( mr );
         }
@@ -1053,7 +1063,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( mr.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).matchingRuleAdded( mr );
             }
@@ -1070,7 +1080,7 @@
     private void notifyMatchingRuleModified( MatchingRuleImpl mr )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.matchingRuleModified( mr );
         }
@@ -1079,7 +1089,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( mr.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).matchingRuleModified( mr );
             }
@@ -1096,7 +1106,7 @@
     private void notifyMatchingRuleRemoved( MatchingRuleImpl mr )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.matchingRuleRemoved( mr );
         }
@@ -1105,7 +1115,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( mr.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).matchingRuleRemoved( mr );
             }
@@ -1122,7 +1132,7 @@
     private void notifySyntaxRuleAdded( SyntaxImpl syntax )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.syntaxAdded( syntax );
         }
@@ -1131,7 +1141,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( syntax.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).syntaxAdded( syntax );
             }
@@ -1148,7 +1158,7 @@
     private void notifySyntaxRuleModified( SyntaxImpl syntax )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.syntaxModified( syntax );
         }
@@ -1157,7 +1167,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( syntax.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).syntaxModified( syntax );
             }
@@ -1174,7 +1184,7 @@
     private void notifySyntaxRemoved( SyntaxImpl syntax )
     {
         // SchemaHandler Listeners
-        for ( SchemaHandlerListener listener : schemaHandlerListeners )
+        for ( SchemaHandlerListener listener : schemaHandlerListeners.toArray( new SchemaHandlerListener[0]
) )
         {
             listener.syntaxRemoved( syntax );
         }
@@ -1183,7 +1193,7 @@
         List<?> listeners = ( List<?> ) schemaListeners.get( getSchema( syntax.getSchema()
) );
         if ( listeners != null )
         {
-            for ( Object object : listeners )
+            for ( Object object : listeners.toArray() )
             {
                 ( ( SchemaListener ) object ).syntaxRemoved( syntax );
             }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditor.java?view=diff&rev=560890&r1=560889&r2=560890
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditor.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditor.java
Mon Jul 30 01:45:46 2007
@@ -23,7 +23,13 @@
 
 import org.apache.directory.studio.apacheds.schemaeditor.Activator;
 import org.apache.directory.studio.apacheds.schemaeditor.PluginUtils;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.AttributeTypeAdapter;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.AttributeTypeListener;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerAdapter;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener;
 import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
 import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.dialogs.IPageChangedListener;
@@ -50,24 +56,23 @@
     /** The ID of the Editor */
     public static final String ID = Activator.PLUGIN_ID + ".view.attributeTypeEditor"; //$NON-NLS-1$
 
-    /** The Overview page */
-    private AttributeTypeEditorOverviewPage overview;
+    /** The dirty state flag */
+    private boolean dirty = false;
 
-    /** The Source Code page */
+    // The pages
+    private AttributeTypeEditorOverviewPage overview;
     private AttributeTypeEditorSourceCodePage sourceCode;
-
-    /** The Used By page */
     private AttributeTypeEditorUsedByPage usedBy;
 
-    /** The dirty state flag */
-    private boolean dirty = false;
-
     /** The original attribute type */
     private AttributeTypeImpl originalAttributeType;
 
     /** The attribute type used to save modifications */
     private AttributeTypeImpl modifiedAttributeType;
 
+    /** The originalSchema */
+    private Schema originalSchema;
+
     /** The listener for page changed */
     private IPageChangedListener pageChangedListener = new IPageChangedListener()
     {
@@ -95,21 +100,64 @@
         }
     };
 
+    /** The editor */
+    private AttributeTypeEditor instance;
+
+    /** The attribute type listener */
+    private AttributeTypeListener attributeTypeListener = new AttributeTypeAdapter()
+    {
+        public void attributeTypeRemoved()
+        {
+            getEditorSite().getPage().closeEditor( instance, false );
+        }
+    };
+
+    /** The originalSchema listener */
+    private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter()
+    {
+        public void schemaRemoved( Schema schema )
+        {
+            if ( schema.equals( originalSchema )  )
+            {
+                getEditorSite().getPage().closeEditor( instance, false );
+            }
+        }
+    };
+
 
     /* (non-Javadoc)
      * @see org.eclipse.ui.forms.editor.FormEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
      */
     public void init( IEditorSite site, IEditorInput input ) throws PartInitException
     {
+        instance = this;
+
         setSite( site );
         setInput( input );
         setPartName( input.getName() );
 
         originalAttributeType = ( ( AttributeTypeEditorInput ) getEditorInput() ).getAttributeType();
-
         modifiedAttributeType = ( AttributeTypeImpl ) PluginUtils.getClone( originalAttributeType
);
 
+        SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler();
+        originalSchema = schemaHandler.getSchema( originalAttributeType.getSchema() );
+        schemaHandler.addListener( originalAttributeType, attributeTypeListener );
+        schemaHandler.addListener( schemaHandlerListener );
+
         addPageChangedListener( pageChangedListener );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
+     */
+    public void dispose()
+    {
+        SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler();
+        schemaHandler.removeListener( originalAttributeType, attributeTypeListener );
+        schemaHandler.removeListener( schemaHandlerListener );
+
+        super.dispose();
     }
 
 

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorOverviewPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorOverviewPage.java?view=diff&rev=560890&r1=560889&r2=560890
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorOverviewPage.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorOverviewPage.java
Mon Jul 30 01:45:46 2007
@@ -87,6 +87,8 @@
     /** The modified object class */
     private AttributeTypeImpl modifiedAttributeType;
 
+    private Schema originalSchema;
+
     /** The SchemaHandler */
     private SchemaHandler schemaHandler;
 
@@ -116,7 +118,10 @@
          */
         public void attributeTypeRemoved( AttributeTypeImpl at )
         {
-            refreshUI();
+            if ( !at.equals( originalAttributeType ) )
+            {
+                refreshUI();
+            }
         }
 
 
@@ -188,7 +193,10 @@
          */
         public void schemaRemoved( Schema schema )
         {
-            refreshUI();
+            if ( !schema.equals( originalSchema ) )
+            {
+                refreshUI();
+            }
         }
 
 
@@ -638,6 +646,7 @@
         // Getting the original and modified attribute types
         modifiedAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getModifiedAttributeType();
         originalAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getOriginalAttributeType();
+        originalSchema = schemaHandler.getSchema( originalAttributeType.getSchema() );
 
         // Creating the base UI
         ScrolledForm form = managedForm.getForm();
@@ -1170,7 +1179,6 @@
     public void dispose()
     {
         schemaHandler.removeListener( schemaHandlerListener );
-        removeListeners();
         super.dispose();
     }
 }



Mime
View raw message