directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r810070 - in /directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio: entryeditors/ ldapbrowser/ui/actions/ ldapbrowser/ui/views/browser/
Date Tue, 01 Sep 2009 14:26:09 GMT
Author: pamarcelot
Date: Tue Sep  1 14:26:09 2009
New Revision: 810070

URL: http://svn.apache.org/viewvc?rev=810070&view=rev
Log:
DIRSTUDIO-516:
o Added implementation for the open mode.

Modified:
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/OpenEntryEditorAction.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java?rev=810070&r1=810069&r2=810070&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java
(original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorManager.java
Tue Sep  1 14:26:09 2009
@@ -259,7 +259,6 @@
             BrowserUIConstants.PREFERENCE_ENTRYEDITORS_USER_PRIORITIES );
         if ( ( userPriorities != null ) && ( !"".equals( userPriorities ) ) )
         {
-
             String[] splittedUserPriorities = userPriorities.split( PRIORITIES_SEPARATOR
);
             if ( ( splittedUserPriorities != null ) && ( splittedUserPriorities.length
> 0 ) )
             {
@@ -314,6 +313,19 @@
     }
 
 
+    /**
+     * Opens an entry editor with the given entry editor extension and one of 
+     * the given entries, search results or bookmarks.
+     *
+     * @param extension
+     *      the entry editor extension
+     * @param entries
+     *      an array of entries
+     * @param searchResults
+     *      an array of search results
+     * @param bookmarks
+     *      an arrays of bookmarks
+     */
     public void openEntryEditor( EntryEditorExtension extension, IEntry[] entries, ISearchResult[]
searchResults,
         IBookmark[] bookmarks )
     {
@@ -343,4 +355,25 @@
             e.printStackTrace();
         }
     }
