directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r505080 - in /directory/ldapstudio/trunk/ldapstudio-browser-ui: icons/ src/main/java/org/apache/directory/ldapstudio/browser/ui/ src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/ src/main/java/org/apache/directory/ldap...
Date Thu, 08 Feb 2007 23:10:46 GMT
Author: seelmann
Date: Thu Feb  8 15:10:45 2007
New Revision: 505080

URL: http://svn.apache.org/viewvc?view=rev&rev=505080
Log:
Partial implementation of DIRSTUDIO-49:
- Added a LinkWithEditor action to the browser view and changed action order in tool bar
- Improved history navigation of selected entries and searches

Added:
    directory/ldapstudio/trunk/ldapstudio-browser-ui/icons/link_with_editor.gif   (with props)
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/LinkWithEditorAction.java
Modified:
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIConstants.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIPreferencesInitializer.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditor.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorInput.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorManager.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorNavigationLocation.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditor.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorInput.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorManager.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorNavigationLocation.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserView.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewActionGroup.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewUniversalListener.java

Added: directory/ldapstudio/trunk/ldapstudio-browser-ui/icons/link_with_editor.gif
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/icons/link_with_editor.gif?view=auto&rev=505080
==============================================================================
Binary file - no diff available.

Propchange: directory/ldapstudio/trunk/ldapstudio-browser-ui/icons/link_with_editor.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIConstants.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIConstants.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIConstants.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIConstants.java Thu Feb  8 15:10:45 2007
@@ -120,6 +120,8 @@
 
     public static final String PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH = "browserSearchResultAbbreviateMaxLength";
 
+    public static final String PREFERENCE_BROWSER_LINK_WITH_EDITOR = "browserLinkWithEditor";
+    
     public static final String PREFERENCE_BROWSER_SHOW_DIT = "browserShowDIT";
 
     public static final String PREFERENCE_BROWSER_SHOW_SEARCHES = "browserShowSearches";
@@ -248,6 +250,8 @@
 
     public static final String IMG_CLEAR = "icons/clear.gif";
 
+    public static final String IMG_LINK_WITH_EDITOR = "icons/link_with_editor.gif";
+    
     public static final String IMG_REFRESH = "icons/refresh.gif";
 
     public static final String IMG_COLLAPSEALL = "icons/collapseall.gif";

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIPreferencesInitializer.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIPreferencesInitializer.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIPreferencesInitializer.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/BrowserUIPreferencesInitializer.java Thu Feb  8 15:10:45 2007
@@ -123,6 +123,7 @@
         store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL, BrowserUIConstants.SHOW_DN );
         store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE, true );
         store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH, 50 );
+        store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_LINK_WITH_EDITOR, true );
         store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SHOW_DIT, true );
         store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SHOW_SEARCHES, true );
         store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SHOW_BOOKMARKS, true );

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditor.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditor.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditor.java Thu Feb  8 15:10:45 2007
@@ -26,13 +26,13 @@
 import org.apache.directory.ldapstudio.browser.ui.editors.ldif.LdifOutlinePage;
 import org.apache.directory.ldapstudio.browser.ui.views.browser.BrowserView;
 import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidget;
-
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.INavigationLocation;
 import org.eclipse.ui.INavigationLocationProvider;
@@ -69,14 +69,22 @@
     public void setInput( IEditorInput input )
     {
         super.setInput( input );
+
         if ( input instanceof EntryEditorInput && this.universalListener != null )
         {
-
             EntryEditorInput eei = ( EntryEditorInput ) input;
-            IEntry entry = eei.getEntry();
+            IEntry entry = eei.getResolvedEntry();
             this.universalListener.setInput( entry );
+
             if ( entry != null )
             {
+                // enable one instance hack before fireing the input change event 
+                // otherwise the navigation history is cleared.
+                EntryEditorInput.enableOneInstanceHack( true );
+                firePropertyChange( IEditorPart.PROP_INPUT );
+
+                // disable one instance hack for marking the location
+                EntryEditorInput.enableOneInstanceHack( false );
                 getSite().getPage().getNavigationHistory().markLocation( this );
             }
 
@@ -84,14 +92,23 @@
             {
                 this.outlinePage.refresh();
             }
+
+            // finally enable the one instance hack 
+            EntryEditorInput.enableOneInstanceHack( true );
         }
     }
 
 
     public void init( IEditorSite site, IEditorInput input ) throws PartInitException
     {
-        this.setInput( input );
         super.setSite( site );
+
+        // mark dummy location, necessary because the first marked
+        // location doesn't appear in history
+        this.setInput( new EntryEditorInput( ( IEntry ) null ) );
+        getSite().getPage().getNavigationHistory().markLocation( this );
+
+        this.setInput( input );
     }
 
 
