Search in sources :

Example 1 with Some

use of org.jowidgets.util.maybe.Some in project jo-client-platform by jo-source.

the class ExecutorAnnotationPostProcessor method evaluateParameterExpression.

IMaybe<Object> evaluateParameterExpression(final Object parameter, final Method method, final int argIndex) {
    final Annotation[] annotations = method.getParameterAnnotations()[argIndex];
    for (final Annotation annotation : annotations) {
        if (annotation instanceof Parameter) {
            final Parameter paramAnno = (Parameter) annotation;
            if (!expressions.containsKey(paramAnno)) {
                expressions.putIfAbsent(paramAnno, expressionParser.parseExpression(paramAnno.value()));
            }
            final Expression expression = expressions.get(paramAnno);
            return new Some<Object>(expression.getValue(parameter, method.getParameterTypes()[argIndex]));
        }
    }
    return Nothing.getInstance();
}
Also used : Some(org.jowidgets.util.maybe.Some) Expression(org.springframework.expression.Expression) Parameter(org.jowidgets.cap.service.api.annotation.Parameter) Annotation(java.lang.annotation.Annotation)

Example 2 with Some

use of org.jowidgets.util.maybe.Some in project jo-client-platform by jo-source.

the class BeanTableBatchEditCommand method getNewValue.

@SuppressWarnings("unchecked")
private IMaybe<Object> getNewValue(final IExecutionContext executionContext, final Object currentValue, final IAttribute<Object> attribute) {
    final ICustomWidgetCreator<IInputControl<Object>> widgetCreator = getWidgetCreator(attribute);
    if (widgetCreator == null) {
        // TODO this should not occur, show an error to the user
        return Nothing.getInstance();
    }
    final IInputDialogBluePrint<Object> dialogBp = BPF.inputDialog(new CurrentValueContentCreator(widgetCreator, attribute));
    dialogBp.setExecutionContext(executionContext);
    dialogBp.setAutoDispose(true);
    dialogBp.setMinPackSize(new Dimension(400, 200));
    dialogBp.setMaxPackSize(new Dimension(800, 600));
    final IInputDialog<Object> dialog = Toolkit.getActiveWindow().createChildWindow(dialogBp);
    dialog.setValue(currentValue);
    dialog.setVisible(true);
    if (dialog.isOkPressed()) {
        return new Some<Object>(dialog.getValue());
    } else {
        return Nothing.getInstance();
    }
}
Also used : Some(org.jowidgets.util.maybe.Some) IInputControl(org.jowidgets.api.widgets.IInputControl) Dimension(org.jowidgets.common.types.Dimension)

Example 3 with Some

use of org.jowidgets.util.maybe.Some in project jo-client-platform by jo-source.

the class ControlPanelProviderBuilderImpl method setObjectLabelConverter.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public IControlPanelProviderBuilder<ELEMENT_VALUE_TYPE> setObjectLabelConverter(final IObjectStringConverter objectStringConverter) {
    if (objectStringConverter instanceof IObjectLabelConverter<?>) {
        setObjectLabelConverter((IObjectLabelConverter<?>) objectStringConverter);
    } else {
        this.objectLabelConverter = null;
        this.objectStringConverter = new Some(objectStringConverter);
    }
    return null;
}
Also used : Some(org.jowidgets.util.maybe.Some) IObjectLabelConverter(org.jowidgets.api.convert.IObjectLabelConverter)

Example 4 with Some

use of org.jowidgets.util.maybe.Some in project jo-client-platform by jo-source.

the class ControlPanelProviderBuilderImpl method setObjectLabelConverter.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public IControlPanelProviderBuilder<ELEMENT_VALUE_TYPE> setObjectLabelConverter(final IObjectLabelConverter objectLabelConverter) {
    this.objectStringConverter = null;
    this.objectLabelConverter = new Some(objectLabelConverter);
    return this;
}
Also used : Some(org.jowidgets.util.maybe.Some)

Example 5 with Some

use of org.jowidgets.util.maybe.Some in project jo-client-platform by jo-source.

