Skip to content

Commit 776a483

Browse files
committed
Merge branch 'dev' into main
2 parents bd8ffa5 + 9899d6d commit 776a483

26 files changed

+1051
-655
lines changed

changeLog.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Change log #
22

3+
## 0.13.0
4+
5+
- **changes of API**:
6+
- introduced `IConfigurablePlugin` for plugins that get
7+
context-sensitive config from the config file
8+
- `ILabelledEntriesProvider` and `ISelectionDialog` are derived from
9+
this new interface now
10+
- `ILabelledEntriesProvider` gets the current editing context now via
11+
`setup(...)`
12+
- configurable plugins are required to provide a method to describe
13+
their configuration arguments now
14+
- introduced a common loader for configurable plugins
15+
- made `de.wwu.scdh.teilsp.services.extensions.ArgumentDescriptor` a
16+
polymorphic interface and `ArgumentDescriptorImpl` an implementation
17+
of it
18+
- this makes evaluating, getting and converting arguments for plugins
19+
from the configuration super straight forward
20+
- introduced `de.wwu.scdh.teilsp.extensions.LabelledEntriesXQuery`, a
21+
provider for labelled entries which produces its collection via
22+
XQuery
23+
324
## 0.12.0
425

526
- added **selection dialogs**

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>de.wwu.scdh.oxbytei</groupId>
77
<artifactId>oxbytei</artifactId>
8-
<version>0.12.0</version>
8+
<version>0.13.0</version>
99

1010
<name>oXbytei</name>
1111
<url>https://github.com/scdh/oxbytei</url>

