Search in sources :

Example 1 with MethodParameterInfo

use of com.haulmont.cuba.core.app.scheduled.MethodParameterInfo in project cuba by cuba-platform.

the class AbstractBeansMetadata method getMethodParameters.

protected List<MethodParameterInfo> getMethodParameters(Method method) {
    ArrayList<MethodParameterInfo> params = new ArrayList<>();
    Class<?>[] parameterTypes = method.getParameterTypes();
    LocalVariableTableParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
    String[] parameterNames = parameterNameDiscoverer.getParameterNames(method);
    if (parameterTypes != null) {
        for (int i = 0; i < parameterTypes.length; i++) {
            String parameterName = parameterNames != null ? parameterNames[i] : "arg" + i;
            MethodParameterInfo parameterInfo = new MethodParameterInfo(parameterTypes[i].getName(), parameterName, null);
            params.add(parameterInfo);
        }
    }
    return params;
}
Also used : LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) MethodParameterInfo(com.haulmont.cuba.core.app.scheduled.MethodParameterInfo)

Example 2 with MethodParameterInfo

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

Example 3 with MethodParameterInfo

use of com.haulmont.cuba.core.app.scheduled.MethodParameterInfo in project cuba by cuba-platform.

the class ScheduledTask method getMethodParameters.

public List<MethodParameterInfo> getMethodParameters() {
    ArrayList<MethodParameterInfo> result = new ArrayList<>();
    String xml = getMethodParamsXml();
    if (!StringUtils.isBlank(xml)) {
        Document doc = Dom4j.readDocument(xml);
        List<Element> elements = Dom4j.elements(doc.getRootElement(), "param");
        for (Element paramEl : elements) {
            String typeName = paramEl.attributeValue("type");
            String name = paramEl.attributeValue("name");
            Object value = paramEl.getText();
            result.add(new MethodParameterInfo(typeName, name, value));
        }
    }
    return result;
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) MethodParameterInfo(com.haulmont.cuba.core.app.scheduled.MethodParameterInfo) Document(org.dom4j.Document)

Example 4 with MethodParameterInfo

use of com.haulmont.cuba.core.app.scheduled.MethodParameterInfo 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)

Example 5 with MethodParameterInfo

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

Aggregations

MethodParameterInfo (com.haulmont.cuba.core.app.scheduled.MethodParameterInfo)8 MethodInfo (com.haulmont.cuba.core.app.scheduled.MethodInfo)4 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 MetaProperty (com.haulmont.chile.core.annotations.MetaProperty)1 SchedulingType (com.haulmont.cuba.core.entity.SchedulingType)1 CubaDefaultListableBeanFactory (com.haulmont.cuba.core.sys.CubaDefaultListableBeanFactory)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 TargetClassAware (org.springframework.aop.TargetClassAware)1 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)1