+
+
+    /**
+     * Opens an entry editor with one of the given entries, search results or bookmarks.
+     *
+     * @param extension
+     *      the entry editor extension
+     * @param entries
+     *      an array of entries
+     * @param searchResults
+     *      an array of search results
+     * @param bookmarks
+     *      an arrays of bookmarks
+     */
+    public void openEntryEditor( IEntry[] entries, ISearchResult[] searchResults, IBookmark[]
bookmarks )
+    {
+        Collection<EntryEditorExtension> entryEditors = getSortedEntryEditorExtensions();
+        // TODO: check if the entry editor can "handle" the entry 
+        EntryEditorExtension next = entryEditors.iterator().next();
+        openEntryEditor( next, entries, searchResults, bookmarks );
+    }
 }

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/OpenEntryEditorAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/OpenEntryEditorAction.java?rev=810070&r1=810069&r2=810070&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/OpenEntryEditorAction.java
(original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/OpenEntryEditorAction.java
Tue Sep  1 14:26:09 2009
@@ -21,9 +21,6 @@
 package org.apache.directory.studio.ldapbrowser.ui.actions;
 
 
-import java.util.Collection;
-
-import org.apache.directory.studio.entryeditors.EntryEditorExtension;
 import org.apache.directory.studio.entryeditors.EntryEditorManager;
 import org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction;
 import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
@@ -53,11 +50,7 @@
     public void run()
     {
         EntryEditorManager entryEditorManager = BrowserUIPlugin.getDefault().getEntryEditorManager();
-        Collection<EntryEditorExtension> entryEditors = entryEditorManager.getSortedEntryEditorExtensions();
-        // TODO: check if the entry editor can "handle" the entry 
-        EntryEditorExtension next = entryEditors.iterator().next();
-        entryEditorManager.openEntryEditor( next, getSelectedEntries(), getSelectedSearchResults(),
-            getSelectedBookmarks() );
+        entryEditorManager.openEntryEditor( getSelectedEntries(), getSelectedSearchResults(),
getSelectedBookmarks() );
     }
 
 

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java?rev=810070&r1=810069&r2=810070&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java
(original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java
Tue Sep  1 14:26:09 2009
@@ -21,12 +21,15 @@
 package org.apache.directory.studio.ldapbrowser.ui.views.browser;
 
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
 import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
+import org.apache.directory.studio.entryeditors.EntryEditorExtension;
+import org.apache.directory.studio.entryeditors.EntryEditorManager;
 import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
 import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
 import org.apache.directory.studio.ldapbrowser.common.actions.BrowserSelectionUtils;
@@ -51,13 +54,19 @@
 import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
 import org.apache.directory.studio.ldapbrowser.ui.editors.entry.EntryEditor;
 import org.apache.directory.studio.ldapbrowser.ui.editors.searchresult.SearchResultEditor;
 import org.apache.directory.studio.ldapbrowser.ui.editors.searchresult.SearchResultEditorInput;
 import org.apache.directory.studio.ldapbrowser.ui.views.connection.ConnectionView;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.OpenStrategy;
+import org.eclipse.jface.viewers.IOpenListener;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.OpenEvent;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
@@ -80,7 +89,6 @@
 public class BrowserViewUniversalListener extends BrowserUniversalListener implements SearchUpdateListener,
     BookmarkUpdateListener
 {
-
     /** This map contains all expanded elements for a particular connection */
     private Map<IBrowserConnection, Object[]> connectionToExpandedElementsMap;
 
@@ -225,7 +233,32 @@
          */
         public void selectionChanged( SelectionChangedEvent event )
         {
-            //ensureEditorsVisible( event.getSelection() );
+            openEditor( event.getSelection() );
+        }
+    };
+
+    /** This listerner is used to listen on the preference settings modifications, especially

+     * the open mode preference value change. */
+    private IPropertyChangeListener preferencePropertyChangeListener = new IPropertyChangeListener()
+    {
+        /**
+         * {@inheritDoc}
+         */
+        public void propertyChange( org.eclipse.jface.util.PropertyChangeEvent event )
+        {
+            if ( BrowserUIConstants.PREFERENCE_ENTRYEDITORS_OPEN_MODE.equals( event.getProperty()
) )
+            {
+                setupOpenModeListeners();
+            }
+        };
+    };
+
+    /** The open mode listener */
+    private IOpenListener openListener = new IOpenListener()
+    {
+        public void open( OpenEvent event )
+        {
+            openEditor( event.getSelection() );
         }
     };
 
@@ -250,79 +283,77 @@
         EventRegistry.addEntryUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner()
);
         ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionUIPlugin.getDefault().getEventRunner()
);
 
+        // listener for shortcuts activation/deactivation
         view.getSite().getPage().addPartListener( partListener );
+
+        // listener for connections
         view.getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(
ConnectionView.getId(),
             connectionSelectionListener );
 
-        viewer.addSelectionChangedListener( viewerSelectionListener );
+        // listener for open mode
+        BrowserUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( preferencePropertyChangeListener
);
+        setupOpenModeListeners();
     }
 
 
