1
1
package de .wwu .scdh .oxbytei ;
2
2
3
3
import java .awt .Frame ;
4
- import java .lang .reflect .InvocationTargetException ;
5
4
import java .net .URL ;
6
5
import java .net .MalformedURLException ;
7
6
import java .util .ArrayList ;
10
9
import java .util .HashMap ;
11
10
import java .util .Map ;
12
11
import javax .xml .transform .URIResolver ;
13
- //import java.nio.file.ProviderNotFoundException;
14
12
15
13
import org .slf4j .Logger ;
16
14
import org .slf4j .LoggerFactory ;
27
25
import de .wwu .scdh .teilsp .config .EditorVariablesExpander ;
28
26
import de .wwu .scdh .teilsp .exceptions .ConfigurationException ;
29
27
import de .wwu .scdh .teilsp .services .extensions .ILabelledEntriesProvider ;
30
- import de .wwu .scdh .teilsp .services .extensions .LabelledEntriesLoader ;
28
+ import de .wwu .scdh .teilsp .services .extensions .ConfiguredPluginLoader ;
31
29
import de .wwu .scdh .teilsp .services .extensions .ExtensionException ;
32
- import de .wwu .scdh .teilsp .services .extensions .SelectionDialogLoader ;
33
30
import de .wwu .scdh .oxbytei .commons .EditorVariablesExpanderImpl ;
34
31
import de .wwu .scdh .oxbytei .commons .WSDocumentReader ;
35
32
import de .wwu .scdh .oxbytei .commons .DocumentReaderException ;
@@ -218,18 +215,28 @@ public SelectLabelledEntryInteraction (AuthorAccess authorAccess) {
218
215
219
216
LOGGER .debug ("Loading providers for {} {} on context {}" , nodeType , nodeName , context );
220
217
providers = new ArrayList <ILabelledEntriesProvider >();
221
- providers = LabelledEntriesLoader .providersForContext
218
+ ConfiguredPluginLoader <ILabelledEntriesProvider > providerLoader =
219
+ new ConfiguredPluginLoader <ILabelledEntriesProvider >
220
+ (ILabelledEntriesProvider .class , OxbyteiConstants .DEFAULT_LABELLED_ENTRIES_PROVIDER );
221
+ providers = providerLoader .providersForContext
222
222
(document ,
223
- currentFileURL .toString (),
224
223
context ,
225
224
nodeType ,
226
225
nodeName ,
227
- uriResolver ,
228
- entityResolver ,
229
226
null ,
230
227
configFile ,
231
228
expander );
232
229
230
+ // setup each provider
231
+ for (ILabelledEntriesProvider provider : providers ) {
232
+ provider .setup
233
+ (uriResolver ,
234
+ entityResolver ,
235
+ document ,
236
+ currentFileURL .toString (),
237
+ context );
238
+ }
239
+
233
240
providersCount = providers .size ();
234
241
return providersCount ;
235
242
}
@@ -247,8 +254,6 @@ public String doUserInteraction(final ArgumentsMap arguments)
247
254
String rollbackOnCancelString =
248
255
OperationArgumentValidator .validateStringArgument (ARGUMENT_ROLLBACK_ON_CANCEL .getName (), arguments );
249
256
boolean rollbackOnCancel = rollbackOnCancelString .equals (AuthorConstants .ARG_VALUE_TRUE );
250
- String message =
251
- OperationArgumentValidator .validateStringArgument (ARGUMENT_MESSAGE .getName (), arguments );
252
257
String iconString =
253
258
OperationArgumentValidator .validateStringArgument (ARGUMENT_ICON .getName (), arguments );
254
259
URL icon ;
@@ -274,36 +279,42 @@ public String doUserInteraction(final ArgumentsMap arguments)
274
279
}
275
280
276
281
// get the dialog
277
- ISelectionDialog dialogView ;
282
+ ISelectionDialog dialogView , dialogViewWithoutFrame ;
278
283
if (providersCount == 0 ) {
279
284
// use fallback dialog
280
285
// TODO: this prevents us from configuring dialogs in
281
286
// contexts without providers. Is this wanted?
282
287
dialogView = fallbackDialog ();
283
288
} else {
284
289
LOGGER .debug ("Loading providers for {} {} on context {}" , nodeType , nodeName , context );
285
- List <ISelectionDialog > dialogs = new ArrayList <ISelectionDialog >();
286
- dialogs = SelectionDialogLoader .providersForContext
290
+ List <ISelectionDialog > dialogs ;
291
+ ConfiguredPluginLoader <ISelectionDialog > dialogLoader =
292
+ new ConfiguredPluginLoader <ISelectionDialog >
293
+ (ISelectionDialog .class , OxbyteiConstants .DEFAULT_SELECTION_DIALOG );
294
+ dialogs = dialogLoader .providersForContext
287
295
(document ,
288
- currentFileURL .toString (),
289
296
context ,
290
297
nodeType ,
291
298
nodeName ,
292
- uriResolver ,
293
- entityResolver ,
294
299
null ,
295
300
configFile ,
296
- frame ,
297
301
expander );
302
+
298
303
if (dialogs .size () == 0 ) {
299
304
dialogView = fallbackDialog ();
300
305
} else {
301
306
// we take the first dialog found in the config
302
- dialogView = dialogs .get (0 );
307
+ dialogViewWithoutFrame = dialogs .get (0 );
308
+
309
+ // reinstantiate because we have to pass the frame to the constructor
310
+ dialogView = ISelectionDialog .reinstantiate (dialogViewWithoutFrame , frame );
311
+ dialogView .init (dialogViewWithoutFrame .getArguments ());
312
+
303
313
// TODO: should we dispose all plugins or does GC the job?
304
314
}
305
315
}
306
316
317
+
307
318
// envoke the dialog and get the selection/input
308
319
List <String > selected ;
309
320
dialogView .setup (currentSelection , providers );
@@ -341,9 +352,12 @@ protected ISelectionDialog fallbackDialog()
341
352
throws ConfigurationException , ExtensionException {
342
353
ISelectionDialog dialog , dialogView ;
343
354
try {
344
- dialog = SelectionDialogLoader .provider ();
345
- Class dialogClass = dialog .getClass ();
346
- dialogView = (ISelectionDialog ) dialogClass .getDeclaredConstructor (Frame .class ).newInstance (frame );
355
+ ConfiguredPluginLoader <ISelectionDialog > dialogLoader =
356
+ new ConfiguredPluginLoader <ISelectionDialog >
357
+ (ISelectionDialog .class , OxbyteiConstants .DEFAULT_SELECTION_DIALOG );
358
+ dialog = dialogLoader .provider ();
359
+
360
+ dialogView = ISelectionDialog .reinstantiate (dialog , frame );
347
361
348
362
Map <String , String > arguments = new HashMap <String , String >();
349
363
arguments .put ("title" , "New value" );
@@ -352,28 +366,8 @@ protected ISelectionDialog fallbackDialog()
352
366
} catch (ProviderNotFoundException e ) {
353
367
throw new ConfigurationException
354
368
("Default dialog view "
355
- + SelectionDialogLoader . DEFAULT_PROVIDER
369
+ + OxbyteiConstants . DEFAULT_SELECTION_DIALOG
356
370
+ " not found" );
357
- } catch (InstantiationException e ) {
358
- throw new ExtensionException
359
- ("Error instantiating user dialog class "
360
- + SelectionDialogLoader .DEFAULT_PROVIDER
361
- + "\n \n " + e );
362
- } catch (IllegalAccessException e ) {
363
- throw new ExtensionException
364
- ("Error accessing user dialog class "
365
- + SelectionDialogLoader .DEFAULT_PROVIDER
366
- + "\n \n " + e );
367
- } catch (NoSuchMethodException e ) {
368
- throw new ExtensionException
369
- ("Error loading dialog class "
370
- + SelectionDialogLoader .DEFAULT_PROVIDER
371
- + "\n \n " + e );
372
- } catch (InvocationTargetException e ) {
373
- throw new ExtensionException
374
- ("Error loading dialog class "
375
- + SelectionDialogLoader .DEFAULT_PROVIDER
376
- + "\n \n " + e );
377
371
}
378
372
379
373
// TODO dispose dialog
0 commit comments