Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
/**
* The DnDialog is used from the Dn value editor to edit and select a Dn.
*
* In multi-select mode it allows the user to manage a list of DNs at once,
* which is useful e.g. when adding multiple members to a group.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/

Expand All @@ -59,13 +62,18 @@ public class DnDialog extends Dialog
/** The connection. */
private IBrowserConnection connection;

/** The dn */
private Dn dn;
/** One dn (single-select mode) or multiple DNs (multi-select mode). */
private Dn[] dns;

/** True when the dialog operates in multi-select mode. */
private boolean multiSelect;


/**
* Creates a new instance of DnDialog.
* Creates a new instance of DnDialog in single-select mode.
*
* Use {@link #getDn()} to retrieve the result after the dialog is closed.
*
* @param parentShell the parent shell
* @param title the title of the dialog
* @param description the description of the dialog
Expand All @@ -79,7 +87,31 @@ public DnDialog( Shell parentShell, String title, String description, IBrowserCo
this.title = title;
this.description = description;
this.connection = connection;
this.dn = dn;
this.dns = dn != null ? new Dn[]{ dn } : new Dn[0];
this.multiSelect = false;
}


/**
* Creates a new instance of DnDialog in multi-select mode.
*
* Use {@link #getDns()} to retrieve the result after the dialog is closed.
*
* @param parentShell the parent shell
* @param title the title of the dialog
* @param description the description of the dialog
* @param connection the connection used to browse the directory
* @param dns the initial list of DNs, may be null or empty
*/
public DnDialog( Shell parentShell, String title, String description, IBrowserConnection connection, Dn[] dns )
{
super( parentShell );
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
this.title = title;
this.description = description;
this.connection = connection;
this.dns = dns != null ? dns : new Dn[0];
this.multiSelect = true;
}


Expand All @@ -99,8 +131,11 @@ protected void configureShell( Shell shell )
*/
protected void okPressed()
{
dn = entryWidget.getDn();
entryWidget.saveDialogSettings();
dns = entryWidget.getDns();
if ( !multiSelect )
{
entryWidget.saveDialogSettings();
}
super.okPressed();
}

Expand All @@ -124,6 +159,10 @@ protected Control createDialogArea( Composite parent )
Composite composite = ( Composite ) super.createDialogArea( parent );
GridData gd = new GridData( GridData.FILL_BOTH );
gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 3 / 2;
if ( multiSelect )
{
gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
}
composite.setLayoutData( gd );

if ( description != null )
Expand All @@ -132,7 +171,17 @@ protected Control createDialogArea( Composite parent )
}

Composite innerComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
entryWidget = new EntryWidget( connection, dn );

if ( multiSelect )
{
entryWidget = new EntryWidget( connection, dns );
innerComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
}
else
{
entryWidget = new EntryWidget( connection, dns.length == 0 ? null : dns[0] );
}

entryWidget.addWidgetModifyListener( new WidgetModifyListener()
{
public void widgetModified( WidgetModifyEvent event )
Expand All @@ -154,20 +203,39 @@ private void updateWidgets()
{
if ( getButton( IDialogConstants.OK_ID ) != null )
{
getButton( IDialogConstants.OK_ID ).setEnabled(
entryWidget.getDn() != null && !"".equals( entryWidget.getDn().toString() ) ); //$NON-NLS-1$
if ( multiSelect )
{
// Always allow confirming in multi-select mode (empty list is valid)
getButton( IDialogConstants.OK_ID ).setEnabled( true );
}
else
{
getButton( IDialogConstants.OK_ID ).setEnabled(
entryWidget.getDn() != null && !"".equals( entryWidget.getDn().toString() ) ); //$NON-NLS-1$
}
}
}


/**
* Gets the dn.
*
* Gets the dn (single-select mode).
*
* @return the dn
*/
public Dn getDn()
{
return dn;
return dns.length == 0 ? null : dns[0];
}


/**
* Gets the list of DNs (multi-select mode).
*
* @return the array of selected DNs, never null
*/
public Dn[] getDns()
{
return dns;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
package org.apache.directory.studio.ldapbrowser.common.dialogs;


import java.util.ArrayList;
import java.util.List;

import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserActionGroup;
import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserConfiguration;
import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserUniversalListener;
Expand Down Expand Up @@ -60,6 +63,9 @@ public class SelectEntryDialog extends Dialog
/** The selected entry. */
private IEntry selectedEntry;

/** All selected entries (supports multi-selection). */
private List<IEntry> selectedEntries;

/** The browser configuration. */
private BrowserConfiguration browserConfiguration;

Expand Down Expand Up @@ -89,6 +95,7 @@ public SelectEntryDialog( Shell parentShell, String title, IEntry rootEntry, IEn
this.rootEntry = rootEntry;
this.initialEntry = initialEntry;
this.selectedEntry = null;
this.selectedEntries = new ArrayList<>();
}


Expand Down Expand Up @@ -128,7 +135,23 @@ public boolean close()
*/
protected void okPressed()
{
selectedEntry = initialEntry;
selectedEntries = new ArrayList<>();
if ( browserWidget != null )
{
IStructuredSelection sel = ( IStructuredSelection ) browserWidget.getViewer().getSelection();
for ( Object o : sel.toList() )
{
if ( o instanceof IEntry )
{
selectedEntries.add( ( IEntry ) o );
}
else if ( o instanceof ISearchResult )
{
selectedEntries.add( ( ( ISearchResult ) o ).getEntry() );
}
}
}
selectedEntry = selectedEntries.isEmpty() ? initialEntry : selectedEntries.get( 0 );
super.okPressed();
}

Expand Down Expand Up @@ -189,14 +212,22 @@ public void selectionChanged( SelectionChangedEvent event )
{
if ( !event.getSelection().isEmpty() )
{
Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
if ( o instanceof IEntry )
IStructuredSelection sel = ( IStructuredSelection ) event.getSelection();
selectedEntries = new ArrayList<>();
for ( Object o : sel.toList() )
{
initialEntry = ( IEntry ) o;
if ( o instanceof IEntry )
{
selectedEntries.add( ( IEntry ) o );
}
else if ( o instanceof ISearchResult )
{
selectedEntries.add( ( ( ISearchResult ) o ).getEntry() );
}
}
else if ( o instanceof ISearchResult )
if ( !selectedEntries.isEmpty() )
{
initialEntry = ( ( ISearchResult ) o ).getEntry();
initialEntry = selectedEntries.get( 0 );
}
}
}
Expand All @@ -222,12 +253,23 @@ else if ( o instanceof ISearchResult )

/**
* Gets the selected entry.
*
* @return the selected entry
*
* @return the selected entry, or null if none
*/
public IEntry getSelectedEntry()
{
return selectedEntry;
}


/**
* Gets all selected entries (supports multi-selection via Ctrl/Shift+click).
*
* @return the list of selected entries, never null
*/
public List<IEntry> getSelectedEntries()
{
return selectedEntries;
}

}
Loading
Loading