directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r750127 - in /directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions: CopyAction.java PasteAction.java messages.properties messages_de.properties
Date Wed, 04 Mar 2009 19:56:17 GMT
Author: seelmann
Date: Wed Mar  4 19:56:16 2009
New Revision: 750127

URL: http://svn.apache.org/viewvc?rev=750127&view=rev
Log:
DIRSTUDIO-455: copy/paste a search

Modified:
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages.properties
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages_de.properties

Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java?rev=750127&r1=750126&r2=750127&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java
(original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java
Wed Mar  4 19:56:16 2009
@@ -26,16 +26,17 @@
 
 import org.apache.directory.studio.ldapbrowser.common.actions.proxy.BrowserActionProxy;
 import org.apache.directory.studio.ldapbrowser.common.dnd.EntryTransfer;
+import org.apache.directory.studio.ldapbrowser.common.dnd.SearchTransfer;
 import org.apache.directory.studio.ldapbrowser.common.dnd.ValuesTransfer;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
 import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
 import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
 import org.apache.directory.studio.ldapbrowser.core.model.IBookmark;
 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.ldifparser.LdifUtils;
-
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.dnd.Clipboard;
 import org.eclipse.swt.dnd.TextTransfer;
@@ -75,22 +76,28 @@
      */
     public String getText()
     {
-
         // entry/searchresult/bookmark
         IEntry[] entries = getEntries();
         if ( entries != null )
         {
-            return entries.length > 1 ? Messages.getString("CopyAction.CopyEntriesDNs")
: Messages.getString("CopyAction.CopyEntryDN"); //$NON-NLS-1$ //$NON-NLS-2$
+            return entries.length > 1 ? Messages.getString( "CopyAction.CopyEntriesDNs"
) : Messages.getString( "CopyAction.CopyEntryDN" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // searches
+        ISearch[] searches = getSearches();
+        if ( searches != null )
+        {
+            return searches.length > 1 ? Messages.getString( "CopyAction.CopySearches"
) : Messages.getString( "CopyAction.CopySearch" ); //$NON-NLS-1$ //$NON-NLS-2$
         }
 
         // values
         IValue[] values = getValues();
         if ( values != null )
         {
-            return values.length > 1 ? Messages.getString("CopyAction.CopyValues") : Messages.getString("CopyAction.CopyValue");
//$NON-NLS-1$ //$NON-NLS-2$
+            return values.length > 1 ? Messages.getString( "CopyAction.CopyValues" ) :
Messages.getString( "CopyAction.CopyValue" ); //$NON-NLS-1$ //$NON-NLS-2$
         }
 
-        return Messages.getString("CopyAction.Copy"); //$NON-NLS-1$
+        return Messages.getString( "CopyAction.Copy" ); //$NON-NLS-1$
     }
 
 
@@ -118,6 +125,7 @@
     public void run()
     {
         IEntry[] entries = getEntries();
+        ISearch[] searches = getSearches();
         IValue[] values = getValues();
         String[] stringProperties = getSelectedProperties();
 
@@ -138,6 +146,14 @@
                 { EntryTransfer.getInstance(), TextTransfer.getInstance() } );
         }
 
+        // searches
+        if ( searches != null )
+        {
+            copyToClipboard( new Object[]
+                { searches }, new Transfer[]
+                { SearchTransfer.getInstance() } );
+        }
+
         // values
         else if ( values != null )
         {
@@ -168,7 +184,7 @@
         else if ( stringProperties != null && stringProperties.length > 0 )
         {
             StringBuffer text = new StringBuffer();
-            
+
             for ( int i = 0; i < stringProperties.length; i++ )
             {
                 text.append( stringProperties[i] );
@@ -177,7 +193,7 @@
                     text.append( BrowserCoreConstants.LINE_SEPARATOR );
                 }
             }
-            
+
             copyToClipboard( new Object[]
                 { text.toString() }, new Transfer[]
                 { TextTransfer.getInstance() } );
@@ -221,13 +237,18 @@
      */
     public boolean isEnabled()
     {
-
         // entry/searchresult/bookmark
         if ( getEntries() != null )
         {
             return true;
         }
 
+        // searches
+        if ( getSearches() != null )
+        {
+            return true;
+        }
+
         // values
         else if ( getValues() != null )
         {
@@ -259,7 +280,6 @@
             + getSelectedAttributes().length + getSelectedValues().length == 0
             && getSelectedEntries().length + getSelectedSearchResults().length +
getSelectedBookmarks().length > 0 )
         {
-
             LinkedHashSet<IEntry> entriesSet = new LinkedHashSet<IEntry>();
             for ( IEntry entry : getSelectedEntries() )
             {
@@ -283,6 +303,33 @@
 
 
     /**
+     * Get the Searches
+     *
+     * @return
+     *      the Searches
+     */
+    private ISearch[] getSearches()
+    {
+        if ( getSelectedConnections().length + getSelectedEntries().length + getSelectedSearchResults().length
+            + getSelectedBookmarks().length + getSelectedAttributeHierarchies().length +
getSelectedAttributes().length
+            + getSelectedValues().length == 0
+            && getSelectedSearches().length > 0 )
+        {
+            LinkedHashSet<ISearch> searchesSet = new LinkedHashSet<ISearch>();
+            for ( ISearch search : getSelectedSearches() )
+            {
+                searchesSet.add( search );
+            }
+            return searchesSet.toArray( new ISearch[searchesSet.size()] );
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
      * Get the Values
      *
      * @return
@@ -294,7 +341,6 @@
             + getSelectedSearches().length == 0
             && getSelectedAttributeHierarchies().length + getSelectedAttributes().length
+ getSelectedValues().length > 0 )
         {
-
             LinkedHashSet<IValue> valuesSet = new LinkedHashSet<IValue>();
             for ( AttributeHierarchy ah : getSelectedAttributeHierarchies() )
             {

Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java?rev=750127&r1=750126&r2=750127&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java
(original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java
Wed Mar  4 19:56:16 2009
@@ -21,21 +21,30 @@
 package org.apache.directory.studio.ldapbrowser.common.actions;
 
 
+import org.apache.directory.studio.connection.core.Utils;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
 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.SearchTransfer;
 import org.apache.directory.studio.ldapbrowser.common.dnd.ValuesTransfer;
 import org.apache.directory.studio.ldapbrowser.core.jobs.CopyEntriesJob;
 import org.apache.directory.studio.ldapbrowser.core.jobs.CreateValuesJob;
+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.IValue;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.preference.PreferenceDialog;
 import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.dnd.Clipboard;
 import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.ISharedImages;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.PreferencesUtil;
 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
 
 
@@ -65,17 +74,24 @@
         IEntry[] entries = getEntriesToPaste();
         if ( entries != null )
         {
-            return entries.length > 1 ? Messages.getString("PasteAction.PasteEntries")
: Messages.getString("PasteAction.PasteEntry"); //$NON-NLS-1$ //$NON-NLS-2$
+            return entries.length > 1 ? Messages.getString( "PasteAction.PasteEntries"
) : Messages.getString( "PasteAction.PasteEntry" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // searches
+        ISearch[] searches = getSearchesToPaste();
+        if ( searches != null )
+        {
+            return searches.length > 1 ? Messages.getString( "PasteAction.PasteSearches"
) : Messages.getString( "PasteAction.PasteSearch" ); //$NON-NLS-1$ //$NON-NLS-2$
         }
 
         // value
         IValue[] values = getValuesToPaste();
         if ( values != null )
         {
-            return values.length > 1 ? Messages.getString("PasteAction.PasteValues") :
Messages.getString("PasteAction.PasteValue"); //$NON-NLS-1$ //$NON-NLS-2$
+            return values.length > 1 ? Messages.getString( "PasteAction.PasteValues" )
: Messages.getString( "PasteAction.PasteValue" ); //$NON-NLS-1$ //$NON-NLS-2$
         }
 
-        return Messages.getString("PasteAction.Paste"); //$NON-NLS-1$
+        return Messages.getString( "PasteAction.Paste" ); //$NON-NLS-1$
     }
 
 
@@ -108,6 +124,12 @@
             return true;
         }
 
+        // search
+        else if ( getSearchesToPaste() != null )
+        {
+            return true;
+        }
+
         // value
         else if ( getValuesToPaste() != null )
         {
@@ -131,6 +153,15 @@
             return;
         }
 
+        // search
+        ISearch[] searches = getSearchesToPaste();
+        if ( searches != null )
+        {
+
+            this.pasteSearches( searches );
+            return;
+        }
+
         // value
         IValue[] values = getValuesToPaste();
         if ( values != null )
@@ -164,7 +195,8 @@
         }
         if ( askForScope )
         {
-            ScopeDialog scopeDialog = new ScopeDialog( Display.getDefault().getActiveShell(),
Messages.getString("PasteAction.SelectCopyDepth"), //$NON-NLS-1$
+            ScopeDialog scopeDialog = new ScopeDialog( Display.getDefault().getActiveShell(),
Messages
+                .getString( "PasteAction.SelectCopyDepth" ), //$NON-NLS-1$
                 entriesToPaste.length > 1 );
             scopeDialog.open();
             scope = scopeDialog.getScope();
@@ -175,6 +207,46 @@
     }
 
 
+    private void pasteSearches( ISearch[] searches )
+    {
+        IBrowserConnection browserConnection = null;
+        if ( getSelectedBrowserViewCategories().length > 0 )
+        {
+            browserConnection = getSelectedBrowserViewCategories()[0].getParent();
+        }
+        else if ( getSelectedSearches().length > 0 )
+        {
+            browserConnection = getSelectedSearches()[0].getBrowserConnection();
+        }
+
+        if ( browserConnection != null )
+        {
+            ISearch clone = null;
+            for ( ISearch search : searches )
+            {
+                clone = ( ISearch ) search.clone();
+                browserConnection.getSearchManager().addSearch( clone );
+            }
+
+            if ( searches.length == 1 )
+            {
+                IAdaptable element = ( IAdaptable ) clone;
+                String pageId = BrowserCommonConstants.PROP_SEARCH;
+                String title = clone.getName();
+
+                PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn( getShell(),
element, pageId, null,
+                    null );
+                if ( dialog != null )
+                {
+                    title = Utils.shorten( title, 30 );
+                }
+                dialog.getShell().setText( NLS.bind( Messages.getString( "PropertiesAction.PropertiesForX"
), title ) ); //$NON-NLS-1$
+                dialog.open();
+            }
+        }
+    }
+
+
     /**
      * Paste Values
      *
@@ -207,21 +279,15 @@
 
         if ( entry != null )
         {
-//            String[] attributeNames = new String[values.length];
-//            Object[] rawValues = new Object[values.length];
-//            for ( int v = 0; v < values.length; v++ )
-//            {
-//                attributeNames[v] = values[v].getAttribute().getDescription();
-//                rawValues[v] = values[v].getRawValue();
-//            }
-//            new CreateValuesJob( entry, attributeNames, rawValues ).execute();
             new CreateValuesJob( entry, values ).execute();
         }
     }
 
 
     /**
-     * Conditions: - an entry is selected - there are entries in clipboard
+     * Conditions: 
+     * <li>an entry is selected</li>
+     * <li>there are entries in clipboard</li>
      * 
      * @return
      */
@@ -245,8 +311,34 @@
 
 
     /**
-     * Conditions: - an attribute or value is selected - there are values in
-     * clipboard
+     * Conditions: 
+     * <li>a search or category is selected</li> 
+     * <li>there are searches in clipboard</li>
+     * 
+     * @return
+     */
+    private ISearch[] getSearchesToPaste()
+    {
+        if ( getSelectedBookmarks().length + getSelectedSearchResults().length + getSelectedEntries().length
+            + getSelectedConnections().length + getSelectedAttributes().length + getSelectedValues().length
== 0
+            && ( getSelectedSearches().length + getSelectedBrowserViewCategories().length
> 0 ) )
+        {
+            Object content = this.getFromClipboard( SearchTransfer.getInstance() );
+            if ( content != null && content instanceof ISearch[] )
+            {
+                ISearch[] searches = ( ISearch[] ) content;
+                return searches;
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Conditions: 
+     * <li>an attribute or value is selected</li>
+     * <li>there are values in clipboard</li>
      * 
      * @return
      */

Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages.properties?rev=750127&r1=750126&r2=750127&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages.properties
(original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages.properties
Wed Mar  4 19:56:16 2009
@@ -18,6 +18,8 @@
 CopyAction.Copy=Copy
 CopyAction.CopyEntriesDNs=Copy Entries / DNs
 CopyAction.CopyEntryDN=Copy Entry / DN
+CopyAction.CopySearches=Copy Searches
+CopyAction.CopySearch=Copy Search
 CopyAction.CopyValue=Copy Value
 CopyAction.CopyValues=Copy Values
 DeleteAction.Delete=Delete
@@ -62,6 +64,8 @@
 PasteAction.Paste=Paste
 PasteAction.PasteEntries=Paste Entries
 PasteAction.PasteEntry=Paste Entry
+PasteAction.PasteSearches=Paste Searches
+PasteAction.PasteSearch=Paste Search
 PasteAction.PasteValue=Paste Value
 PasteAction.PasteValues=Paste Values
 PasteAction.SelectCopyDepth=Select Copy Depth

Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages_de.properties?rev=750127&r1=750126&r2=750127&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages_de.properties
(original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/messages_de.properties
Wed Mar  4 19:56:16 2009
@@ -18,6 +18,8 @@
 CopyAction.Copy=Kopieren
 CopyAction.CopyEntriesDNs=Einträge / DNs kopieren
 CopyAction.CopyEntryDN=Eintrag / DN kopieren
+CopyAction.CopySearches=Suchen kopieren
+CopyAction.CopySearch=Suche kopieren
 CopyAction.CopyValue=Werte kopieren
 CopyAction.CopyValues=Wert kopieren
 DeleteAction.Delete=Löschen
@@ -62,6 +64,8 @@
 PasteAction.Paste=Einfügen
 PasteAction.PasteEntries=Einträge einfügen
 PasteAction.PasteEntry=Eintrag einfügen
+PasteAction.PasteSearches=Suchen einfügen
+PasteAction.PasteSearch=Suche einfügen
 PasteAction.PasteValue=Wert einfügen
 PasteAction.PasteValues=Werte einfügen
 PasteAction.SelectCopyDepth=Kopiertiefe auswählen



Mime
View raw message