@@ -178,9 +195,6 @@
 
     public void dispose()
     {
-
-        EntryEditorManager.editorClosed();
-
         if ( this.configuration != null )
         {
             this.universalListener.dispose();
@@ -252,7 +266,6 @@
 
     public INavigationLocation createEmptyNavigationLocation()
     {
-        System.out.println( "EntryEditor#createEmptyNavigationLocation()" );
         return null;
     }
 

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorInput.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorInput.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorInput.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorInput.java Thu Feb  8 15:10:45 2007
@@ -21,72 +21,299 @@
 package org.apache.directory.ldapstudio.browser.ui.editors.entry;
 
 
+import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
-
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IPersistableElement;
 
 
+/**
+ * The input for the entry editor.
+ * 
+ * There is a trick to provide a single instance of the entry editor:
+ * <ul>
+ * <li>If oneInstanceHackEnabled is true the equals method returns always 
+ *     true as long as the compared object is also of type EntryEditorInput. 
+ *     With this trick only one instance of the entry editor is opened
+ *     by the eclipse editor framework.
+ * <li>If oneInstanceHackEnabled is false the equals method returns 
+ *     true only if the wrapped objects (IEntry, ISearchResult or 
+ *     IBookmark) are equal. This is necessary for the history navigation
+ *     because it must be able to distinguish the different 
+ *     input objects.
+ * </ul>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class EntryEditorInput implements IEditorInput
 {
 
+    /** The entry input */
     private IEntry entry;
-
-
+    
+    /** The search result input */
+    private ISearchResult searchResult;
+    
+    /** The bookmark input */
+    private IBookmark bookmark;
+
+    /** One instance hack flag */
+    private static boolean oneInstanceHackEnabled = true;
+
+
+    /**
+     * Creates a new instance of EntryEditorInput with an IEntry as 
+     * domain object.
+     *
+     * @param entry the entry input
+     */
     public EntryEditorInput( IEntry entry )
     {
         this.entry = entry;
+        this.searchResult = null;
+        this.bookmark = null;
+    }
+
+
+    /**
+     * Creates a new instance of EntryEditorInput with an ISearchResult as 
+     * domain object.
+     *
+     * @param searchResult the search result input
+     */
+    public EntryEditorInput( ISearchResult searchResult )
+    {
+        this.entry = null;
+        this.searchResult = searchResult;
+        this.bookmark = null;
     }
 
 
+    /**
+     * Creates a new instance of EntryEditorInput with an IBookmark as 
+     * domain object.
+     *
+     * @param bookmark the bookmark input
+     */
+    public EntryEditorInput( IBookmark bookmark )
+    {
+        this.entry = null;
+        this.searchResult = null;
+        this.bookmark = bookmark;
+    }
+
+
+    /**
+     * This implementation always return false because
+     * an entry should not be visible in the 
+     * "File Most Recently Used" menu.
+     * 
+     * {@inheritDoc}
+     */
     public boolean exists()
     {
         return false;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public ImageDescriptor getImageDescriptor()
     {
         return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_ATTRIBUTE );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getName()
     {
         return "Entry Editor";
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getToolTipText()
     {
-        return this.entry != null ? this.entry.getDn().toString() : "";
+        return getResolvedEntry() != null ? getResolvedEntry().getDn().toString() : "";
     }
 
-
+    /**
+     * This implementation always return null.
+     * 
+     * {@inheritDoc}
+     */
     public IPersistableElement getPersistable()
     {
         return null;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Object getAdapter( Class adapter )
     {
         return null;
     }
 
 
-    public IEntry getEntry()
+    /**
+     * Gets the resolved entry, either the entry input itself
+     * or the entry behind the search result intput or the entry behind 
+     * the bookmark input.
+     * 
+     * @return the resolved entry
+     */
+    public IEntry getResolvedEntry()
+    {
+        if ( entry != null )
+        {
+            return entry;
+        }
+        else if ( searchResult != null )
+        {
+            return searchResult.getEntry();
+        }
+        else if ( bookmark != null )
+        {
+            return bookmark.getEntry();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * Gets the entry input, may be null.
+     *
+     * @return the entry input or null
+     */
+    public IEntry getEntryInput()
     {
         return entry;
     }
 
 
+    /**
+     * Gets the search result input, may be null.
+     *
+     * @return the search result input or null
+     */
+    public ISearchResult getSearchResultInput()
+    {
+        return searchResult;
+    }
+
+
+    /**
+     * Gets the bookmark input, may be null.
+     *
+     * @return the bookmark input or null
+     */
+    public IBookmark getBookmarkInput()
+    {
+        return bookmark;
+    }
+
+
+    /**
+     * Gets the input, may be null.
+     *
+     * @return the input or null
+     */
+    public Object getInput()
+    {
+        if ( entry != null )
+        {
+            return entry;
+        }
+        else if ( searchResult != null )
+        {
+            return searchResult;
+        }
+        else if ( bookmark != null )
+        {
+            return bookmark;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int hashCode()
+    {
+        return getToolTipText().hashCode();
+    }
+
+
+    /**
+     * The result depends 
+     * 
+     * {@inheritDoc}
+     */
     public boolean equals( Object obj )
     {
-        return obj instanceof EntryEditorInput;
+        boolean equal;
+
+        if ( oneInstanceHackEnabled )
+        {
+            equal = ( obj instanceof EntryEditorInput );
+        }
+        else
+        {
+            if ( obj instanceof EntryEditorInput )
+            {
+                EntryEditorInput other = ( EntryEditorInput ) obj;
+                if ( this.getInput() == null && other.getInput() == null )
+                {
+                    return true;
+                }
+                else if ( this.getInput() == null || other.getInput() == null )
+                {
+                    return false;
+                }
+                else
+                {
+                    equal = other.getInput().equals( this.getInput() );
+                }
+            }
+            else
+            {
+                equal = false;
+            }
+        }
+
+        return equal;
+    }
+
+
+    /**
+     * Enables or disabled the one instance hack.
+     *
+     * @param b 
+     *      true to enable the one instance hack,
+     *      false to disable the one instance hack
+     */
+    public static void enableOneInstanceHack( boolean b )
+    {
+        oneInstanceHackEnabled = b;
     }
 
 }

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorManager.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorManager.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorManager.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorManager.java Thu Feb  8 15:10:45 2007
@@ -21,26 +21,76 @@
 package org.apache.directory.ldapstudio.browser.ui.editors.entry;
 
 
+import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
-
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 
 
+/**
+ * The EntryEditorManager is used to set and get the the input
+ * of the single entry editor instance.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class EntryEditorManager
 {
 
-    private static EntryEditor editor;
+    /** The dummy input, to find the single entry editor instance */
+    private static EntryEditorInput DUMMY_INPUT = new EntryEditorInput( ( IEntry ) null );
 
 
+    /**
+     * Sets the entry input to the entry editor.
+     *
+     * @param entry the entry input, may be null to clear the editor
+     */
     public static void setInput( IEntry entry )
     {
+        EntryEditorInput input = new EntryEditorInput( entry );
+        setInput( input );
+    }
+
+
+    /**
+     * Sets the search result input to the entry editor.
+     *
+     * @param searchResult the search result input, may be null to clear the editor
+     */
+    public static void setInput( ISearchResult searchResult )
+    {
+        EntryEditorInput input = new EntryEditorInput( searchResult );
+        setInput( input );
+    }
+
+
+    /**
+     * Sets the bookmark input to the entry editor.
+     *
+     * @param bookmark the bookmark input, may be null to clear the editor
+     */
+    public static void setInput( IBookmark bookmark )
+    {
+        EntryEditorInput input = new EntryEditorInput( bookmark );
+        setInput( input );
+    }
 
-        IEditorInput input = new EntryEditorInput( entry );
 
-        if ( editor == null && entry != null )
+    /**
+     * Sets the input to the entry edtior. 
+     *
+     * @param input the input
+     */
+    private static void setInput( EntryEditorInput input )
+    {
+        EntryEditor editor = ( EntryEditor ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+            .findEditor( DUMMY_INPUT );
+        if ( editor == null && input.getResolvedEntry() != null )
         {
+            // open new entry editor
             try
             {
                 editor = ( EntryEditor ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
@@ -51,10 +101,13 @@
                 e.printStackTrace();
             }
         }
-        else if ( editor != null )
+        else
         {
+            // set the input to already opened entry editor
             editor.setInput( input );
-            if ( entry != null )
+
+            // bring entry editor to top only if an entry is displayed in it. 
+            if ( input.getResolvedEntry() != null )
             {
                 if ( !PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().isPartVisible( editor ) )
                 {
@@ -65,9 +118,30 @@
     }
 
 
-    static void editorClosed()
+    /**
+     * Get the input of the entry editor. 
+     * May be null if the editor is not opended 
+     * or it the editor has an invalid input.
+     *
+     * @return the editor input or null
+     */
+    public static Object getInput()
     {
-        editor = null;
+        EntryEditor editor = ( EntryEditor ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+            .findEditor( DUMMY_INPUT );
+
+        if ( editor != null )
+        {
+            IEditorInput input = editor.getEditorInput();
+            if ( input != null && input instanceof EntryEditorInput )
+            {
+                EntryEditorInput eei = ( EntryEditorInput ) input;
+                return eei.getInput();
+            }
+
+        }
+
+        return null;
     }
 
 }

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorNavigationLocation.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorNavigationLocation.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorNavigationLocation.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/entry/EntryEditorNavigationLocation.java Thu Feb  8 15:10:45 2007
@@ -23,56 +23,159 @@
 
 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
 import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IRootDSE;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
 import org.apache.directory.ldapstudio.browser.core.model.NameException;
-
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IMemento;
 import org.eclipse.ui.INavigationLocation;
 import org.eclipse.ui.NavigationLocation;
 
 
+/**
+ * This class is used to mark the entry editor input to the navigation history.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class EntryEditorNavigationLocation extends NavigationLocation
 {
 
-    protected EntryEditorNavigationLocation( EntryEditor editor )
+    /**
+     * Creates a new instance of EntryEditorNavigationLocation.
+     *
+     * @param editor the entry editor
+     */
+    EntryEditorNavigationLocation( EntryEditor editor )
     {
         super( editor );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getText()
     {
-        IEntry entry = getEntry();
-        if ( entry != null )
-        {
-            return entry.getDn().toString();
-        }
-        else
+        EntryEditorInput eei = getEntryEditorInput();
+        if ( eei != null )
         {
-            return super.getText();
+            if ( eei.getEntryInput() != null )
+            {
+                if ( eei.getEntryInput() instanceof IRootDSE )
+                {
+                    return "Root DSE";
+                }
+                else
+                {
+                    return "Entry " + eei.getEntryInput().getDn().toString();
+                }
+            }
+            else if ( eei.getSearchResultInput() != null )
+            {
+                if ( eei.getSearchResultInput() instanceof IRootDSE )
+                {
+                    return "Root DSE";
+                }
+                else
+                {
+                    return "Search Result " + eei.getSearchResultInput().getDn().toString();
+                }
+            }
+            else if ( eei.getBookmarkInput() != null )
+            {
+                if ( eei.getBookmarkInput() instanceof IRootDSE )
+                {
+                    return "Root DSE";
+                }
+                else
+                {
+                    return "Bookmark " + eei.getBookmarkInput().getDn().toString();
+                }
+            }
         }
+        return super.getText();
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void saveState( IMemento memento )
     {
-        IEntry entry = getEntry();
-        memento.putString( "DN", entry.getDn().toString() );
-        memento.putString( "CONNECTION", entry.getConnection().getName() );
+        EntryEditorInput eei = getEntryEditorInput();
+        if ( eei != null )
+        {
+            if ( eei.getEntryInput() != null )
+            {
+                IEntry entry = eei.getEntryInput();
+                memento.putString( "TYPE", "IEntry" );
+                memento.putString( "DN", entry.getDn().toString() );
+                memento.putString( "CONNECTION", entry.getConnection().getName() );
+            }
+            else if ( eei.getSearchResultInput() != null )
+            {
+                ISearchResult searchResult = eei.getSearchResultInput();
+                memento.putString( "TYPE", "ISearchResult" );
+                memento.putString( "DN", searchResult.getDn().toString() );
+                memento.putString( "SEARCH", searchResult.getSearch().getName() );
+                memento.putString( "CONNECTION", searchResult.getSearch().getConnection().getName() );
+            }
+            else if ( eei.getBookmarkInput() != null )
+            {
+                IBookmark bookmark = eei.getBookmarkInput();
+                memento.putString( "TYPE", "IBookmark" );
+                memento.putString( "BOOKMARK", bookmark.getName() );
+                memento.putString( "CONNECTION", bookmark.getConnection().getName() );
+            }
+        }
+
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void restoreState( IMemento memento )
     {
         try
         {
-            IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
-                memento.getString( "CONNECTION" ) );
-            DN dn = new DN( memento.getString( "DN" ) );
-            IEntry entry = connection.getEntryFromCache( dn );
-            super.setInput( new EntryEditorInput( entry ) );
+            String type = memento.getString( "TYPE" );
+            if ( "IEntry".equals( type ) )
+            {
+                IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
+                    memento.getString( "CONNECTION" ) );
+                DN dn = new DN( memento.getString( "DN" ) );
+                IEntry entry = connection.getEntryFromCache( dn );
+                super.setInput( new EntryEditorInput( entry ) );
+            }
+            else if ( "ISearchResult".equals( type ) )
+            {
+                IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
+                    memento.getString( "CONNECTION" ) );
+                ISearch search = connection.getSearchManager().getSearch( memento.getString( "SEARCH" ) );
+                ISearchResult[] searchResults = search.getSearchResults();
+                DN dn = new DN( memento.getString( "DN" ) );
+                for ( int i = 0; i < searchResults.length; i++ )
+                {
+                    if ( dn.equals( searchResults[i].getDn() ) )
+                    {
+                        super.setInput( new EntryEditorInput( searchResults[i] ) );
+                        break;
+                    }
+                }
+            }
+            else if ( "IBookmark".equals( type ) )
+            {
+                IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
+                    memento.getString( "CONNECTION" ) );
+                IBookmark bookmark = connection.getBookmarkManager().getBookmark( memento.getString( "BOOKMARK" ) );
+                super.setInput( new EntryEditorInput( bookmark ) );
+            }
         }
         catch ( NameException e )
         {
@@ -82,6 +185,9 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void restoreLocation()
     {
         IEditorPart editorPart = getEditorPart();
@@ -93,33 +199,73 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean mergeInto( INavigationLocation currentLocation )
     {
-        return false;
+        if ( currentLocation == null )
+        {
+            return false;
+        }
+
+        if ( getClass() != currentLocation.getClass() )
+        {
+            return false;
+        }
+
+        EntryEditorNavigationLocation location = ( EntryEditorNavigationLocation ) currentLocation;
+        Object other = location.getEntryEditorInput().getInput();
+        Object entry = getEntryEditorInput().getInput();
+
+        if ( other == null && entry == null )
+        {
+            return true;
+        }
+        else if ( other == null || entry == null )
+        {
+            return false;
+        }
+        else
+        {
+            return entry.equals( other );
+        }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void update()
     {
-
     }
 
 
-    private IEntry getEntry()
+    /**
+     * Gets the input.
+     *
+     * @return the input
+     */
+    private EntryEditorInput getEntryEditorInput()
     {
 
         Object editorInput = getInput();
         if ( editorInput != null && editorInput instanceof EntryEditorInput )
         {
             EntryEditorInput entryEditorInput = ( EntryEditorInput ) editorInput;
-            IEntry entry = entryEditorInput.getEntry();
-            if ( entry != null )
-            {
-                return entry;
-            }
+            return entryEditorInput;
         }
 
         return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return "" + getEntryEditorInput().getInput();
     }
 
 }

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditor.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditor.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditor.java Thu Feb  8 15:10:45 2007
@@ -34,6 +34,7 @@
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.INavigationLocation;
 import org.eclipse.ui.INavigationLocationProvider;
@@ -64,10 +65,11 @@
         return SearchResultEditor.class.getName();
     }
 
-
+    
     public void setInput( IEditorInput input )
     {
         super.setInput( input );
+        
         if ( input instanceof SearchResultEditorInput && this.universalListener != null )
         {
             SearchResultEditorInput srei = ( SearchResultEditorInput ) input;
@@ -76,19 +78,19 @@
 
             if ( search != null )
             {
-                // INavigationLocation[] locations =
-                // getSite().getPage().getNavigationHistory().getLocations();
-                // if(locations != null && locations.length > 0) {
-                // if(locations[locations.length-1].getInput() instanceof
-                // SearchResultEditorInput &&
-                // ((SearchResultEditorInput)locations[locations.length-1].getInput()).getSearch()
-                // == search) {
-                // return;
-                // }
-                // }
+                // enable one instance hack before fireing the input change event 
+                // otherwise the navigation history is cleared.
+                SearchResultEditorInput.enableOneInstanceHack( true );
+                firePropertyChange( IEditorPart.PROP_INPUT );
+
+                // disable one instance hack for marking the location
+                SearchResultEditorInput.enableOneInstanceHack( false );
                 getSite().getPage().getNavigationHistory().markLocation( this );
             }
         }
+
+        // finally enable the one instance hack 
+        SearchResultEditorInput.enableOneInstanceHack( true );
     }
 
 
@@ -103,8 +105,14 @@
 
     public void init( IEditorSite site, IEditorInput input ) throws PartInitException
     {
-        setInput( input );
         super.setSite( site );
+
+        // mark dummy location, necessary because the first marked
+        // location doesn't appear in history
+        this.setInput( new SearchResultEditorInput( null ) );
+        getSite().getPage().getNavigationHistory().markLocation( this );
+
+        this.setInput( input );
     }
 
 
@@ -154,9 +162,6 @@
 
     public void dispose()
     {
-
-        SearchResultEditorManager.editorClosed();
-
         if ( this.configuration != null )
         {
             this.actionGroup.dispose();

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorInput.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorInput.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorInput.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorInput.java Thu Feb  8 15:10:45 2007
@@ -24,69 +24,180 @@
 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
-
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IPersistableElement;
 
 
+/**
+ * The input for the search result editor.
+ * 
+ * There is a trick to provide a single instance of the search result editor:
+ * <ul>
+ * <li>If oneInstanceHackEnabled is true the equals method returns always 
+ *     true as long as the compared object is also of type SearchResultEditorInput. 
+ *     With this trick only one instance of the search result editor is opened
+ *     by the eclipse editor framework.
+ * <li>If oneInstanceHackEnabled is false the equals method returns 
+ *     true only if the wrapped objects (ISearchare equal. This is 
+ *     necessary for the history navigation because it must be able 
+ *     to distinguish the different input objects.
+ * </ul>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class SearchResultEditorInput implements IEditorInput
 {
 
+    /** The search input */
     private ISearch search;
 
+    /** One instance hack flag */
+    private static boolean oneInstanceHackEnabled = true;
+
 
+    /**
+     * Creates a new instance of SearchResultEditorInput.
+     *
+     * @param search the searc input
+     */
     public SearchResultEditorInput( ISearch search )
     {
         this.search = search;
     }
 
 
+    /**
+     * This implementation always return false because
+     * a search should not be visible in the 
+     * "File Most Recently Used" menu.
+     * 
+     * {@inheritDoc}
+     */
     public boolean exists()
     {
         return false;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public ImageDescriptor getImageDescriptor()
     {
         return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_BROWSER_SEARCHRESULTEDITOR );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getName()
     {
         return "Search Result Editor";
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getToolTipText()
     {
-        return this.search != null ? this.search.getName() : "";
+        return search != null ? this.search.getName() : "";
     }
 
 
+    /**
+     * This implementation always return null.
+     * 
+     * {@inheritDoc}
+     */
     public IPersistableElement getPersistable()
     {
         return null;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Object getAdapter( Class adapter )
     {
         return null;
     }
 
 
+    /**
+     * Gets the search input, may be null.
+     *
+     * @return the search input or null
+     */
     public ISearch getSearch()
     {
         return search;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
+    public int hashCode()
+    {
+        return getToolTipText().hashCode();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public boolean equals( Object obj )
     {
-        return obj instanceof SearchResultEditorInput;
+
+        boolean equal;
+
+        if ( oneInstanceHackEnabled )
+        {
+            equal = ( obj instanceof SearchResultEditorInput );
+        }
+        else
+        {
+            if ( obj instanceof SearchResultEditorInput )
+            {
+                SearchResultEditorInput other = ( SearchResultEditorInput ) obj;
+                if ( this.search == null && other.search == null )
+                {
+                    return true;
+                }
+                else if ( this.search == null || other.search == null )
+                {
+                    return false;
+                }
+                else
+                {
+                    equal = other.search.equals( this.search );
+                }
+            }
+            else
+            {
+                equal = false;
+            }
+        }
+
+        return equal;
+    }
+
+
+    /**
+     * Enables or disabled the one instance hack.
+     *
+     * @param b 
+     *      true to enable the one instance hack,
+     *      false to disable the one instance hack
+     */
+    public static void enableOneInstanceHack( boolean b )
+    {
+        oneInstanceHackEnabled = b;
     }
 
 }

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorManager.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorManager.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorManager.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorManager.java Thu Feb  8 15:10:45 2007
@@ -22,39 +22,67 @@
 
 
 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
-
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 
 
+/**
+ * The SearchResultEditorManager is used to set and get the the input
+ * of the single search result editor instance.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class SearchResultEditorManager
 {
 
-    private static SearchResultEditor editor;
+    /** The dummy input, to find the single entry editor instance */
+    private static SearchResultEditorInput DUMMY_INPUT = new SearchResultEditorInput( null );
 
 
+    /**
+     * Sets the input to the search result editor.
+     *
+     * @param entry the search input, may be null to clear the editor
+     */
     public static void setInput( ISearch search )
     {
+        SearchResultEditorInput input = new SearchResultEditorInput( search );
+        setInput( input );
+    }
 
-        IEditorInput input = new SearchResultEditorInput( search );
 
-        if ( editor == null && search != null )
+    /**
+     * Sets the input to the search result edtior. 
+     *
+     * @param input the input
+     */
+    private static void setInput( SearchResultEditorInput input )
+    {
+        SearchResultEditor editor = ( SearchResultEditor ) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+            .getActivePage().findEditor( DUMMY_INPUT );
+        if ( editor == null && input.getSearch() != null )
         {
+            // open new search result editor
             try
             {
                 editor = ( SearchResultEditor ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                     .openEditor( input, SearchResultEditor.getId(), false );
+                editor.setInput( input );
             }
             catch ( PartInitException e )
             {
                 e.printStackTrace();
             }
         }
-        else if ( editor != null )
+        else
         {
+            // set the input to already opened search result editor
             editor.setInput( input );
-            if ( search != null )
+
+            // bring search result editor to top only if an search is displayed in it. 
+            if ( input.getSearch() != null )
             {
                 if ( !PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().isPartVisible( editor ) )
                 {
@@ -65,9 +93,30 @@
     }
 
 
-    static void editorClosed()
+    /**
+     * Get the input of the search result editor. 
+     * May be null if the editor is not opended 
+     * or it the editor has an invalid input.
+     *
+     * @return the editor input or null
+     */
+    public static ISearch getInput()
     {
-        editor = null;
+        SearchResultEditor editor = ( SearchResultEditor ) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+            .getActivePage().findEditor( DUMMY_INPUT );
+
+        if ( editor != null )
+        {
+            IEditorInput input = editor.getEditorInput();
+            if ( input != null && input instanceof SearchResultEditorInput )
+            {
+                SearchResultEditorInput srei = ( SearchResultEditorInput ) input;
+                return srei.getSearch();
+            }
+
+        }
+
+        return null;
     }
 
 }

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorNavigationLocation.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorNavigationLocation.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorNavigationLocation.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/searchresult/SearchResultEditorNavigationLocation.java Thu Feb  8 15:10:45 2007
@@ -24,28 +24,41 @@
 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
-
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IMemento;
 import org.eclipse.ui.INavigationLocation;
 import org.eclipse.ui.NavigationLocation;
 
 
+/**
+ * This class is used to mark the search result editor input to the navigation history.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class SearchResultEditorNavigationLocation extends NavigationLocation
 {
 
-    protected SearchResultEditorNavigationLocation( SearchResultEditor editor )
+    /**
+     * Creates a new instance of SearchResultEditorNavigationLocation.
+     *
+     * @param editor the search result editor
+     */
+    SearchResultEditorNavigationLocation( SearchResultEditor editor )
     {
         super( editor );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getText()
     {
         ISearch search = getSearch();
         if ( search != null )
         {
-            return search.getName();
+            return "Search " + search.getName();
         }
         else
         {
@@ -54,6 +67,9 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void saveState( IMemento memento )
     {
         ISearch search = getSearch();
@@ -62,6 +78,9 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void restoreState( IMemento memento )
     {
         IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
@@ -71,6 +90,9 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void restoreLocation()
     {
         IEditorPart editorPart = getEditorPart();
@@ -82,17 +104,53 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean mergeInto( INavigationLocation currentLocation )
     {
-        return false;
+        if ( currentLocation == null )
+        {
+            return false;
+        }
+
+        if ( getClass() != currentLocation.getClass() )
+        {
+            return false;
+        }
+
+        SearchResultEditorNavigationLocation location = ( SearchResultEditorNavigationLocation ) currentLocation;
+        ISearch other = location.getSearch();
+        ISearch search = getSearch();
+
+        if ( other == null && search == null )
+        {
+            return true;
+        }
+        else if ( other == null || search == null )
+        {
+            return false;
+        }
+        else
+        {
+            return search.equals( other );
+        }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void update()
     {
     }
 
 
+    /**
+     * Gets the search.
+     *
+     * @return the search
+     */
     private ISearch getSearch()
     {
 
@@ -108,6 +166,15 @@
         }
 
         return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return "" + getSearch();
     }
 
 }

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserView.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserView.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserView.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserView.java Thu Feb  8 15:10:45 2007
@@ -25,6 +25,7 @@
 import java.util.List;
 
 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
@@ -142,6 +143,17 @@
 
     public void select( Object obj )
     {
+        if ( obj instanceof ISearch )
+        {
+            ISearch search = ( ISearch ) obj;
+
+            this.mainWidget.getViewer().expandToLevel( search, 0 );
+
+            this.mainWidget.getViewer().reveal( search );
+            this.mainWidget.getViewer().refresh( search, true );
+            this.mainWidget.getViewer().setSelection( new StructuredSelection( search ), true );
+            this.mainWidget.getViewer().setSelection( new StructuredSelection( search ), true );
+        }
         if ( obj instanceof ISearchResult )
         {
             ISearchResult searchResult = ( ISearchResult ) obj;
@@ -153,6 +165,17 @@
             this.mainWidget.getViewer().refresh( searchResult, true );
             this.mainWidget.getViewer().setSelection( new StructuredSelection( searchResult ), true );
             this.mainWidget.getViewer().setSelection( new StructuredSelection( searchResult ), true );
+        }
+        if ( obj instanceof IBookmark )
+        {
+            IBookmark bookmark = ( IBookmark ) obj;
+            
+            this.mainWidget.getViewer().expandToLevel( bookmark, 0 );
+            
+            this.mainWidget.getViewer().reveal( bookmark );
+            this.mainWidget.getViewer().refresh( bookmark, true );
+            this.mainWidget.getViewer().setSelection( new StructuredSelection( bookmark ), true );
+            this.mainWidget.getViewer().setSelection( new StructuredSelection( bookmark ), true );
         }
         if ( obj instanceof IEntry )
         {

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewActionGroup.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewActionGroup.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewActionGroup.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewActionGroup.java Thu Feb  8 15:10:45 2007
@@ -41,6 +41,7 @@
 import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserActionGroup;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.commands.ActionHandler;
@@ -64,6 +65,8 @@
 
     private OpenBrowserPreferencePageAction openBrowserPreferencePageAction;
 
+    private LinkWithEditorAction linkWithEditorAction;
+
     private static final String locateEntryInDitAction = "locateEntryInDitAction";
 
     private static final String newEntryAction = "newEntryAction";
@@ -122,6 +125,7 @@
         super( view.getMainWidget(), view.getConfiguration() );
         TreeViewer viewer = view.getMainWidget().getViewer();
 
+        this.linkWithEditorAction = new LinkWithEditorAction( view );
         this.showDITAction = new ShowDITAction();
         this.showSearchesAction = new ShowSearchesAction();
         this.showBookmarksAction = new ShowBookmarksAction();
@@ -185,6 +189,8 @@
     {
         if ( this.openBrowserPreferencePageAction != null )
         {
+            linkWithEditorAction.dispose();
+            linkWithEditorAction = null;
 
             this.showDITAction.dispose();
             this.showDITAction = null;
@@ -201,6 +207,20 @@
         }
 
         super.dispose();
+    }
+
+
+    public void fillToolBar( IToolBarManager toolBarManager )
+    {
+
+        toolBarManager.add( ( IAction ) this.browserActionMap.get( upAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( ( IAction ) this.browserActionMap.get( refreshAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( collapseAllAction );
+        toolBarManager.add( linkWithEditorAction );
+        toolBarManager.update( true );
+
     }
 
 

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewUniversalListener.java?view=diff&rev=505080&r1=505079&r2=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewUniversalListener.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/BrowserViewUniversalListener.java Thu Feb  8 15:10:45 2007
@@ -48,7 +48,6 @@
 import org.apache.directory.ldapstudio.browser.ui.editors.searchresult.SearchResultEditorManager;
 import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserCategory;
 import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserUniversalListener;
-
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -134,30 +133,35 @@
 
         ISearch[] searches = SelectionUtils.getSearches( selection );
 
-        ISearch search = null;
-        IEntry entry = null;
         if ( entries.length + searchResults.length + bookmarks.length + searches.length == 1 )
         {
             if ( entries.length == 1 )
             {
-                entry = entries[0];
+                EntryEditorManager.setInput( entries[0] );
+                SearchResultEditorManager.setInput( null );
             }
             else if ( searchResults.length == 1 )
             {
-                entry = searchResults[0].getEntry();
+                EntryEditorManager.setInput( searchResults[0] );
+                SearchResultEditorManager.setInput( null );
             }
             else if ( bookmarks.length == 1 )
             {
-                entry = bookmarks[0].getEntry();
+                EntryEditorManager.setInput( bookmarks[0] );
+                SearchResultEditorManager.setInput( null );
             }
             else if ( searches.length == 1 )
             {
-                search = searches[0];
+                EntryEditorManager.setInput( ( IEntry ) null );
+                SearchResultEditorManager.setInput( searches[0] );
             }
         }
+        else
+        {
+            EntryEditorManager.setInput( ( IEntry ) null );
+            SearchResultEditorManager.setInput( null );
+        }
 
-        EntryEditorManager.setInput( entry );
-        SearchResultEditorManager.setInput( search );
     }
 
 
@@ -279,7 +283,7 @@
 
     public void entryUpdated( EntryModificationEvent event )
     {
-        
+
         // Don't handle attribute initalization, could cause double
         // retrieval of children. 
         //

Added: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/LinkWithEditorAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/LinkWithEditorAction.java?view=auto&rev=505080
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/LinkWithEditorAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/views/browser/LinkWithEditorAction.java Thu Feb  8 15:10:45 2007
@@ -0,0 +1,229 @@
+/*
+ *  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.ldapstudio.browser.ui.views.browser;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.editors.entry.EntryEditor;
+import org.apache.directory.ldapstudio.browser.ui.editors.entry.EntryEditorManager;
+import org.apache.directory.ldapstudio.browser.ui.editors.searchresult.SearchResultEditor;
+import org.apache.directory.ldapstudio.browser.ui.editors.searchresult.SearchResultEditorManager;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class implements the Link With Editor Action for the Browser View
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LinkWithEditorAction extends Action
+{
+    /** The browser view */
+    private BrowserView browserView;
+
+    /** The listener listening on changes on editors */
+    private IPartListener2 editorListener = new IPartListener2()
+    {
+        /* (non-Javadoc)
+         * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
+         */
+        public void partBroughtToTop( IWorkbenchPartReference partRef )
+        {
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
+         */
+        public void partActivated( IWorkbenchPartReference partRef )
+        {
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
+         */
+        public void partClosed( IWorkbenchPartReference partRef )
+        {
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
+         */
+        public void partDeactivated( IWorkbenchPartReference partRef )
+        {
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
+         */
+        public void partHidden( IWorkbenchPartReference partRef )
+        {
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
+         */
+        public void partInputChanged( IWorkbenchPartReference partRef )
+        {
+            linkViewWithEditor( partRef.getId() );
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
+         */
+        public void partOpened( IWorkbenchPartReference partRef )
+        {
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
+         */
+        public void partVisible( IWorkbenchPartReference partRef )
+        {
+        }
+    };
+
+
+    /**
+     * Creates a new instance of LinkWithEditorAction.
+     *
+     * @param view
+     *      the associated view
+     */
+    public LinkWithEditorAction( BrowserView browserView )
+    {
+        super( "Link with editor", AS_CHECK_BOX );
+        //        super.setActionDefinitionId( Activator.PLUGIN_ID + "linkwitheditorschemasview" );
+
+        super.setImageDescriptor( BrowserUIPlugin.getDefault().getImageDescriptor(
+            BrowserUIConstants.IMG_LINK_WITH_EDITOR ) );
+        super.setEnabled( true );
+        this.browserView = browserView;
+
+        super.setChecked( BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+            BrowserUIConstants.PREFERENCE_BROWSER_LINK_WITH_EDITOR ) );
+
+        // Enabling the listeners
+        if ( isChecked() )
+        {
+            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener( editorListener );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.action.Action#run()
+     */
+    public void run()
+    {
+        setChecked( isChecked() );
+        BrowserUIPlugin.getDefault().getPreferenceStore().setValue(
+            BrowserUIConstants.PREFERENCE_BROWSER_LINK_WITH_EDITOR, isChecked() );
+
+        if ( isChecked() )
+        {
+            // Enabling the listeners
+            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener( editorListener );
+
+            IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+                .getActiveEditor();
+            if ( activeEditor instanceof EntryEditor )
+            {
+                linkViewWithEditor( EntryEditor.getId() );
+            }
+            else if ( activeEditor instanceof SearchResultEditor )
+            {
+                linkViewWithEditor( SearchResultEditor.getId() );
+            }
+        }
+        else
+        {
+            // Disabling the listeners
+            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().removePartListener( editorListener );
+        }
+    }
+
+
+    /**
+     * Links the view with the right editor
+     *
+     * @param editorID
+     *      the id of the editor
+     */
+    private void linkViewWithEditor( String editorID )
+    {
+        Object objectToSelect = null;
+
+        // Only entry editor and search result editor are accepted
+        if ( editorID.equals( EntryEditor.getId() ) )
+        {
+            Object input = EntryEditorManager.getInput();
+            objectToSelect = input;
+
+        }
+        else if ( editorID.equals( SearchResultEditor.getId() ) )
+        {
+            ISearch search = SearchResultEditorManager.getInput();
+            objectToSelect = search;
+        }
+
+        if ( objectToSelect != null )
+        {
+            // do not select if already selected!
+            // necessary to avoid infinite loops!
+            IStructuredSelection selection = ( IStructuredSelection ) browserView.getMainWidget().getViewer()
+                .getSelection();
+            if ( selection.size() != 1 || !selection.getFirstElement().equals( objectToSelect ) )
+            {
+                browserView.select( objectToSelect );
+            }
+        }
+    }
+
+
+    /**
+     * Disposes this action.
+     */
+    public void dispose()
+    {
+        if ( editorListener != null )
+        {
+            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().removePartListener( editorListener );
+            editorListener = null;
+        }
+
+        browserView = null;
+    }
+
+}



Mime
View raw message