-    // TODO: remove this, use "open mode" instead
-//    /**
-//     * Ensures that the entry editor or the search result editor are
-//     * opended and ready to show the given selection.
-//     *
-//     * @param selection the browser's selection.
-//     */
-//    private void ensureEditorsVisible( ISelection selection )
-//    {
-//        if ( view != null )
-//        {
-//            IEntry[] entries = BrowserSelectionUtils.getEntries( selection );
-//            ISearchResult[] searchResults = BrowserSelectionUtils.getSearchResults( selection
);
-//            IBookmark[] bookmarks = BrowserSelectionUtils.getBookmarks( selection );
-//            ISearch[] searches = BrowserSelectionUtils.getSearches( selection );
-//
-//            if ( entries.length + searchResults.length + bookmarks.length + searches.length
== 1 )
-//            {
-//                if ( entries.length == 1 )
-//                {
-//                    try
-//                    {
-//                        EntryEditorInput input = new EntryEditorInput( entries[0] );
-//                        view.getSite().getPage().openEditor( input, EntryEditor.getId(),
false );
-//                    }
-//                    catch ( PartInitException e )
-//                    {
-//                    }
-//                }
-//                else if ( searchResults.length == 1 )
-//                {
-//                    try
-//                    {
-//                        EntryEditorInput input = new EntryEditorInput( searchResults[0]
);
-//                        view.getSite().getPage().openEditor( input, EntryEditor.getId(),
false );
-//                    }
-//                    catch ( PartInitException e )
-//                    {
-//                    }
-//                }
-//                else if ( bookmarks.length == 1 )
-//                {
-//                    try
-//                    {
-//                        EntryEditorInput input = new EntryEditorInput( bookmarks[0] );
-//                        view.getSite().getPage().openEditor( input, EntryEditor.getId(),
false );
-//                    }
-//                    catch ( PartInitException e )
-//                    {
-//                    }
-//                }
-//                else if ( searches.length == 1 )
-//                {
-//                    try
-//                    {
-//                        SearchResultEditorInput input = new SearchResultEditorInput( searches[0]
);
-//                        view.getSite().getPage().openEditor( input, SearchResultEditor.getId(),
false );
-//                    }
-//                    catch ( PartInitException e )
-//                    {
-//                    }
-//                }
-//            }
-//        }
-//    }
+    /**
+     * Sets up the open mode listeners according the preferences.
+     */
+    private void setupOpenModeListeners()
+    {
+        int openMode = BrowserUIPlugin.getDefault().getPluginPreferences().getInt(
+            BrowserUIConstants.PREFERENCE_ENTRYEDITORS_OPEN_MODE );
+
+        if ( openMode == BrowserUIConstants.PREFERENCE_ENTRYEDITORS_OPEN_MODE_HISTORICAL_BEHAVIOR
)
+        {
+            // Historical Behavior
+            viewer.removeOpenListener( openListener );
+            viewer.addSelectionChangedListener( viewerSelectionListener );
+        }
+        else if ( openMode == BrowserUIConstants.PREFERENCE_ENTRYEDITORS_OPEN_MODE_APPLICATION_WIDE
)
+        {
+            // Application Wide Setting
+            viewer.removeSelectionChangedListener( viewerSelectionListener );
+            viewer.addOpenListener( openListener );
+        }
+    }
+
+
+    /**
+     * Opens an editor to show the given selection.
+     *
+     * @param selection the browser's selection.
+     */
+    private void openEditor( ISelection selection )
+    {
+        if ( view != null )
+        {
+            IEntry[] entries = BrowserSelectionUtils.getEntries( selection );
+            ISearchResult[] searchResults = BrowserSelectionUtils.getSearchResults( selection
);
+            IBookmark[] bookmarks = BrowserSelectionUtils.getBookmarks( selection );
+            ISearch[] searches = BrowserSelectionUtils.getSearches( selection );
+
+            if ( entries.length + searchResults.length + bookmarks.length + searches.length
== 1 )
+            {
+                if ( ( entries.length == 1 ) || ( searchResults.length == 1 ) || ( bookmarks.length
== 1 ) )
+                {
+                    EntryEditorManager entryEditorManager = BrowserUIPlugin.getDefault().getEntryEditorManager();
+                    entryEditorManager.openEntryEditor( entries, searchResults, bookmarks
);
+                }
+                else if ( searches.length == 1 )
+                {
+                    try
+                    {
+                        SearchResultEditorInput input = new SearchResultEditorInput( searches[0]
);
+                        view.getSite().getPage().openEditor( input, SearchResultEditor.getId(),
false );
+                    }
+                    catch ( PartInitException e )
+                    {
+                    }
+                }
+            }
+        }
+    }
 
 
     /**
@@ -341,6 +372,9 @@
             view.getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(
                 ConnectionView.getId(), connectionSelectionListener );
 
+            viewer.removeOpenListener( openListener );
+            viewer.removeSelectionChangedListener( viewerSelectionListener );
+
             view = null;
             connectionToExpandedElementsMap.clear();
             connectionToExpandedElementsMap = null;



Mime
View raw message