directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r598395 [4/7] - in /directory/sandbox/felixk: studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ studio-aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/ studio-aciitemedito...
Date Mon, 26 Nov 2007 19:44:37 GMT
Modified: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java Mon Nov 26 11:44:28 2007
@@ -31,7 +31,7 @@
 import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.IValue;
-import org.apache.directory.studio.ldapbrowser.core.utils.LdifUtils;
+import org.apache.directory.studio.ldifparser.LdifUtils;
 
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.dnd.Clipboard;

Modified: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java Mon Nov 26 11:44:28 2007
@@ -21,6 +21,7 @@
 package org.apache.directory.studio.ldapbrowser.common.actions;
 
 
+import org.apache.directory.studio.ldapbrowser.common.dialogs.EntryExistsCopyStrategyDialogImpl;
 import org.apache.directory.studio.ldapbrowser.common.dialogs.ScopeDialog;
 import org.apache.directory.studio.ldapbrowser.common.dnd.EntryTransfer;
 import org.apache.directory.studio.ldapbrowser.common.dnd.ValuesTransfer;
@@ -169,7 +170,8 @@
             scope = scopeDialog.getScope();
         }
 
-        new CopyEntriesJob( parent, entriesToPaste, scope ).execute();
+        new CopyEntriesJob( parent, entriesToPaste, scope, new EntryExistsCopyStrategyDialogImpl( Display.getDefault()
+            .getActiveShell() ) ).execute();
     }
 
 

Modified: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PropertiesAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PropertiesAction.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PropertiesAction.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PropertiesAction.java Mon Nov 26 11:44:28 2007
@@ -22,8 +22,7 @@
 
 
 import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
-import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
-
+import org.apache.directory.studio.connection.core.Utils;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.jface.preference.PreferenceDialog;
 import org.eclipse.jface.resource.ImageDescriptor;

Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java Mon Nov 26 11:44:28 2007
@@ -0,0 +1,261 @@
+/*
+ *  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.ldapbrowser.common.dialogs;
+
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.DnBuilderWidget;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyEvent;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyListener;
+import org.apache.directory.studio.ldapbrowser.core.jobs.EntryExistsCopyStrategyDialog;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * A dialog to select the copy strategy if an entry already exists.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryExistsCopyStrategyDialogImpl extends Dialog implements EntryExistsCopyStrategyDialog
+{
+
+    /** The dialog title. */
+    private String dialogTitle = "Select copy strategy";
+
+    /** The break button. */
+    private Button breakButton;
+
+    /** The ignore button. */
+    private Button ignoreButton;
+//
+//    /** The overwrite button. */
+//    private Button overwriteButton;
+
+    /** The rename button. */
+    private Button renameButton;
+//
+//    /** The remember check box. */
+//    private Button rememberCheckbox;
+
+    /** The DN builder widget. */
+    private DnBuilderWidget dnBuilderWidget;
+
+    /** The new RDN. */
+    private Rdn rdn;
+
+    /** The strategy */
+    private EntryExistsCopyStrategy strategy;
+
+    /** The remember flag */
+    private boolean isRememberStrategy;
+
+    private IBrowserConnection browserConnection;
+
+    private LdapDN dn;
+
+
+    /**
+     * Creates a new instance of ScopeDialog.
+     * 
+     * @param parentShell the parent shell
+     * @param dialogTitle the dialog title
+     * @param multipleEntriesSelected the multiple entries selected
+     */
+    public EntryExistsCopyStrategyDialogImpl( Shell parentShell )
+    {
+        super( parentShell );
+        super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+    }
+
+
+    /**
+     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+     */
+    protected void configureShell( Shell shell )
+    {
+        super.configureShell( shell );
+        shell.setText( dialogTitle );
+    }
+
+
+    /**
+     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+     */
+    protected void okPressed()
+    {
+        rdn = null;
+//        isRememberStrategy = rememberCheckbox.getSelection() && rememberCheckbox.isEnabled();
+
+        if ( breakButton.getSelection() )
+        {
+            strategy = EntryExistsCopyStrategy.BREAK;
+        }
+        else if ( ignoreButton.getSelection() )
+        {
+            strategy = EntryExistsCopyStrategy.IGNORE_AND_CONTINUE;
+        }
+//        else if ( overwriteButton.getSelection() )
+//        {
+//            strategy = EntryExistsCopyStrategy.OVERWRITE_AND_CONTINUE;
+//        }
+        else if ( renameButton.getSelection() )
+        {
+            strategy = EntryExistsCopyStrategy.RENAME_AND_CONTINUE;
+            rdn = dnBuilderWidget.getRdn();
+        }
+
+        super.okPressed();
+    }
+
+
+    /**
+     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+     */
+    protected void createButtonsForButtonBar( Composite parent )
+    {
+        createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+        //createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+    }
+
+
+    /**
+     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     */
+    protected Control createDialogArea( Composite parent )
+    {
+        Composite composite = ( Composite ) super.createDialogArea( parent );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        composite.setLayoutData( gd );
+
+        String text = "The entry " + dn.getUpName() + " already exists. Please select how to proceed.";
+        BaseWidgetUtils.createLabel( composite, text, 1 );
+
+        Composite group2 = BaseWidgetUtils.createGroup( composite, "", 1 );
+        Composite group = BaseWidgetUtils.createColumnContainer( group2, 2, 1 );
+
+        SelectionListener listener = new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                validate();
+            }
+        };
+
+        breakButton = BaseWidgetUtils.createRadiobutton( group, "Stop copy process", 2 );
+        breakButton.setSelection( true );
+        breakButton.addSelectionListener( listener );
+
+        ignoreButton = BaseWidgetUtils.createRadiobutton( group, "Ignore entry and continue", 2 );
+        ignoreButton.addSelectionListener( listener );
+//
+//        overwriteButton = BaseWidgetUtils.createRadiobutton( group, "Overwrite entry and continue", 2 );
+//        overwriteButton.setEnabled( false );
+//        overwriteButton.addSelectionListener( listener );
+
+        renameButton = BaseWidgetUtils.createRadiobutton( group, "Rename entry and continue", 2 );
+        renameButton.addSelectionListener( listener );
+
+        BaseWidgetUtils.createRadioIndent( group, 1 );
+        dnBuilderWidget = new DnBuilderWidget( true, false );
+        dnBuilderWidget.addWidgetModifyListener( new WidgetModifyListener()
+        {
+            public void widgetModified( WidgetModifyEvent event )
+            {
+                validate();
+            }
+        } );
+        dnBuilderWidget.createContents( group );
+        dnBuilderWidget.setInput( browserConnection, browserConnection.getSchema().getAttributeTypeDescriptionNames(),
+            dn.getRdn(), null );
+
+//        rememberCheckbox = BaseWidgetUtils.createCheckbox( composite, "Remember decision", 2 );
+
+        validate();
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    private void validate()
+    {
+        dnBuilderWidget.setEnabled( renameButton.getSelection() );
+        if ( renameButton.getSelection() )
+        {
+            getButton( IDialogConstants.OK_ID ).setEnabled( dnBuilderWidget.getRdn() != null );
+        }
+//        rememberCheckbox.setEnabled( overwriteButton.getSelection() || ignoreButton.getSelection() );
+    }
+
+
+    public int open()
+    {
+        final int[] result = new int[1];
+        Display.getDefault().syncExec( new Runnable()
+        {
+            public void run()
+            {
+                result[0] = EntryExistsCopyStrategyDialogImpl.super.open();
+            }
+        } );
+        return result[0];
+    }
+
+
+    public EntryExistsCopyStrategy getStrategy()
+    {
+        return strategy;
+    }
+
+
+    public Rdn getRdn()
+    {
+        return rdn;
+    }
+
+
+    public boolean isRememberSelection()
+    {
+        return isRememberStrategy;
+    }
+
+
+    public void setExistingEntry( IBrowserConnection browserConnection, LdapDN dn )
+    {
+        this.browserConnection = browserConnection;
+        this.dn = dn;
+    }
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/MoveEntriesDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/MoveEntriesDialog.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/MoveEntriesDialog.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/MoveEntriesDialog.java Mon Nov 26 11:44:28 2007
@@ -22,12 +22,12 @@
 
 
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.connection.core.DnUtils;
 import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
 import org.apache.directory.studio.ldapbrowser.common.widgets.DnBuilderWidget;
 import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyEvent;
 import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyListener;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