src/main/java/de/wwu/scdh/oxbytei/OxbyteiConstants.java

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public class OxbyteiConstants {
2222

2323
private static final Logger LOGGER = LoggerFactory.getLogger(OxbyteiConstants.class);
2424

25+
public static final String DEFAULT_SELECTION_DIALOG =
26+
"de.wwu.scdh.teilsp.ui.EditableComboBoxSelectDialog";
27+
28+
public static final String DEFAULT_LABELLED_ENTRIES_PROVIDER =
29+
"de.wwu.scdh.teilsp.extensions.LabelledEntriesFromXML";
30+
2531
public static final String DOCUMENT_XPATH = "root(/)";
2632

2733
public static final String CONTEXT_XPATH =

src/main/java/de/wwu/scdh/oxbytei/OxbyteiSchemaManagerFilter.java

+24-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import de.wwu.scdh.teilsp.config.EditorVariablesExpander;
2727
import de.wwu.scdh.teilsp.services.extensions.ILabelledEntriesProvider;
28-
import de.wwu.scdh.teilsp.services.extensions.LabelledEntriesLoader;
28+
import de.wwu.scdh.teilsp.services.extensions.ConfiguredPluginLoader;
2929
import de.wwu.scdh.teilsp.services.extensions.LabelledEntry;
3030
import de.wwu.scdh.teilsp.services.extensions.ExtensionException;
3131
import de.wwu.scdh.teilsp.exceptions.ConfigurationException;
@@ -80,6 +80,7 @@ protected List<ILabelledEntriesProvider> providersForContext(Context context, St
8080
EditorVariablesExpander expander = new EditorVariablesExpanderImpl(currentFileURL, true);
8181

8282
List<Object> docNodes = context.executeXPath(OxbyteiConstants.DOCUMENT_XPATH, namespaces, true);
83+
Document document = (Document) docNodes.get(0);
8384
String ctx =
8485
context.computeContextXPathExpression().replaceAll("/", "/*:"); //.substring(1);
8586

@@ -89,18 +90,29 @@ protected List<ILabelledEntriesProvider> providersForContext(Context context, St
8990
((Document) docNodes.get(0)).getDocumentElement().getLocalName());
9091

9192
// get the initialized providers
93+
ConfiguredPluginLoader<ILabelledEntriesProvider> providerLoader =
94+
new ConfiguredPluginLoader<ILabelledEntriesProvider>
95+
(ILabelledEntriesProvider.class, OxbyteiConstants.DEFAULT_LABELLED_ENTRIES_PROVIDER);
9296
List<ILabelledEntriesProvider> providers =
93-
LabelledEntriesLoader.providersForContext((Document) docNodes.get(0),
94-
context.getSystemID(),
95-
ctx,
96-
nodeType,
97-
nodeName,
98-
uriResolver,
99-
entityResolver,
100-
null,
101-
configFile,
102-
expander);
103-
97+
providerLoader.providersForContext
98+
(document,
99+
ctx,
100+
nodeType,
101+
nodeName,
102+
null,
103+
configFile,
104+
expander);
105+
106+
// setup each provider
107+
for (ILabelledEntriesProvider provider : providers) {
108+
provider.setup
109+
(uriResolver,
110+
entityResolver,
111+
document,
112+
currentFileURL.toString(),
113+
ctx);
114+
}
115+
104116
return providers;
105117
} catch (MalformedURLException e) {
106118
LOGGER.error("Path to current edited file is not a valid URL: {}", context.getSystemID());

src/main/java/de/wwu/scdh/oxbytei/SelectLabelledEntryInteraction.java

+36-42
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package de.wwu.scdh.oxbytei;
22

33
import java.awt.Frame;
4-
import java.lang.reflect.InvocationTargetException;
54
import java.net.URL;
65
import java.net.MalformedURLException;
76
import java.util.ArrayList;
@@ -10,7 +9,6 @@
109
import java.util.HashMap;
1110
import java.util.Map;
1211
import javax.xml.transform.URIResolver;
13-
//import java.nio.file.ProviderNotFoundException;
1412

1513
import org.slf4j.Logger;
1614
import org.slf4j.LoggerFactory;
@@ -27,9 +25,8 @@
2725
import de.wwu.scdh.teilsp.config.EditorVariablesExpander;
2826
import de.wwu.scdh.teilsp.exceptions.ConfigurationException;
2927
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;
3129
import de.wwu.scdh.teilsp.services.extensions.ExtensionException;
32-
import de.wwu.scdh.teilsp.services.extensions.SelectionDialogLoader;
3330
import de.wwu.scdh.oxbytei.commons.EditorVariablesExpanderImpl;
3431
import de.wwu.scdh.oxbytei.commons.WSDocumentReader;
3532
import de.wwu.scdh.oxbytei.commons.DocumentReaderException;
@@ -218,18 +215,28 @@ public SelectLabelledEntryInteraction (AuthorAccess authorAccess) {
218215

219216
LOGGER.debug("Loading providers for {} {} on context {}", nodeType, nodeName, context);
220217
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
222222
(document,
223-
currentFileURL.toString(),
224223
context,
225224
nodeType,
226225
nodeName,
227-
uriResolver,
228-
entityResolver,
229226
null,
230227
configFile,
231228
expander);
232229

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+
233240
providersCount = providers.size();
234241
return providersCount;
235242
}
@@ -247,8 +254,6 @@ public String doUserInteraction(final ArgumentsMap arguments)
247254
String rollbackOnCancelString =
248255
OperationArgumentValidator.validateStringArgument(ARGUMENT_ROLLBACK_ON_CANCEL.getName(), arguments);
249256
boolean rollbackOnCancel = rollbackOnCancelString.equals(AuthorConstants.ARG_VALUE_TRUE);
250-
String message =
251-
OperationArgumentValidator.validateStringArgument(ARGUMENT_MESSAGE.getName(), arguments);
252257
String iconString =
253258
OperationArgumentValidator.validateStringArgument(ARGUMENT_ICON.getName(), arguments);
254259
URL icon;
@@ -274,36 +279,42 @@ public String doUserInteraction(final ArgumentsMap arguments)
274279
}
275280

276281
// get the dialog
277-
ISelectionDialog dialogView;
282+
ISelectionDialog dialogView, dialogViewWithoutFrame;
278283
if (providersCount == 0) {
279284
// use fallback dialog
280285
// TODO: this prevents us from configuring dialogs in
281286
// contexts without providers. Is this wanted?
282287
dialogView = fallbackDialog();
283288
} else {
284289
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
287295
(document,
288-
currentFileURL.toString(),
289296
context,
290297
nodeType,
291298
nodeName,
292-
uriResolver,
293-
entityResolver,
294299
null,
295300
configFile,
296-
frame,
297301
expander);
302+
298303
if (dialogs.size() == 0) {
299304
dialogView = fallbackDialog();
300305
} else {
301306
// 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+
303313
// TODO: should we dispose all plugins or does GC the job?
304314
}
305315
}
306316

317+
307318
// envoke the dialog and get the selection/input
308319
List<String> selected;
309320
dialogView.setup(currentSelection, providers);
@@ -341,9 +352,12 @@ protected ISelectionDialog fallbackDialog()
341352
throws ConfigurationException, ExtensionException {
342353
ISelectionDialog dialog, dialogView;
343354
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);
347361

348362
Map<String, String> arguments = new HashMap<String, String>();
349363
arguments.put("title", "New value");
@@ -352,28 +366,8 @@ protected ISelectionDialog fallbackDialog()
352366
} catch (ProviderNotFoundException e) {
353367
throw new ConfigurationException
354368
("Default dialog view "
355-
+ SelectionDialogLoader.DEFAULT_PROVIDER
369+
+ OxbyteiConstants.DEFAULT_SELECTION_DIALOG
356370
+ " 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);
377371
}
378372

379373
// TODO dispose dialog

src/main/java/de/wwu/scdh/oxbytei/commons/EdiarumSelectionDialog.java

+27-12
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,30 @@
1111
package de.wwu.scdh.oxbytei.commons;
1212

1313
import java.awt.Frame;
14-
import java.net.URL;
1514
import java.util.Map;
1615
import java.util.List;
1716
import java.util.ArrayList;
1817
import java.util.Arrays;
1918

2019
import org.bbaw.telota.ediarum.InsertRegisterDialog;
2120

21+
import de.wwu.scdh.teilsp.exceptions.ConfigurationException;
2222
import de.wwu.scdh.teilsp.services.extensions.ILabelledEntriesProvider;
2323
import de.wwu.scdh.teilsp.services.extensions.LabelledEntry;
2424
import de.wwu.scdh.teilsp.services.extensions.ExtensionException;
2525
import de.wwu.scdh.teilsp.ui.ISelectionDialog;
26+
import de.wwu.scdh.teilsp.services.extensions.ArgumentDescriptor;
2627

2728

2829
public class EdiarumSelectionDialog
2930
implements ISelectionDialog {
3031

31-
Frame frame;
32-
boolean MULTIPLE = true;
33-
String title;
34-
List<String> currentValue, result;
35-
List<ILabelledEntriesProvider> providers;
32+
private Frame frame;
33+
private boolean MULTIPLE = true;
34+
private String title;
35+
private List<String> currentValue, result;
36+
private List<ILabelledEntriesProvider> providers;
37+
private Map<String, String> arguments;
3638

3739
public EdiarumSelectionDialog() {
3840
frame = new Frame();
@@ -42,12 +44,25 @@ public EdiarumSelectionDialog(Frame frame) {
4244
this.frame = frame;
4345
}
4446

45-
public void init(Map<String, String> arguments) {
46-
if (arguments.containsKey("title")) {
47-
title = arguments.get("title");
48-
} else {
49-
title = "Select";
50-
}
47+
private static final ArgumentDescriptor<String> ARGUMENT_TITLE =
48+
ISelectionDialog.ARGUMENT_TITLE;
49+
50+
private static final ArgumentDescriptor<?>[] ARGUMENTS = new ArgumentDescriptor<?>[] {
51+
ARGUMENT_TITLE
52+
};
53+
54+
public ArgumentDescriptor<?>[] getArgumentDescriptor() {
55+
return ARGUMENTS;
56+
}
57+
58+
public void init(Map<String, String> arguments)
59+
throws ConfigurationException {
60+
this.arguments = arguments;
61+
title = ARGUMENT_TITLE.getValue(arguments);
62+
}
63+
64+
public Map<String, String> getArguments() {
65+
return arguments;
5166
}
5267

5368
public void setup(List<String> currentVal,

src/main/java/de/wwu/scdh/oxbytei/commons/OxygenSelectionDialog.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;
1919
import ro.sync.exml.workspace.api.PluginWorkspace;
2020

21+
import de.wwu.scdh.teilsp.exceptions.ConfigurationException;
2122
import de.wwu.scdh.teilsp.services.extensions.ILabelledEntriesProvider;
2223
import de.wwu.scdh.teilsp.services.extensions.LabelledEntry;
2324
import de.wwu.scdh.teilsp.services.extensions.ExtensionException;
2425
import de.wwu.scdh.teilsp.exceptions.UIException;
2526
import de.wwu.scdh.teilsp.ui.ISelectionDialog;
27+
import de.wwu.scdh.teilsp.services.extensions.ArgumentDescriptor;
2628

2729

2830
public class OxygenSelectionDialog
@@ -33,18 +35,32 @@ public class OxygenSelectionDialog
3335
boolean multiple;
3436
List<String> currentValue, result;
3537
List<ILabelledEntriesProvider> providers;
38+
Map<String, String> arguments;
3639

3740
public OxygenSelectionDialog(Frame frame) {}
3841

3942
public OxygenSelectionDialog() {
4043
}
4144

42-
public void init(Map<String, String> arguments) {
43-
if (arguments.containsKey("title")) {
44-
title = arguments.get("title");
45-
} else {
46-
title = "Select";
47-
}
45+
private static final ArgumentDescriptor<String> ARGUMENT_TITLE =
46+
ISelectionDialog.ARGUMENT_TITLE;
47+
48+
private static final ArgumentDescriptor<?>[] ARGUMENTS = new ArgumentDescriptor<?>[] {
49+
ARGUMENT_TITLE
50+
};
51+
52+
public ArgumentDescriptor<?>[] getArgumentDescriptor() {
53+
return ARGUMENTS;
54+
}
55+
56+
public void init(Map<String, String> arguments)
57+
throws ConfigurationException {
58+
this.arguments = arguments;
59+
title = ARGUMENT_TITLE.getValue(arguments);
60+
}
61+
62+
public Map<String, String> getArguments() {
63+
return arguments;
4864
}
4965

5066
public void setup(List<String> currentVal,

0 commit comments

Comments
 (0)