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);
Object obj = reference.getProperty("AD_Window_UU");
if (obj instanceof String) {
String uuid = (String) reference.getProperty("AD_Window_UU"); String uuid = (String) reference.getProperty("AD_Window_UU");
if (uuid == null || "*".equals(uuid)) { if (uuid == null || "*".equals(uuid)) {
globalValidators.add(service); globalValidators.add(service);
return 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,16 +63,30 @@ public class WindowValidatorManager implements BundleActivator, ServiceTrackerCu
@Override @Override
public void removedService(ServiceReference<WindowValidator> reference, public void removedService(ServiceReference<WindowValidator> reference,
WindowValidator service) { WindowValidator service) {
Object obj = reference.getProperty("AD_Window_UU");
if (obj instanceof String) {
String uuid = (String) reference.getProperty("AD_Window_UU"); String uuid = (String) reference.getProperty("AD_Window_UU");
if (uuid == null || "*".equals(uuid)) { if (uuid == null || "*".equals(uuid)) {
globalValidators.remove(service); globalValidators.remove(service);
} else { }
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); List<WindowValidator> list = validatorMap.get(uuid);
if (list != null) { if (list != null) {
list.remove(service); list.remove(service);
} }
} }
}
@Override @Override
public void start(BundleContext context) throws Exception { public void start(BundleContext context) throws Exception {