-import org.apache.directory.studio.ldapbrowser.core.utils.DnUtils;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.swt.SWT;

Modified: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java Mon Nov 26 11:44:28 2007
@@ -28,9 +28,9 @@
 import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.studio.connection.core.DnUtils;
 import org.apache.directory.studio.ldapbrowser.common.widgets.search.EntryWidget;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
-import org.apache.directory.studio.ldapbrowser.core.utils.DnUtils;
 import org.eclipse.jface.fieldassist.ComboContentAdapter;
 import org.eclipse.jface.fieldassist.ContentProposalAdapter;
 import org.eclipse.jface.fieldassist.DecoratedField;
@@ -82,9 +82,15 @@
 
     /** The selected parent DN. */
     private LdapDN parentDn;
+    
+    /** The entry widget label. */
+    private Label parentEntryLabel;
 
     /** The entry widget to enter/select the parent DN. */
     private EntryWidget parentEntryWidget;
+    
+    /** The RDN label */
+    private Label rdnLabel;
 
     /** The composite that contains the RdnLines. */
     private Composite rdnComposite;
@@ -94,6 +100,9 @@
 
     /** The list of RdnLines. */
     private ArrayList<RdnLine> rdnLineList;
+    
+    /** The preview label. */
+    private Label previewLabel;
 
     /** The preview text. */
     private Text previewText;
@@ -234,7 +243,7 @@
         // draw parent
         if ( showParent )
         {
-            BaseWidgetUtils.createLabel( composite, "Parent:", 1 );
+            parentEntryLabel = BaseWidgetUtils.createLabel( composite, "Parent:", 1 );
             parentEntryWidget = new EntryWidget();
             parentEntryWidget.createWidget( composite );
             parentEntryWidget.addWidgetModifyListener( new WidgetModifyListener()
@@ -251,7 +260,7 @@
         // draw RDN group
         if ( showRDN )
         {
-            BaseWidgetUtils.createLabel( composite, "RDN:", 1 );
+            rdnLabel = BaseWidgetUtils.createLabel( composite, "RDN:", 1 );
             rdnComposite = BaseWidgetUtils.createColumnContainer( composite, 5, 2 );
             rdnLineList = new ArrayList<RdnLine>();
             BaseWidgetUtils.createSpacer( composite, 3 );
@@ -260,7 +269,7 @@
         // draw dn/rdn preview
         if ( showRDN )
         {
-            BaseWidgetUtils.createLabel( composite, showParent ? "DN Preview: " : "RDN Preview: ", 1 );
+            previewLabel = BaseWidgetUtils.createLabel( composite, showParent ? "DN Preview: " : "RDN Preview: ", 1 );
             previewText = BaseWidgetUtils.createReadonlyText( composite, "", 2 );
             BaseWidgetUtils.createSpacer( composite, 3 );
         }
@@ -295,7 +304,6 @@
      */
     public void validate()
     {
-
         Exception rdnE = null;
         if ( showRDN )
         {
@@ -379,7 +387,7 @@
                 {
                     dn = new LdapDN();
                 }
-                previewText.setText( dn.toString() );
+                previewText.setText( dn.getUpName() );
             }
         }
 
@@ -596,6 +604,39 @@
 
         /** The rdn delete button. */
         private Button rdnDeleteButton;
+    }
+
+
+    /**
+     * Enables or disables this widget.
+     * 
+     * @param b true to enable, false to disable 
+     */
+    public void setEnabled( boolean b )
+    {
+        if ( parentEntryWidget != null )
+        {
+            parentEntryLabel.setEnabled( b );
+            parentEntryWidget.setEnabled( b );
+        }
+        if ( rdnComposite != null && rdnLineList != null )
+        {
+            rdnLabel.setEnabled( b );
+            rdnComposite.setEnabled( b );
+            for ( RdnLine rdnLine : rdnLineList )
+            {
+                rdnLine.rdnTypeCombo.setEnabled( b );
+                rdnLine.rdnEqualsLabel.setEnabled( b );
+                rdnLine.rdnValueText.setEnabled( b );
+                rdnLine.rdnAddButton.setEnabled( b );
+                rdnLine.rdnDeleteButton.setEnabled( b && rdnLineList.size() > 1 );
+            }
+        }
+        if ( previewText != null )
+        {
+            previewLabel.setEnabled( b );
+            previewText.setEnabled( b );
+        }
     }
 
 }

Modified: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java Mon Nov 26 11:44:28 2007
@@ -36,7 +36,7 @@
 import org.apache.directory.studio.ldapbrowser.core.model.impl.BaseDNEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.impl.DirectoryMetadataEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.impl.ReferralBaseEntry;
-import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
+import org.apache.directory.studio.connection.core.Utils;
 import org.eclipse.jface.preference.PreferenceConverter;
 import org.eclipse.jface.viewers.IColorProvider;
 import org.eclipse.jface.viewers.IFontProvider;

Modified: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/EntryWidget.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/EntryWidget.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/EntryWidget.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/EntryWidget.java Mon Nov 26 11:44:28 2007
@@ -24,6 +24,7 @@
 import javax.naming.InvalidNameException;
 
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.connection.core.DnUtils;
 import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
 import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
 import org.apache.directory.studio.ldapbrowser.common.dialogs.SelectEntryDialog;
@@ -34,7 +35,6 @@
 import org.apache.directory.studio.ldapbrowser.core.jobs.ReadEntryJob;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
-import org.apache.directory.studio.ldapbrowser.core.utils.DnUtils;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;

Modified: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorManager.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorManager.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorManager.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorManager.java Mon Nov 26 11:44:28 2007
@@ -43,8 +43,8 @@
 import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeTypeDescription;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.LdapSyntaxDescription;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
-import org.apache.directory.studio.ldapbrowser.core.utils.LdifUtils;
 import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
+import org.apache.directory.studio.ldifparser.LdifUtils;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtension;
 import org.eclipse.core.runtime.IExtensionPoint;

Modified: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionManager.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionManager.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionManager.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionManager.java Mon Nov 26 11:44:28 2007
@@ -22,13 +22,10 @@
 
 
 import java.beans.Encoder;
-import java.beans.ExceptionListener;
 import java.beans.Expression;
 import java.beans.PersistenceDelegate;
 import java.beans.XMLDecoder;
-import java.beans.XMLEncoder;
 import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -45,6 +42,7 @@
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
 import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.Utils;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
 import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
 import org.apache.directory.studio.connection.core.io.ConnectionIOException;
@@ -60,15 +58,10 @@
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.AliasDereferencingMethod;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
 import org.apache.directory.studio.ldapbrowser.core.model.impl.Bookmark;
 import org.apache.directory.studio.ldapbrowser.core.model.impl.BrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
-import org.apache.directory.studio.ldapbrowser.core.utils.LdifUtils;
-import org.eclipse.core.runtime.IPath;
 
 
 /**
@@ -109,28 +102,7 @@
     public static final String getSchemaCacheFileName( IBrowserConnection browserConnection )
     {
         return BrowserCorePlugin.getDefault().getStateLocation().append(
-            "schema-" + toSaveString( browserConnection.getConnection().getId() ) + ".ldif" ).toOSString(); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-
-
-    /**
-     * Gets the Modification Log filename for the corresponding browser connection.
-     *
-     * @param browserConnection
-     *      the browser connection
-     * @return
-     *      the Modification Log filename
-     */
-    public static final String getModificationLogFileName( IBrowserConnection browserConnection )
-    {
-        IPath p = BrowserCorePlugin.getDefault().getStateLocation().append( "logs" ); //$NON-NLS-1$
-        File file = p.toFile();
-        if ( !file.exists() )
-        {
-            file.mkdir();
-        }
-        return p
-            .append( "modifications-" + toSaveString( browserConnection.getConnection().getId() ) + "-%u-%g.ldiflog" ).toOSString(); //$NON-NLS-1$ //$NON-NLS-2$
+            "schema-" + Utils.getFilenameString( browserConnection.getConnection().getId() ) + ".ldif" ).toOSString(); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
 
@@ -175,47 +147,6 @@
         }
 
         return filename;
