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}
0 commit comments