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