You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2009/10/05 17:33:23 UTC
svn commit: r821853 - in
/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio:
entryeditors/EntryEditorExtension.java entryeditors/EntryEditorManager.java
ldapbrowser/ui/actions/EntryEditorMenuManager.java
Author: pamarcelot
Date: Mon Oct 5 15:33:23 2009
New Revision: 821853
URL: http://svn.apache.org/viewvc?rev=821853&view=rev
Log:
DIRSTUDIO-515 (Add extensibility to Entry Editor).
o The EntryEditorManager.openEntryEditor(...) and the EntryEditorMenuManager.menuAboutToShow(...) methods now uses the canHandle(...) of the IEntryEditor interface to determine if the editor is able to display the entry.
Modified:
directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorExtension.java
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/EntryEditorMenuManager.java
Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorExtension.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorExtension.java?rev=821853&r1=821852&r2=821853&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorExtension.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/entryeditors/EntryEditorExtension.java Mon Oct 5 15:33:23 2009
@@ -33,7 +33,6 @@
*/
public class EntryEditorExtension
{
-
/** The ID. */
private String id = null;
@@ -61,6 +60,9 @@
/** The configuration element. */
private IConfigurationElement member = null;
+ /** The editor instance */
+ private IEntryEditor editorInstance = null;
+
/**
* Gets the id.
@@ -260,6 +262,30 @@
}
+ /**
+ * Gets the editor instance.
+ *
+ * @return
+ * the editor instance
+ */
+ public IEntryEditor getEditorInstance()
+ {
+ return editorInstance;
+ }
+
+
+ /**
+ * Sets the editor instance
+ *
+ * @param editorInstance
+ * the editor instance
+ */
+ public void setEditorInstance( IEntryEditor editorInstance )
+ {
+ this.editorInstance = editorInstance;
+ }
+
+
@Override
public String toString()
{
@@ -267,6 +293,4 @@
+ editorId + ", icon=" + icon + ", id=" + id + ", member=" + member + ", name=" + name + ", priority="
+ priority + ", multiWindow=" + multiWindow + "]";
}
-
-
}
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=821853&r1=821852&r2=821853&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 Mon Oct 5 15:33:23 2009
@@ -56,6 +56,7 @@
import org.apache.directory.studio.ldifparser.model.LdifFile;
import org.apache.directory.studio.ldifparser.model.container.LdifChangeModDnRecord;
import org.apache.directory.studio.ldifparser.model.container.LdifRecord;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
@@ -463,6 +464,15 @@
bean.setMultiWindow( "true".equalsIgnoreCase( member.getAttribute( MULTI_WINDOW_ATTR ) ) ); //$NON-NLS-1$
bean.setPriority( Integer.parseInt( member.getAttribute( PRIORITY_ATTR ) ) );
+ try
+ {
+ bean.setEditorInstance( ( IEntryEditor ) member.createExecutableExtension( CLASS_ATTR ) );
+ }
+ catch ( CoreException e )
+ {
+ // Will never happen
+ }
+
entryEditorExtensions.put( bean.getId(), bean );
}
}
@@ -717,10 +727,36 @@
*/
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 );
+ // Looking for the entry to test the editor on
+ IEntry entry = null;
+ if ( entries.length == 1 )
+ {
+ entry = entries[0];
+ }
+ else if ( searchResults.length == 1 )
+ {
+ entry = searchResults[0].getEntry();
+ }
+ else if ( bookmarks.length == 1 )
+ {
+ entry = bookmarks[0].getEntry();
+ }
+
+ // Checking if we've found the entry
+ if ( entry != null )
+ {
+ // Looking for the correct entry editor
+ for ( EntryEditorExtension entryEditor : getSortedEntryEditorExtensions() )
+ {
+ // Verifying that the editor can handle the entry
+ if ( entryEditor.getEditorInstance().canHandle( entry ) )
+ {
+ // The correct editor has been found, let's open the entry in the editor
+ openEntryEditor( entryEditor, entries, searchResults, bookmarks );
+ return;
+ }
+ }
+ }
}
Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/EntryEditorMenuManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/EntryEditorMenuManager.java?rev=821853&r1=821852&r2=821853&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/EntryEditorMenuManager.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/EntryEditorMenuManager.java Mon Oct 5 15:33:23 2009
@@ -37,6 +37,7 @@
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
public class EntryEditorMenuManager extends MenuManager implements IMenuListener
@@ -54,7 +55,7 @@
*/
public EntryEditorMenuManager( ISelectionProvider selectionProvider )
{
- super( Messages.getString("EntryEditorMenuManager.OpenWith") ); //$NON-NLS-1$
+ super( Messages.getString( "EntryEditorMenuManager.OpenWith" ) ); //$NON-NLS-1$
this.selectionProvider = selectionProvider;
openEntryEditorsPreferencePageAction = new OpenEntryEditorsPreferencePageAction();
addMenuListener( this );
@@ -70,12 +71,23 @@
// remove all the previously added actions
removeAll();
- // Getting the entry editors and creating an action for each
- Collection<EntryEditorExtension> entryEditors = BrowserUIPlugin.getDefault().getEntryEditorManager()
- .getSortedEntryEditorExtensions();
- for ( EntryEditorExtension entryEditorExtension : entryEditors )
+ // Getting the currently selected entry
+ IEntry selectedEntry = getCurrentSelection();
+ if ( selectedEntry != null )
{
- add( createAction( entryEditorExtension ) );
+ // Getting the entry editors and creating an action for each one
+ // that can handle the entry
+ Collection<EntryEditorExtension> entryEditors = BrowserUIPlugin.getDefault().getEntryEditorManager()
+ .getSortedEntryEditorExtensions();
+ for ( EntryEditorExtension entryEditor : entryEditors )
+ {
+ // Verifying that the editor can handle the entry
+ if ( entryEditor.getEditorInstance().canHandle( selectedEntry ) )
+ {
+ // Creating the action associated with the entry editor
+ add( createAction( entryEditor ) );
+ }
+ }
}
// Separator
@@ -87,6 +99,36 @@
/**
+ * Gets the currently selected entry.
+ *
+ * @return
+ * the currently selected entry
+ */
+ private IEntry getCurrentSelection()
+ {
+ StructuredSelection structuredSelection = ( StructuredSelection ) selectionProvider.getSelection();
+ if ( !structuredSelection.isEmpty() )
+ {
+ Object selection = structuredSelection.getFirstElement();
+ if ( selection instanceof IEntry )
+ {
+ return ( IEntry ) selection;
+ }
+ else if ( selection instanceof ISearchResult )
+ {
+ return ( ( ISearchResult ) selection ).getEntry();
+ }
+ else if ( selection instanceof IBookmark )
+ {
+ return ( ( IBookmark ) selection ).getEntry();
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
* Creates an action for the given entry editor.
*
* @param entryEditorExtension
@@ -110,10 +152,6 @@
}
};
- // TODO Add enable/disable action if the entry editor can "handle" the entry.
- // TODO Or do include this entry editor in the list of available entry editors.
- //action.setEnabled( false );
-
return action;
}