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/08/14 10:29:20 UTC
svn commit: r804125 - in
/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio:
entryeditors/EntryEditorManager.java
ldapbrowser/ui/dialogs/preferences/EntryEditorsPreferencePage.java
Author: pamarcelot
Date: Fri Aug 14 08:29:20 2009
New Revision: 804125
URL: http://svn.apache.org/viewvc?rev=804125&view=rev
Log:
DIRSTUDIO-516:
o Refactored the preference page and EntryEditorManager
o Moved the methods to get the sorted lists of entry editors in the EntryEditorManager.
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/dialogs/preferences/EntryEditorsPreferencePage.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=804125&r1=804124&r2=804125&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 Fri Aug 14 08:29:20 2009
@@ -22,8 +22,15 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
@@ -54,8 +61,54 @@
private static final String MULTI_WINDOW_ATTR = "multiWindow"; //$NON-NLS-1$
private static final String PRIORITY_ATTR = "priority"; //$NON-NLS-1$
+ /** The priorities separator */
+ public static final String PRIORITIES_SEPARATOR = ",";
+
+ /** The list of entry editors */
private Collection<EntryEditorExtension> entryEditorExtensions = new ArrayList<EntryEditorExtension>();
+ /** The comparator for entry editors */
+ private Comparator<EntryEditorExtension> entryEditorComparator = new Comparator<EntryEditorExtension>()
+ {
+ public int compare( EntryEditorExtension o1, EntryEditorExtension o2 )
+ {
+ if ( o1 == null )
+ {
+ return ( o2 == null ) ? 0 : -1;
+ }
+
+ if ( o2 == null )
+ {
+ return 1;
+ }
+
+ // Getting priorities
+ int o1Priority = o1.getPriority();
+ int o2Priority = o2.getPriority();
+
+ if ( o1Priority != o2Priority )
+ {
+ return ( o1Priority > o2Priority ) ? -1 : 1;
+ }
+
+ // Getting names
+ String o1Name = o1.getName();
+ String o2Name = o2.getName();
+
+ if ( o1Name == null )
+ {
+ return ( o2Name == null ) ? 0 : -1;
+ }
+
+ if ( o2 == null )
+ {
+ return 1;
+ }
+
+ return o1Name.compareTo( o2Name );
+ }
+ };
+
/**
* Creates a new instance of EntryEditorManager.
@@ -114,4 +167,130 @@
{
return entryEditorExtensions;
}
+
+
+ /**
+ * Gets the sorted entry editor extensions.
+ *
+ * @return
+ * the sorted entry editor extensions
+ */
+ public Collection<EntryEditorExtension> getSortedEntryEditorExtensions()
+ {
+ boolean useUserPriority = ConnectionCorePlugin.getDefault().getPluginPreferences().getBoolean(
+ BrowserUIConstants.PREFERENCE_ENTRYEDITORS_USE_USER_PRIORITIES );
+
+ if ( useUserPriority )
+ {
+ return getEntryEditorExtensionsSortedByUserPriority();
+ }
+ else
+ {
+ return getEntryEditorExtensionsSortedByDefaultPriority();
+ }
+ }
+
+
+ /**
+ * Gets the entry editor extensions sorted by default priority.
+ *
+ * @return
+ * the entry editor extensions sorted by default priority
+ */
+ public Collection<EntryEditorExtension> getEntryEditorExtensionsSortedByDefaultPriority()
+ {
+ // Getting all entry editors
+ Collection<EntryEditorExtension> entryEditorExtensions = getEntryEditorExtensions();
+
+ // Creating the sorted entry editors list
+ ArrayList<EntryEditorExtension> sortedEntryEditorsList = new ArrayList<EntryEditorExtension>(
+ entryEditorExtensions.size() );
+
+ // Adding the remaining entry editors
+ for ( EntryEditorExtension entryEditorExtension : entryEditorExtensions )
+ {
+ sortedEntryEditorsList.add( entryEditorExtension );
+ }
+
+ // Sorting the remaining entry editors based on their priority
+ Collections.sort( sortedEntryEditorsList, entryEditorComparator );
+
+ return sortedEntryEditorsList;
+ }
+
+
+ /**
+ * Gets the entry editor extensions sorted by user's priority.
+ *
+ * @return
+ * the entry editor extensions sorted by user's priority
+ */
+ public Collection<EntryEditorExtension> getEntryEditorExtensionsSortedByUserPriority()
+ {
+ // Getting all entry editors
+ Collection<EntryEditorExtension> entryEditorExtensions = BrowserUIPlugin.getDefault().getEntryEditorManager()
+ .getEntryEditorExtensions();
+
+ // Creating the sorted entry editors list
+ Collection<EntryEditorExtension> sortedEntryEditorsList = new ArrayList<EntryEditorExtension>(
+ entryEditorExtensions.size() );
+
+ // Getting the user's priorities
+ String userPriorities = ConnectionCorePlugin.getDefault().getPluginPreferences().getString(
+ BrowserUIConstants.PREFERENCE_ENTRYEDITORS_USER_PRIORITIES );
+ if ( ( userPriorities != null ) && ( !"".equals( userPriorities ) ) )
+ {
+
+ String[] splittedUserPriorities = userPriorities.split( PRIORITIES_SEPARATOR );
+ if ( ( splittedUserPriorities != null ) && ( splittedUserPriorities.length > 0 ) )
+ {
+
+ // Creating a map where entry editors are accessible via their ID
+ Map<String, EntryEditorExtension> entryEditorsMap = new HashMap<String, EntryEditorExtension>();
+ for ( EntryEditorExtension entryEditorExtension : entryEditorExtensions )
+ {
+ entryEditorsMap.put( entryEditorExtension.getId(), entryEditorExtension );
+ }
+
+ // Adding the entry editors according to the user's priority
+ for ( String entryEditorId : splittedUserPriorities )
+ {
+ // Verifying the entry editor is present in the map
+ if ( entryEditorsMap.containsKey( entryEditorId ) )
+ {
+ // Adding it to the sorted list
+ sortedEntryEditorsList.add( entryEditorsMap.get( entryEditorId ) );
+ }
+ }
+ }
+
+ // If some new plugins have been added recently, their new
+ // entry editors may not be present in the string stored in
+ // the preferences.
+ // We are then adding them at the end of the sorted list.
+
+ // Creating a list of remaining entry editors
+ List<EntryEditorExtension> remainingEntryEditors = new ArrayList<EntryEditorExtension>();
+ for ( EntryEditorExtension entryEditorExtension : entryEditorExtensions )
+ {
+ // Verifying the entry editor is present in the sorted list
+ if ( !sortedEntryEditorsList.contains( entryEditorExtension ) )
+ {
+ // Adding it to the remaining list
+ remainingEntryEditors.add( entryEditorExtension );
+ }
+ }
+
+ // Sorting the remaining entry editors based on their priority
+ Collections.sort( remainingEntryEditors, entryEditorComparator );
+
+ // Adding the remaining entry editors
+ for ( EntryEditorExtension entryEditorExtension : remainingEntryEditors )
+ {
+ sortedEntryEditorsList.add( entryEditorExtension );
+ }
+ }
+
+ return sortedEntryEditorsList;
+ }
}
Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/preferences/EntryEditorsPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/preferences/EntryEditorsPreferencePage.java?rev=804125&r1=804124&r2=804125&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/preferences/EntryEditorsPreferencePage.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/preferences/EntryEditorsPreferencePage.java Fri Aug 14 08:29:20 2009
@@ -21,16 +21,12 @@
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
import org.apache.directory.studio.connection.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.entryeditors.EntryEditorExtension;
+import org.apache.directory.studio.entryeditors.EntryEditorManager;
import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
import org.eclipse.jface.preference.PreferencePage;
@@ -63,8 +59,6 @@
*/
public class EntryEditorsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
{
- /** The priorities separator */
- private static final String PRIORITIES_SEPARATOR = ",";
/** A flag indicating whether or not to use the user's priority for entry editors */
private boolean useUserPriority = false;
@@ -72,48 +66,6 @@
/** The ordered list of entry editors */
private List<EntryEditorExtension> sortedEntryEditorsList;
- /** */
- private Comparator<EntryEditorExtension> entryEditorComparator = new Comparator<EntryEditorExtension>()
- {
- public int compare( EntryEditorExtension o1, EntryEditorExtension o2 )
- {
- if ( o1 == null )
- {
- return ( o2 == null ) ? 0 : -1;
- }
-
- if ( o2 == null )
- {
- return 1;
- }
-
- // Getting priorities
- int o1Priority = o1.getPriority();
- int o2Priority = o2.getPriority();
-
- if ( o1Priority != o2Priority )
- {
- return ( o1Priority > o2Priority ) ? -1 : 1;
- }
-
- // Getting names
- String o1Name = o1.getName();
- String o2Name = o2.getName();
-
- if ( o1Name == null )
- {
- return ( o2Name == null ) ? 0 : -1;
- }
-
- if ( o2 == null )
- {
- return 1;
- }
-
- return o1Name.compareTo( o2Name );
- }
- };
-
// UI fields
private TableViewer entryEditorsTableViewer;
private Button upButton;
@@ -253,70 +205,12 @@
*/
private void sortEntryEditorsByUserPriority()
{
- // Getting the user's priorities
- String userPriorities = ConnectionCorePlugin.getDefault().getPluginPreferences().getString(
- BrowserUIConstants.PREFERENCE_ENTRYEDITORS_USER_PRIORITIES );
- if ( ( userPriorities != null ) && ( !"".equals( userPriorities ) ) )
- {
- // Getting all entry editors
- Collection<EntryEditorExtension> entryEditorExtensions = BrowserUIPlugin.getDefault()
- .getEntryEditorManager().getEntryEditorExtensions();
-
- String[] splittedUserPriorities = userPriorities.split( PRIORITIES_SEPARATOR );
- if ( ( splittedUserPriorities != null ) && ( splittedUserPriorities.length > 0 ) )
- {
-
- // Creating a map where entry editors are accessible via their ID
- Map<String, EntryEditorExtension> entryEditorsMap = new HashMap<String, EntryEditorExtension>();
- for ( EntryEditorExtension entryEditorExtension : entryEditorExtensions )
- {
- entryEditorsMap.put( entryEditorExtension.getId(), entryEditorExtension );
- }
-
- // Creating the sorted entry editors list
- sortedEntryEditorsList = new ArrayList<EntryEditorExtension>( entryEditorExtensions.size() );
-
- // Adding the entry editors according to the user's priority
- for ( String entryEditorId : splittedUserPriorities )
- {
- // Verifying the entry editor is present in the map
- if ( entryEditorsMap.containsKey( entryEditorId ) )
- {
- // Adding it to the sorted list
- sortedEntryEditorsList.add( entryEditorsMap.get( entryEditorId ) );
- }
- }
- }
+ // Getting the entry editors sorted by user's priority
+ sortedEntryEditorsList = new ArrayList<EntryEditorExtension>( BrowserUIPlugin.getDefault()
+ .getEntryEditorManager().getEntryEditorExtensionsSortedByUserPriority() );
- // If some new plugins have been added recently, their new
- // entry editors may not be present in the string stored in
- // the preferences.
- // We are then adding them at the end of the sorted list.
-
- // Creating a list of remaining entry editors
- List<EntryEditorExtension> remainingEntryEditors = new ArrayList<EntryEditorExtension>();
- for ( EntryEditorExtension entryEditorExtension : entryEditorExtensions )
- {
- // Verifying the entry editor is present in the sorted list
- if ( !sortedEntryEditorsList.contains( entryEditorExtension ) )
- {
- // Adding it to the remaining list
- remainingEntryEditors.add( entryEditorExtension );
- }
- }
-
- // Sorting the remaining entry editors based on their priority
- Collections.sort( remainingEntryEditors, entryEditorComparator );
-
- // Adding the remaining entry editors
- for ( EntryEditorExtension entryEditorExtension : remainingEntryEditors )
- {
- sortedEntryEditorsList.add( entryEditorExtension );
- }
-
- // Assigning the sorted editors to the viewer
- entryEditorsTableViewer.setInput( sortedEntryEditorsList );
- }
+ // Assigning the sorted editors to the viewer
+ entryEditorsTableViewer.setInput( sortedEntryEditorsList );
}
@@ -325,21 +219,9 @@
*/
private void sortEntryEditorsByDefaultPriority()
{
- // Getting all entry editors
- Collection<EntryEditorExtension> entryEditorExtensions = BrowserUIPlugin.getDefault().getEntryEditorManager()
- .getEntryEditorExtensions();
-
- // Creating the sorted entry editors list
- sortedEntryEditorsList = new ArrayList<EntryEditorExtension>( entryEditorExtensions.size() );
-
- // Adding the remaining entry editors
- for ( EntryEditorExtension entryEditorExtension : entryEditorExtensions )
- {
- sortedEntryEditorsList.add( entryEditorExtension );
- }
-
- // Sorting the remaining entry editors based on their priority
- Collections.sort( sortedEntryEditorsList, entryEditorComparator );
+ // Getting the entry editors sorted by default priority
+ sortedEntryEditorsList = new ArrayList<EntryEditorExtension>( BrowserUIPlugin.getDefault()
+ .getEntryEditorManager().getEntryEditorExtensionsSortedByDefaultPriority() );
// Assigning the sorted editors to the viewer
entryEditorsTableViewer.setInput( sortedEntryEditorsList );
@@ -427,6 +309,22 @@
}
}
+
+ /**
+ * Updates the state of the buttons.
+ */
+ private void updateButtonsState()
+ {
+ StructuredSelection selection = ( StructuredSelection ) entryEditorsTableViewer.getSelection();
+ if ( selection.size() == 1 )
+ {
+ EntryEditorExtension entryEditor = ( EntryEditorExtension ) selection.getFirstElement();
+
+ // Updating the state of the buttons
+ updateButtonsState( entryEditor );
+ }
+ }
+
/**
* This enum is used to determine in which direction the entry editor
* should be moved.
@@ -453,7 +351,7 @@
StringBuilder sb = new StringBuilder();
for ( EntryEditorExtension entryEditor : sortedEntryEditorsList )
{
- sb.append( entryEditor.getId() + PRIORITIES_SEPARATOR );
+ sb.append( entryEditor.getId() + EntryEditorManager.PRIORITIES_SEPARATOR );
}
if ( sb.length() > 0 )
@@ -486,6 +384,8 @@
sortEntryEditorsByDefaultPriority();
}
+ updateButtonsState();
+
super.performDefaults();
}
}
\ No newline at end of file