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/11/16 17:56:37 UTC
svn commit: r475813 [3/3] - in
/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser: ./ META-INF/
resources/ resources/icons/ src/ src/main/ src/main/java/
src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/directory/ src/main...
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/ImageKeys.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/ImageKeys.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/ImageKeys.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/ImageKeys.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,44 @@
+/*
+ * 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.view;
+
+
+/**
+ * This class is used to define path for images
+ */
+public class ImageKeys
+{
+ // Images for Views
+ public static final String CONNECTION = "resources/icons/connection.gif"; //$NON-NLS-1$
+ public static final String CONNECTION_DELETE = "resources/icons/connection_delete.gif"; //$NON-NLS-1$
+ public static final String CONNECTION_EDIT = "resources/icons/connection_edit.gif"; //$NON-NLS-1$
+ public static final String CONNECTION_NEW = "resources/icons/connection_new.gif"; //$NON-NLS-1$
+ public static final String ENTRY = "resources/icons/entry.gif"; //$NON-NLS-1$
+ public static final String ENTRY_NEW = "resources/icons/entry_new.gif"; //$NON-NLS-1$
+ public static final String ENTRY_DELETE = "resources/icons/entry_delete.gif"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_NEW = "resources/icons/attribute_new.gif"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_DELETE = "resources/icons/attribute_delete.gif"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_EDIT = "resources/icons/attribute_edit.gif"; //$NON-NLS-1$
+ public static final String FOLDER_ENTRY = "resources/icons/folder_entry.gif"; //$NON-NLS-1$
+ public static final String WIZARD_CONNECTION = "resources/icons/wizard_connection.gif"; //$NON-NLS-1$
+ public static final String REFRESH = "resources/icons/refresh.gif"; //$NON-NLS-1$
+ public static final String CONNECTION_ERROR = "resources/icons/connection_error.gif"; //$NON-NLS-1$
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/perspectives/LdapBrowserPerspective.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/perspectives/LdapBrowserPerspective.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/perspectives/LdapBrowserPerspective.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/perspectives/LdapBrowserPerspective.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,50 @@
+/*
+ * 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.view.perspectives;
+
+
+import org.apache.directory.ldapstudio.browser.Activator;
+import org.apache.directory.ldapstudio.browser.view.views.AttributesView;
+import org.apache.directory.ldapstudio.browser.view.views.BrowserView;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+
+public class LdapBrowserPerspective implements IPerspectiveFactory
+{
+
+ /** The perspective's ID */
+ public static final String ID = Activator.PLUGIN_ID + ".ldapBrowserPerspective";
+
+
+ public void createInitialLayout( IPageLayout layout )
+ {
+ String editorArea = layout.getEditorArea();
+ layout.setEditorAreaVisible( false );
+
+ layout.addStandaloneView( BrowserView.ID, true, IPageLayout.LEFT, 1f, editorArea );
+ layout.getViewLayout( BrowserView.ID ).setCloseable( false );
+
+ layout.addStandaloneView( AttributesView.ID, true, IPageLayout.RIGHT, 0.6f, BrowserView.ID );
+ layout.getViewLayout( AttributesView.ID ).setCloseable( false );
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesView.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesView.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesView.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesView.java Thu Nov 16 08:56:34 2006
@@ -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.view.views;
+
+
+import org.apache.directory.ldapstudio.browser.Activator;
+import org.apache.directory.ldapstudio.browser.controller.AttributesViewController;
+import org.apache.directory.ldapstudio.browser.controller.actions.RenameAttributeAction;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+
+
+/**
+ * This class implements the Browser View of the LDAP Browser's Perspective
+ */
+public class AttributesView extends ViewPart
+{
+ /** The Attributes View's ID */
+ public static final String ID = Activator.PLUGIN_ID + ".AttributesView";
+ private Table table;
+ private TableViewer viewer;
+ private AttributesView instance;
+ private AttributesViewController controller;
+
+
+ public AttributesView()
+ {
+ controller = AttributesViewController.getInstance();
+ }
+
+
+ @Override
+ public void createPartControl( Composite parent )
+ {
+ instance = this;
+
+ table = new Table( parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL );
+ table.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
+ table.setLinesVisible( true );
+ table.setHeaderVisible( true );
+ table.setEnabled( false ); // The table is disabled by default since nothing is selected in the Browser View
+
+ viewer = new TableViewer( table );
+ viewer.setUseHashlookup( true );
+
+ // Adding columns headers
+ TableColumn attributeColumn = new TableColumn( table, SWT.NONE );
+ attributeColumn.setText( "Attribute" );
+ TableColumn valueColumn = new TableColumn( table, SWT.NONE );
+ valueColumn.setText( "Value" );
+
+ // Initializing ContentProvider and LabelProvider
+ viewer.setContentProvider( new AttributesViewContentProvider() );
+ viewer.setLabelProvider( new AttributesViewLabelProvider() );
+
+ // Displaying and resizing the columns
+ resizeColumsToFit();
+
+ // Registering the view to the controller and creating the Actions
+ controller.setView( this );
+ controller.createActions();
+
+ // Registering the Viewer, so other views can be notified when the viewer selection changes
+ getSite().setSelectionProvider( viewer );
+
+ // Handling selection of the Browser View to update this view TODO This should be done by the controller
+ getSite().getPage().addPostSelectionListener( BrowserView.ID, new ISelectionListener()
+ {
+ public void selectionChanged( IWorkbenchPart part, ISelection selection )
+ {
+ // Setting the new input
+ setInput( ( ( TreeSelection ) selection ).getFirstElement() );
+
+ // Resizing columns to fit
+ resizeColumsToFit();
+ }
+ } );
+
+ // Handling the double click modification
+ table.addSelectionListener( new SelectionAdapter()
+ {
+
+ public void widgetDefaultSelected( SelectionEvent e )
+ {
+ new RenameAttributeAction( instance, table, "Rename" ).run();
+ }
+ } );
+
+ createContextMenu();
+
+ createToolbarButtons();
+ }
+
+
+ private void createContextMenu()
+ {
+ // Initialization of the Menu Manager used to display context menu
+ MenuManager manager = new MenuManager();
+ manager.setRemoveAllWhenShown( true );
+ manager.addMenuListener( controller );
+ // Set the context menu to the table viewer
+ viewer.getControl().setMenu( manager.createContextMenu( viewer.getControl() ) );
+ // Register the context menu to enable extension actions
+ getSite().registerContextMenu( manager, viewer );
+ }
+
+
+ private void createToolbarButtons()
+ {
+ IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
+
+ // Adding the Actions
+ toolBarManager.add( controller.getAttributeNewAction() );
+ toolBarManager.add( controller.getAttributeEditAction() );
+ toolBarManager.add( controller.getAttributeDeleteAction() );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ @Override
+ public void setFocus()
+ {
+ table.setFocus();
+ }
+
+
+ /**
+ * Sets the input of the TableViewer
+ * @param input the input to send to the TableViewer
+ */
+ public void setInput( Object input )
+ {
+ viewer.setInput( input );
+ }
+
+
+ /**
+ * Resizes the columns to fit the size of the cells
+ */
+ public void resizeColumsToFit()
+ {
+ // Resizing the first column
+ table.getColumn( 0 ).pack();
+ // Adding a little space to the first column
+ table.getColumn( 0 ).setWidth( table.getColumn( 0 ).getWidth() + 5 );
+ // Resizing the second column
+ table.getColumn( 1 ).pack();
+ }
+
+
+ public TableItem getSelectedAttributeTableItem()
+ {
+ return table.getSelection()[0];
+ }
+
+
+ public TableViewer getViewer()
+ {
+ return viewer;
+ }
+
+
+ /**
+ * Refreshes the UI
+ */
+ public void refresh()
+ {
+ // Getting the selected Entry in the Browser View
+ BrowserView browserView = ( BrowserView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .findView( BrowserView.ID );
+ setInput( ( ( TreeSelection ) browserView.getViewer().getSelection() ).getFirstElement() );
+
+ // Resizing columns to fit
+ resizeColumsToFit();
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesViewContentProvider.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesViewContentProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesViewContentProvider.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,125 @@
+/*
+ * 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.view.views;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+
+import org.apache.directory.ldapstudio.browser.view.views.wrappers.EntryWrapper;
+import org.apache.directory.shared.ldap.codec.search.SearchResultEntry;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class is the Content Provider for the Attributes View
+ *
+ */
+public class AttributesViewContentProvider implements IStructuredContentProvider
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements( Object inputElement )
+ {
+ if ( inputElement instanceof EntryWrapper )
+ {
+ // Initializing the retun list
+ List<List<String>> returnList = new ArrayList<List<String>>();
+
+ // Getting the entry and looping on its attributes
+ SearchResultEntry entry = ( ( EntryWrapper ) inputElement ).getEntry();
+ NamingEnumeration ne = entry.getPartialAttributeList().getAll();
+
+ while ( ne.hasMoreElements() )
+ {
+ Attribute attribute = ( Attribute ) ne.nextElement();
+ for ( int i = 0; i < attribute.size(); i++ )
+ {
+ try
+ {
+ // A List is constructed : {Attribute ID, Attribute Value}
+ List<String> list = new ArrayList<String>( 2 );
+ list.add( 0, attribute.getID() );
+ list.add( 1, ( String ) attribute.get( i ) );
+
+ returnList.add( list );
+ }
+ catch ( NamingException e )
+ {
+ // Displaying an error
+ MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Error !", "An error has ocurred.\n" + e.getMessage() );
+ return null;
+ }
+ }
+ }
+
+ // Sorting the attributes
+ Collections.sort( returnList, new Comparator<List<String>>()
+ {
+ public int compare( List<String> l1, List<String> l2 )
+ {
+ String s1 = l1.get( 0 );
+ String s2 = l2.get( 0 );
+
+ return s1.compareTo( s2 );
+ }
+ } );
+
+ return returnList.toArray();
+ }
+
+ // Default return (should never be used)
+ return new Object[0];
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose()
+ {
+ // Nothing to do here but the method is needed
+ // by IContentProvider Interface
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+ {
+ // Nothing to do here but the method is needed
+ // by IContentProvider Interface
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesViewLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesViewLabelProvider.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesViewLabelProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/AttributesViewLabelProvider.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,60 @@
+/*
+ * 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.view.views;
+
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * This class is the Label Provider for the Attributes View
+ */
+public class AttributesViewLabelProvider extends LabelProvider implements ITableLabelProvider
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
+ */
+ public Image getColumnImage( Object element, int columnIndex )
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
+ */
+ public String getColumnText( Object element, int columnIndex )
+ {
+ if ( element instanceof List )
+ {
+ List<String> couple = ( List<String> ) element;
+ return couple.get( columnIndex );
+ }
+
+ // Default return (should never be used)
+ return "";
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserView.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserView.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserView.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserView.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,181 @@
+/*
+ * 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.view.views;
+
+
+import org.apache.directory.ldapstudio.browser.Activator;
+import org.apache.directory.ldapstudio.browser.controller.BrowserViewController;
+import org.apache.directory.ldapstudio.browser.model.Connections;
+import org.apache.directory.ldapstudio.browser.model.ConnectionsEvent;
+import org.apache.directory.ldapstudio.browser.model.ConnectionsListener;
+import org.apache.directory.ldapstudio.browser.view.views.wrappers.TreeViewerRootNode;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+
+
+/**
+ * This class implements the Browser View of the LDAP Browser's Perspective
+ */
+public class BrowserView extends ViewPart implements ConnectionsListener
+{
+ /** The Browser View's ID */
+ public static final String ID = Activator.PLUGIN_ID + ".BrowserView";
+ private TreeViewer viewer;
+ private BrowserViewController controller;
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createPartControl( Composite parent )
+ {
+ viewer = new TreeViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
+
+ // Initializing ContentProvider and LabelProvider
+ viewer.setContentProvider( new BrowserViewContentProvider() );
+ viewer.setLabelProvider( new BrowserViewLabelProvider() );
+
+ // Adding DoubleClick behavior TODO This handling should be in the controller
+ viewer.addDoubleClickListener( new IDoubleClickListener()
+ {
+ public void doubleClick( DoubleClickEvent event )
+ {
+ // What we get from the treeViewer is a StructuredSelection
+ StructuredSelection selection = ( StructuredSelection ) event.getSelection();
+
+ // Here's the real object
+ Object objectSelection = selection.getFirstElement();
+
+ viewer.setExpandedState( objectSelection, !viewer.getExpandedState( objectSelection ) );
+ }
+ } );
+
+ // Creating the controller, registering the view to the controller and creating the Actions
+ controller = BrowserViewController.getInstance();
+ controller.setView( this );
+ controller.createActions();
+
+ // Registring the view as a Listener for Connections changes
+ Connections.getInstance().addListener( this );
+
+ // Registering the Viewer, so other views can be notified when the viewer selection changes
+ getSite().setSelectionProvider( viewer );
+
+ createContextMenu();
+
+ createToolbarButtons();
+
+ // Creating the First Node and displaying Connections
+ viewer.setInput( TreeViewerRootNode.getInstance() );
+ }
+
+
+ private void createContextMenu()
+ {
+ // Initialization of the Menu Manager used to display context menu
+ MenuManager manager = new MenuManager();
+ manager.setRemoveAllWhenShown( true );
+ manager.addMenuListener( controller );
+ // Set the context menu to the table viewer
+ viewer.getControl().setMenu( manager.createContextMenu( viewer.getControl() ) );
+ // Register the context menu to enable extension actions
+ getSite().registerContextMenu( manager, viewer );
+ }
+
+
+ private void createToolbarButtons()
+ {
+ IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
+
+ // Adding the Actions
+ toolBarManager.add( controller.getConnectionNewAction() );
+ toolBarManager.add( controller.getConnectionEditAction() );
+ toolBarManager.add( controller.getConnectionDeleteAction() );
+ toolBarManager.add( new Separator() );
+ toolBarManager.add( controller.getRefreshAction() );
+ toolBarManager.add( new Separator() );
+ toolBarManager.add( controller.getEntryNewAction() );
+ toolBarManager.add( controller.getEntryDeleteAction() );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ @Override
+ public void setFocus()
+ {
+ viewer.getControl().setFocus();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.ViewPart#setPartName(java.lang.String)
+ */
+ public void setPartName( String partName )
+ {
+ super.setPartName( partName );
+ }
+
+
+ /**
+ * Gets the TreeViewer of the Browser View
+ * @return the TreeViewer of the Browser View
+ */
+ public TreeViewer getViewer()
+ {
+ return viewer;
+ }
+
+
+ /**
+ * Gets the TreeViewer's ContentProvider
+ * @return
+ */
+ public IContentProvider getContentProvider()
+ {
+ return viewer.getContentProvider();
+ }
+
+
+ public void connectionsChanged( Connections connections, ConnectionsEvent event )
+ {
+ Object[] expandedObjects = viewer.getExpandedElements();
+
+ TreeViewerRootNode treeViewerRootNode = ( TreeViewerRootNode ) viewer.getInput();
+
+ treeViewerRootNode.updateChildren( event );
+
+ viewer.refresh( treeViewerRootNode );
+
+ viewer.setExpandedElements( expandedObjects );
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserViewContentProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserViewContentProvider.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserViewContentProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserViewContentProvider.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,122 @@
+/*
+ * 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.view.views;
+
+
+import org.apache.directory.ldapstudio.browser.view.views.wrappers.ConnectionWrapper;
+import org.apache.directory.ldapstudio.browser.view.views.wrappers.EntryWrapper;
+import org.apache.directory.ldapstudio.browser.view.views.wrappers.TreeViewerRootNode;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * This class is the Content Provider for the Browser View
+ */
+public class BrowserViewContentProvider implements IStructuredContentProvider, ITreeContentProvider
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements( Object inputElement )
+ {
+ return getChildren( inputElement );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ public Object[] getChildren( Object parentElement )
+ {
+ if ( parentElement instanceof TreeViewerRootNode ) // => launched by the Connection
+ {
+ // Getting the ConnectionWrapper and the Connection
+ TreeViewerRootNode treeViewerRootNode = ( TreeViewerRootNode ) parentElement;
+
+ return treeViewerRootNode.getChildren();
+ }
+ else if ( parentElement instanceof ConnectionWrapper ) // => launched by the Connection
+ {
+ // Getting the ConnectionWrapper and the Connection
+ ConnectionWrapper connectionWrapper = ( ConnectionWrapper ) parentElement;
+
+ return connectionWrapper.getChildren();
+ }
+ else if ( parentElement instanceof EntryWrapper ) // Any Other Node
+ {
+ // Getting the EntryWrapper and the connection
+ EntryWrapper wrapper = ( EntryWrapper ) parentElement;
+
+ return wrapper.getChildren();
+ }
+
+ // Default return (Should never be used)
+ return new Object[0];
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ public boolean hasChildren( Object element )
+ {
+ if ( element instanceof EntryWrapper )
+ {
+ EntryWrapper wrapper = ( EntryWrapper ) element;
+ return wrapper.hasChildren();
+ }
+
+ // Default return (Should never be used)
+ return true;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose()
+ {
+ // Nothing to do here but the method is needed
+ // by IContentProvider Interface
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+ {
+ // Nothing to do here but the method is needed
+ // by IContentProvider Interface
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ public Object getParent( Object element )
+ {
+ return null;
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserViewLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserViewLabelProvider.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserViewLabelProvider.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/BrowserViewLabelProvider.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,66 @@
+/*
+ * 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.view.views;
+
+
+import org.apache.directory.ldapstudio.browser.view.views.wrappers.DisplayableTreeViewerElement;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * This class is the Label Provider for the Browser View
+ */
+public class BrowserViewLabelProvider extends LabelProvider implements ILabelProvider
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
+ */
+ @Override
+ public Image getImage( Object element )
+ {
+ if ( element instanceof DisplayableTreeViewerElement )
+ {
+ return ( ( DisplayableTreeViewerElement ) element ).getDisplayImage();
+ }
+
+ // Default return (Should never be used)
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText( Object element )
+ {
+ if ( element instanceof DisplayableTreeViewerElement )
+ {
+ return ( ( DisplayableTreeViewerElement ) element ).getDisplayName();
+ }
+ // Default return (Should never be used)
+ return element.toString();
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/ConnectionWizard.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/ConnectionWizard.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/ConnectionWizard.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/ConnectionWizard.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,127 @@
+/*
+ * 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.view.views;
+
+
+import org.apache.directory.ldapstudio.browser.model.Connection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IWorkbench;
+
+
+/**
+ * This class implements the Connection Wizard
+ */
+public class ConnectionWizard extends Wizard
+{
+ public static final String CONNECTIONS_PREFS = "connections_prefs";
+
+ public enum ConnectionWizardType
+ {
+ NEW, EDIT
+ };
+
+ private ConnectionWizardType type;
+
+ /** The Connection Information Page */
+ private ConnectionWizardInformationPage cwip;
+
+
+ public void init( IWorkbench workbench, IStructuredSelection selection )
+ {
+ cwip = new ConnectionWizardInformationPage();
+ addPage( cwip );
+ setWindowTitle( "Connection" );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish()
+ {
+ // Saving the connection
+ cwip.saveConnection();
+
+ return true;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#canFinish()
+ */
+ @Override
+ public boolean canFinish()
+ {
+ return cwip.canFinish();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#needsPreviousAndNextButtons()
+ */
+ @Override
+ public boolean needsPreviousAndNextButtons()
+ {
+ return false;
+ }
+
+
+ /**
+ * Gets the Connection
+ * @return the Connection
+ */
+ public Connection getConnection()
+ {
+ return cwip.getConnection();
+ }
+
+
+ /**
+ * Gets the currently selected Connection
+ * @return the currently selected Connection, null if no Connection is selected
+ */
+ public void setConnection( Connection connection )
+ {
+ cwip.setConnection( connection );
+ }
+
+
+ /**
+ * Gets the Connection Type
+ * @return the Connection Type
+ */
+ public ConnectionWizardType getType()
+ {
+ return type;
+ }
+
+
+ /**
+ * Sets the Connection Type
+ * @param type the Connection Type
+ */
+ public void setType( ConnectionWizardType type )
+ {
+ this.type = type;
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/ConnectionWizardInformationPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/ConnectionWizardInformationPage.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/ConnectionWizardInformationPage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/ConnectionWizardInformationPage.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,496 @@
+/*
+ * 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.view.views;
+
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.ldapstudio.browser.Activator;
+import org.apache.directory.ldapstudio.browser.model.Connection;
+import org.apache.directory.ldapstudio.browser.model.Connections;
+import org.apache.directory.ldapstudio.browser.view.ImageKeys;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class implements the Connection Information Page of the Connection Wizard
+ */
+public class ConnectionWizardInformationPage extends WizardPage
+{
+
+ private Connection connection;
+
+ private Group connectionGroup;
+
+ private Label nameLabel;
+ private Text nameText;
+
+ private Group hostGroup;
+
+ private Label hostLabel;
+ private Text hostText;
+
+ private Label portLabel;
+ private Text portText;
+
+ private Label baseDNLabel;
+ private Text baseDNText;
+
+ private Button anonymousBind;
+
+ private Group userGroup;
+
+ private Label userDNLabel;
+ private Text userDNText;
+
+ private Label passwordLabel;
+ private Text passwordText;
+
+ private Button prefixUserDN;
+
+
+ protected ConnectionWizardInformationPage()
+ {
+ super( "ConnectionInformationPage" );
+ setTitle( "Specify information for this connection" );
+ setDescription( "Specify your settings and click \"Finish\" to save." );
+ setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+ ImageKeys.WIZARD_CONNECTION ) );
+ }
+
+
+ public void createControl( Composite parent )
+ {
+ Composite container = new Composite( parent, SWT.NULL );
+ GridLayout layout = new GridLayout();
+ container.setLayout( layout );
+ layout.numColumns = 1;
+
+ // Connection Group
+ connectionGroup = new Group( container, SWT.NONE );
+ connectionGroup.setText( "Connection Information" );
+ connectionGroup.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+ connectionGroup.setLayout( new GridLayout( 2, false ) );
+
+ // Name
+ nameLabel = new Label( connectionGroup, SWT.NONE );
+ nameLabel.setText( "Name: " );
+ nameText = new Text( connectionGroup, SWT.BORDER );
+ nameText.setText( "" );
+ nameText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+ // Host Group
+ hostGroup = new Group( container, SWT.NONE );
+ hostGroup.setText( "Host Information" );
+ hostGroup.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+ hostGroup.setLayout( new GridLayout( 2, false ) );
+
+ // Host
+ hostLabel = new Label( hostGroup, SWT.NONE );
+ hostLabel.setText( "Host:" );
+ hostText = new Text( hostGroup, SWT.BORDER );
+ hostText.setText( "" );
+ hostText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+ // Port
+ portLabel = new Label( hostGroup, SWT.NONE );
+ portLabel.setText( "Port:" );
+ portText = new Text( hostGroup, SWT.BORDER );
+ portText.setText( "" );
+ portText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+ // Base DN
+ baseDNLabel = new Label( hostGroup, SWT.NONE );
+ baseDNLabel.setText( "Base DN:" );
+ baseDNText = new Text( hostGroup, SWT.BORDER );
+ baseDNText.setText( "" );
+ baseDNText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+ // Anonymous Bind
+ Label anonymousBindLabel = new Label( hostGroup, SWT.NONE );
+ anonymousBind = new Button( hostGroup, SWT.CHECK );
+ anonymousBind.setText( "Anonymous Bind" );
+ anonymousBind.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+ // User Group
+ userGroup = new Group( container, SWT.NONE );
+ userGroup.setText( "User Information" );
+ userGroup.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+ userGroup.setLayout( new GridLayout( 2, false ) );
+
+ // User DN
+ userDNLabel = new Label( userGroup, SWT.NONE );
+ userDNLabel.setText( "User DN:" );
+ userDNText = new Text( userGroup, SWT.BORDER );
+ userDNText.setText( "" );
+ userDNText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+ // Prefix User DN with Base DN
+ Label prefixUserDNLabel = new Label( userGroup, SWT.NONE );
+ prefixUserDN = new Button( userGroup, SWT.CHECK );
+ prefixUserDN.setText( "Prefix User DN with Base DN" );
+ prefixUserDN.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+ // Password
+ passwordLabel = new Label( userGroup, SWT.NONE );
+ passwordLabel.setText( "Password:" );
+ passwordText = new Text( userGroup, SWT.BORDER | SWT.PASSWORD );
+ passwordText.setText( "" );
+ passwordText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+ setControl( nameText );
+
+ // Initializing the fields
+ initFieldsFromConnection();
+
+ // Initializing Listeners
+ initListeners();
+ }
+
+
+ /**
+ * Initilizes the Listeners on the SWT UI Components (List, Button, etc.)
+ */
+ private void initListeners()
+ {
+ // Name
+ nameText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ verifyConnection();
+ }
+ } );
+
+ // Host
+ hostText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ verifyConnection();
+ }
+ } );
+
+ // Port
+ portText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ verifyConnection();
+ }
+ } );
+
+ // Base DN
+ baseDNText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ verifyConnection();
+ }
+ } );
+
+ // Anonymous Bind
+ anonymousBind.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ verifyConnection();
+
+ if ( anonymousBind.getSelection() )
+ {
+ // If the checkbox is checked, we have to disable the User Information fields
+ disableUserInformation();
+ }
+ else
+ {
+ // If the the checkbox isn't checked, we have to enable the User Information fields
+ enableUserInformation();
+ }
+ }
+ } );
+
+ // User DN
+ userDNText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ verifyConnection();
+ }
+ } );
+
+ // Password
+ passwordText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ verifyConnection();
+ }
+ } );
+ }
+
+
+ /**
+ * Saves the modifications done on the Connection
+ */
+ private void verifyConnection()
+ {
+ // We need to use asyncExec to be able to access the UI. See http://wiki.eclipse.org/index.php/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
+ Display.getDefault().asyncExec( new Runnable()
+ {
+ public void run()
+ {
+ // Reseting previous message
+ setErrorMessage( null );
+ setPageComplete( true );
+
+ // Name
+ if ( ( nameText.getText() == null ) || ( "".equals( nameText.getText() ) ) )
+ {
+ setErrorMessage( "Name can't be empty." );
+ setPageComplete( false );
+ return;
+ }
+ else
+ {
+ Connections connections = Connections.getInstance();
+
+ if ( !connections.isConnectionNameAvailable( nameText.getText(), connection.getName() ) )
+ {
+ setErrorMessage( "A connection with same Name already exists." );
+ setPageComplete( false );
+ return;
+ }
+ }
+
+ // Host
+ if ( ( hostText.getText() == null ) || ( "".equals( hostText.getText() ) ) )
+ {
+ setErrorMessage( "Host can't be empty." );
+ setPageComplete( false );
+ return;
+ }
+
+ // Port
+ if ( ( portText.getText() == null ) || ( "".equals( portText.getText() ) ) )
+ {
+ setErrorMessage( "Port can't be empty." );
+ setPageComplete( false );
+ return;
+ }
+ else
+ {
+ try
+ {
+ int port = Integer.parseInt( portText.getText() );
+ if ( ( port <= 0 ) || ( port > 65535 ) )
+ {
+ setErrorMessage( "Port must between 1 and 65535" );
+ setPageComplete( false );
+ return;
+ }
+ }
+ catch ( NumberFormatException e )
+ {
+ setErrorMessage( "Port must be an integer" );
+ setPageComplete( false );
+ return;
+ }
+ }
+
+ // Base DN
+ if ( ( baseDNText.getText() != null ) && ( !"".equals( baseDNText.getText() ) ) )
+ {
+ try
+ {
+ LdapDN ldapDN = new LdapDN( baseDNText.getText() );
+ }
+ catch ( InvalidNameException e )
+ {
+ setErrorMessage( "Base DN is not a correct DN." );
+ setPageComplete( false );
+ return;
+ }
+ }
+
+ // User DN
+ if ( !anonymousBind.getSelection() )
+ {
+ if ( ( userDNText.getText() == null ) || ( "".equals( userDNText.getText() ) ) )
+ {
+ setErrorMessage( "User DN can't be empty." );
+ setPageComplete( false );
+ return;
+ }
+ }
+ if ( ( userDNText.getText() != null ) && ( !"".equals( userDNText.getText() ) ) )
+ {
+ try
+ {
+ LdapDN ldapDN = new LdapDN( userDNText.getText() );
+ }
+ catch ( InvalidNameException e )
+ {
+ setErrorMessage( "User DN is not a correct DN." );
+ setPageComplete( false );
+ return;
+ }
+ }
+
+ }
+ } );
+ }
+
+
+ /**
+ * Initializes the UI fields from the Connection
+ */
+ private void initFieldsFromConnection()
+ {
+ // Name
+ nameText.setText( ( connection.getName() == null ) ? "" : connection.getName() );
+
+ // Host
+ hostText.setText( ( connection.getHost() == null ) ? "" : connection.getHost() );
+
+ // Port
+ portText.setText( ( connection.getPort() == 0 ) ? "" : ( connection.getPort() + "" ) );
+
+ // Base DN
+ baseDNText.setText( ( connection.getBaseDN() == null ) ? "" : connection.getBaseDN().getNormName() );
+
+ // Anonymous Bind
+ if ( connection.isAnonymousBind() )
+ {
+ anonymousBind.setSelection( true );
+ disableUserInformation();
+ }
+ else
+ {
+ anonymousBind.setSelection( false );
+ }
+
+ // User DN
+ userDNText.setText( ( connection.getUserDN() == null ) ? "" : connection.getUserDN().getNormName() );
+
+ // Password
+ passwordText.setText( ( connection.getPassword() == null ) ? "" : connection.getPassword() );
+ }
+
+
+ /**
+ * Enables the User Information fields
+ */
+ private void enableUserInformation()
+ {
+ userGroup.setEnabled( true );
+ userDNLabel.setEnabled( true );
+ userDNText.setEnabled( true );
+ prefixUserDN.setEnabled( true );
+ passwordLabel.setEnabled( true );
+ passwordText.setEnabled( true );
+ }
+
+
+ /**
+ * Disables the User Information fields
+ */
+ private void disableUserInformation()
+ {
+ userGroup.setEnabled( false );
+ userDNLabel.setEnabled( false );
+ userDNText.setEnabled( false );
+ prefixUserDN.setEnabled( false );
+ passwordLabel.setEnabled( false );
+ passwordText.setEnabled( false );
+ }
+
+
+ /**
+ * Saves the modifications made on the connection within the UI
+ */
+ public void saveConnection()
+ {
+ try
+ {
+ connection.setName( nameText.getText() );
+ connection.setHost( hostText.getText() );
+ int port = Integer.parseInt( portText.getText() );
+ connection.setPort( port );
+ connection.setBaseDN( ( "".equals( baseDNText.getText() ) ? LdapDN.EMPTY_LDAPDN : new LdapDN( baseDNText
+ .getText() ) ) );
+ connection.setAnonymousBind( anonymousBind.getSelection() );
+ connection.setUserDN( ( "".equals( userDNText.getText() ) ? LdapDN.EMPTY_LDAPDN : new LdapDN( userDNText
+ .getText() ) ) );
+ connection.setPrefixUserDNWithBaseDN( prefixUserDN.getSelection() );
+ connection.setPassword( passwordText.getText() );
+ }
+ catch ( InvalidNameException e )
+ {
+ // Should never arrive since the "Finish Button" can't be pushed until the
+ // Base DN and User DN are correct
+ }
+ }
+
+
+ /**
+ * Indicates if the Wizard is able to finish
+ * @return true if the Wizard is able to finish
+ */
+ public boolean canFinish()
+ {
+ return isPageComplete();
+ }
+
+
+ /**
+ * Gets the Connection
+ * @return the Connection
+ */
+ public Connection getConnection()
+ {
+ return connection;
+ }
+
+
+ /**
+ * Gets the currently selected Connection
+ * @return the currently selected Connection, null if no Connection is selected
+ */
+ public void setConnection( Connection connection )
+ {
+ this.connection = connection;
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/ConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/ConnectionWrapper.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/ConnectionWrapper.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/ConnectionWrapper.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,240 @@
+/*
+ * 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.view.views.wrappers;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.Activator;
+import org.apache.directory.ldapstudio.browser.model.Connection;
+import org.apache.directory.ldapstudio.browser.view.ImageKeys;
+import org.apache.directory.ldapstudio.browser.view.views.BrowserView;
+import org.apache.directory.shared.ldap.codec.LdapResponse;
+import org.apache.directory.shared.ldap.codec.search.SearchResultEntry;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2ResponseParser;
+import org.apache.directory.ldapstudio.dsmlv2.engine.Dsmlv2Engine;
+import org.apache.directory.ldapstudio.dsmlv2.reponse.ErrorResponse;
+import org.apache.directory.ldapstudio.dsmlv2.reponse.SearchResponse;
+
+
+/**
+ * ConnectionWrapper used to display a Connection in the TreeViewer
+ * of the Browser View
+ */
+public class ConnectionWrapper implements Comparable<ConnectionWrapper>, DisplayableTreeViewerElement
+{
+ private Object parent;
+
+ private List<EntryWrapper> children;
+
+ /** The wrapped conneection */
+ private Connection connection;
+
+ /** The hasError Flag */
+ private boolean hasError = false;
+
+
+ public ConnectionWrapper( Connection connection )
+ {
+ this.connection = connection;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.ldapstudio.browser.view.views.wrappers.DisplayableTreeViewerElement#getDisplayName()
+ */
+ public String getDisplayName()
+ {
+ return connection.getName();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.ldapstudio.browser.view.views.wrappers.DisplayableTreeViewerElement#getDisplayImage()
+ */
+ public Image getDisplayImage()
+ {
+ if ( hasError() )
+ {
+ return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, ImageKeys.CONNECTION_ERROR )
+ .createImage();
+ }
+
+ return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, ImageKeys.CONNECTION ).createImage();
+ }
+
+
+ /**
+ * Gets the wrapped connection
+ * @return the wrapped connection
+ */
+ public Connection getConnection()
+ {
+ return connection;
+ }
+
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo( ConnectionWrapper o )
+ {
+ ConnectionWrapper otherWrapper = ( ConnectionWrapper ) o;
+ return getDisplayName().compareToIgnoreCase( otherWrapper.getDisplayName() );
+ }
+
+
+ /**
+ * Get parent object in the TreeViewer Hierarchy
+ * @return the parent
+ */
+ public Object getParent()
+ {
+ return parent;
+ }
+
+
+ /**
+ * 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 = new Dsmlv2Engine( connection.getHost(), connection.getPort(), connection
+ .getUserDN().getNormName(), connection.getPassword() );
+ Dsmlv2ResponseParser parser = new Dsmlv2ResponseParser();
+
+ String request = "<batchRequest>" + " <searchRequest dn=\"" + connection.getBaseDN().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 SearchResponse )
+ {
+ // Updating the HasError Flag and updating the UI
+ if ( hasError() )
+ {
+ setHasError( false );
+
+ // Getting the Browser View
+ BrowserView browserView = ( BrowserView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().findView( BrowserView.ID );
+ browserView.getViewer().update( this, null );
+ }
+
+ // Getting the Base DN
+ SearchResultEntry baseDN = ( ( SearchResponse ) ldapResponse ).getCurrentSearchResultEntry();
+
+ EntryWrapper baseDNWrapper = new EntryWrapper( baseDN );
+ baseDNWrapper.setParent( this );
+ baseDNWrapper.setIsBaseDN( true );
+
+ children.add( baseDNWrapper );
+ }
+ else if ( ldapResponse instanceof ErrorResponse )
+ {
+ setHasError( true );
+ clearChildren();
+
+ // Getting the Browser View
+ BrowserView browserView = ( BrowserView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().findView( BrowserView.ID );
+
+ ErrorResponse errorResponse = ( ErrorResponse ) ldapResponse;
+ // Displaying an error
+ MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Error !", "An error has ocurred.\n" + errorResponse.getMessage() );
+
+ browserView.getViewer().update( this, null );
+
+ return 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;
+ }
+
+
+ /**
+ * Gets the hasError Flag
+ * @return
+ */
+ public boolean hasError()
+ {
+ return hasError;
+ }
+
+
+ /**
+ * Sets the hasError Flag
+ * @param hasError the value of the flag
+ */
+ public void setHasError( boolean hasError )
+ {
+ this.hasError = hasError;
+ }
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/DisplayableTreeViewerElement.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/DisplayableTreeViewerElement.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/DisplayableTreeViewerElement.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/DisplayableTreeViewerElement.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,74 @@
+/*
+ * 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.view.views.wrappers;
+
+
+import org.apache.directory.ldapstudio.browser.model.Connection;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * All objects that want to be displayed in the JFace TreeViewer
+ * should implement this interface.
+ */
+public interface DisplayableTreeViewerElement
+{
+ /**
+ * Get the image that should be displayed in the TreeViewer
+ * @return the display image
+ */
+ public Image getDisplayImage();
+
+
+ /**
+ * Get the name that should be displayed in the TreeViewer
+ * @return the display name
+ */
+ public String getDisplayName();
+
+
+ /**
+ * Get the Connection associated
+ * @return the connection
+ */
+ public Connection getConnection();
+
+
+ /**
+ * Get parent object in the TreeViewer Hierarchy
+ * @return the parent
+ */
+ public Object getParent();
+
+
+ /**
+ * Set the parent object in the TreeViewer Hierarchy
+ * @param parent the parent element
+ */
+ public void setParent( Object parent );
+
+
+ /**
+ * Gets the children of the object
+ * @return the children of the object
+ */
+ public Object[] getChildren();
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/EntryWrapper.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/EntryWrapper.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/EntryWrapper.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/EntryWrapper.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,319 @@
+/*
+ * 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.view.views.wrappers;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.Activator;
+import org.apache.directory.ldapstudio.browser.model.Connection;
+import org.apache.directory.ldapstudio.browser.view.ImageKeys;
+import org.apache.directory.ldapstudio.browser.view.views.BrowserView;
+import org.apache.directory.shared.ldap.codec.LdapResponse;
+import org.apache.directory.shared.ldap.codec.search.SearchResultEntry;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2ResponseParser;
+import org.apache.directory.ldapstudio.dsmlv2.engine.Dsmlv2Engine;
+import org.apache.directory.ldapstudio.dsmlv2.reponse.ErrorResponse;
+import org.apache.directory.ldapstudio.dsmlv2.reponse.SearchResponse;
+
+
+/**
+ * EntryWrapper used to displays an entry in the TreeViewer of the Browser View
+ */
+public class EntryWrapper implements Comparable<EntryWrapper>, DisplayableTreeViewerElement
+{
+ private Object parent;
+
+ private List<EntryWrapper> children;
+
+ /** The real entry */
+ private SearchResultEntry sre;
+
+ /** HasChilden Flag */
+ private boolean hasChildren = true;
+
+ /** 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 );
+ }
+ }
+
+
+ /* (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();
+ }
+ }
+
+
+ /**
+ * Gets the real entry
+ * @return the real entry
+ */
+ public SearchResultEntry getEntry()
+ {
+ return sre;
+ }
+
+
+ /**
+ * 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;
+ }
+
+
+ /**
+ * 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;
+ }
+
+
+ /* (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;
+ }
+
+
+ /**
+ * Get parent object in the TreeViewer Hierarchy
+ * @return the parent
+ */
+ public Object getParent()
+ {
+ return parent;
+ }
+
+
+ /**
+ * Set the parent object in the TreeViewer Hierarchy
+ * @param parent the parent element
+ */
+ public void setParent( Object parent )
+ {
+ this.parent = 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;
+ }
+
+
+ public Object[] getChildren()
+ {
+ if ( children == null )
+ {
+ children = new ArrayList<EntryWrapper>();
+
+ try
+ {
+ // Initialization of the DSML Engine and the DSML Response Parser
+ Dsmlv2Engine engine = new Dsmlv2Engine( getConnection().getHost(), getConnection().getPort(),
+ getConnection().getUserDN().getNormName(), getConnection().getPassword() );
+ Dsmlv2ResponseParser parser = new Dsmlv2ResponseParser();
+
+ 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 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() );
+ 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] );
+ }
+
+
+ public void clearChildren()
+ {
+ children = null;
+ hasChildren = true;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/TreeViewerRootNode.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/TreeViewerRootNode.java?view=auto&rev=475813
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/TreeViewerRootNode.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser/src/main/java/org/apache/directory/ldapstudio/browser/view/views/wrappers/TreeViewerRootNode.java Thu Nov 16 08:56:34 2006
@@ -0,0 +1,179 @@
+/*
+ * 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.view.views.wrappers;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.model.Connection;
+import org.apache.directory.ldapstudio.browser.model.Connections;
+import org.apache.directory.ldapstudio.browser.model.ConnectionsEvent;
+import org.apache.directory.ldapstudio.browser.model.ConnectionsEvent.ConnectionsEventType;
+import org.apache.directory.ldapstudio.browser.view.views.BrowserView;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.PlatformUI;
+
+
+public class TreeViewerRootNode implements DisplayableTreeViewerElement
+{
+ private List<ConnectionWrapper> children;
+
+ private static TreeViewerRootNode instance;
+
+ private Connections connections;
+
+ // Static thread-safe singleton initializer
+ 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;
+ }
+
+
+ public void setParent( Object parent )
+ {
+ // Nothing to do, since the root element has no parent
+ }
+
+}