Skip to content

Commit e8c80f9

Browse files
authored
Merge pull request #112 from schorschii/multi-member-selection
Thanks a lot for the submission, I integrate it in the current trunk so that we can have it in the coming release!
2 parents 0393b4f + f449ac9 commit e8c80f9

6 files changed

Lines changed: 426 additions & 43 deletions

File tree

plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/DnDialog.java

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
/**
4242
* The DnDialog is used from the Dn value editor to edit and select a Dn.
4343
*
44+
* In multi-select mode it allows the user to manage a list of DNs at once,
45+
* which is useful e.g. when adding multiple members to a group.
46+
*
4447
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
4548
*/
4649

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

62-
/** The dn */
63-
private Dn dn;
65+
/** One dn (single-select mode) or multiple DNs (multi-select mode). */
66+
private Dn[] dns;
67+
68+
/** True when the dialog operates in multi-select mode. */
69+
private boolean multiSelect;
6470

6571

6672
/**
67-
* Creates a new instance of DnDialog.
73+
* Creates a new instance of DnDialog in single-select mode.
6874
*
75+
* Use {@link #getDn()} to retrieve the result after the dialog is closed.
76+
*
6977
* @param parentShell the parent shell
7078
* @param title the title of the dialog
7179
* @param description the description of the dialog
@@ -79,7 +87,31 @@ public DnDialog( Shell parentShell, String title, String description, IBrowserCo
7987
this.title = title;
8088
this.description = description;
8189
this.connection = connection;
82-
this.dn = dn;
90+
this.dns = dn != null ? new Dn[]{ dn } : new Dn[0];
91+
this.multiSelect = false;
92+
}
93+
94+
95+
/**
96+
* Creates a new instance of DnDialog in multi-select mode.
97+
*
98+
* Use {@link #getDns()} to retrieve the result after the dialog is closed.
99+
*
100+
* @param parentShell the parent shell
101+
* @param title the title of the dialog
102+
* @param description the description of the dialog
103+
* @param connection the connection used to browse the directory
104+
* @param dns the initial list of DNs, may be null or empty
105+
*/
106+
public DnDialog( Shell parentShell, String title, String description, IBrowserConnection connection, Dn[] dns )
107+
{
108+
super( parentShell );
109+
super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
110+
this.title = title;
111+
this.description = description;
112+
this.connection = connection;
113+
this.dns = dns != null ? dns : new Dn[0];
114+
this.multiSelect = true;
83115
}
84116

85117

@@ -99,8 +131,11 @@ protected void configureShell( Shell shell )
99131
*/
100132
protected void okPressed()
101133
{
102-
dn = entryWidget.getDn();
103-
entryWidget.saveDialogSettings();
134+
dns = entryWidget.getDns();
135+
if ( !multiSelect )
136+
{
137+
entryWidget.saveDialogSettings();
138+
}
104139
super.okPressed();
105140
}
106141

@@ -124,6 +159,10 @@ protected Control createDialogArea( Composite parent )
124159
Composite composite = ( Composite ) super.createDialogArea( parent );
125160
GridData gd = new GridData( GridData.FILL_BOTH );
126161
gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 3 / 2;
162+
if ( multiSelect )
163+
{
164+
gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
165+
}
127166
composite.setLayoutData( gd );
128167

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