-    }
-
-
-    /**
-     * Converts a String into a Saveable String.
-     *
-     * @param s
-     *      the String to convert
-     * @return
-     *      the converted String
-     */
-    private static String toSaveString( String s )
-    {
-        if ( s == null )
-        {
-            return null;
-        }
-
-        byte[] b = LdifUtils.utf8encode( s );
-        StringBuffer sb = new StringBuffer();
-        for ( int i = 0; i < b.length; i++ )
-        {
-
-            if ( b[i] == '-' || b[i] == '_' || ( '0' <= b[i] && b[i] <= '9' ) || ( 'A' <= b[i] && b[i] <= 'Z' )
-                || ( 'a' <= b[i] && b[i] <= 'z' ) )
-            {
-                sb.append( ( char ) b[i] );
-            }
-            else
-            {
-                int x = ( int ) b[i];
-                if ( x < 0 )
-                    x = 256 + x;
-                String t = Integer.toHexString( x );
-                if ( t.length() == 1 )
-                    t = "0" + t; //$NON-NLS-1$
-                sb.append( t );
-            }
-        }
-
-        return sb.toString();
     }
 
 

Modified: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCoreConstants.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCoreConstants.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCoreConstants.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCoreConstants.java Mon Nov 26 11:44:28 2007
@@ -43,8 +43,6 @@
 
     public static final String DEFAULT_ENCODING = new OutputStreamWriter( new ByteArrayOutputStream() ).getEncoding();
 
-    public static final String DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS"; //$NON-NLS-1$
-
     public static final String PREFERENCE_CHECK_FOR_CHILDREN = "checkForChildren"; //$NON-NLS-1$
 
     public static final String PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS = "showAliasAndReferralObjects"; //$NON-NLS-1$

Modified: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCorePlugin.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCorePlugin.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCorePlugin.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserCorePlugin.java Mon Nov 26 11:44:28 2007
@@ -23,7 +23,6 @@
 
 import org.apache.directory.studio.ldapbrowser.core.events.CoreEventRunner;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRunner;
-import org.apache.directory.studio.ldapbrowser.core.model.IReferralHandler;
 import org.eclipse.core.runtime.Plugin;
 import org.osgi.framework.BundleContext;
 
@@ -42,9 +41,6 @@
     /** The connection manager */
     private BrowserConnectionManager connectionManager;
 
-    /** The connection provider */
-    private IReferralHandler referralHandler;
-
     /** The preferences */
     private BrowserCorePreferences preferences;
 
@@ -136,30 +132,6 @@
     public BrowserCorePreferences getCorePreferences()
     {
         return preferences;
-    }
-
-
-    /**
-     * Gets the ReferralHanlder
-     *
-     * @return
-     *      the ReferralHandler
-     */
-    public IReferralHandler getReferralHandler()
-    {
-        return referralHandler;
-    }
-
-
-    /**
-     * Sets the ReferralHandler
-     *
-     * @param referralHandler
-     *      the ReferralHandler to set
-     */
-    public void setReferralHandler( IReferralHandler referralHandler )
-    {
-        this.referralHandler = referralHandler;
     }
 
 

Modified: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java Mon Nov 26 11:44:28 2007
@@ -26,34 +26,39 @@
 import java.util.Iterator;
 import java.util.List;
 
-import javax.naming.InvalidNameException;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
 
 import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.DnUtils;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.events.ChildrenInitializedEvent;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.jobs.EntryExistsCopyStrategyDialog.EntryExistsCopyStrategy;
 import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
-import org.apache.directory.studio.ldapbrowser.core.model.IValue;
-import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.AliasDereferencingMethod;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Entry;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Value;
-import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils;
-import org.apache.directory.studio.ldapbrowser.core.utils.DnUtils;
+import org.apache.directory.studio.ldapbrowser.core.utils.JNDIUtils;
 
 
 /**
  * Job to copy entries asynchronously.
+ * 
+ * TODO: implement overwrite strategy
+ * TODO: implement remember selection
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -70,6 +75,9 @@
     /** The copy scope */
     private SearchScope scope;
 
+    /** The dialog to ask for the strategy */
+    private EntryExistsCopyStrategyDialog dialog;
+
 
     /**
      * Creates a new instance of CopyEntriesJob.
@@ -77,12 +85,15 @@
      * @param parent the parent entry
      * @param entriesToCopy the entries to copy
      * @param scope the copy scope
+     * @param dialog the dialog
      */
-    public CopyEntriesJob( final IEntry parent, final IEntry[] entriesToCopy, SearchScope scope )
+    public CopyEntriesJob( final IEntry parent, final IEntry[] entriesToCopy, SearchScope scope,
+        EntryExistsCopyStrategyDialog dialog )
     {
         this.parent = parent;
         this.entriesToCopy = entriesToCopy;
         this.scope = scope;
+        this.dialog = dialog;
         setName( entriesToCopy.length == 1 ? BrowserCoreMessages.jobs__copy_entries_name_1
             : BrowserCoreMessages.jobs__copy_entries_name_n );
     }
