directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r558721 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller: SchemaViewController.java actions/DeleteSchemaElementAction.java actions/OpenElementAction.java
Date Mon, 23 Jul 2007 13:32:33 GMT
Author: pamarcelot
Date: Mon Jul 23 06:32:32 2007
New Revision: 558721

URL: http://svn.apache.org/viewvc?view=rev&rev=558721
Log:
Corrected the OpenElementAction to open also the Schemas in Editors.
Added implementation for the DeleteSchemaElementAction.

Modified:
    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/controller/actions/DeleteSchemaElementAction.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/OpenElementAction.java

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=558721&r1=558720&r2=558721
==============================================================================
--- 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 06:32:32 2007
@@ -366,7 +366,7 @@
         newAttributeType = new NewAttributeTypeAction();
         newObjectClass = new NewObjectClassAction();
         openElement = new OpenElementAction( viewer );
-        deleteSchemaElement = new DeleteSchemaElementAction();
+        deleteSchemaElement = new DeleteSchemaElementAction( viewer );
         importSchemasFromOpenLdap = new ImportSchemasFromOpenLdapAction();
         importSchemasFromXml = new ImportSchemasFromXmlAction();
         exportSchemasAsOpenLdap = new ExportSchemasAsOpenLdapAction( viewer );

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/DeleteSchemaElementAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/DeleteSchemaElementAction.java?view=diff&rev=558721&r1=558720&r2=558721
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/DeleteSchemaElementAction.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/DeleteSchemaElementAction.java
Mon Jul 23 06:32:32 2007
@@ -20,11 +20,30 @@
 package org.apache.directory.studio.apacheds.schemaeditor.controller.actions;
 
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+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.SchemaHandler;
+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.Schema;
+import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.AttributeTypeWrapper;
+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.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
@@ -38,10 +57,14 @@
  */
 public class DeleteSchemaElementAction extends Action implements IWorkbenchWindowActionDelegate
 {
+    /** The associated viewer */
+    private TreeViewer viewer;
+
+
     /**
      * Creates a new instance of DeleteSchemaElementAction.
      */
-    public DeleteSchemaElementAction()
+    public DeleteSchemaElementAction( TreeViewer viewer )
     {
         super( "Delete" );
         setToolTipText( getText() );
@@ -49,6 +72,41 @@
         setImageDescriptor( AbstractUIPlugin
             .imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_DELETE )
);
         setEnabled( true );
+        this.viewer = viewer;
+        this.viewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                StructuredSelection selection = ( StructuredSelection ) event.getSelection();
+                if ( selection.size() > 0 )
+                {
+                    boolean enabled = false;
+
+                    for ( Iterator<?> iterator = selection.iterator(); iterator.hasNext();
)
+                    {
+                        Object selectedItem = iterator.next();
+                        if ( selectedItem instanceof SchemaWrapper )
+                        {
+                            enabled = true;
+                        }
+                        else if ( selectedItem instanceof AttributeTypeWrapper )
+                        {
+                            enabled = true;
+                        }
+                        else if ( selectedItem instanceof ObjectClassWrapper )
+                        {
+                            enabled = true;
+                        }
+                    }
+
+                    setEnabled( enabled );
+                }
+                else
+                {
+                    setEnabled( false );
+                }
+            }
+        } );
     }
 
 
@@ -57,7 +115,59 @@
      */
     public void run()
     {
-        // TODO implement
+        StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
+
+        if ( !selection.isEmpty() )
+        {
+            Map<String, Schema> schemasMap = new HashMap<String, Schema>();
+            List<SchemaObject> schemaObjectsList = new ArrayList<SchemaObject>();
+
+            for ( Iterator<?> iterator = selection.iterator(); iterator.hasNext();
)
+            {
+                Object selectedItem = iterator.next();
+                if ( selectedItem instanceof SchemaWrapper )
+                {
+                    Schema schema = ( ( SchemaWrapper ) selectedItem ).getSchema();
+                    schemasMap.put( schema.getName().toLowerCase(), schema );
+                }
+                else if ( selectedItem instanceof AttributeTypeWrapper )
+                {
+                    AttributeTypeImpl at = ( ( AttributeTypeWrapper ) selectedItem ).getAttributeType();
+                    schemaObjectsList.add( at );
+                }
+                else if ( selectedItem instanceof ObjectClassWrapper )
+                {
+                    ObjectClassImpl oc = ( ( ObjectClassWrapper ) selectedItem ).getObjectClass();
+                    schemaObjectsList.add( oc );
+                }
+            }
+
+            SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler();
+            // Removing schema objects
+            for ( SchemaObject schemaObject : schemaObjectsList )
+            {
+                if ( !schemasMap.containsKey( schemaObject.getSchema().toLowerCase() ) )
+                {
+                    // If the schema object is not part of deleted schema, we need to delete
it.
+                    // But, we don't delete schema objects that are part of a deleted schema,
since
+                    // deleting the schema will also delete this schema object.
+                    if ( schemaObject instanceof AttributeTypeImpl )
+                    {
+                        schemaHandler.removeAttributeType( ( AttributeTypeImpl ) schemaObject
);
+                    }
+                    else if ( schemaObject instanceof ObjectClassImpl )
+                    {
+                        schemaHandler.removeObjectClass( ( ObjectClassImpl ) schemaObject
);
+                    }
+                }
+            }
+
+            // Removing schemas
+            for ( Schema schema : schemasMap.values() )
+            {
+                schemaHandler.removeSchema( schema );
+            }
+        }
     }
 
 

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/OpenElementAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/OpenElementAction.java?view=diff&rev=558721&r1=558720&r2=558721
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/OpenElementAction.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/OpenElementAction.java
Mon Jul 23 06:32:32 2007
@@ -27,6 +27,8 @@
 import org.apache.directory.studio.apacheds.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput;
 import org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass.ObjectClassEditor;
 import org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass.ObjectClassEditorInput;
+import org.apache.directory.studio.apacheds.schemaeditor.view.editors.schema.SchemaEditor;
+import org.apache.directory.studio.apacheds.schemaeditor.view.editors.schema.SchemaEditorInput;
 import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.AttributeTypeWrapper;
 import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.Folder;
 import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.ObjectClassWrapper;
@@ -102,7 +104,19 @@
                     // TODO Add logging
                 }
             }
-            else if ( ( selectedItem instanceof Folder ) || ( selectedItem instanceof SchemaWrapper
) )
+            else if ( selectedItem instanceof SchemaWrapper )
+            {
+                try
+                {
+                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(
+                        new SchemaEditorInput( ( ( SchemaWrapper ) selectedItem ).getSchema()
), SchemaEditor.ID );
+                }
+                catch ( PartInitException e )
+                {
+                    // TODO Add logging
+                }
+            }
+            else if ( selectedItem instanceof Folder )
             {
                 viewer.setExpandedState( selectedItem, !viewer.getExpandedState( selectedItem
) );
             }



Mime
View raw message