IDEMPIERE-3460 Ability to share window validators by several windows

This commit is contained in:
Nicolas Micoud 2017-08-29 15:50:30 +02:00
parent 09ecb2fc0b
commit 205edcdb73
1 changed files with 41 additions and 15 deletions

View File

@ -27,20 +27,32 @@ public class WindowValidatorManager implements BundleActivator, ServiceTrackerCu
public WindowValidator addingService(
ServiceReference<WindowValidator> reference) {
WindowValidator service = context.getService(reference);
String uuid = (String) reference.getProperty("AD_Window_UU");
if (uuid == null || "*".equals(uuid)) {
globalValidators.add(service);
return service;
Object obj = reference.getProperty("AD_Window_UU");
if (obj instanceof String) {
String uuid = (String) reference.getProperty("AD_Window_UU");
if (uuid == null || "*".equals(uuid)) {
globalValidators.add(service);
return service;
}
addService(service, uuid);
}
else if (obj instanceof String []) {
String[] uuids = (String []) reference.getProperty("AD_Window_UU");
for (String uuid : uuids)
addService(service, uuid);
}
return service;
}
void addService(WindowValidator service, String uuid) {
List<WindowValidator> list = validatorMap.get(uuid);
if (list == null) {
list = new ArrayList<WindowValidator>();
validatorMap.put(uuid, list);
}
list.add(service);
return service;
list.add(service);
}
@Override
@ -51,14 +63,28 @@ public class WindowValidatorManager implements BundleActivator, ServiceTrackerCu
@Override
public void removedService(ServiceReference<WindowValidator> reference,
WindowValidator service) {
String uuid = (String) reference.getProperty("AD_Window_UU");
if (uuid == null || "*".equals(uuid)) {
globalValidators.remove(service);
} else {
List<WindowValidator> list = validatorMap.get(uuid);
if (list != null) {
list.remove(service);
Object obj = reference.getProperty("AD_Window_UU");
if (obj instanceof String) {
String uuid = (String) reference.getProperty("AD_Window_UU");
if (uuid == null || "*".equals(uuid)) {
globalValidators.remove(service);
}
else
removeService(service, uuid);
}
else if (obj instanceof String []) {
String[] uuids = (String []) reference.getProperty("AD_Window_UU");
for (String uuid : uuids)
removeService(service, uuid);
}
}
void removeService(WindowValidator service, String uuid) {
List<WindowValidator> list = validatorMap.get(uuid);
if (list != null) {
list.remove(service);
}
}