@@ -126,6 +137,10 @@
 
         if ( scope == SearchScope.OBJECT || scope == SearchScope.ONELEVEL || scope == SearchScope.SUBTREE )
         {
+            StudioProgressMonitor dummyMonitor = new StudioProgressMonitor( monitor );
+            int copyScope = scope == SearchScope.SUBTREE ? SearchControls.SUBTREE_SCOPE
+                : scope == SearchScope.ONELEVEL ? SearchControls.ONELEVEL_SCOPE : SearchControls.OBJECT_SCOPE;
+
             int num = 0;
             for ( int i = 0; !monitor.isCanceled() && i < entriesToCopy.length; i++ )
             {
@@ -134,7 +149,8 @@
                 if ( scope == SearchScope.OBJECT
                     || !parent.getDn().getNormName().endsWith( entryToCopy.getDn().getNormName() ) )
                 {
-                    num = copyEntryRecursive( entryToCopy, parent, scope, num, monitor );
+                    num = copyEntry( entryToCopy.getBrowserConnection(), entryToCopy.getDn(), parent.getDn(),
+                        copyScope, num, dummyMonitor, monitor );
                 }
                 else
                 {
@@ -166,213 +182,157 @@
     }
 
 
-    /**
-     * Copies the entry recursive.
-     * 
-     * @param entryToCopy the entry to copy
-     * @param parent the parent entry
-     * @param scope the copy scope
-     * @param num the number of copied entries
-     * @param monitor the progress monitor
-     * 
-     * @return the number of copied entries
-     */
-    private int copyEntryRecursive( IEntry entryToCopy, IEntry parent, SearchScope scope, int num, StudioProgressMonitor monitor )
+    private int copyEntry( IBrowserConnection browserConnection, LdapDN dnToCopy, LdapDN parentDn, int scope,
+        int numberOfCopiedEntries, StudioProgressMonitor dummyMonitor, StudioProgressMonitor monitor )
+    {
+        SearchControls searchControls = new SearchControls();
+        searchControls.setCountLimit( 1 );
+        searchControls.setReturningAttributes( new String[]
+            { ISearch.ALL_USER_ATTRIBUTES, IAttribute.REFERRAL_ATTRIBUTE } );
+        searchControls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        NamingEnumeration<SearchResult> result = browserConnection.getConnection().getJNDIConnectionWrapper().search(
+            dnToCopy.getUpName(), ISearch.FILTER_TRUE, searchControls, "never", JNDIConnectionWrapper.REFERRAL_IGNORE,
+            null, monitor, null );
+
+        numberOfCopiedEntries = copyEntryRecursive( browserConnection, result, parentDn, scope, numberOfCopiedEntries,
+            dummyMonitor, monitor );
+
+        return numberOfCopiedEntries;
+    }
+
+
+    private int copyEntryRecursive( IBrowserConnection browserConnection, NamingEnumeration<SearchResult> entries,
+        LdapDN parentDn, int scope, int numberOfCopiedEntries, StudioProgressMonitor dummyMonitor,
+        StudioProgressMonitor monitor )
     {
         try
         {
-            // TODO: use JNDI here!!!
-            SearchParameter param = new SearchParameter();
-            param.setSearchBase( entryToCopy.getDn() );
-            param.setFilter( ISearch.FILTER_TRUE );
-            param.setScope( SearchScope.OBJECT );
-            param.setAliasesDereferencingMethod( AliasDereferencingMethod.NEVER );
-            param.setReferralsHandlingMethod( ReferralHandlingMethod.IGNORE );
-            param.setReturningAttributes( new String[]
-                { ISearch.ALL_USER_ATTRIBUTES, IAttribute.REFERRAL_ATTRIBUTE } );
-            ISearch search = new Search( entryToCopy.getBrowserConnection(), param );
-            
-            SearchJob.searchAndUpdateModel( entryToCopy.getBrowserConnection(), search, monitor );
-
-            ISearchResult[] srs = search.getSearchResults();
-            if ( !monitor.isCanceled() && srs != null && srs.length == 1 )
+            while ( !monitor.isCanceled() && entries.hasMore() )
             {
-                entryToCopy = srs[0].getEntry();
-                IAttribute[] attributesToCopy = entryToCopy.getAttributes();
+                SearchResult sr = entries.next();
 
-                // create new entry
-                Rdn rdn = entryToCopy.getRdn();
-                IEntry newEntry = new Entry( parent, rdn );
-
-                // change RDN if entry already exists
-                StudioProgressMonitor testMonitor = new StudioProgressMonitor( monitor );
-                IEntry testEntry = ReadEntryJob.getEntry( parent.getBrowserConnection(), newEntry.getDn(), testMonitor );
-                if ( testEntry != null )
-                {
-                    Object rdnValue = rdn.getUpValue();
-                    String newRdnValue = BrowserCoreMessages.bind( BrowserCoreMessages.copy_n_of_s, "", rdnValue ); //$NON-NLS-1$
-                    Rdn newRdn = getNewRdn( rdn, newRdnValue );
-                    newEntry = new Entry( parent, newRdn );
-                    testEntry = ReadEntryJob.getEntry( parent.getBrowserConnection(), newEntry.getDn(), testMonitor );
-                    for ( int i = 2; testEntry != null; i++ )
-                    {
-                        newRdnValue = BrowserCoreMessages.bind( BrowserCoreMessages.copy_n_of_s, i + " ", rdnValue ); //$NON-NLS-1$
-                        newRdn = getNewRdn( rdn, newRdnValue );
-                        newEntry = new Entry( parent, newRdn );
-                        testEntry = ReadEntryJob.getEntry( parent.getBrowserConnection(), newEntry.getDn(), testMonitor );
-                    }
-                }
+                // compose new DN
+                LdapDN oldLdapDn = JNDIUtils.getDn( sr );
+                String oldDn = oldLdapDn.getUpName();
+                Rdn oldRdn = oldLdapDn.getRdn();
+                LdapDN newLdapDn = DnUtils.composeDn( oldRdn, parentDn );
+                String newDn = newLdapDn.getUpName();
 
                 // copy attributes
-                for ( int i = 0; i < attributesToCopy.length; i++ )
-                {
-                    IAttribute attributeToCopy = attributesToCopy[i];
+                Attributes oldAttributes = sr.getAttributes();
+                Attributes newAttributes = oldAttributes;
 
-                    if ( SchemaUtils.isModifyable( attributeToCopy.getAttributeTypeDescription() )
-                        || IAttribute.REFERRAL_ATTRIBUTE.equalsIgnoreCase( attributeToCopy.getDescription() ) )
-                    {
-                        IAttribute newAttribute = new Attribute( newEntry, attributeToCopy.getDescription() );
-                        newEntry.addAttribute( newAttribute );
-                        IValue[] valuesToCopy = attributeToCopy.getValues();
-                        for ( int j = 0; j < valuesToCopy.length; j++ )
-                        {
-                            IValue valueToCopy = valuesToCopy[j];
-                            IValue newValue = new Value( newAttribute, valueToCopy.getRawValue() );
-                            newAttribute.addValue( newValue );
-                        }
-                    }
-                }
+                // create entry
+                browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( newDn, newAttributes, null,
+                    dummyMonitor );
 
-                // check if RDN attributes ar present
-                Rdn newRdn = newEntry.getRdn();
-                Iterator<AttributeTypeAndValue> atavIterator = newRdn.iterator();
-                while(atavIterator.hasNext())
+                while ( dummyMonitor.errorsReported() )
                 {
-                    AttributeTypeAndValue atav = atavIterator.next();
-                    IAttribute rdnAttribute = newEntry.getAttribute( atav.getUpType() );
-                    if ( rdnAttribute != null )
+                    if ( dummyMonitor.getException() instanceof NameAlreadyBoundException )
                     {
-                        IValue[] values = rdnAttribute.getValues();
-                        for ( int ii = 0; ii < values.length; ii++ )
+                        // open dialog
+                        dialog.setExistingEntry( browserConnection, newLdapDn );
+                        dialog.open();
+                        EntryExistsCopyStrategy strategy = dialog.getStrategy();
+//                        boolean rememberSelection = dialog.isRememberSelection();
+                        if ( strategy != null )
                         {
-                            if ( atav.getUpValue().equals( values[ii].getRawValue() ) )
-                            {
-                                rdnAttribute.deleteValue( values[ii] );
-                            }
-                            if ( rdnAttribute.getValueSize() == 0 )
+                            dummyMonitor.reset();
+
+                            switch ( strategy )
                             {
-                                newEntry.deleteAttribute( rdnAttribute );
+                                case BREAK:
+                                    monitor.setCanceled( true );
+                                    break;
+                                case IGNORE_AND_CONTINUE:
+                                    break;
+//                                case OVERWRITE_AND_CONTINUE:
+//                                    break;
+                                case RENAME_AND_CONTINUE:
+                                    Rdn renamedRdn = dialog.getRdn();
+                                    for ( Iterator<AttributeTypeAndValue> it = oldRdn.iterator(); it.hasNext(); )
+                                    {
+                                        AttributeTypeAndValue atav = it.next();
+                                        Attribute attribute = newAttributes.get( atav.getUpType() );
+                                        if ( attribute != null )
+                                        {
+                                            attribute.remove( atav.getUpValue() );
+                                            if ( attribute.size() == 0 )
+                                            {
+                                                newAttributes.remove( atav.getUpType() );
+                                            }
+                                        }
+                                    }
+                                    for ( Iterator<AttributeTypeAndValue> it = renamedRdn.iterator(); it.hasNext(); )
+                                    {
+                                        AttributeTypeAndValue atav = it.next();
+                                        Attribute attribute = newAttributes.get( atav.getUpType() );
+                                        if ( attribute == null )
+                                        {
+                                            attribute = new BasicAttribute( atav.getUpType() );
+                                            newAttributes.put( attribute );
+                                        }
+                                        if ( !attribute.contains( atav.getUpValue() ) )
+                                        {
+                                            attribute.add( atav.getUpValue() );
+                                        }
+                                    }
+
+                                    newLdapDn = DnUtils.composeDn( renamedRdn, parentDn );
+                                    newDn = newLdapDn.getUpName();
+
+                                    browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( newDn,
+                                        newAttributes, null, dummyMonitor );
+
+                                    break;
                             }
                         }
-                    }
-                }
-                atavIterator = newRdn.iterator();
-                while(atavIterator.hasNext())
-                {
-                    AttributeTypeAndValue atav = atavIterator.next();
-                    IAttribute rdnAttribute = newEntry.getAttribute( atav.getUpType() );
-                    if ( rdnAttribute == null )
-                    {
-                        rdnAttribute = new Attribute( newEntry, atav.getUpType() );
-                        newEntry.addAttribute( rdnAttribute );
-                        rdnAttribute.addValue( new Value( rdnAttribute, atav.getUpValue() ) );
+                        else
+                        {
+                            monitor.reportError( dummyMonitor.getException() );
+                            dummyMonitor.reset();
+                        }
                     }
                     else
                     {
-                        boolean mustAdd = true;
-                        IValue[] values = rdnAttribute.getValues();
-                        for ( int ii = 0; ii < values.length; ii++ )
-                        {
-                            if ( atav.getUpValue().equals( values[ii].getStringValue() ) )
-                            {
-                                mustAdd = false;
-                                break;
-                            }
-                        }
-                        if ( mustAdd )
-                        {
-                            rdnAttribute.addValue( new Value( rdnAttribute, atav.getUpValue() ) );
-                        }
+                        monitor.reportError( dummyMonitor.getException() );
+                        dummyMonitor.reset();
                     }
                 }
 
-                CreateEntryJob.createEntry( newEntry.getBrowserConnection(), newEntry, monitor );
-                newEntry.setHasChildrenHint( false );
-
-                num++;
-                monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__copied_n_entries,
-                    new String[]
-                        { Integer.toString( num ) } ) );
-
-                // check for children
-                if ( !monitor.isCanceled() && ( scope == SearchScope.ONELEVEL || scope == SearchScope.SUBTREE ) )
+                if ( !monitor.isCanceled() && !monitor.errorsReported() )
                 {
-                    // TODO: use JNDI here!!!
-                    SearchParameter subParam = new SearchParameter();
-                    subParam.setSearchBase( entryToCopy.getDn() );
-                    subParam.setFilter( ISearch.FILTER_TRUE );
-                    subParam.setScope( SearchScope.ONELEVEL );
-                    subParam.setReturningAttributes( ISearch.NO_ATTRIBUTES );
-                    ISearch subSearch = new Search( entryToCopy.getBrowserConnection(), subParam );
-                    SearchJob.searchAndUpdateModel( entryToCopy.getBrowserConnection(), subSearch, monitor );
+                    numberOfCopiedEntries++;
 
-                    ISearchResult[] subSrs = subSearch.getSearchResults();
-                    if ( !monitor.isCanceled() && subSrs != null && subSrs.length > 0 )
+                    // copy recursively
+                    if ( scope == SearchControls.ONELEVEL_SCOPE || scope == SearchControls.SUBTREE_SCOPE )
                     {
-                        for ( int i = 0; i < subSrs.length; i++ )
-                        {
-                            ISearchResult subSearchResult = subSrs[i];
-                            IEntry childEntry = subSearchResult.getEntry();
+                        SearchControls searchControls = new SearchControls();
+                        searchControls.setCountLimit( 0 );
+                        searchControls.setReturningAttributes( new String[]
+                            { ISearch.ALL_USER_ATTRIBUTES, IAttribute.REFERRAL_ATTRIBUTE } );
+                        searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+                        NamingEnumeration<SearchResult> childEntries = browserConnection.getConnection()
+                            .getJNDIConnectionWrapper().search( oldDn, ISearch.FILTER_TRUE, searchControls, "never",
+                                JNDIConnectionWrapper.REFERRAL_IGNORE, null, monitor, null );
 
-                            if ( scope == SearchScope.ONELEVEL )
-                            {
-                                num = this
-                                    .copyEntryRecursive( childEntry, newEntry,SearchScope.OBJECT, num, monitor );
-                            }
-                            else if ( scope == SearchScope.SUBTREE )
-                            {
-                                num = this.copyEntryRecursive( childEntry, newEntry, SearchScope.SUBTREE, num,
-                                    monitor );
-                            }
+                        if ( scope == SearchControls.ONELEVEL_SCOPE )
+                        {
+                            scope = SearchControls.OBJECT_SCOPE;
                         }
 
+                        numberOfCopiedEntries = copyEntryRecursive( browserConnection, childEntries, newLdapDn, scope,
+                            numberOfCopiedEntries, dummyMonitor, monitor );
                     }
                 }
             }
         }
-        catch ( Exception e )
+        catch ( NamingException e )
         {
             monitor.reportError( e );
         }
-        return num;
-    }
-
 
-    /**
-     * Gets the new rdn.
-     * 
-     * @param rdn the rdn
-     * @param newRdnValue the new rdn value
-     * 
-     * @return the new rdn
-     * @throws InvalidNameException 
-     */
-    private Rdn getNewRdn( Rdn rdn, String newRdnValue ) throws InvalidNameException
-    {
-        String[] rdnTypes = new String[rdn.size()];
-        String[] rdnValues = new String[rdn.size()];
-        int i = 0;
-        Iterator<AttributeTypeAndValue> atavIterator = rdn.iterator();
-        while(atavIterator.hasNext())
-        {
-            AttributeTypeAndValue atav = atavIterator.next();
-            rdnTypes[i] = atav.getUpType();
-            rdnValues[i] = ( String ) atav.getUpValue();
-            i++;
-        }
-        rdnValues[0] = newRdnValue;
-        Rdn newRdn = DnUtils.composeRdn( rdnTypes, rdnValues );
-        return newRdn;
+        return numberOfCopiedEntries;
     }
 
 }

