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();
}
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();
}
}
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;
}
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;
}
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();
}
}
Aggregations