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 2006/12/18 18:57:49 UTC

svn commit: r488371 [14/14] - in /directory/sandbox/pamarcelot/ldapstudio: ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/jobs/ ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/perspective/ ldapstudio-browser-u...

Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-ldapbrowser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/EntryWrapper.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-ldapbrowser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/EntryWrapper.java?view=diff&rev=488371&r1=488370&r2=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-ldapbrowser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/EntryWrapper.java (original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-ldapbrowser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/EntryWrapper.java Mon Dec 18 09:57:38 2006
@@ -20,6 +20,7 @@
 
 package org.apache.directory.ldapstudio.browser.view.views.wrappers;
 
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -39,13 +40,14 @@
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 
+
 /**
  * EntryWrapper used to displays an entry in the TreeViewer of the Browser View
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class EntryWrapper implements Comparable<EntryWrapper>,
-	DisplayableTreeViewerElement {
+public class EntryWrapper implements Comparable<EntryWrapper>, DisplayableTreeViewerElement
+{
     private Object parent;
 
     private List<EntryWrapper> children;
@@ -59,345 +61,381 @@
     /** isBaseDN Flag */
     private boolean isBaseDN = false;
 
+
     /**
-         * Default constructor
-         * 
-         * @param sre
-         *                the Search Result Entry to wrap
-         */
-    public EntryWrapper(SearchResultEntry sre) {
-	this.sre = sre;
-
-	// Root DSE Special Case
-	if (sre.getObjectName().toString().equals("")) {
-	    setHasChildren(false);
-	}
+     * Default constructor
+     * 
+     * @param sre
+     *                the Search Result Entry to wrap
+     */
+    public EntryWrapper( SearchResultEntry sre )
+    {
+        this.sre = sre;
+
+        // Root DSE Special Case
+        if ( sre.getObjectName().toString().equals( "" ) )
+        {
+            setHasChildren( false );
+        }
     }
 
+
     /*
-         * (non-Javadoc)
-         * 
-         * @see org.apache.directory.ldapstudio.browser.view.views.wrappers.DisplayableTreeViewerElement#getDisplayName()
-         */
-    public String getDisplayName() {
-	if (isBaseDN()) {
-	    // Root DSE Special Case
-	    if (sre.getObjectName().toString().equals("")) {
-		return "Root DSE";
-	    }
-
-	    return sre.getObjectName().toString();
-	} else {
-	    return sre.getObjectName().getRdn().toString();
-	}
+     * (non-Javadoc)
+     * 
+     * @see org.apache.directory.ldapstudio.browser.view.views.wrappers.DisplayableTreeViewerElement#getDisplayName()
+     */
+    public String getDisplayName()
+    {
+        if ( isBaseDN() )
+        {
+            // Root DSE Special Case
+            if ( sre.getObjectName().toString().equals( "" ) )
+            {
+                return "Root DSE";
+            }
+
+            return sre.getObjectName().toString();
+        }
+        else
+        {
+            return sre.getObjectName().getRdn().toString();
+        }
     }
 
+
     /*
-         * (non-Javadoc)
-         * 
-         * @see org.apache.directory.ldapstudio.browser.view.views.wrappers.DisplayableTreeViewerElement#getDisplayImage()
-         */
-    public Image getDisplayImage() {
-	if (hasChildren()) {
-	    return AbstractUIPlugin.imageDescriptorFromPlugin(
-		    Activator.PLUGIN_ID, ImageKeys.FOLDER_ENTRY).createImage();
-	} else {
-	    return AbstractUIPlugin.imageDescriptorFromPlugin(
-		    Activator.PLUGIN_ID, ImageKeys.ENTRY).createImage();
-	}
+     * (non-Javadoc)
+     * 
+     * @see org.apache.directory.ldapstudio.browser.view.views.wrappers.DisplayableTreeViewerElement#getDisplayImage()
+     */
+    public Image getDisplayImage()
+    {
+        if ( hasChildren() )
+        {
+            return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, ImageKeys.FOLDER_ENTRY )
+                .createImage();
+        }
+        else
+        {
+            return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, ImageKeys.ENTRY ).createImage();
+        }
     }
 
+
     /**
-         * Gets the real entry
-         * 
-         * @return the real entry
-         */
-    public SearchResultEntry getEntry() {
-	return sre;
+     * Gets the real entry
+     * 
+     * @return the real entry
+     */
+    public SearchResultEntry getEntry()
+    {
+        return sre;
     }
 
+
     /**
-         * Gets the HasChildren Flag
-         * 
-         * @return
-         */
-    public boolean hasChildren() {
-	return hasChildren;
+     * Gets the HasChildren Flag
+     * 
+     * @return
+     */
+    public boolean hasChildren()
+    {
+        return hasChildren;
     }
 
+
     /**
-         * Sets the HasChildren Flag
-         * 
-         * @param hasChildren
-         *                the value of the flag
-         */
-    public void setHasChildren(boolean hasChildren) {
-	this.hasChildren = hasChildren;
+     * Sets the HasChildren Flag
+     * 
+     * @param hasChildren
+     *                the value of the flag
+     */
+    public void setHasChildren( boolean hasChildren )
+    {
+        this.hasChildren = hasChildren;
     }
 
+
     /**
-         * Gets the isBaseDN Flag
-         * 
-         * @return
-         */
-    public boolean isBaseDN() {
-	return isBaseDN;
+     * Gets the isBaseDN Flag
+     * 
+     * @return
+     */
+    public boolean isBaseDN()
+    {
+        return isBaseDN;
     }
 
+
     /**
-         * Sets the isBaseDN Flag
-         * 
-         * @param isBaseDN
-         *                the value of the flag
-         */
-    public void setIsBaseDN(boolean isBaseDN) {
-	this.isBaseDN = isBaseDN;
+     * Sets the isBaseDN Flag
+     * 
+     * @param isBaseDN
+     *                the value of the flag
+     */
+    public void setIsBaseDN( boolean isBaseDN )
+    {
+        this.isBaseDN = isBaseDN;
     }
 
+
     /*
-         * (non-Javadoc)
-         * 
-         * @see java.lang.Comparable#compareTo(java.lang.Object)
-         */
-    public int compareTo(EntryWrapper o) {
-	EntryWrapper otherWrapper = (EntryWrapper) o;
-	return getDisplayName().compareToIgnoreCase(
-		otherWrapper.getDisplayName());
-    }
-
-    public Connection getConnection() {
-	Object parent = getParent();
-	if (parent instanceof EntryWrapper) {
-	    return ((EntryWrapper) parent).getConnection();
-	} else if (parent instanceof ConnectionWrapper) {
-	    return ((ConnectionWrapper) parent).getConnection();
-	}
-	return null;
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    public int compareTo( EntryWrapper o )
+    {
+        EntryWrapper otherWrapper = ( EntryWrapper ) o;
+        return getDisplayName().compareToIgnoreCase( otherWrapper.getDisplayName() );
     }
 
-    /**
-         * Get parent object in the TreeViewer Hierarchy
-         * 
-         * @return the parent
-         */
-    public Object getParent() {
-	return parent;
+
+    public Connection getConnection()
+    {
+        Object parent = getParent();
+        if ( parent instanceof EntryWrapper )
+        {
+            return ( ( EntryWrapper ) parent ).getConnection();
+        }
+        else if ( parent instanceof ConnectionWrapper )
+        {
+            return ( ( ConnectionWrapper ) parent ).getConnection();
+        }
+        return null;
     }
 
+
     /**
-         * Set the parent object in the TreeViewer Hierarchy
-         * 
-         * @param parent
-         *                the parent element
-         */
-    public void setParent(Object parent) {
-	this.parent = parent;
+     * Get parent object in the TreeViewer Hierarchy
+     * 
+     * @return the parent
+     */
+    public Object getParent()
+    {
+        return parent;
     }
 
-    @Override
-    public boolean equals(Object obj) {
-	if (obj instanceof EntryWrapper) {
-	    EntryWrapper entryWrapper = (EntryWrapper) obj;
-
-	    return ((this.getConnection().equals(entryWrapper.getConnection())) && (this.sre
-		    .equals(entryWrapper.getEntry())));
-	}
 
-	return false;
+    /**
+     * Set the parent object in the TreeViewer Hierarchy
+     * 
+     * @param parent
+     *                the parent element
+     */
+    public void setParent( Object parent )
+    {
+        this.parent = parent;
     }
 
-    public Object[] getChildren() {
-	if (children == null) {
-	    children = new ArrayList<EntryWrapper>();
 
-	    try {
-		// Initialization of the DSML Engine and the DSML Response
-                // Parser
-		Dsmlv2Engine engine = getDsmlv2Engine();
-		Dsmlv2ResponseParser parser = new Dsmlv2ResponseParser();
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( obj instanceof EntryWrapper )
+        {
+            EntryWrapper entryWrapper = ( EntryWrapper ) obj;
 
-		String request = "<batchRequest>"
-			+ "	<searchRequest dn=\""
-			+ getEntry().getObjectName().getNormName()
-			+ "\""
-			+ "			scope=\"singleLevel\" derefAliases=\"neverDerefAliases\">"
-			+ "		<filter><present name=\"objectclass\"></present></filter>"
-			+ "       <attributes>" + "			<attribute name=\"*\"/>"
-			+ "			<attribute name=\"namingContexts\"/>"
-			+ "			<attribute name=\"subSchemaSubEntry\"/>"
-			+ "			<attribute name=\"altServer\"/>"
-			+ "			<attribute name=\"supportedExtension\"/>"
-			+ "			<attribute name=\"supportedControl\"/>"
-			+ "			<attribute name=\"supportedSaslMechanism\"/>"
-			+ "			<attribute name=\"supportedLdapVersion\"/>"
-			+ "       </attributes>" + "	</searchRequest>"
-			+ "</batchRequest>";
+            return ( ( this.getConnection().equals( entryWrapper.getConnection() ) ) && ( this.sre.equals( entryWrapper
+                .getEntry() ) ) );
+        }
 
-		// Executing the request and sending the result to the Response
-                // Parser
-		parser.setInput(engine.processDSML(request));
-		parser.parse();
+        return false;
+    }
 
-		LdapResponse ldapResponse = parser.getBatchResponse()
-			.getCurrentResponse();
 
-		if (ldapResponse instanceof ErrorResponse) {
-		    ErrorResponse errorResponse = ((ErrorResponse) ldapResponse);
+    public Object[] getChildren()
+    {
+        if ( children == null )
+        {
+            children = new ArrayList<EntryWrapper>();
 
-		    // Displaying an error
-		    MessageDialog.openError(PlatformUI.getWorkbench()
-			    .getActiveWorkbenchWindow().getShell(), "Error !",
-			    "An error has ocurred.\n"
-				    + errorResponse.getMessage());
-		    return null;
-		} else if (ldapResponse instanceof SearchResponse) {
-
-		    // Getting the Search Result Entry List containing our
-                        // objects for the response
-		    SearchResponse searchResponse = ((SearchResponse) ldapResponse);
-		    List<SearchResultEntry> sreList = searchResponse
-			    .getSearchResultEntryList();
-
-		    // Adding each Search Result Entry
-		    for (int i = 0; i < sreList.size(); i++) {
-			EntryWrapper entryWrapper = new EntryWrapper(sreList
-				.get(i));
-			entryWrapper.setParent(this);
-			children.add(entryWrapper);
-		    }
-
-		    // Sorting the list
-		    Collections.sort(children);
-
-		    boolean oldValue = hasChildren();
-
-		    // Updating the HasChildren Flag of the Entry
-		    setHasChildren((sreList.size() >= 1));
-
-		    // if the Value has changed, we update the UI to change
-                        // the icon.
-		    if (oldValue != hasChildren()) {
-			// Getting the Browser View
-			BrowserView browserView = (BrowserView) PlatformUI
-				.getWorkbench().getActiveWorkbenchWindow()
-				.getActivePage().findView(BrowserView.ID);
-
-			browserView.getViewer().update(this, null);
-		    }
-		}
-	    } catch (Exception e) {
-		// Displaying an error
-		MessageDialog.openError(PlatformUI.getWorkbench()
-			.getActiveWorkbenchWindow().getShell(), "Error !",
-			"An error has ocurred.\n" + e.getMessage());
-		return null;
-	    }
-	}
-
-	return children.toArray(new Object[0]);
-    }
-
-    /**
-         * Erases the Children List
-         */
-    public void clearChildren() {
-	children = null;
-	hasChildren = true;
-    }
-
-    /**
-         * Gets the Dsmlv2Engine
-         * 
-         * @return the Dsmlv2Engine
-         */
-    public Dsmlv2Engine getDsmlv2Engine() {
-	Object parent = getParent();
-
-	if (parent instanceof EntryWrapper) {
-	    return ((EntryWrapper) parent).getDsmlv2Engine();
-	} else if (parent instanceof ConnectionWrapper) {
-	    return ((ConnectionWrapper) parent).getDsmlv2Engine();
-	}
-
-	return null;
-    }
-
-    /**
-         * Refreshes the Entry Executes a request on the server to re-fecth the
-         * attributes of the entry and its children
-         */
-    public void refreshAttributes() {
-	try {
-	    // Initialization of the DSML Engine and the DSML Response
+            try
+            {
+                // Initialization of the DSML Engine and the DSML Response
                 // Parser
-	    Dsmlv2Engine engine = getDsmlv2Engine();
-	    Dsmlv2ResponseParser parser = new Dsmlv2ResponseParser();
+                Dsmlv2Engine engine = getDsmlv2Engine();
+                Dsmlv2ResponseParser parser = new Dsmlv2ResponseParser();
 
-	    String request = "<batchRequest>"
-		    + "   <searchRequest dn=\""
-		    + getEntry().getObjectName().getNormName()
-		    + "\""
-		    + "         scope=\"baseObject\" derefAliases=\"neverDerefAliases\">"
-		    + "     <filter><present name=\"objectclass\"></present></filter>"
-		    + "       <attributes>"
-		    + "         <attribute name=\"*\"/>"
-		    + "            <attribute name=\"namingContexts\"/>"
-		    + "         <attribute name=\"subSchemaSubEntry\"/>"
-		    + "            <attribute name=\"altServer\"/>"
-		    + "         <attribute name=\"supportedExtension\"/>"
-		    + "           <attribute name=\"supportedControl\"/>"
-		    + "         <attribute name=\"supportedSaslMechanism\"/>"
-		    + "           <attribute name=\"supportedLdapVersion\"/>"
-		    + "       </attributes>" + "    </searchRequest>"
-		    + "</batchRequest>";
+                String request = "<batchRequest>" + "	<searchRequest dn=\"" + getEntry().getObjectName().getNormName()
+                    + "\"" + "			scope=\"singleLevel\" derefAliases=\"neverDerefAliases\">"
+                    + "		<filter><present name=\"objectclass\"></present></filter>" + "       <attributes>"
+                    + "			<attribute name=\"*\"/>" + "			<attribute name=\"namingContexts\"/>"
+                    + "			<attribute name=\"subSchemaSubEntry\"/>" + "			<attribute name=\"altServer\"/>"
+                    + "			<attribute name=\"supportedExtension\"/>" + "			<attribute name=\"supportedControl\"/>"
+                    + "			<attribute name=\"supportedSaslMechanism\"/>"
+                    + "			<attribute name=\"supportedLdapVersion\"/>" + "       </attributes>" + "	</searchRequest>"
+                    + "</batchRequest>";
 
-	    // Executing the request and sending the result to the Response
+                // Executing the request and sending the result to the Response
                 // Parser
-	    parser.setInput(engine.processDSML(request));
-	    parser.parse();
+                parser.setInput( engine.processDSML( request ) );
+                parser.parse();
 
-	    LdapResponse ldapResponse = parser.getBatchResponse()
-		    .getCurrentResponse();
+                LdapResponse ldapResponse = parser.getBatchResponse().getCurrentResponse();
 
-	    if (ldapResponse instanceof ErrorResponse) {
-		ErrorResponse errorResponse = ((ErrorResponse) ldapResponse);
+                if ( ldapResponse instanceof ErrorResponse )
+                {
+                    ErrorResponse errorResponse = ( ( ErrorResponse ) ldapResponse );
+
+                    // Displaying an error
+                    MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+                        "Error !", "An error has ocurred.\n" + errorResponse.getMessage() );
+                    return null;
+                }
+                else if ( ldapResponse instanceof SearchResponse )
+                {
+
+                    // Getting the Search Result Entry List containing our
+                    // objects for the response
+                    SearchResponse searchResponse = ( ( SearchResponse ) ldapResponse );
+                    List<SearchResultEntry> sreList = searchResponse.getSearchResultEntryList();
+
+                    // Adding each Search Result Entry
+                    for ( int i = 0; i < sreList.size(); i++ )
+                    {
+                        EntryWrapper entryWrapper = new EntryWrapper( sreList.get( i ) );
+                        entryWrapper.setParent( this );
+                        children.add( entryWrapper );
+                    }
+
+                    // Sorting the list
+                    Collections.sort( children );
+
+                    boolean oldValue = hasChildren();
+
+                    // Updating the HasChildren Flag of the Entry
+                    setHasChildren( ( sreList.size() >= 1 ) );
+
+                    // if the Value has changed, we update the UI to change
+                    // the icon.
+                    if ( oldValue != hasChildren() )
+                    {
+                        // Getting the Browser View
+                        BrowserView browserView = ( BrowserView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+                            .getActivePage().findView( BrowserView.ID );
+
+                        browserView.getViewer().update( this, null );
+                    }
+                }
+            }
+            catch ( Exception e )
+            {
+                // Displaying an error
+                MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error !",
+                    "An error has ocurred.\n" + e.getMessage() );
+                return null;
+            }
+        }
+
+        return children.toArray( new Object[0] );
+    }
+
+
+    /**
+     * Erases the Children List
+     */
+    public void clearChildren()
+    {
+        children = null;
+        hasChildren = true;
+    }
+
+
+    /**
+     * Gets the Dsmlv2Engine
+     * 
+     * @return the Dsmlv2Engine
+     */
+    public Dsmlv2Engine getDsmlv2Engine()
+    {
+        Object parent = getParent();
+
+        if ( parent instanceof EntryWrapper )
+        {
+            return ( ( EntryWrapper ) parent ).getDsmlv2Engine();
+        }
+        else if ( parent instanceof ConnectionWrapper )
+        {
+            return ( ( ConnectionWrapper ) parent ).getDsmlv2Engine();
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Refreshes the Entry Executes a request on the server to re-fecth the
+     * attributes of the entry and its children
+     */
+    public void refreshAttributes()
+    {
+        try
+        {
+            // Initialization of the DSML Engine and the DSML Response
+            // Parser
+            Dsmlv2Engine engine = getDsmlv2Engine();
+            Dsmlv2ResponseParser parser = new Dsmlv2ResponseParser();
+
+            String request = "<batchRequest>" + "   <searchRequest dn=\"" + getEntry().getObjectName().getNormName()
+                + "\"" + "         scope=\"baseObject\" derefAliases=\"neverDerefAliases\">"
+                + "     <filter><present name=\"objectclass\"></present></filter>" + "       <attributes>"
+                + "         <attribute name=\"*\"/>" + "            <attribute name=\"namingContexts\"/>"
+                + "         <attribute name=\"subSchemaSubEntry\"/>" + "            <attribute name=\"altServer\"/>"
+                + "         <attribute name=\"supportedExtension\"/>"
+                + "           <attribute name=\"supportedControl\"/>"
+                + "         <attribute name=\"supportedSaslMechanism\"/>"
+                + "           <attribute name=\"supportedLdapVersion\"/>" + "       </attributes>"
+                + "    </searchRequest>" + "</batchRequest>";
+
+            // Executing the request and sending the result to the Response
+            // Parser
+            parser.setInput( engine.processDSML( request ) );
+            parser.parse();
+
+            LdapResponse ldapResponse = parser.getBatchResponse().getCurrentResponse();
+
+            if ( ldapResponse instanceof ErrorResponse )
+            {
+                ErrorResponse errorResponse = ( ( ErrorResponse ) ldapResponse );
+
+                // Displaying an error
+                MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error !",
+                    "An error has ocurred.\n" + errorResponse.getMessage() );
 
-		// Displaying an error
-		MessageDialog.openError(PlatformUI.getWorkbench()
-			.getActiveWorkbenchWindow().getShell(), "Error !",
-			"An error has ocurred.\n" + errorResponse.getMessage());
-
-		// Creating an empty children list (this prevents the refresh to
+                // Creating an empty children list (this prevents the refresh to
                 // getting a new error)
-		children = new ArrayList<EntryWrapper>(0);
+                children = new ArrayList<EntryWrapper>( 0 );
 
-		return;
-	    } else if (ldapResponse instanceof SearchResponse) {
+                return;
+            }
+            else if ( ldapResponse instanceof SearchResponse )
+            {
 
-		// Getting the Search Result Entry List containing our objects
+                // Getting the Search Result Entry List containing our objects
                 // for the response
-		SearchResponse searchResponse = ((SearchResponse) ldapResponse);
-
-		SearchResultEntry sre = searchResponse
-			.getSearchResultEntryList().get(0);
+                SearchResponse searchResponse = ( ( SearchResponse ) ldapResponse );
 
-		getEntry().setPartialAttributeList(
-			sre.getPartialAttributeList());
-		return;
-	    }
-	} catch (Exception e) {
-	    // Displaying an error
-	    MessageDialog.openError(PlatformUI.getWorkbench()
-		    .getActiveWorkbenchWindow().getShell(), "Error !",
-		    "An error has ocurred.\n" + e.getMessage());
+                SearchResultEntry sre = searchResponse.getSearchResultEntryList().get( 0 );
 
-	    // Creating an empty children list (this prevents the refresh to
-                // getting a new error)
-	    children = new ArrayList<EntryWrapper>(0);
+                getEntry().setPartialAttributeList( sre.getPartialAttributeList() );
+                return;
+            }
+        }
+        catch ( Exception e )
+        {
+            // Displaying an error
+            MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error !",
+                "An error has ocurred.\n" + e.getMessage() );
+
+            // Creating an empty children list (this prevents the refresh to
+            // getting a new error)
+            children = new ArrayList<EntryWrapper>( 0 );
 
-	    return;
-	}
+            return;
+        }
 
-	clearChildren();
+        clearChildren();
     }
 }

Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-ldapbrowser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/TreeViewerRootNode.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-ldapbrowser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/TreeViewerRootNode.java?view=diff&rev=488371&r1=488370&r2=488371
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-ldapbrowser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/TreeViewerRootNode.java (original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-ldapbrowser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/TreeViewerRootNode.java Mon Dec 18 09:57:38 2006
@@ -20,6 +20,7 @@
 
 package org.apache.directory.ldapstudio.browser.view.views.wrappers;
 
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -32,12 +33,14 @@
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.PlatformUI;
 
+
 /**
  * This class represents the Root Node of the Browser View Table
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class TreeViewerRootNode implements DisplayableTreeViewerElement {
+public class TreeViewerRootNode implements DisplayableTreeViewerElement
+{
     private List<ConnectionWrapper> children;
 
     private static TreeViewerRootNode instance;
@@ -45,111 +48,138 @@
     private Connections connections;
 
     // Static thread-safe singleton initializer
-    static {
-	try {
-	    instance = new TreeViewerRootNode();
-	} catch (Throwable e) {
-	    throw new RuntimeException(e.getMessage());
-	}
+    static
+    {
+        try
+        {
+            instance = new TreeViewerRootNode();
+        }
+        catch ( Throwable e )
+        {
+            throw new RuntimeException( e.getMessage() );
+        }
     }
 
+
     /**
-         * Use this method to get the singleton instance of the Root Node
-         * 
-         * @return
-         */
-    public static TreeViewerRootNode getInstance() {
-	return instance;
-    }
-
-    private TreeViewerRootNode() {
-	connections = Connections.getInstance();
-    }
-
-    public Object[] getChildren() {
-	if (children == null) {
-	    children = new ArrayList<ConnectionWrapper>();
-
-	    // Sorting the connections
-	    connections.sort();
-
-	    // Adding each Connection
-	    for (int i = 0; i < connections.size(); i++) {
-		ConnectionWrapper connectionWrapper = new ConnectionWrapper(
-			connections.getConnection(i));
-
-		connectionWrapper.setParent(this);
-
-		children.add(connectionWrapper);
-	    }
-	}
-
-	return children.toArray(new Object[0]);
-    }
-
-    public void updateChildren(ConnectionsEvent event) {
-	// Getting the Browser View
-	BrowserView browserView = (BrowserView) PlatformUI.getWorkbench()
-		.getActiveWorkbenchWindow().getActivePage().findView(
-			BrowserView.ID);
-
-	// A CONNECTION HAS BEEN ADDED
-	if (event.getType().equals(ConnectionsEventType.ADD)) {
-	    // Adding the new connection
-	    children.add(new ConnectionWrapper(event.getConnection()));
-
-	    // Sorting
-	    Collections.sort(children);
-	}
-	// A CONNECTION HAS BEEN UPDATED
-	else if (event.getType().equals(ConnectionsEventType.UPDATE)) {
-	    // Searching for the correct ConnectionWrapper Node.
-	    for (ConnectionWrapper connectionWrapper : children) {
-		if (event.getConnection().equals(
-			connectionWrapper.getConnection())) {
-		    // Updating the node
-		    browserView.getViewer().update(connectionWrapper, null);
-		}
-	    }
-
-	    // Sorting
-	    Collections.sort(children);
-	}
-	// A CONNECTION HAS BEEN REMOVED
-	else if (event.getType().equals(ConnectionsEventType.REMOVE)) {
-	    // Searching for the correct ConnectionWrapper Node.
-	    for (ConnectionWrapper connectionWrapper : children) {
-		if (event.getConnection().equals(
-			connectionWrapper.getConnection())) {
-		    children.remove(connectionWrapper);
-		    break;
-		}
-	    }
-	}
-    }
-
-    public Connection getConnection() {
-	// The root element is not linked to any connection
-	return null;
-    }
-
-    public Image getDisplayImage() {
-	// No image to display
-	return null;
-    }
-
-    public String getDisplayName() {
-	// No name to display
-	return null;
-    }
-
-    public Object getParent() {
-	// This is root element, so it has no parent
-	return null;
+     * Use this method to get the singleton instance of the Root Node
+     * 
+     * @return
+     */
+    public static TreeViewerRootNode getInstance()
+    {
+        return instance;
     }
 
-    public void setParent(Object parent) {
-	// Nothing to do, since the root element has no parent
+
+    private TreeViewerRootNode()
+    {
+        connections = Connections.getInstance();
+    }
+
+
+    public Object[] getChildren()
+    {
+        if ( children == null )
+        {
+            children = new ArrayList<ConnectionWrapper>();
+
+            // Sorting the connections
+            connections.sort();
+
+            // Adding each Connection
+            for ( int i = 0; i < connections.size(); i++ )
+            {
+                ConnectionWrapper connectionWrapper = new ConnectionWrapper( connections.getConnection( i ) );
+
+                connectionWrapper.setParent( this );
+
+                children.add( connectionWrapper );
+            }
+        }
+
+        return children.toArray( new Object[0] );
+    }
+
+
+    public void updateChildren( ConnectionsEvent event )
+    {
+        // Getting the Browser View
+        BrowserView browserView = ( BrowserView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+            .findView( BrowserView.ID );
+
+        // A CONNECTION HAS BEEN ADDED
+        if ( event.getType().equals( ConnectionsEventType.ADD ) )
+        {
+            // Adding the new connection
+            children.add( new ConnectionWrapper( event.getConnection() ) );
+
+            // Sorting
+            Collections.sort( children );
+        }
+        // A CONNECTION HAS BEEN UPDATED
+        else if ( event.getType().equals( ConnectionsEventType.UPDATE ) )
+        {
+            // Searching for the correct ConnectionWrapper Node.
+            for ( ConnectionWrapper connectionWrapper : children )
+            {
+                if ( event.getConnection().equals( connectionWrapper.getConnection() ) )
+                {
+                    // Updating the node
+                    browserView.getViewer().update( connectionWrapper, null );
+                }
+            }
+
+            // Sorting
+            Collections.sort( children );
+        }
+        // A CONNECTION HAS BEEN REMOVED
+        else if ( event.getType().equals( ConnectionsEventType.REMOVE ) )
+        {
+            // Searching for the correct ConnectionWrapper Node.
+            for ( ConnectionWrapper connectionWrapper : children )
+            {
+                if ( event.getConnection().equals( connectionWrapper.getConnection() ) )
+                {
+                    children.remove( connectionWrapper );
+                    break;
+                }
+            }
+        }
+    }
+
+
+    public Connection getConnection()
+    {
+        // The root element is not linked to any connection
+        return null;
+    }
+
+
+    public Image getDisplayImage()
+    {
+        // No image to display
+        return null;
+    }
+
+
+    public String getDisplayName()
+    {
+        // No name to display
+        return null;
+    }
+
+
+    public Object getParent()
+    {
+        // This is root element, so it has no parent
+        return null;
+    }
+
+
+    public void setParent( Object parent )
+    {
+        // Nothing to do, since the root element has no parent
     }
 
 }