Modified: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesJob.java Mon Nov 26 11:44:28 2007
@@ -28,55 +28,91 @@
 import java.util.List;
 import java.util.Set;
 
-import javax.naming.ldap.Control;
-import javax.naming.ldap.ManageReferralControl;
+import javax.naming.ContextNotEmptyException;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.BasicControl;
 
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.events.ChildrenInitializedEvent;
 import org.apache.directory.studio.ldapbrowser.core.events.EntryDeletedEvent;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
 import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateEvent;
-import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.ConnectionException;
+import org.apache.directory.studio.ldapbrowser.core.model.Control;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
-import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.AliasDereferencingMethod;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
+import org.apache.directory.studio.ldapbrowser.core.utils.JNDIUtils;
 
 
-/*
- * Search+Delete vs. Delete+SearchOnError
- * 
- * Test for:
- * - delete leaf entry 100.000 times
- * - tree with 100.000 childs
- * - tree with 1000 childs each with 1000 childs 
+/**
+ * Job to delete entries.
  * 
+ * Deletes the entry recursively in a optimistic way:
+ * <ol>
+ * <li>Delete the entry
+ * <li>If that fails with error code 66 then perform a one-level search
+ *     and start from 1. for each entry. 
+ * </ol>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
  */
-
 public class DeleteEntriesJob extends AbstractNotificationJob
 {
 
     private IEntry[] entriesToDelete;
+    private boolean useTreeDeleteContol;
+    private boolean useManageDsaITControl;
+    private boolean useSubentriesControl;
+
+    private Set<IEntry> deletedEntriesSet;
+
+    private Set<IEntry> entriesToUpdateSet;
+
+    private Set<ISearch> searchesToUpdateSet;
+
+
+    /**
+     * Creates a new instance of DeleteEntriesJob. 
+     * 
+     * @param entriesToDelete the entries to delete
+     * @param useTreeDeleteContol true to use the Tree Delete Control
+     * @param useManageDsaITControl true to use the Manage DSA IT Control
+     * @param useSubentriesControl true to delete sub-entries
+     */
+    public DeleteEntriesJob( final IEntry[] entriesToDelete, boolean useTreeDeleteContol,
+        boolean useManageDsaITControl, boolean useSubentriesControl )
+    {
+        this.entriesToDelete = entriesToDelete;
+        this.useTreeDeleteContol = useTreeDeleteContol;
+        this.useManageDsaITControl = useManageDsaITControl;
+        this.useSubentriesControl = useSubentriesControl;
+
+        this.deletedEntriesSet = new HashSet<IEntry>();
+        this.entriesToUpdateSet = new HashSet<IEntry>();
+        this.searchesToUpdateSet = new HashSet<ISearch>();
 
-    private Set deletedEntriesSet = new HashSet();
-
-    private Set entriesToUpdateSet = new HashSet();
-
-    private Set searchesToUpdateSet = new HashSet();
+        setName( entriesToDelete.length == 1 ? BrowserCoreMessages.jobs__delete_entries_name_1
+            : BrowserCoreMessages.jobs__delete_entries_name_n );
+    }
 
 
+    /**
+     * Creates a new instance of DeleteEntriesJob. 
+     * 
+     * @param entriesToDelete the entries to delete
+     */
     public DeleteEntriesJob( final IEntry[] entriesToDelete )
     {
-        this.entriesToDelete = entriesToDelete;
-        setName( entriesToDelete.length == 1 ? BrowserCoreMessages.jobs__delete_entries_name_1
-            : BrowserCoreMessages.jobs__delete_entries_name_n );
+        this( entriesToDelete, false, false, false );
     }
 
 
@@ -93,7 +129,7 @@
 
     protected Object[] getLockedObjects()
     {
-        List l = new ArrayList();
+        List<Object> l = new ArrayList<Object>();
         l.addAll( Arrays.asList( entriesToDelete ) );
         return l.toArray();
     }
@@ -101,7 +137,6 @@
 
     protected void executeNotificationJob( StudioProgressMonitor monitor )
     {
-
         monitor.beginTask( entriesToDelete.length == 1 ? BrowserCoreMessages.bind(
             BrowserCoreMessages.jobs__delete_entries_task_1, new String[]
                 { entriesToDelete[0].getDn().getUpName() } ) : BrowserCoreMessages.bind(
@@ -111,49 +146,65 @@
         monitor.worked( 1 );
 
         int num = 0;
+        StudioProgressMonitor dummyMonitor = new StudioProgressMonitor( monitor );
         for ( int i = 0; !monitor.isCanceled() && !monitor.errorsReported() && i < entriesToDelete.length; i++ )
         {
-
             IEntry entryToDelete = entriesToDelete[i];
-            IBrowserConnection connection = entryToDelete.getBrowserConnection();
+            IBrowserConnection browserConnection = entryToDelete.getBrowserConnection();
 
             // delete from directory
-            // TODO: use TreeDelete Control, if available
             int errorStatusSize1 = monitor.getErrorStatus( "" ).getChildren().length; //$NON-NLS-1$
-            num = deleteEntryRecursive( entryToDelete, false, num, monitor );
+            num = optimisticDeleteEntryRecursive( browserConnection, entryToDelete.getDn().getUpName(), num,
+                dummyMonitor, monitor );
             int errorStatusSize2 = monitor.getErrorStatus( "" ).getChildren().length; //$NON-NLS-1$
-            deletedEntriesSet.add( entryToDelete );
 
-            if ( errorStatusSize1 == errorStatusSize2 )
+            if ( !monitor.isCanceled() )
             {
-                // delete from parent
-                entryToDelete.getParententry().deleteChild( entryToDelete );
-                entriesToUpdateSet.add( entryToDelete.getParententry() );
-
-                // delete from searches
-                ISearch[] searches = connection.getSearchManager().getSearches();
-                for ( int j = 0; j < searches.length; j++ )
+                if ( errorStatusSize1 == errorStatusSize2 )
                 {
-                    ISearch search = searches[j];
-                    if ( search.getSearchResults() != null )
+                    // delete
+                    deletedEntriesSet.add( entryToDelete );
+                    entryToDelete.setChildrenInitialized( false );
+
+                    // delete from parent entry
+                    entriesToUpdateSet.add( entryToDelete.getParententry() );
+                    entryToDelete.getParententry().setChildrenInitialized( false );
+                    entryToDelete.getParententry().deleteChild( entryToDelete );
+
+                    // delete from searches
+                    ISearch[] searches = browserConnection.getSearchManager().getSearches();
+                    for ( ISearch search : searches )
                     {
-                        ISearchResult[] searchResults = search.getSearchResults();
-                        for ( int k = 0; k < searchResults.length; k++ )
+                        if ( search.getSearchResults() != null )
                         {
-                            ISearchResult result = searchResults[k];
-                            if ( entryToDelete.equals( result.getEntry() ) )
+                            ISearchResult[] searchResults = search.getSearchResults();
+                            List<ISearchResult> searchResultList = new ArrayList<ISearchResult>();
+                            searchResultList.addAll( Arrays.asList( searchResults ) );
+                            for ( Iterator<ISearchResult> it = searchResultList.iterator(); it.hasNext(); )
+                            {
+                                ISearchResult result = it.next();
+                                if ( entryToDelete.equals( result.getEntry() ) )
+                                {
+                                    it.remove();
+                                    searchesToUpdateSet.add( search );
+                                }
+                            }
+                            if ( searchesToUpdateSet.contains( search ) )
                             {
-                                ISearchResult[] newsrs = new ISearchResult[searchResults.length - 1];
-                                System.arraycopy( searchResults, 0, newsrs, 0, k );
-                                System.arraycopy( searchResults, k + 1, newsrs, k, searchResults.length - k - 1 );
-                                search.setSearchResults( newsrs );
-                                searchResults = newsrs;
-                                k--;
-                                searchesToUpdateSet.add( search );
+                                search.setSearchResults( searchResultList.toArray( new ISearchResult[searchResultList
+                                    .size()] ) );
                             }
                         }
                     }
                 }
+
+                // delete from cache
+                browserConnection.uncacheEntryRecursive( entryToDelete );
+            }
+            else
+            {
+                entriesToUpdateSet.add( entryToDelete );
+                entryToDelete.setChildrenInitialized( false );
             }
 
             monitor.worked( 1 );
@@ -161,101 +212,111 @@
     }
 
 
-    
-    private int deleteEntryRecursive( IBrowserConnection browserConnection, String dn, int numberOfDeletedEntries, StudioProgressMonitor monitor )
-    {
-//        int numberInBatch;
-//        
-//        JNDIConnectionWrapper connectionWrapper = browserConnection.getConnection().getJNDIConnectionWrapper();
-//        
-//        SearchControls searchControls = new SearchControls();
-//        searchControls.setCountLimit( 1000 );
-//        searchControls.setReturningAttributes( new String[]
-//                                                          { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
-//        searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-//        
-//        connectionWrapper.search( dn, ISearch.FILTER_TRUE, searchControls, derefAliasMethod, handleReferralsMethod, controls, monitor )
-        
-        return 0;
-    }
-    
-    
-    private int deleteEntryRecursive( IEntry entry, boolean refInitialized, int numberOfDeletedEntries,
-        StudioProgressMonitor monitor )
+    /**
+     * Deletes the entry recursively in a optimistic way:
+     * <ol>
+     * <li>Deletes the entry
+     * <li>If that fails then perform a one-level search and call the 
+     * method for each found entry
+     * </ol>
+     * 
+     * @param browserConnection the browser connection
+     * @param dn the DN to delete
+     * @param numberOfDeletedEntries the number of delted entries
+     * @param dummyMonitor the dummy monitor
+     * @param monitor the progress monitor
+     * @return the cululative number of deleted entries
+     */
+    private int optimisticDeleteEntryRecursive( IBrowserConnection browserConnection, String dn,
+        int numberOfDeletedEntries, StudioProgressMonitor dummyMonitor, StudioProgressMonitor monitor )
     {
-        try
+        // try to delete entry
+        dummyMonitor.reset();
+        deleteEntry( browserConnection, dn, useTreeDeleteContol, useManageDsaITControl, dummyMonitor );
+
+        if ( !dummyMonitor.errorsReported() )
+        {
+            numberOfDeletedEntries++;
+            monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__deleted_n_entries,
+                new String[]
+                    { "" + numberOfDeletedEntries } ) ); //$NON-NLS-1$
+        }
+        else if ( dummyMonitor.getException() instanceof ContextNotEmptyException )
         {
+            // perform one-level search and delete recursively
+            // TODO: ManageDsaIT control
+            // TODO: Subentries search
             int numberInBatch;
+            dummyMonitor.reset();
             do
             {
                 numberInBatch = 0;
-                
-                // TODO: use JNDI here!!!
-                
-                SearchParameter subParam = new SearchParameter();
-                subParam.setSearchBase( entry.getDn() );
-                subParam.setFilter( ISearch.FILTER_TRUE );
-                subParam.setScope( SearchScope.ONELEVEL );
-                subParam.setAliasesDereferencingMethod( AliasDereferencingMethod.NEVER );
-                subParam.setReferralsHandlingMethod( ReferralHandlingMethod.IGNORE );
-                subParam.setReturningAttributes( new String[]
-                    { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
-                subParam.setCountLimit( 1000 );
-                ISearch search = new Search( entry.getBrowserConnection(), subParam );
-                SearchJob.searchAndUpdateModel( entry.getBrowserConnection(), search, monitor );
 
-                ISearchResult[] srs = search.getSearchResults();
-                for ( int i = 0; !monitor.isCanceled() && srs != null && i < srs.length; i++ )
-                {
-                    IEntry childEntry = srs[i].getEntry();
-                    numberOfDeletedEntries = this.deleteEntryRecursive( childEntry, true, numberOfDeletedEntries,
-                        monitor );
-                    numberInBatch++;
-                }
-            }
-            while ( numberInBatch > 0 && !monitor.isCanceled() && !monitor.errorsReported() );
+                SearchControls searchControls = new SearchControls();
+                searchControls.setCountLimit( 1000 );
+                searchControls.setReturningAttributes( new String[0] );
+                searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+                NamingEnumeration<SearchResult> result = browserConnection.getConnection().getJNDIConnectionWrapper()
+                    .search( dn, ISearch.FILTER_TRUE, searchControls, "never", JNDIConnectionWrapper.REFERRAL_IGNORE,
+                        null, dummyMonitor, null );
 
-            if ( !monitor.isCanceled() && !monitor.errorsReported() )
-            {
-                // check for referrals
-                if ( !refInitialized )
+                try
                 {
-                    // TODO: use JNDI here!!!
-                    SearchParameter param = new SearchParameter();
-                    param.setSearchBase( entry.getDn() );
-                    param.setFilter( ISearch.FILTER_TRUE );
-                    param.setScope( SearchScope.OBJECT );
-                    param.setAliasesDereferencingMethod( AliasDereferencingMethod.NEVER );
-                    param.setReferralsHandlingMethod( ReferralHandlingMethod.IGNORE );
-                    param.setReturningAttributes( new String[]
-                        { IAttribute.OBJECTCLASS_ATTRIBUTE, IAttribute.REFERRAL_ATTRIBUTE } );
-                    ISearch search = new Search( entry.getBrowserConnection(), param );
-                    SearchJob.searchAndUpdateModel( entry.getBrowserConnection(), search, monitor );
-
-                    ISearchResult[] srs = search.getSearchResults();
-                    if ( !monitor.isCanceled() && srs != null && srs.length == 1 )
+                    // delete all child entries
+                    while ( !dummyMonitor.isCanceled() && result.hasMore() )
                     {
-                        entry = srs[0].getEntry();
+                        if ( dummyMonitor.errorsReported() )
+                        {
+                            throw dummyMonitor.getException();
+                        }
+
+                        SearchResult sr = result.next();
+                        LdapDN ldapDn = JNDIUtils.getDn( sr );
+                        String childDn = ldapDn.getUpName();
+
+                        numberOfDeletedEntries = optimisticDeleteEntryRecursive( browserConnection, childDn,
+                            numberOfDeletedEntries, dummyMonitor, monitor );
+                        numberInBatch++;
                     }
                 }
-
-                int errorStatusSize1 = monitor.getErrorStatus( "" ).getChildren().length; //$NON-NLS-1$
-                deleteEntry( entry.getBrowserConnection(), entry, monitor );
-                int errorStatusSize2 = monitor.getErrorStatus( "" ).getChildren().length; //$NON-NLS-1$
-
-                if ( errorStatusSize1 == errorStatusSize2 )
+                catch ( Throwable e )
                 {
-                    numberOfDeletedEntries++;
-                    monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__deleted_n_entries,
-                        new String[]
-                            { "" + numberOfDeletedEntries } ) ); //$NON-NLS-1$
+                    ConnectionException ce = JNDIUtils.createConnectionException( null, e );
+
+                    if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
+                    {
+                        // continue with search
+                    }
+                    else
+                    {
+                        dummyMonitor.reportError( ce );
+                        break;
+                    }
                 }
             }
+            while ( numberInBatch > 0 && !monitor.isCanceled() && !dummyMonitor.errorsReported() );
 
+            // try to delete the entry again 
+            if ( !dummyMonitor.errorsReported() )
+            {
+                deleteEntry( browserConnection, dn, useTreeDeleteContol, useManageDsaITControl, dummyMonitor );
+            }
+            if ( !dummyMonitor.errorsReported() )
+            {
+                numberOfDeletedEntries++;
+                monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__deleted_n_entries,
+                    new String[]
+                        { "" + numberOfDeletedEntries } ) ); //$NON-NLS-1$
+            }
         }
-        catch ( Exception e )
+        else
         {
-            monitor.reportError( e );
+            Throwable exception = dummyMonitor.getException();
+            // we have another exception
+            // report it to the dummy monitor if we are in the recursion
+            dummyMonitor.reportError( exception );
+            // also report it to the real monitor
+            monitor.reportError( exception );
         }
 
         return numberOfDeletedEntries;
@@ -264,20 +325,18 @@
 
     protected void runNotification()
     {
-        for ( Iterator it = deletedEntriesSet.iterator(); it.hasNext(); )
+        for ( IEntry entry : deletedEntriesSet )
         {
-            IEntry entry = ( IEntry ) it.next();
             EventRegistry.fireEntryUpdated( new EntryDeletedEvent( entry.getBrowserConnection(), entry ), this );
         }
-        for ( Iterator it = entriesToUpdateSet.iterator(); it.hasNext(); )
+        for ( IEntry parent : entriesToUpdateSet )
         {
-            IEntry parent = ( IEntry ) it.next();
             EventRegistry.fireEntryUpdated( new ChildrenInitializedEvent( parent ), this );
         }
-        for ( Iterator it = searchesToUpdateSet.iterator(); it.hasNext(); )
+        for ( ISearch search : searchesToUpdateSet )
         {
-            ISearch search = ( ISearch ) it.next();
-            EventRegistry.fireSearchUpdated( new SearchUpdateEvent( search, SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ), this );
+            EventRegistry.fireSearchUpdated( new SearchUpdateEvent( search,
+                SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ), this );
         }
     }
 
@@ -288,20 +347,28 @@
             : BrowserCoreMessages.jobs__delete_entries_error_n;
     }
 
