Search in sources :

Example 1 with SchedulingType

use of com.haulmont.cuba.core.entity.SchedulingType 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);
        }
    });
}
Also used : SchedulingType(com.haulmont.cuba.core.entity.SchedulingType) MethodInfo(com.haulmont.cuba.core.app.scheduled.MethodInfo) MethodParameterInfo(com.haulmont.cuba.core.app.scheduled.MethodParameterInfo)

Aggregations

MethodInfo (com.haulmont.cuba.core.app.scheduled.MethodInfo)1 MethodParameterInfo (com.haulmont.cuba.core.app.scheduled.MethodParameterInfo)1 SchedulingType (com.haulmont.cuba.core.entity.SchedulingType)1