use of com.haulmont.cuba.core.app.scheduled.MethodInfo in project cuba by cuba-platform.
the class ScheduledTaskEditor method setInitialMethodNameValue.
/**
* Method reads values of methodName and parameters from item,
* finds appropriate MethodInfo object in methodInfoField's optionsList
* and sets found value to methodInfoField
*/
protected void setInitialMethodNameValue(ScheduledTask task) {
if (availableMethods == null)
return;
List<MethodParameterInfo> methodParamInfos = task.getMethodParameters();
MethodInfo currentMethodInfo = new MethodInfo(task.getMethodName(), methodParamInfos);
for (MethodInfo availableMethod : availableMethods) {
if (currentMethodInfo.definitionEquals(availableMethod)) {
availableMethod.setParameters(currentMethodInfo.getParameters());
methodNameField.setValue(availableMethod);
break;
}
}
}
use of com.haulmont.cuba.core.app.scheduled.MethodInfo in project cuba by cuba-platform.
the class ScheduledTaskEditor method init.
@Override
public void init(Map<String, Object> params) {
schedulingTypeField.setOptionsList(Arrays.asList(SchedulingType.values()));
schedulingTypeField.addValueChangeListener(e -> setSchedulingTypeField((SchedulingType) e.getValue()));
definedByField.setOptionsList(Arrays.asList(ScheduledTaskDefinedBy.values()));
definedByField.addValueChangeListener(e -> {
if (ScheduledTaskDefinedBy.BEAN == e.getValue()) {
clear(classNameField, scriptNameField);
hideAll();
show(beanNameField, beanNameLabel, methodNameField, methodNameLabel, methodNameHbox);
} else if (ScheduledTaskDefinedBy.CLASS == e.getValue()) {
clear(beanNameField, methodNameField, scriptNameField);
hideAll();
show(classNameField, classNameLabel);
} else if (ScheduledTaskDefinedBy.SCRIPT == e.getValue()) {
clear(beanNameField, methodNameField, classNameField);
hideAll();
show(scriptNameField, scriptNameLabel);
} else {
clear(beanNameField, methodNameField, classNameField, scriptNameField);
hideAll();
}
});
Map<String, List<MethodInfo>> availableBeans = service.getAvailableBeans();
beanNameField.setOptionsList(new ArrayList<>(availableBeans.keySet()));
beanNameField.addValueChangeListener(e -> {
methodNameField.setValue(null);
hide(methodParamsBox);
if (e.getValue() == null) {
methodNameField.setOptionsList(Collections.emptyList());
} else {
availableMethods = availableBeans.get(e.getValue());
if (availableMethods != null) {
HashMap<String, Object> optionsMap = new HashMap<>();
for (MethodInfo availableMethod : availableMethods) {
optionsMap.put(availableMethod.getMethodSignature(), availableMethod);
}
methodNameField.setOptionsMap(optionsMap);
}
}
});
methodNameField.addValueChangeListener(e -> {
clearMethodParamsGrid();
if (e.getValue() != null) {
createMethodParamsGrid((MethodInfo) e.getValue());
if (methodParamsBox.getComponents().size() > 1) {
show(methodParamsBox);
} else {
hide(methodParamsBox);
}
}
String methodName = (e.getValue() != null) ? ((MethodInfo) e.getValue()).getName() : null;
taskDs.getItem().setMethodName(methodName);
List<MethodParameterInfo> methodParams = (e.getValue() != null) ? ((MethodInfo) e.getValue()).getParameters() : Collections.<MethodParameterInfo>emptyList();
taskDs.getItem().updateMethodParameters(methodParams);
});
userNameField.setOptionsList(service.getAvailableUsers());
logFinishField.addValueChangeListener(e -> {
if (Boolean.TRUE.equals(e.getValue())) {
logStartField.setValue(true);
logStartField.setEditable(false);
} else {
logStartField.setEditable(true);
}
});
}
use of com.haulmont.cuba.core.app.scheduled.MethodInfo in project cuba by cuba-platform.
the class ScheduledTaskEditor method createMethodParamsGrid.
protected void createMethodParamsGrid(MethodInfo methodInfo) {
GridLayout methodParamsGrid = componentsFactory.createComponent(GridLayout.class);
methodParamsGrid.setSpacing(true);
methodParamsGrid.setColumns(2);
int rowsCount = 0;
for (final MethodParameterInfo parameterInfo : methodInfo.getParameters()) {
Label nameLabel = componentsFactory.createComponent(Label.class);
nameLabel.setValue(parameterInfo.getType().getSimpleName() + " " + parameterInfo.getName());
TextField valueTextField = componentsFactory.createComponent(TextField.class);
valueTextField.setWidth(themeConstants.get("cuba.gui.ScheduledTaskEditor.valueTextField.width"));
valueTextField.setValue(parameterInfo.getValue());
valueTextField.addValueChangeListener(e -> {
parameterInfo.setValue(e.getValue());
MethodInfo selectedMethod = methodNameField.getValue();
taskDs.getItem().updateMethodParameters(selectedMethod.getParameters());
});
methodParamsGrid.setRows(++rowsCount);
methodParamsGrid.add(nameLabel, 0, rowsCount - 1);
methodParamsGrid.add(valueTextField, 1, rowsCount - 1);
}
methodParamsBox.add(methodParamsGrid);
}
use of com.haulmont.cuba.core.app.scheduled.MethodInfo in project cuba by cuba-platform.
the class AbstractBeansMetadata method getAvailableMethods.
protected List<MethodInfo> getAvailableMethods(String beanName) {
List<MethodInfo> methods = new ArrayList<>();
try {
AutowireCapableBeanFactory beanFactory = AppContext.getApplicationContext().getAutowireCapableBeanFactory();
if (beanFactory instanceof CubaDefaultListableBeanFactory) {
BeanDefinition beanDefinition = ((CubaDefaultListableBeanFactory) beanFactory).getBeanDefinition(beanName);
if (beanDefinition.isAbstract())
return methods;
}
Object bean = AppBeans.get(beanName);
@SuppressWarnings("unchecked") List<Class> classes = ClassUtils.getAllInterfaces(bean.getClass());
for (Class aClass : classes) {
if (aClass.getName().startsWith("org.springframework."))
continue;
Class<?> targetClass = bean instanceof TargetClassAware ? ((TargetClassAware) bean).getTargetClass() : bean.getClass();
for (Method method : aClass.getMethods()) {
if (isMethodAvailable(method)) {
Method targetClassMethod = targetClass.getMethod(method.getName(), method.getParameterTypes());
List<MethodParameterInfo> methodParameters = getMethodParameters(targetClassMethod);
MethodInfo methodInfo = new MethodInfo(method.getName(), methodParameters);
addMethod(methods, methodInfo);
}
}
if (methods.isEmpty()) {
for (Method method : bean.getClass().getMethods()) {
if (!method.getDeclaringClass().equals(Object.class) && isMethodAvailable(method)) {
List<MethodParameterInfo> methodParameters = getMethodParameters(method);
MethodInfo methodInfo = new MethodInfo(method.getName(), methodParameters);
addMethod(methods, methodInfo);
}
}
}
}
} catch (Throwable t) {
log.debug(t.getMessage());
}
return methods;
}
Aggregations