use of org.jowidgets.util.ValueHolder in project jo-client-platform by jo-source.
the class ProgressResponseCallback method setSubProgress.
private void setSubProgress(final Progress progress, final IExecutionCallback executionCallback) {
for (final Progress subProgress : progress.getSubProgressList()) {
// set the subProgress recursively
setSubProgress(subProgress, executionCallback);
// check if the task id is already registered
Tuple<ValueHolder<Progress>, IExecutionCallback> subCallback = subCallbacks.get(subProgress.getTaskId());
// if not, create a sub execution
if (subCallback == null) {
final ValueHolder<Progress> newProgress = new ValueHolder<Progress>(new Progress());
subCallback = new Tuple<ValueHolder<Progress>, IExecutionCallback>(newProgress, executionCallback.createSubExecution(subProgress.getStepProportion()));
subCallbacks.put(subProgress.getTaskId(), subCallback);
}
// set the progress on the execution callback and set the last progress to the current progress
setProgress(subProgress, subCallback.getFirst().get(), subCallback.getSecond());
subCallback.getFirst().set(subProgress);
}
}
use of org.jowidgets.util.ValueHolder in project jo-client-platform by jo-source.
the class BeanProxyImpl method validateProperties.
private void validateProperties(Collection<String> propertyNames) {
if (!isValidationNecessary()) {
clearValidationResults();
return;
}
propertyNames = getDependendProperties(propertyNames);
final IBeanValidationResultListBuilder builder = CapCommonToolkit.beanValidationResultListBuilder();
final ValueHolder<IBeanValidationResult> firstWorstIndependendResultHolder = new ValueHolder<IBeanValidationResult>();
for (final String propertyName : propertyNames) {
builder.addResult(validateProperty(propertyName));
}
Map<String, IBeanValidationResult> consolidatedResult;
consolidatedResult = consolidateBeanValidationResult(firstWorstIndependendResultHolder, builder.build());
// validate all results external
if (!consolidatedResult.isEmpty()) {
final List<IBeanValidationResult> externalResults = new LinkedList<IBeanValidationResult>();
for (final Entry<String, IBeanValidationResult> parentResultEntry : consolidatedResult.entrySet()) {
final String propertyName = parentResultEntry.getKey();
final IBeanValidationResult parentResult = parentResultEntry.getValue();
for (final IExternalBeanValidator externalValidator : getRegisteredExternalValidators(propertyName)) {
externalResults.addAll(externalValidator.validate(Collections.singletonList(parentResult)));
}
}
if (!externalResults.isEmpty()) {
consolidatedResult = consolidateBeanValidationResult(consolidatedResult, firstWorstIndependendResultHolder, externalResults);
}
}
setValidationResults(firstWorstIndependendResultHolder, consolidatedResult.values());
}
use of org.jowidgets.util.ValueHolder in project jo-client-platform by jo-source.
the class BeanTableHeaderFormatMenuModel method addRadioItemListener.
private static void addRadioItemListener(final IRadioItemModel radioItemModel, final IAttribute<?> attribute, final DisplayFormat displayFormat) {
final ValueHolder<IItemStateListener> itemStateListenerHolder = new ValueHolder<IItemStateListener>();
final ValueHolder<IChangeListener> changeListenerHolder = new ValueHolder<IChangeListener>();
itemStateListenerHolder.set(new IItemStateListener() {
@Override
public void itemStateChanged() {
if (!attribute.getLabelDisplayFormat().equals(displayFormat) && radioItemModel.isSelected()) {
attribute.removeChangeListener(changeListenerHolder.get());
attribute.setLabelDisplayFormat(displayFormat);
attribute.addChangeListener(changeListenerHolder.get());
}
}
});
changeListenerHolder.set(new IChangeListener() {
@Override
public void changed() {
if (attribute.getLabelDisplayFormat().equals(displayFormat) && !radioItemModel.isSelected()) {
radioItemModel.removeItemListener(itemStateListenerHolder.get());
radioItemModel.setSelected(true);
radioItemModel.addItemListener(itemStateListenerHolder.get());
}
}
});
radioItemModel.addItemListener(itemStateListenerHolder.get());
attribute.addChangeListener(changeListenerHolder.get());
}
use of org.jowidgets.util.ValueHolder in project jo-client-platform by jo-source.
the class BeanTableModelImpl method addLastBean.
private void addLastBean() {
if (lastBean == null) {
lastBean = beanProxyFactory.createLastRowDummyProxy();
final ValueHolder<PropertyChangeListener> listenerHolder = new ValueHolder<PropertyChangeListener>();
final PropertyChangeListener listener = new PropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent evt) {
if (lastBean.hasModifications()) {
lastBean.removePropertyChangeListener(listenerHolder.get());
for (final Entry<String, Object> entry : defaultValues.entrySet()) {
final String propertyName = entry.getKey();
if (!NullCompatibleEquivalence.equals(evt.getPropertyName(), propertyName)) {
lastBean.setValue(propertyName, entry.getValue());
}
}
final IBeanProxy<BEAN_TYPE> beanToAdd = lastBean;
beanToAdd.clearLastRowDummyState();
addBeans(Collections.singletonList(beanToAdd), false, false);
lastBean = null;
addLastBean();
}
}
};
listenerHolder.set(listener);
lastBean.addPropertyChangeListener(listener);
fireBeansChanged();
fireSelectionChanged();
}
}
use of org.jowidgets.util.ValueHolder in project jo-client-platform by jo-source.
the class ServerExecutionCallback method userQuestion.
@Override
public UserQuestionResult userQuestion(final String question) {
final ValueHolder<UserQuestionResult> result = new ValueHolder<UserQuestionResult>();
final Lock lock = new ReentrantLock();
final Condition condition = lock.newCondition();
interimRequestCallback.request(new IInterimResponseCallback<Object>() {
@Override
public void response(final Object response) {
final UserQuestionResult userQuestionResult = (UserQuestionResult) response;
result.set(userQuestionResult);
lock.lock();
condition.signal();
lock.unlock();
}
}, new UserQuestionRequest(question));
lock.lock();
condition.awaitUninterruptibly();
lock.unlock();
return result.get();
}
Aggregations