You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/04/09 11:49:57 UTC

svn commit: r526693 [10/17] - in /directory/ldapstudio/trunk/ldapstudio-browser-common: ./ META-INF/ resources/ resources/icons/ resources/templates/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/di...

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserActionGroup.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserActionGroup.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserActionGroup.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserActionGroup.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,310 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.common.actions.CollapseAllAction;
+import org.apache.directory.ldapstudio.browser.common.actions.FilterChildrenAction;
+import org.apache.directory.ldapstudio.browser.common.actions.PropertiesAction;
+import org.apache.directory.ldapstudio.browser.common.actions.RefreshAction;
+import org.apache.directory.ldapstudio.browser.common.actions.UnfilterChildrenAction;
+import org.apache.directory.ldapstudio.browser.common.actions.UpAction;
+import org.apache.directory.ldapstudio.browser.common.actions.proxy.BrowserViewActionProxy;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.commands.ICommandService;
+
+
+/**
+ * This class manages all the actions of the browser widget.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserActionGroup implements IMenuListener
+{
+
+    /** The open sort dialog action. */
+    protected OpenSortDialogAction openSortDialogAction;
+
+    /** The collapse all action. */
+    protected CollapseAllAction collapseAllAction;
+
+    /** The Constant upAction. */
+    protected static final String upAction = "upAction";
+
+    /** The Constant refreshAction. */
+    protected static final String refreshAction = "refreshAction";
+
+    /** The Constant filterChildrenAction. */
+    protected static final String filterChildrenAction = "filterChildrenAction";
+
+    /** The Constant unfilterChildrenAction. */
+    protected static final String unfilterChildrenAction = "unfilterChildrenAction";
+
+    /** The Constant propertyDialogAction. */
+    protected static final String propertyDialogAction = "propertyDialogAction";
+
+    /** The browser action map. */
+    protected Map<String, BrowserViewActionProxy> browserActionMap;
+
+    /** The action bars. */
+    protected IActionBars actionBars;
+
+    /** The browser's main widget. */
+    protected BrowserWidget mainWidget;
+
+
+    /**
+     * Creates a new instance of BrowserActionGroup.
+     *
+     * @param mainWidget the browser's main widget
+     * @param configuration the  browser's configuration
+     */
+    public BrowserActionGroup( BrowserWidget mainWidget, BrowserConfiguration configuration )
+    {
+        this.mainWidget = mainWidget;
+        this.browserActionMap = new HashMap<String, BrowserViewActionProxy>();
+
+        TreeViewer viewer = mainWidget.getViewer();
+        openSortDialogAction = new OpenSortDialogAction( ( BrowserPreferences ) configuration.getPreferences() );
+        collapseAllAction = new CollapseAllAction( viewer );
+
+        browserActionMap.put( upAction, new BrowserViewActionProxy( viewer, new UpAction( viewer ) ) );
+        browserActionMap.put( refreshAction, new BrowserViewActionProxy( viewer, new RefreshAction() ) );
+        browserActionMap.put( filterChildrenAction, new BrowserViewActionProxy( viewer, new FilterChildrenAction() ) );
+        browserActionMap
+            .put( unfilterChildrenAction, new BrowserViewActionProxy( viewer, new UnfilterChildrenAction() ) );
+        browserActionMap.put( propertyDialogAction, new BrowserViewActionProxy( viewer, new PropertiesAction() ) );
+    }
+
+
+    /**
+     * Disposes this action group.
+     */
+    public void dispose()
+    {
+        if ( mainWidget != null )
+        {
+
+            openSortDialogAction.dispose();
+            openSortDialogAction = null;
+            collapseAllAction.dispose();
+            collapseAllAction = null;
+
+            for ( Iterator it = browserActionMap.keySet().iterator(); it.hasNext(); )
+            {
+                String key = ( String ) it.next();
+                BrowserViewActionProxy action = ( BrowserViewActionProxy ) browserActionMap.get( key );
+                action.dispose();
+                action = null;
+                it.remove();
+            }
+            browserActionMap.clear();
+            browserActionMap = null;
+
+            actionBars = null;
+            mainWidget = null;
+        }
+    }
+
+
+    /**
+     * Enables the action handlers.
+     *
+     * @param actionBars the action bars
+     */
+    public void enableGlobalActionHandlers( IActionBars actionBars )
+    {
+        this.actionBars = actionBars;
+        activateGlobalActionHandlers();
+    }
+
+
+    /**
+     * Fills the tool bar.
+     *
+     * @param toolBarManager the tool bar manager
+     */
+    public void fillToolBar( IToolBarManager toolBarManager )
+    {
+        toolBarManager.add( ( IAction ) browserActionMap.get( upAction ) );
+        toolBarManager.add( new Separator() );
+        toolBarManager.add( collapseAllAction );
+        toolBarManager.add( ( IAction ) browserActionMap.get( refreshAction ) );
+        toolBarManager.update( true );
+    }
+
+
+    /**
+     * Fills the local menu.
+     *
+     * @param menuManager the local menu manager
+     */
+    public void fillMenu( IMenuManager menuManager )
+    {
+        menuManager.add( openSortDialogAction );
+        menuManager.add( new Separator() );
+        menuManager.update( true );
+    }
+
+
+    /**
+     * Fills the context menu.
+     *
+     * @param menuManager the context menu manager
+     */
+    public void fillContextMenu( IMenuManager menuManager )
+    {
+        menuManager.setRemoveAllWhenShown( true );
+        menuManager.addMenuListener( this );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     * 
+     * This implementation fills the context menu.
+     */
+    public void menuAboutToShow( IMenuManager menuManager )
+    {
+        // up
+        menuManager.add( ( IAction ) browserActionMap.get( upAction ) );
+        menuManager.add( new Separator() );
+
+        // filter
+        menuManager.add( ( IAction ) browserActionMap.get( filterChildrenAction ) );
+        if ( ( ( IAction ) browserActionMap.get( unfilterChildrenAction ) ).isEnabled() )
+        {
+            menuManager.add( ( IAction ) browserActionMap.get( unfilterChildrenAction ) );
+        }
+        menuManager.add( new Separator() );
+
+        // refresh
+        menuManager.add( ( IAction ) browserActionMap.get( refreshAction ) );
+        menuManager.add( new Separator() );
+
+        // properties
+        menuManager.add( ( IAction ) browserActionMap.get( propertyDialogAction ) );
+    }
+
+
+    /**
+     * Activates the action handlers.
+     */
+    public void activateGlobalActionHandlers()
+    {
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.REFRESH.getId(), ( IAction ) browserActionMap
+                .get( refreshAction ) );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), ( IAction ) browserActionMap
+                .get( propertyDialogAction ) );
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction pda = ( IAction ) browserActionMap.get( propertyDialogAction );
+                pda.setActionDefinitionId( "org.apache.directory.ldapstudio.browser.action.properties" );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( new ActionHandler( pda ) );
+
+                IAction ra = ( IAction ) browserActionMap.get( refreshAction );
+                commandService.getCommand( ra.getActionDefinitionId() ).setHandler( new ActionHandler( ra ) );
+            }
+        }
+
+        if ( commandService != null )
+        {
+            IAction ua = ( IAction ) browserActionMap.get( upAction );
+            commandService.getCommand( ua.getActionDefinitionId() ).setHandler( new ActionHandler( ua ) );
+        }
+    }
+
+
+    /**
+     * Deactivates the action handlers.
+     */
+    public void deactivateGlobalActionHandlers()
+    {
+
+        ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter(
+            ICommandService.class );
+
+        if ( actionBars != null )
+        {
+            actionBars.setGlobalActionHandler( ActionFactory.REFRESH.getId(), null );
+            actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), null );
+            actionBars.updateActionBars();
+        }
+        else
+        {
+            if ( commandService != null )
+            {
+                IAction pda = ( IAction ) browserActionMap.get( propertyDialogAction );
+                commandService.getCommand( pda.getActionDefinitionId() ).setHandler( null );
+
+                IAction ra = ( IAction ) browserActionMap.get( refreshAction );
+                commandService.getCommand( ra.getActionDefinitionId() ).setHandler( null );
+            }
+        }
+
+        if ( commandService != null )
+        {
+            IAction ua = ( IAction ) browserActionMap.get( upAction );
+            commandService.getCommand( ua.getActionDefinitionId() ).setHandler( null );
+        }
+
+    }
+
+
+    /**
+     * Sets the connection input to all actions
+     *
+     * @param connection the connection
+     */
+    public void setInput( IConnection connection )
+    {
+        for ( Iterator it = browserActionMap.values().iterator(); it.hasNext(); )
+        {
+            BrowserViewActionProxy action = ( BrowserViewActionProxy ) it.next();
+            action.inputChanged( connection );
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserCategory.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserCategory.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserCategory.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserCategory.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,121 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+
+
+/**
+ * A BrowserCategory is the top-level node in the browser widget. 
+ * There are three types: DIT categories, searches categories
+ * and bookmarks categories.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserCategory
+{
+
+    /** The Constant TYPE_DIT identifies DIT categories. */
+    public static final int TYPE_DIT = 0;
+
+    /** The Constant TYPE_SEARCHES identifies searches categories. */
+    public static final int TYPE_SEARCHES = 1;
+
+    /** The Constant TYPE_BOOKMARKS identifies bookmark categories. */
+    public static final int TYPE_BOOKMARKS = 2;
+
+    /** The title for the DIT categoy */
+    public static final String TITLE_DIT = "DIT";
+
+    /** The title for the searches categoy */
+    public static final String TITLE_SEARCHES = "Searches";
+
+    /** The title for the bookmarks categoy */
+    public static final String TITLE_BOOKMARKS = "Bookmarks";
+
+    /** The category's connection */
+    private IConnection parent;
+
+    /** The category's type */
+    private int type;
+
+
+    /**
+     * Creates a new instance of BrowserCategory.
+     *
+     * @param type the category's type, one of TYPE_DIT, TYPE_SEARCHES or TYPE_BOOKMARKS
+     * @param parent the category's connection
+     */
+    public BrowserCategory( int type, IConnection parent )
+    {
+        this.parent = parent;
+        this.type = type;
+    }
+
+
+    /**
+     * Gets the category's parent, which is always a connection.
+     * 
+     * @return the parent connection
+     */
+    public IConnection getParent()
+    {
+        return parent;
+    }
+
+
+    /**
+     * Gets the category's type, one of TYPE_DIT, TYPE_SEARCHES or TYPE_BOOKMARKS.
+     *
+     * @return the category's type.
+     */
+    public int getType()
+    {
+        return type;
+    }
+
+
+    /**
+     * Gets the category's title.
+     *
+     * @return the category's title
+     */
+    public String getTitle()
+    {
+        switch ( type )
+        {
+            case TYPE_DIT:
+                return TITLE_DIT;
+
+            case TYPE_SEARCHES:
+                return TITLE_SEARCHES;
+
+            case TYPE_BOOKMARKS:
+                return TITLE_BOOKMARKS;
+
+            default:
+                return "ERROR";
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserConfiguration.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserConfiguration.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserConfiguration.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserConfiguration.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,206 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Menu;
+
+
+/**
+ * The BrowserConfiguration contains the content provider, the
+ * label provider, the sorter, the context menu manager and the
+ * preferences for the browser widget. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserConfiguration
+{
+
+    /** The disposed flag */
+    private boolean disposed = false;
+
+    /** The sorter. */
+    protected BrowserSorter sorter;
+
+    /** The preferences. */
+    protected BrowserPreferences preferences;
+
+    /** The content provider. */
+    protected BrowserContentProvider contentProvider;
+
+    /** The label provider. */
+    protected BrowserLabelProvider labelProvider;
+
+    /** The decorating label provider. */
+    protected DecoratingLabelProvider decoratingLabelProvider;
+
+    /** The context menu manager. */
+    protected MenuManager contextMenuManager;
+
+
+    /**
+     * Creates a new instance of BrowserConfiguration.
+     */
+    public BrowserConfiguration()
+    {
+    }
+
+
+    /**
+     * Disposes this configuration.
+     */
+    public void dispose()
+    {
+        if ( !disposed )
+        {
+            if ( sorter != null )
+            {
+                sorter.dispose();
+                sorter = null;
+            }
+
+            if ( preferences != null )
+            {
+                preferences.dispose();
+                preferences = null;
+            }
+
+            if ( contentProvider != null )
+            {
+                contentProvider.dispose();
+                contentProvider = null;
+            }
+
+            if ( labelProvider != null )
+            {
+                labelProvider.dispose();
+                labelProvider = null;
+                decoratingLabelProvider.dispose();
+                decoratingLabelProvider = null;
+            }
+
+            if ( contextMenuManager != null )
+            {
+                contextMenuManager.dispose();
+                contextMenuManager = null;
+            }
+
+            disposed = true;
+        }
+    }
+
+
+    /**
+     * Gets the context menu manager.
+     * 
+     * @param viewer the browser widget's tree viewer 
+     * 
+     * @return the context menu manager
+     */
+    public IMenuManager getContextMenuManager( TreeViewer viewer )
+    {
+        if ( contextMenuManager == null )
+        {
+            contextMenuManager = new MenuManager();
+            Menu menu = contextMenuManager.createContextMenu( viewer.getControl() );
+            viewer.getControl().setMenu( menu );
+        }
+
+        return contextMenuManager;
+    }
+
+
+    /**
+     * Gets the content provider.
+     * 
+     * @param viewer the browser widget's tree viewer 
+     * 
+     * @return the content provider
+     */
+    public BrowserContentProvider getContentProvider( TreeViewer viewer )
+    {
+        if ( contentProvider == null )
+        {
+            contentProvider = new BrowserContentProvider( getPreferences(), getSorter() );
+        }
+
+        return contentProvider;
+    }
+
+
+    /**
+     * Gets the label provider.
+     * 
+     * @param viewer the browser widget's tree viewer 
+     * 
+     * @return the label provider
+     */
+    public DecoratingLabelProvider getLabelProvider( TreeViewer viewer )
+    {
+        if ( labelProvider == null )
+        {
+            labelProvider = new BrowserLabelProvider( getPreferences() );
+            decoratingLabelProvider = new DecoratingLabelProvider( labelProvider, BrowserCommonActivator.getDefault().getWorkbench()
+                .getDecoratorManager().getLabelDecorator() );
+        }
+
+        return decoratingLabelProvider;
+    }
+
+
+    /**
+     * Gets the sorter.
+     * 
+     * @return the sorter
+     */
+    public BrowserSorter getSorter()
+    {
+        if ( sorter == null )
+        {
+            sorter = new BrowserSorter( getPreferences() );
+        }
+
+        return sorter;
+    }
+
+
+    /**
+     * Gets the preferences.
+     * 
+     * @return the preferences
+     */
+    public BrowserPreferences getPreferences()
+    {
+        if ( preferences == null )
+        {
+            preferences = new BrowserPreferences();
+        }
+
+        return preferences;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserContentProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserContentProvider.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserContentProvider.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserContentProvider.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,554 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.internal.model.DirectoryMetadataEntry;
+import org.apache.directory.ldapstudio.browser.core.jobs.InitializeChildrenJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.OpenConnectionsJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.SearchJob;
+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.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * The BrowserContentProvider implements the content provider for
+ * the browser widget. It accepts an IConnection as input.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserContentProvider implements ITreeContentProvider
+{
+
+    /** The prefernces */
+    protected BrowserPreferences preferences;
+
+    /** The sorter */
+    protected BrowserSorter sorter;
+
+    /** This map contains the pages for entries with many children (if folding is activated) */
+    private Map<IEntry, BrowserEntryPage[]> entryToEntryPagesMap;
+
+    /** This map contains the pages for searches with many results (if folding is activated) */
+    private Map<ISearch, BrowserSearchResultPage[]> searchToSearchResultPagesMap;
+
+    /** This map contains the top-level categories for each connection */
+    private Map<IConnection, BrowserCategory[]> connectionToCategoriesMap;
+
+
+    /**
+     * Creates a new instance of BrowserContentProvider.
+     *
+     * @param preferences the preferences
+     * @param sorter the sorter
+     */
+    public BrowserContentProvider( BrowserPreferences preferences, BrowserSorter sorter )
+    {
+        this.preferences = preferences;
+        this.sorter = sorter;
+        this.entryToEntryPagesMap = new HashMap<IEntry, BrowserEntryPage[]>();
+        this.searchToSearchResultPagesMap = new HashMap<ISearch, BrowserSearchResultPage[]>();
+        this.connectionToCategoriesMap = new HashMap<IConnection, BrowserCategory[]>();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void inputChanged( Viewer v, Object oldInput, Object newInput )
+    {
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose()
+    {
+        if ( entryToEntryPagesMap != null )
+        {
+            entryToEntryPagesMap.clear();
+            entryToEntryPagesMap = null;
+        }
+        if ( searchToSearchResultPagesMap != null )
+        {
+            searchToSearchResultPagesMap.clear();
+            searchToSearchResultPagesMap = null;
+        }
+        if ( connectionToCategoriesMap != null )
+        {
+            connectionToCategoriesMap.clear();
+            connectionToCategoriesMap = null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object[] getElements( Object parent )
+    {
+        if ( parent instanceof IConnection )
+        {
+            IConnection connection = ( IConnection ) parent;
+            if ( !connectionToCategoriesMap.containsKey( connection ) )
+            {
+                BrowserCategory[] categories = new BrowserCategory[3];
+                categories[0] = new BrowserCategory( BrowserCategory.TYPE_DIT, connection );
+                categories[1] = new BrowserCategory( BrowserCategory.TYPE_SEARCHES, connection );
+                categories[2] = new BrowserCategory( BrowserCategory.TYPE_BOOKMARKS, connection );
+                connectionToCategoriesMap.put( connection, categories );
+            }
+
+            BrowserCategory[] categories = connectionToCategoriesMap.get( connection );
+
+            List<BrowserCategory> catList = new ArrayList<BrowserCategory>( 3 );
+            if ( preferences.isShowDIT() )
+            {
+                catList.add( categories[0] );
+            }
+            if ( preferences.isShowSearches() )
+            {
+                catList.add( categories[1] );
+            }
+            if ( preferences.isShowBookmarks() )
+            {
+                catList.add( categories[2] );
+            }
+
+            return catList.toArray( new BrowserCategory[0] );
+        }
+        else if ( parent instanceof IEntry[] )
+        {
+            return ( IEntry[] ) parent;
+        }
+        else
+        {
+            return getChildren( parent );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object getParent( final Object child )
+    {
+        if ( child instanceof BrowserCategory )
+        {
+            return ( ( BrowserCategory ) child ).getParent();
+        }
+        else if ( child instanceof BrowserEntryPage )
+        {
+            return ( ( BrowserEntryPage ) child ).getParent();
+        }
+        else if ( child instanceof IEntry )
+        {
+            IEntry parentEntry = ( ( IEntry ) child ).getParententry();
+            if ( parentEntry == null )
+            {
+                if ( connectionToCategoriesMap.get( ( ( IEntry ) child ).getConnection() ) != null )
+                {
+                    return connectionToCategoriesMap.get( ( ( IEntry ) child ).getConnection() )[0];
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            else if ( entryToEntryPagesMap.containsKey( parentEntry ) )
+            {
+                BrowserEntryPage[] entryPages = entryToEntryPagesMap.get( parentEntry );
+                BrowserEntryPage ep = null;
+                for ( int i = 0; i < entryPages.length && ep == null; i++ )
+                {
+                    ep = entryPages[i].getParentOf( ( IEntry ) child );
+                }
+                return ep;
+            }
+            else
+            {
+                return parentEntry;
+            }
+        }
+        else if ( child instanceof BrowserSearchResultPage )
+        {
+            return ( ( BrowserSearchResultPage ) child ).getParent();
+        }
+        else if ( child instanceof ISearch )
+        {
+            ISearch search = ( ( ISearch ) child );
+            return connectionToCategoriesMap.get( search.getConnection() )[1];
+        }
+        else if ( child instanceof ISearchResult )
+        {
+            ISearch parentSearch = ( ( ISearchResult ) child ).getSearch();
+            if ( parentSearch != null && searchToSearchResultPagesMap.containsKey( parentSearch ) )
+            {
+                BrowserSearchResultPage[] srPages = searchToSearchResultPagesMap.get( parentSearch );
+                BrowserSearchResultPage srp = null;
+                for ( int i = 0; i < srPages.length && srp == null; i++ )
+                {
+                    srp = srPages[i].getParentOf( ( ISearchResult ) child );
+                }
+                return srp;
+            }
+            else
+            {
+                return parentSearch;
+            }
+        }
+        else if ( child instanceof IBookmark )
+        {
+            IBookmark bookmark = ( ( IBookmark ) child );
+            return connectionToCategoriesMap.get( bookmark.getConnection() )[2];
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object[] getChildren( Object parent )
+    {
+        if ( parent instanceof BrowserEntryPage )
+        {
+            BrowserEntryPage entryPage = ( BrowserEntryPage ) parent;
+            Object[] objects = entryPage.getChildren();
+            if ( objects == null )
+            {
+                return new String[]
+                    { "Fetching Entries..." };
+            }
+            else if ( objects instanceof IEntry[] )
+            {
+                IEntry[] entries = ( IEntry[] ) objects;
+                return entries;
+            }
+            else
+            {
+                return objects;
+            }
+        }
+        else if ( parent instanceof IRootDSE )
+        {
+            final IRootDSE rootDSE = ( IRootDSE ) parent;
+
+            if ( !rootDSE.isChildrenInitialized() && rootDSE.isDirectoryEntry() )
+            {
+                new InitializeChildrenJob( new IEntry[]
+                    { rootDSE } ).execute();
+                return new String[]
+                    { "Fetching Entries..." };
+            }
+
+            // get base entries
+            List<IEntry> entryList = new ArrayList<IEntry>();
+            entryList.addAll( Arrays.asList( rootDSE.getChildren() ) );
+
+            // remove non-visible entries
+            for ( Iterator<IEntry> it = entryList.iterator(); it.hasNext(); )
+            {
+                Object o = it.next();
+                if ( !preferences.isShowDirectoryMetaEntries() && ( o instanceof DirectoryMetadataEntry ) )
+                {
+                    it.remove();
+                }
+            }
+
+            return entryList.toArray();
+        }
+        else if ( parent instanceof IEntry )
+            {
+                final IEntry parentEntry = ( IEntry ) parent;
+
+            if ( !parentEntry.isChildrenInitialized() && parentEntry.isDirectoryEntry() )
+            {
+                new InitializeChildrenJob( new IEntry[]
+                    { parentEntry } ).execute();
+                return new String[]
+                    { "Fetching Entries..." };
+            }
+
+            int childrenCount = parentEntry.getChildrenCount();
+            if ( childrenCount <= preferences.getFoldingSize() || !preferences.isUseFolding() )
+            {
+                if ( entryToEntryPagesMap.containsKey( parentEntry ) )
+                {
+                    entryToEntryPagesMap.remove( parentEntry );
+                }
+
+                IEntry[] entries = parentEntry.getChildren();
+                if ( entries == null )
+                {
+                    return new String[]
+                        { "Fetching Entries..." };
+                }
+                else
+                {
+                    return entries;
+                }
+            }
+            else
+            {
+                BrowserEntryPage[] entryPages = null;
+                if ( !entryToEntryPagesMap.containsKey( parentEntry ) )
+                {
+                    entryPages = getEntryPages( parentEntry, 0, childrenCount - 1 );
+                    entryToEntryPagesMap.put( parentEntry, entryPages );
+                }
+                else
+                {
+                    entryPages = entryToEntryPagesMap.get( parentEntry );
+                    if ( childrenCount - 1 != entryPages[entryPages.length - 1].getLast() )
+                    {
+                        entryPages = getEntryPages( parentEntry, 0, childrenCount - 1 );
+                        entryToEntryPagesMap.put( parentEntry, entryPages );
+                    }
+                }
+                return entryPages;
+            }
+        }
+        else if ( parent instanceof BrowserSearchResultPage )
+        {
+            BrowserSearchResultPage srPage = ( BrowserSearchResultPage ) parent;
+            Object[] objects = srPage.getChildren();
+            if ( objects == null )
+            {
+                return new String[]
+                    { "Fetching Search Results..." };
+            }
+            else if ( objects instanceof ISearchResult[] )
+            {
+                ISearchResult[] srs = ( ISearchResult[] ) objects;
+                return srs;
+            }
+            else
+            {
+                return objects;
+            }
+        }
+        else if ( parent instanceof ISearch )
+        {
+            ISearch search = ( ISearch ) parent;
+            if ( search.getSearchResults() == null )
+            {
+                new SearchJob( new ISearch[]
+                    { search } ).execute();
+                return new String[]
+                    { "Performing Search..." };
+            }
+            else if ( search.getSearchResults().length == 0 )
+            {
+                return new String[]
+                    { "No Results" };
+            }
+            else if ( search.getSearchResults().length <= preferences.getFoldingSize() || !preferences.isUseFolding() )
+            {
+                ISearchResult[] results = search.getSearchResults();
+                return results;
+            }
+            else
+            {
+                BrowserSearchResultPage[] srPages = null;
+                if ( !searchToSearchResultPagesMap.containsKey( search ) )
+                {
+                    srPages = getSearchResultPages( search, 0, search.getSearchResults().length - 1 );
+                    searchToSearchResultPagesMap.put( search, srPages );
+                }
+                else
+                {
+                    srPages = searchToSearchResultPagesMap.get( search );
+                    if ( search.getSearchResults().length - 1 != srPages[srPages.length - 1].getLast() )
+                    {
+                        srPages = getSearchResultPages( search, 0, search.getSearchResults().length - 1 );
+                        searchToSearchResultPagesMap.put( search, srPages );
+                    }
+                }
+                return srPages;
+            }
+        }
+        else if ( parent instanceof BrowserCategory )
+        {
+            BrowserCategory category = ( BrowserCategory ) parent;
+            IConnection connection = category.getParent();
+
+            switch ( category.getType() )
+            {
+                case BrowserCategory.TYPE_DIT:
+                {
+                    // open connection when expanding DIT
+                    if ( !connection.isOpened() )
+                    {
+                        new OpenConnectionsJob( connection ).execute();
+                        return new String[]
+                            { "Opening Connection..." };
+                    }
+
+                    return new Object[]
+                        { connection.getRootDSE() };
+                }
+
+                case BrowserCategory.TYPE_SEARCHES:
+                {
+                    return connection.getSearchManager().getSearches();
+                }
+
+                case BrowserCategory.TYPE_BOOKMARKS:
+                {
+                    return connection.getBookmarkManager().getBookmarks();
+                }
+            }
+
+            return new Object[0];
+        }
+        else
+        {
+            return new Object[0];
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasChildren( Object parent )
+    {
+        if ( parent instanceof IEntry )
+        {
+            IEntry parentEntry = ( IEntry ) parent;
+            return parentEntry.hasChildren()
+                || ( BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
+                    BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ) && ( parentEntry.isAlias() || parentEntry
+                    .isReferral() ) );
+        }
+        else if ( parent instanceof BrowserEntryPage )
+        {
+            return true;
+        }
+        else if ( parent instanceof BrowserSearchResultPage )
+        {
+            return true;
+        }
+        else if ( parent instanceof ISearchResult )
+        {
+            return false;
+        }
+        else if ( parent instanceof ISearch )
+        {
+            return true;
+        }
+        else if ( parent instanceof BrowserCategory )
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+
+    /**
+     * Creates and returns the entry pages for the given entry. The number of pages
+     * depends on the number of entries and the paging size. 
+     *
+     * @param entry the parent entry
+     * @param first the index of the first child entry
+     * @param last the index of the last child entry
+     * @return the created entry pages
+     */
+    private BrowserEntryPage[] getEntryPages( IEntry entry, int first, int last )
+    {
+        int pagingSize = preferences.getFoldingSize();
+
+        int diff = last - first;
+        int factor = diff > 0 ? ( int ) ( Math.log( diff ) / Math.log( pagingSize ) ) : 0;
+
+        int groupFirst = first;
+        int groupLast = first;
+        BrowserEntryPage[] pages = new BrowserEntryPage[( int ) ( diff / Math.pow( pagingSize, factor ) ) + 1];
+        for ( int i = 0; i < pages.length; i++ )
+        {
+            groupFirst = ( int ) ( i * Math.pow( pagingSize, factor ) ) + first;
+            groupLast = ( int ) ( ( i + 1 ) * Math.pow( pagingSize, factor ) ) + first - 1;
+            groupLast = groupLast > last ? last : groupLast;
+            BrowserEntryPage[] subpages = ( factor > 1 ) ? getEntryPages( entry, groupFirst, groupLast ) : null;
+            pages[i] = new BrowserEntryPage( entry, groupFirst, groupLast, subpages, sorter );
+        }
+
+        return pages;
+    }
+
+
+    /**
+     * Creates and returns the search result pages for the given search. The number of pages
+     * depends on the number of search results and the paging size. 
+     *
+     * @param search the parent search
+     * @param first the index of the first search result
+     * @param last the index of the last child search result
+     * @return the created search result pages
+     */
+    private BrowserSearchResultPage[] getSearchResultPages( ISearch search, int first, int last )
+    {
+        int pagingSize = preferences.getFoldingSize();
+
+        int diff = last - first;
+        int factor = diff > 0 ? ( int ) ( Math.log( diff ) / Math.log( pagingSize ) ) : 0;
+
+        int groupFirst = first;
+        int groupLast = first;
+        BrowserSearchResultPage[] pages = new BrowserSearchResultPage[( int ) ( diff / Math.pow( pagingSize, factor ) ) + 1];
+        for ( int i = 0; i < pages.length; i++ )
+        {
+            groupFirst = ( int ) ( i * Math.pow( pagingSize, factor ) ) + first;
+            groupLast = ( int ) ( ( i + 1 ) * Math.pow( pagingSize, factor ) ) + first - 1;
+            groupLast = groupLast > last ? last : groupLast;
+            BrowserSearchResultPage[] subpages = ( factor > 1 ) ? getSearchResultPages( search, groupFirst, groupLast )
+                : null;
+            pages[i] = new BrowserSearchResultPage( search, groupFirst, groupLast, subpages, sorter );
+        }
+
+        return pages;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserEntryPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserEntryPage.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserEntryPage.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserEntryPage.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,209 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+
+
+/**
+ * A BrowserEntryPage is a container for entries or other nested browser entry pages.
+ * It is used when folding large branches. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserEntryPage
+{
+    /** The tree sorter */
+    private BrowserSorter sorter;
+
+    /** The index of the first child entry in this page */ 
+    private int first;
+
+    /** The index of the last child entry in this page */
+    private int last;
+
+    /** The parent entry */
+    private IEntry entry;
+
+    /** The parent entry page or null if not nested */
+    private BrowserEntryPage parentEntryPage;
+
+    /** The sub pages */
+    private BrowserEntryPage[] subpages;
+
+
+    /**
+     * Creates a new instance of BrowserEntryPage.
+     *
+     * @param entry the parent entry
+     * @param first the index of the first child entry in this page
+     * @param last the index of the last child entry in this page
+     * @param subpages the sub pages
+     * @param sorter the sorter
+     */
+    public BrowserEntryPage( IEntry entry, int first, int last, BrowserEntryPage[] subpages, BrowserSorter sorter )
+    {
+        this.entry = entry;
+        this.first = first;
+        this.last = last;
+        this.subpages = subpages;
+        this.sorter = sorter;
+
+        if ( subpages != null )
+        {
+            for ( int i = 0; i < subpages.length; i++ )
+            {
+                subpages[i].parentEntryPage = this;
+            }
+        }
+    }
+
+
+    /**
+     * Gets the children, either the sub pages or 
+     * the entries contained in this page.
+     *
+     * @return the children
+     */
+    public Object[] getChildren()
+    {
+        if ( subpages != null )
+        {
+            return subpages;
+        }
+        else
+        {
+            // 1. get children
+            IEntry[] children = entry.getChildren();
+
+            // 2. sort
+            sorter.sort( null, children );
+
+            // 3. extraxt range
+            if ( children != null )
+            {
+                IEntry[] childrenRange = new IEntry[last - first + 1];
+                for ( int i = first; i <= last; i++ )
+                {
+                    childrenRange[i - first] = children[i];
+                }
+                return childrenRange;
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }
+
+
+    
+    /**
+     * Gets the first.
+     * 
+     * @return the first
+     */
+    public int getFirst()
+    {
+        return first;
+    }
+
+
+    /**
+     * Gets the last.
+     * 
+     * @return the last
+     */
+    public int getLast()
+    {
+        return last;
+    }
+
+
+    /**
+     * Gets the parent entry.
+     * 
+     * @return the parent entry
+     */
+    public IEntry getEntry()
+    {
+        return entry;
+    }
+
+
+    /**
+     * Gets the parent page if the given entry is contained in this page
+     * or one of the sub pages.
+     * 
+     * @param entry the entry
+     * 
+     * @return the parent page of the given entry.
+     */
+    public BrowserEntryPage getParentOf( IEntry entry )
+    {
+        if ( subpages != null )
+        {
+            BrowserEntryPage ep = null;
+            for ( int i = 0; i < subpages.length && ep == null; i++ )
+            {
+                ep = subpages[i].getParentOf( entry );
+            }
+            return ep;
+        }
+        else
+        {
+            IEntry[] sr = ( IEntry[] ) getChildren();
+            if ( sr != null && Arrays.asList( sr ).contains( entry ) )
+            {
+                return this;
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }
+
+
+    /**
+     * Gets the direct parent, either a page or the entry.
+     * 
+     * @return the direct parent
+     */
+    public Object getParent()
+    {
+        return ( parentEntryPage != null ) ? ( Object ) parentEntryPage : ( Object ) entry;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return entry.toString() + "[" + first + "..." + last + "]" + hashCode();
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserLabelProvider.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserLabelProvider.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserLabelProvider.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,515 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.internal.model.AliasBaseEntry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.BaseDNEntry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.DirectoryMetadataEntry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.ReferralBaseEntry;
+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.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.RDN;
+import org.apache.directory.ldapstudio.browser.core.model.RDNPart;
+import org.apache.directory.ldapstudio.browser.core.utils.Utils;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * The BrowserLabelProvider implements the label provider for
+ * the browser widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserLabelProvider extends LabelProvider implements IFontProvider, IColorProvider
+{
+
+    /** The preferences. */
+    private BrowserPreferences preferences;
+
+
+    /**
+     * Creates a new instance of BrowserLabelProvider.
+     *
+     * @param preferences the preferences
+     */
+    public BrowserLabelProvider( BrowserPreferences preferences )
+    {
+        this.preferences = preferences;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getText( Object obj )
+    {
+        if ( obj instanceof IEntry )
+        {
+            IEntry entry = ( IEntry ) obj;
+
+            StringBuffer append = new StringBuffer();
+            if ( entry instanceof IRootDSE )
+            {
+                append.append( "Root DSE" );
+            }
+            if ( entry.isChildrenInitialized() && ( entry.getChildrenCount() > 0 ) || entry.getChildrenFilter() != null )
+            {
+                append.append( " (" ).append( entry.getChildrenCount() );
+                if ( entry.hasMoreChildren() )
+                {
+                    append.append( "+" );
+                }
+                if ( entry.getChildrenFilter() != null )
+                {
+                    append.append( ", filtered" );
+                }
+                append.append( ")" );
+            }
+
+            if ( entry instanceof ReferralBaseEntry )
+            {
+                return entry.getUrl().toString() + " " + append.toString();
+            }
+            else if ( entry instanceof AliasBaseEntry )
+            {
+                return entry.getDn().toString() + " " + append.toString();
+            }
+            else if ( entry instanceof BaseDNEntry )
+            {
+                return entry.getDn().toString() + " " + append.toString();
+            }
+            else if ( entry.hasParententry() )
+            {
+
+                String label = "";
+                if ( preferences.getEntryLabel() == BrowserCommonConstants.SHOW_DN )
+                {
+                    label = entry.getDn().toString();
+                }
+                else if ( preferences.getEntryLabel() == BrowserCommonConstants.SHOW_RDN )
+                {
+                    label = entry.getRdn().toString();
+
+                }
+                else if ( preferences.getEntryLabel() == BrowserCommonConstants.SHOW_RDN_VALUE )
+                {
+                    label = entry.getRdn().getValue();
+                }
+
+                label += append.toString();
+
+                if ( preferences.isEntryAbbreviate() && label.length() > preferences.getEntryAbbreviateMaxLength() )
+                {
+                    label = Utils.shorten( label, preferences.getEntryAbbreviateMaxLength() );
+                }
+
+                return label;
+            }
+            else
+            {
+                return entry.getDn() + append.toString();
+            }
+        }
+        else if ( obj instanceof BrowserEntryPage )
+        {
+            BrowserEntryPage container = ( BrowserEntryPage ) obj;
+            return "[" + ( container.getFirst() + 1 ) + "..." + ( container.getLast() + 1 ) + "]";
+        }
+        else if ( obj instanceof BrowserSearchResultPage )
+        {
+            BrowserSearchResultPage container = ( BrowserSearchResultPage ) obj;
+            return "[" + ( container.getFirst() + 1 ) + "..." + ( container.getLast() + 1 ) + "]";
+        }
+        else if ( obj instanceof ISearch )
+        {
+            ISearch search = ( ISearch ) obj;
+            ISearchResult[] results = search.getSearchResults();
+            StringBuffer append = new StringBuffer( search.getName() );
+            if ( results != null )
+            {
+                append.append( " (" ).append( results.length );
+                if ( search.isCountLimitExceeded() )
+                {
+                    append.append( "+" );
+                }
+                append.append( ")" );
+            }
+            return append.toString();
+        }
+        else if ( obj instanceof IBookmark )
+        {
+            IBookmark bookmark = ( IBookmark ) obj;
+            return bookmark.getName();
+        }
+        else if ( obj instanceof ISearchResult )
+        {
+            ISearchResult sr = ( ISearchResult ) obj;
+
+            if ( !sr.getSearch().getConnection().equals( sr.getEntry().getConnection() ) )
+            {
+                return sr.getEntry().getUrl().toString();
+            }
+            else if ( sr.getEntry().hasParententry() || sr.getEntry() instanceof IRootDSE )
+            {
+                String label = "";
+                if ( sr.getEntry() instanceof IRootDSE )
+                {
+                    label = "Root DSE";
+                }
+                else if ( preferences.getSearchResultLabel() == BrowserCommonConstants.SHOW_DN )
+                {
+                    label = sr.getEntry().getDn().toString();
+                }
+                else if ( preferences.getSearchResultLabel() == BrowserCommonConstants.SHOW_RDN )
+                {
+                    label = sr.getEntry().getRdn().toString();
+                }
+                else if ( preferences.getSearchResultLabel() == BrowserCommonConstants.SHOW_RDN_VALUE )
+                {
+                    label = sr.getEntry().getRdn().getValue();
+                }
+
+                if ( preferences.isSearchResultAbbreviate()
+                    && label.length() > preferences.getSearchResultAbbreviateMaxLength() )
+                {
+                    label = Utils.shorten( label, preferences.getSearchResultAbbreviateMaxLength() );
+                }
+
+                return label;
+            }
+            else
+            {
+                return sr.getEntry().getDn().toString();
+            }
+
+        }
+        else if ( obj instanceof BrowserCategory )
+        {
+            BrowserCategory category = ( BrowserCategory ) obj;
+            return category.getTitle();
+        }
+        else if ( obj != null )
+        {
+            return obj.toString();
+        }
+        else
+        {
+            return "";
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Image getImage( Object obj )
+    {
+        if ( obj instanceof IEntry )
+        {
+            IEntry entry = ( IEntry ) obj;
+            return getImageByRdn( entry );
+        }
+        else if ( obj instanceof BrowserEntryPage )
+        {
+            return PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJ_FOLDER );
+        }
+        else if ( obj instanceof BrowserSearchResultPage )
+        {
+            return PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJ_FOLDER );
+        }
+        else if ( obj instanceof ISearch )
+        {
+            ISearch search = ( ISearch ) obj;
+            if ( search.getConnection().isOpened() && search.getSearchResults() != null )
+            {
+                return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SEARCH );
+            }
+            else
+            {
+                return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SEARCH_UNPERFORMED );
+            }
+        }
+        else if ( obj instanceof IBookmark )
+        {
+            return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_BOOKMARK );
+        }
+        else if ( obj instanceof ISearchResult )
+        {
+            ISearchResult sr = ( ISearchResult ) obj;
+            IEntry entry = sr.getEntry();
+            return getImageByRdn( entry );
+        }
+        else if ( obj instanceof BrowserCategory )
+        {
+            BrowserCategory category = ( BrowserCategory ) obj;
+            if ( category.getType() == BrowserCategory.TYPE_DIT )
+            {
+                return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_DIT );
+            }
+            else if ( category.getType() == BrowserCategory.TYPE_SEARCHES )
+            {
+                return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SEARCHES );
+            }
+            else if ( category.getType() == BrowserCategory.TYPE_BOOKMARKS )
+            {
+                return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_BOOKMARKS );
+            }
+            else
+            {
+                return null;
+            }
+        }
+        else
+        {
+            // return
+            // Activator.getDefault().getImage("icons/sandglass.gif");
+            return null;
+        }
+    }
+
+
+    /**
+     * Gets the image depending on the RDN attribute
+     *
+     * @param entry the entry
+     * @return the image
+     */
+    private Image getImageByRdn( IEntry entry )
+    {
+        if ( entry instanceof IRootDSE )
+        {
+            return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY_ROOT );
+        }
+        else if ( entry instanceof DirectoryMetadataEntry && ( ( DirectoryMetadataEntry ) entry ).isSchemaEntry() )
+        {
+            return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_BROWSER_SCHEMABROWSEREDITOR );
+        }
+        else if ( entry.getDn().equals( entry.getConnection().getSchema().getDn() ) )
+        {
+            return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_BROWSER_SCHEMABROWSEREDITOR );
+        }
+        else if ( preferences.isDerefAliasesAndReferralsWhileBrowsing() && entry.isAlias() )
+        {
+            return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY_ALIAS );
+        }
+        else if ( preferences.isDerefAliasesAndReferralsWhileBrowsing() && entry.isReferral() )
+        {
+            return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY_REF );
+        }
+        else if ( entry.isSubentry() )
+        {
+            return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_BROWSER_SCHEMABROWSEREDITOR );
+        }
+        else
+        {
+            RDN rdn = entry.getRdn();
+            RDNPart[] rdnParts = rdn.getParts();
+            for ( int i = 0; i < rdnParts.length; i++ )
+            {
+                RDNPart part = rdnParts[i];
+                if ( "cn".equals( part.getType() ) || "sn".equals( part.getType() ) || "uid".equals( part.getType() )
+                    || "userid".equals( part.getType() ) )
+                {
+                    return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY_PERSON );
+                }
+                else if ( "ou".equals( part.getType() ) || "o".equals( part.getType() ) )
+                {
+                    return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY_ORG );
+                }
+                else if ( "dc".equals( part.getType() ) || "c".equals( part.getType() ) || "l".equals( part.getType() ) )
+                {
+                    return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY_DC );
+                }
+            }
+        }
+
+        return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY );
+    }
+
+
+    // private Image getImageByObjectclass(IEntry entry) {
+    // IAttribute oc = entry.getAttribute(IAttribute.OBJECTCLASS_ATTRIBUTE);
+    // if(oc != null && oc.getStringValues() != null) {
+    // String[] ocValues = oc.getStringValues();
+    // Set ocSet = new HashSet();
+    // for(int i=0; i<ocValues.length; i++) {
+    // ocSet.add(ocValues[i].toUpperCase());
+    // }
+    //			
+    // if(entry instanceof IRootDSE) {
+    // return
+    // Activator.getDefault().getImage(BrowserWidgetsConstants.IMG_ENTRY_ROOT);
+    // }
+    // else
+    // if(entry.getDn().equals(entry.getConnection().getSchema().getDn()))
+    // {
+    // return
+    // Activator.getDefault().getImage(BrowserWidgetsConstants.IMG_BROWSER_SCHEMABROWSEREDITOR);
+    // }
+    // else if(ocSet.contains(ObjectClassDescription.OC_ALIAS.toUpperCase())
+    // || ocSet.contains(ObjectClassDescription.OC_REFERRAL.toUpperCase()))
+    // {
+    // return
+    // Activator.getDefault().getImage(BrowserWidgetsConstants.IMG_ENTRY_REF);
+    // }
+    // else
+    // if(ocSet.contains(ObjectClassDescription.OC_PERSON.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_ORGANIZATIONALPERSON.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_INETORGPERSON.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_RESIDENTIALPERSON.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_PILOTPERSON.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_NEWPILOTPERSON.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_ORGANIZATIONALROLE.toUpperCase())
+    // || ocSet.contains(ObjectClassDescription.OC_ACCOUNT.toUpperCase())) {
+    // return
+    // Activator.getDefault().getImage(BrowserWidgetsConstants.IMG_ENTRY_PERSON);
+    // }
+    // else
+    // if(ocSet.contains(ObjectClassDescription.OC_ORGANIZATION.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_ORGANIZATIONALUNIT.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_PILOTORGANIZATION.toUpperCase())
+    // || ocSet.contains(ObjectClassDescription.OC_DMD.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_APPLICATIONPROCESS.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_APPLICATIONENTITY.toUpperCase()))
+    // {
+    // return
+    // Activator.getDefault().getImage(BrowserWidgetsConstants.IMG_ENTRY_ORG);
+    // }
+    // else
+    // if(ocSet.contains(ObjectClassDescription.OC_COUNTRY.toUpperCase())
+    // || ocSet.contains(ObjectClassDescription.OC_LOCALITY.toUpperCase())
+    // || ocSet.contains(ObjectClassDescription.OC_DCOBJECT.toUpperCase())
+    // || ocSet.contains(ObjectClassDescription.OC_DOMAIN.toUpperCase())) {
+    // return
+    // Activator.getDefault().getImage(BrowserWidgetsConstants.IMG_ENTRY_DC);
+    // }
+    // else
+    // if(ocSet.contains(ObjectClassDescription.OC_GROUPOFNAMES.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_GROUPOFUNIQUENAMES.toUpperCase())
+    // ||
+    // ocSet.contains(ObjectClassDescription.OC_POSIXGROUP.toUpperCase())) {
+    // return
+    // Activator.getDefault().getImage(BrowserWidgetsConstants.IMG_ENTRY_GROUP);
+    // }
+    //			
+    // }
+    //		
+    // return
+    // Activator.getDefault().getImage(BrowserWidgetsConstants.IMG_ENTRY);
+    // }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Font getFont( Object element )
+    {
+
+        IEntry entry = null;
+        if ( element instanceof IEntry )
+        {
+            entry = ( IEntry ) element;
+        }
+        else if ( element instanceof ISearchResult )
+        {
+            entry = ( ( ISearchResult ) element ).getEntry();
+        }
+
+        if ( entry != null )
+        {
+            if ( !entry.isConsistent() )
+            {
+                FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault()
+                    .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_ERROR_FONT );
+                return BrowserCommonActivator.getDefault().getFont( fontData );
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Color getForeground( Object element )
+    {
+
+        IEntry entry = null;
+        if ( element instanceof IEntry )
+        {
+            entry = ( IEntry ) element;
+        }
+        else if ( element instanceof ISearchResult )
+        {
+            entry = ( ( ISearchResult ) element ).getEntry();
+        }
+
+        if ( entry != null )
+        {
+            if ( !entry.isConsistent() )
+            {
+                RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(),
+                    BrowserCommonConstants.PREFERENCE_ERROR_COLOR );
+                return BrowserCommonActivator.getDefault().getColor( rgb );
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Color getBackground( Object element )
+    {
+        return null;
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserPreferences.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserPreferences.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserPreferences.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserPreferences.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,361 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+
+
+/**
+ * This class is a wrapper for the preferences of the browser widget.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserPreferences implements IPropertyChangeListener, Preferences.IPropertyChangeListener
+{
+
+    /** The tree viewer */
+    protected TreeViewer viewer;
+
+
+    /**
+     * Creates a new instance of BrowserPreferences.
+     */
+    public BrowserPreferences()
+    {
+        BrowserCommonActivator.getDefault().getPreferenceStore().addPropertyChangeListener( this );
+        BrowserCorePlugin.getDefault().getPluginPreferences().addPropertyChangeListener( this );
+    }
+
+
+    /**
+     * Connects the tree viewer to this preferences.
+     *
+     * @param viewer the tree viewer
+     */
+    public void connect( TreeViewer viewer )
+    {
+        this.viewer = viewer;
+    }
+
+
+    /**
+     * Disposes this preferences.
+     */
+    public void dispose()
+    {
+        BrowserCommonActivator.getDefault().getPreferenceStore().removePropertyChangeListener( this );
+        BrowserCorePlugin.getDefault().getPluginPreferences().removePropertyChangeListener( this );
+        viewer = null;
+    }
+
+
+    /**
+     * Gets the sort by, one of BrowserCoreConstants.SORT_BY_NONE, 
+     * BrowserCoreConstants.SORT_BY_RDN or BrowserCoreConstants.SORT_BY_RDN_VALUE.
+     * 
+     * @return the sort by
+     */
+    public int getSortBy()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BY );
+    }
+
+
+    /**
+     * Gets the sort order, one of one of BrowserCoreConstants.SORT_ORDER_NONE, 
+     * BrowserCoreConstants.SORT_ORDER_ASCENDING or BrowserCoreConstants.SORT_ORDER_DESCENDING.
+     * 
+     * @return the sort order
+     */
+    public int getSortOrder()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_BROWSER_SORT_ORDER );
+    }
+
+
+    /**
+     * Gets the sort limit.
+     * 
+     * @return the sort limit
+     */
+    public int getSortLimit()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_BROWSER_SORT_LIMIT );
+    }
+
+
+    /**
+     * Returns true if leaf entries should be shown before non-leaf entries.
+     * 
+     * @return true, if leaf entries should be shown first
+     */
+    public boolean isLeafEntriesFirst()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST );
+    }
+
+
+    /**
+     * Returns true if meta entries should be shown after non-meta entries.
+     * 
+     * @return true, if meta entries should be shown first
+     */
+    public boolean isMetaEntriesLast()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST );
+    }
+
+
+    /**
+     * Returns true if the bookmark category should be visible.
+     *
+     * @return true if the bookmark category should be visible
+     */
+    public boolean isShowBookmarks()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_BOOKMARKS );
+    }
+
+
+    /**
+     * Returns true if the DIT category should be visible.
+     *
+     * @return true if the DIT category should be visible
+     */
+    public boolean isShowDIT()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIT );
+    }
+
+
+    /**
+     * Returns true if the searches category should be visible.
+     *
+     * @return true if the searches category should be visible
+     */
+    public boolean isShowSearches()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_SEARCHES );
+    }
+
+
+    /**
+     * Gets the folding size.
+     * 
+     * @return the folding size
+     */
+    public int getFoldingSize()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE );
+    }
+
+
+    /**
+     * Returns true if folding is enabled.
+     *
+     * @return true if folding is enabled
+     */
+    public boolean isUseFolding()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING );
+    }
+
+
+    /**
+     * Returns true if meta entries should be visible.
+     *
+     * @return true if meta entries should be visible
+     */
+    public boolean isShowDirectoryMetaEntries()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIRECTORY_META_ENTRIES );
+    }
+
+
+    /**
+     * Returns true if entry lables should be abbreviated.
+     *
+     * @return true if entry lables should be abbreviated
+     */
+    public boolean isEntryAbbreviate()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE );
+    }
+
+
+    /**
+     * Gets the entry's maximum label length.
+     * 
+     * @return the entry's maximum label length
+     */
+    public int getEntryAbbreviateMaxLength()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH );
+    }
+
+
+    /**
+     * Gets the entry label, one of BrowserWidgetsConstants.SHOW_DN, 
+     * BrowserWidgetsConstants.SHOW_RDN or BrowserWidgetsConstants.SHOW_RDN_VALUE.
+     * 
+     * @return the entry label
+     */
+    public int getEntryLabel()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL );
+    }
+
+
+    /**
+     * Returns true if search result lables should be abbreviated.
+     *
+     * @return true if search result lables should be abbreviated
+     */
+    public boolean isSearchResultAbbreviate()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE );
+    }
+
+
+    /**
+     * Gets the search result's maximum label length.
+     * 
+     * @return the search result's maximum label length
+     */
+    public int getSearchResultAbbreviateMaxLength()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH );
+    }
+
+
+    /**
+     * Gets the search result label, one of BrowserWidgetsConstants.SHOW_DN, 
+     * BrowserWidgetsConstants.SHOW_RDN or BrowserWidgetsConstants.SHOW_RDN_VALUE.
+     * 
+     * @return the entry label
+     */
+    public int getSearchResultLabel()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getInt(
+            BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL );
+    }
+
+
+    /**
+     * Returns true if the base entries should be expanded when
+     * opening connection.
+     *
+     * @return true if the base entries should be expanded
+     */
+    public boolean isExpandBaseEntries()
+    {
+        return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean(
+            BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES );
+    }
+
+
+    /**
+     * Returns true if the browser should check for children
+     * while browsing the directory.
+     *
+     * @return true if the browser should check for children
+     */
+    public boolean isCheckForChildren()
+    {
+        Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
+        return coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN );
+    }
+
+
+    /**
+     * Returns true if the browser should dereference aliases and referrals.
+     * 
+     *
+     * @return true if the browser should dereference aliases and referrals
+     */
+    public boolean isDerefAliasesAndReferralsWhileBrowsing()
+    {
+        Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
+        return coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS );
+    }
+
+
+    /**
+     * Returns true if subentries should be fetched while browsing.
+     * 
+     *
+     * @return true if subentries should be fetched while browsing
+     */
+    public boolean isFetchSubentries()
+    {
+        Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
+        return coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void propertyChange( PropertyChangeEvent event )
+    {
+        if ( viewer != null )
+        {
+            viewer.refresh();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void propertyChange( org.eclipse.core.runtime.Preferences.PropertyChangeEvent event )
+    {
+        if ( viewer != null )
+        {
+            viewer.refresh();
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSearchResultPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSearchResultPage.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSearchResultPage.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/browser/BrowserSearchResultPage.java Mon Apr  9 02:49:48 2007
@@ -0,0 +1,211 @@
+/*
+ *  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.common.widgets.browser;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
+
+
+/**
+ * A BrowserSearchResultPage is a container for search results or other nested browser search result pages.
+ * It is used when folding searches with many results. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserSearchResultPage
+{
+
+    /** The tree sorter */
+    private BrowserSorter sorter;
+
+    /** The index of the first child search result in this page */
+    private int first;
+
+    /** The index of the last child search result in this page */
+    private int last;
+
+    /** The parent search */
+    private ISearch search;
+
+    /** The parent search result page or null if not nested */
+    private BrowserSearchResultPage parentSearchResultPage;
+
+    /** The sub pages */
+    private BrowserSearchResultPage[] subpages;
+
+
+    /**
+     * Creates a new instance of BrowserSearchResultPage.
+     *
+     * @param search the parent search
+     * @param first the index of the first child search result in this page
+     * @param last the index of the last child search result in this page
+     * @param subpages the sub pages
+     * @param sorter the sorter
+     */
+    public BrowserSearchResultPage( ISearch search, int first, int last, BrowserSearchResultPage[] subpages,
+        BrowserSorter sorter )
+    {
+        this.search = search;
+        this.first = first;
+        this.last = last;
+        this.subpages = subpages;
+        this.sorter = sorter;
+
+        if ( subpages != null )
+        {
+            for ( int i = 0; i < subpages.length; i++ )
+            {
+                subpages[i].parentSearchResultPage = this;
+            }
+        }
+    }
+
+
+    /**
+     * Gets the children, either the sub pages or 
+     * the search results contained in this page.
+     *
+     * @return the children
+     */
+    public Object[] getChildren()
+    {
+        if ( subpages != null )
+        {
+            return subpages;
+        }
+        else
+        {
+            // 1. get children
+            ISearchResult[] children = search.getSearchResults();
+
+            // 2. sort
+            sorter.sort( null, children );
+
+            // 3. extraxt range
+            if ( children != null )
+            {
+                ISearchResult[] childrenRange = new ISearchResult[last - first + 1];
+                for ( int i = first; i <= last; i++ )
+                {
+                    childrenRange[i - first] = children[i];
+                }
+                return childrenRange;
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }
+
+
+    /**
+     * Gets the first.
+     * 
+     * @return the first
+     */
+    public int getFirst()
+    {
+        return first;
+    }
+
+
+    /**
+     * Gets the last.
+     * 
+     * @return the last
+     */
+    public int getLast()
+    {
+        return last;
+    }
+
+
+    /**
+     * Gets the search.
+     * 
+     * @return the search
+     */
+    public ISearch getSearch()
+    {
+        return search;
+    }
+
+
+    /**
+     * Gets the parent page if the given search result is contained in this page
+     * or one of the sub pages.
+     * 
+     * @param searchResult the search result
+     * 
+     * @return the parent page of the given search result.
+     */
+    public BrowserSearchResultPage getParentOf( ISearchResult searchResult )
+    {
+        if ( subpages != null )
+        {
+            BrowserSearchResultPage ep = null;
+            for ( int i = 0; i < subpages.length && ep == null; i++ )
+            {
+                ep = subpages[i].getParentOf( searchResult );
+            }
+            return ep;
+        }
+        else
+        {
+            ISearchResult[] sr = ( ISearchResult[] ) getChildren();
+            if ( sr != null && Arrays.asList( sr ).contains( searchResult ) )
+            {
+                return this;
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }
+
+
+    /**
+     * Gets the direct parent, either a page or the search.
+     * 
+     * @return the direct parent
+     */
+    public Object getParent()
+    {
+        return ( parentSearchResultPage != null ) ? ( Object ) parentSearchResultPage : ( Object ) search;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return search.toString() + "[" + first + "..." + last + "]" + hashCode();
+    }
+
+}