-    static void deleteEntry( IBrowserConnection browserConnection, IEntry entry, StudioProgressMonitor monitor )
-    {
-        // dn
-        String dn = entry.getDn().getUpName();
 
+    static void deleteEntry( IBrowserConnection browserConnection, String dn, boolean useTreeDeleteControl,
+        boolean useManageDsaITControl, StudioProgressMonitor monitor )
+    {
         // controls
-        Control[] controls = null;
-        if ( entry.isReferral() )
+        List<BasicControl> controls = new ArrayList<BasicControl>();
+        if ( useTreeDeleteControl )
         {
-            controls = new Control[]
-                { new ManageReferralControl() };
+            BasicControl treeDeleteControl = new BasicControl( Control.TREEDELETE_CONTROL.getOid(),
+                Control.TREEDELETE_CONTROL.isCritical(), Control.TREEDELETE_CONTROL.getControlValue() );
+            controls.add( treeDeleteControl );
+        }
+        if ( useManageDsaITControl )
+        {
+            BasicControl manageDsaITControl = new BasicControl( Control.MANAGEDSAIT_CONTROL.getOid(),
+                Control.MANAGEDSAIT_CONTROL.isCritical(), Control.MANAGEDSAIT_CONTROL.getControlValue() );
+            controls.add( manageDsaITControl );
         }
 
-        browserConnection.getConnection().getJNDIConnectionWrapper()
-            .deleteEntry( dn, controls, monitor );
+        // delete entry
+        browserConnection.getConnection().getJNDIConnectionWrapper().deleteEntry( dn,
+            controls.toArray( new BasicControl[controls.size()] ), monitor );
     }
+
 }

Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java?rev=598395&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java Mon Nov 26 11:44:28 2007
@@ -0,0 +1,100 @@
+/*
+ *  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.ldapbrowser.core.jobs;
+
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+
+
+/**
+ * A dialog to select the copy strategy if an entry already exists.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface EntryExistsCopyStrategyDialog
+{
+
+    /**
+     * Sets the existing entry.
+     * 
+     * @param browserConnection the browser connection
+     * @param newLdapDn the new DN
+     */
+    void setExistingEntry( IBrowserConnection browserConnection, LdapDN newLdapDn );
+
+
+    /**
+     * Gets the copy strategy.
+     * 
+     * @return the copy strategy
+     */
+    EntryExistsCopyStrategy getStrategy();
+
+
+    /**
+     * Gets the RDN if {@link EntryExistsCopyStrategy.RENAME_AND_CONTINUE} was selected.
+     * Returns null if another strategy was selected.
+     * 
+     * @return the RDN
+     */
+    Rdn getRdn();
+
+
+    /**
+     * Returns true to remember the selected copy strategy.
+     * 
+     * @return true, to remember the selected copy strategy
+     */
+    boolean isRememberSelection();
+
+
+    /**
+     * Opens the dialog.
+     * 
+     * @return the status code
+     */
+    int open();
+
+    /**
+     * Enum for the copy strategy.
+     * 
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    public enum EntryExistsCopyStrategy
+    {
+
+        /** Break strategy, don't continue copy process. */
+        BREAK,
+
+        /** Ignore the entry to copy and continue the copy process. */
+        IGNORE_AND_CONTINUE,
+
+        /** Overwrite the entry to copy and continue the copy process. */
+        OVERWRITE_AND_CONTINUE,
+
+        /** Rename the entry to copy and continue the copy process. */
+        RENAME_AND_CONTINUE;
+    }
+
+}

Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExecuteLdifJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExecuteLdifJob.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExecuteLdifJob.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExecuteLdifJob.java Mon Nov 26 11:44:28 2007
@@ -32,8 +32,8 @@
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.parser.LdifParser;
+import org.apache.directory.studio.ldifparser.model.LdifEnumeration;
+import org.apache.directory.studio.ldifparser.parser.LdifParser;
 
 
 /**

Modified: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java?rev=598395&r1=598394&r2=598395&view=diff
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java (original)
+++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportCsvJob.java Mon Nov 26 11:44:28 2007
@@ -35,18 +35,15 @@
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
+import org.apache.directory.studio.ldapbrowser.core.jobs.ExportLdifJob.JndiLdifEnumeration;
 import org.apache.directory.studio.ldapbrowser.core.model.AttributeDescription;
 import org.apache.directory.studio.ldapbrowser.core.model.ConnectionException;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.ReferralException;
 import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
-import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine;
-import org.apache.directory.studio.ldapbrowser.core.utils.LdifUtils;
+import org.apache.directory.studio.ldifparser.LdifUtils;
+import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
+import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
+import org.apache.directory.studio.ldifparser.model.lines.LdifAttrValLine;
 import org.eclipse.core.runtime.Preferences;
 
 
@@ -198,10 +195,10 @@
     {
         try
         {
-            LdifEnumeration enumeration = ExportLdifJob.search( browserConnection, searchParameter, monitor );
-            while ( !monitor.isCanceled() && enumeration.hasNext( monitor ) )
+            JndiLdifEnumeration enumeration = ExportLdifJob.search( browserConnection, searchParameter, monitor );
+            while ( !monitor.isCanceled() && enumeration.hasNext() )
             {
-                LdifContainer container = enumeration.next( monitor );
+                LdifContainer container = enumeration.next();
 
                 if ( container instanceof LdifContentRecord )
                 {
@@ -223,24 +220,6 @@
             if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
             {
                 // nothing
-            }
-            else if ( ce instanceof ReferralException )
-            {
-
-                if ( searchParameter.getReferralsHandlingMethod() == ReferralHandlingMethod.FOLLOW )
-                {
-                    ReferralException re = ( ReferralException ) ce;
-                    ISearch[] referralSearches = re.getReferralSearches();
-                    for ( int i = 0; i < referralSearches.length; i++ )
-                    {
-                        ISearch referralSearch = referralSearches[i];
-
-                        // export recursive
-                        exportToCsv( referralSearch.getBrowserConnection(), referralSearch.getSearchParameter(),
-                            bufferedWriter, count, monitor, attributes, attributeDelimiter, valueDelimiter,
-                            quoteCharacter, lineSeparator, encoding, binaryEncoding, exportDn );
-                    }
-                }
             }
             else
             {



Mime
View raw message