the class FilterUtil method hasLessOrEqualResults.

public static IMaybe<Boolean> hasLessOrEqualResults(final IBooleanFilter oldFilter, final IBooleanFilter newFilter) {
    Assert.paramNotNull(oldFilter, "oldFilter");
    Assert.paramNotNull(newFilter, "newFilter");
    if (oldFilter.equals(newFilter)) {
        return new Some<Boolean>(Boolean.TRUE);
    } else if (oldFilter.getOperator() == BooleanOperator.OR && newFilter.getOperator() == BooleanOperator.OR) {
        final HashSet<IFilter> oldFilterChildren = new HashSet<IFilter>(oldFilter.getFilters());
        final HashSet<IFilter> newFilterChildren = new HashSet<IFilter>(newFilter.getFilters());
        // test if all conditions of the new filter are part of the old filter
        for (final IFilter newFilterChild : newFilter.getFilters()) {
            if (oldFilterChildren.remove(newFilterChild)) {
                newFilterChildren.remove(newFilterChild);
            }
        }
        if (newFilterChildren.size() == 0) {
            // all conditions of the new filter are part of the old filter
            return new Some<Boolean>(Boolean.TRUE);
        } else if (oldFilterChildren.size() == 1 && newFilterChildren.size() == 1) {
            // they differ by one condition, so check this condition
            return (hasLessOrEqualResults(oldFilterChildren.iterator().next(), newFilterChildren.iterator().next()));
        } else {
            // TODO add more complex tests here
            return Nothing.getInstance();
        }
    } else if (oldFilter.getOperator() == BooleanOperator.AND && newFilter.getOperator() == BooleanOperator.AND) {
        final HashSet<IFilter> oldFilterChildren = new HashSet<IFilter>(oldFilter.getFilters());
        final HashSet<IFilter> newFilterChildren = new HashSet<IFilter>(newFilter.getFilters());
        // test if all conditions of the old filter are part of the new filter
        for (final IFilter newFilterChild : newFilter.getFilters()) {
            if (newFilterChildren.remove(newFilterChild)) {
                oldFilterChildren.remove(newFilterChild);
            }
        }
        if (oldFilterChildren.size() == 0) {
            // all conditions of the old filter are part of the new filter
            return new Some<Boolean>(Boolean.TRUE);
        } else if (oldFilterChildren.size() == 1 && newFilterChildren.size() == 1) {
            // they differ by one condition, so check this condition
            return (hasLessOrEqualResults(oldFilterChildren.iterator().next(), newFilterChildren.iterator().next()));
        } else {
            // TODO add more complex tests here
            return Nothing.getInstance();
        }
    } else {
        // if operators changed, it is not predictable
        return Nothing.getInstance();
    }
}
Also used : Some(org.jowidgets.util.maybe.Some) IFilter(org.jowidgets.cap.common.api.filter.IFilter) HashSet(java.util.HashSet)

Aggregations

Some (org.jowidgets.util.maybe.Some)6 File (java.io.File)1 Annotation (java.lang.annotation.Annotation)1 HashSet (java.util.HashSet)1 IObjectLabelConverter (org.jowidgets.api.convert.IObjectLabelConverter)1 IFileChooser (org.jowidgets.api.widgets.IFileChooser)1 IInputControl (org.jowidgets.api.widgets.IInputControl)1 IQuestionDialog (org.jowidgets.api.widgets.IQuestionDialog)1 IFileChooserBluePrint (org.jowidgets.api.widgets.blueprint.IFileChooserBluePrint)1 IQuestionDialogBluePrint (org.jowidgets.api.widgets.blueprint.IQuestionDialogBluePrint)1 IFilter (org.jowidgets.cap.common.api.filter.IFilter)1 Parameter (org.jowidgets.cap.service.api.annotation.Parameter)1 ICsvExportParameter (org.jowidgets.cap.ui.api.table.ICsvExportParameter)1 DialogResult (org.jowidgets.common.types.DialogResult)1 Dimension (org.jowidgets.common.types.Dimension)1 Expression (org.springframework.expression.Expression)1