134173
Composite innerComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
135-
entryWidget = new EntryWidget( connection, dn );
174+
175+
if ( multiSelect )
176+
{
177+
entryWidget = new EntryWidget( connection, dns );
178+
innerComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
179+
}
180+
else
181+
{
182+
entryWidget = new EntryWidget( connection, dns.length == 0 ? null : dns[0] );
183+
}
184+
136185
entryWidget.addWidgetModifyListener( new WidgetModifyListener()
137186
{
138187
public void widgetModified( WidgetModifyEvent event )
@@ -154,20 +203,39 @@ private void updateWidgets()
154203
{
155204
if ( getButton( IDialogConstants.OK_ID ) != null )
156205
{
157-
getButton( IDialogConstants.OK_ID ).setEnabled(
158-
entryWidget.getDn() != null && !"".equals( entryWidget.getDn().toString() ) ); //$NON-NLS-1$
206+
if ( multiSelect )
207+
{
208+
// Always allow confirming in multi-select mode (empty list is valid)
209+
getButton( IDialogConstants.OK_ID ).setEnabled( true );
210+
}
211+
else
212+
{
213+
getButton( IDialogConstants.OK_ID ).setEnabled(
214+
entryWidget.getDn() != null && !"".equals( entryWidget.getDn().toString() ) ); //$NON-NLS-1$
215+
}
159216
}
160217
}
161218

162219

163220
/**
164-
* Gets the dn.
165-
*
221+
* Gets the dn (single-select mode).
222+
*
166223
* @return the dn
167224
*/
168225
public Dn getDn()
169226
{
170-
return dn;
227+
return dns.length == 0 ? null : dns[0];
228+
}
229+
230+
231+
/**
232+
* Gets the list of DNs (multi-select mode).
233+
*
234+
* @return the array of selected DNs, never null
235+
*/
236+
public Dn[] getDns()
237+
{
238+
return dns;
171239
}
172240

173241
}

plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectEntryDialog.java

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
package org.apache.directory.studio.ldapbrowser.common.dialogs;
2222

2323

24+
import java.util.ArrayList;
25+
import java.util.List;
26+
2427
import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserActionGroup;
2528
import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserConfiguration;
2629
import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserUniversalListener;
@@ -60,6 +63,9 @@ public class SelectEntryDialog extends Dialog
6063
/** The selected entry. */
6164
private IEntry selectedEntry;
6265

66+
/** All selected entries (supports multi-selection). */
67+
private List<IEntry> selectedEntries;
68+
6369
/** The browser configuration. */
6470
private BrowserConfiguration browserConfiguration;
6571

@@ -89,6 +95,7 @@ public SelectEntryDialog( Shell parentShell, String title, IEntry rootEntry, IEn
8995
this.rootEntry = rootEntry;
9096
this.initialEntry = initialEntry;
9197
this.selectedEntry = null;
98+
this.selectedEntries = new ArrayList<>();
9299
}
93100

94101

@@ -128,7 +135,23 @@ public boolean close()
128135
*/
129136
protected void okPressed()
130137
{
131-
selectedEntry = initialEntry;
138+
selectedEntries = new ArrayList<>();
139+
if ( browserWidget != null )
140+
{
141+
IStructuredSelection sel = ( IStructuredSelection ) browserWidget.getViewer().getSelection();
142+
for ( Object o : sel.toList() )
143+
{
144+
if ( o instanceof IEntry )
145+
{
146+
selectedEntries.add( ( IEntry ) o );
147+
}
148+
else if ( o instanceof ISearchResult )
149+
{
150+
selectedEntries.add( ( ( ISearchResult ) o ).getEntry() );
151+
}
152+
}
153+
}
154+
selectedEntry = selectedEntries.isEmpty() ? initialEntry : selectedEntries.get( 0 );
132155
super.okPressed();
133156
}
134157

@@ -189,14 +212,22 @@ public void selectionChanged( SelectionChangedEvent event )
189212
{
190213
if ( !event.getSelection().isEmpty() )
191214
{
192-
Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
193-
if ( o instanceof IEntry )
215+
IStructuredSelection sel = ( IStructuredSelection ) event.getSelection();
216+
selectedEntries = new ArrayList<>();
217+
for ( Object o : sel.toList() )
194218
{
195-
initialEntry = ( IEntry ) o;
219+
if ( o instanceof IEntry )
220+
{
221+
selectedEntries.add( ( IEntry ) o );
222+
}
223+
else if ( o instanceof ISearchResult )
224+
{
225+
selectedEntries.add( ( ( ISearchResult ) o ).getEntry() );
226+
}
196227
}
197-
else if ( o instanceof ISearchResult )
228+
if ( !selectedEntries.isEmpty() )
198229
{
199-
initialEntry = ( ( ISearchResult ) o ).getEntry();
230+
initialEntry = selectedEntries.get( 0 );
200231
}
201232
}
202233
}
@@ -222,12 +253,23 @@ else if ( o instanceof ISearchResult )
222253

223254
/**
224255
* Gets the selected entry.
225-
*
226-
* @return the selected entry
256+
*
257+
* @return the selected entry, or null if none
227258
*/
228259
public IEntry getSelectedEntry()
229260
{
230261
return selectedEntry;
231262
}
232263

264+
265+
/**
266+
* Gets all selected entries (supports multi-selection via Ctrl/Shift+click).
267+
*
268+
* @return the list of selected entries, never null
269+
*/
270+
public List<IEntry> getSelectedEntries()
271+
{
272+
return selectedEntries;
273+
}
274+
233275
}

0 commit comments

Comments
 (0)