Search in sources :

Example 1 with ValueHolder

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);
    }
}
Also used : Progress(org.jowidgets.cap.remoting.common.Progress) IExecutionCallback(org.jowidgets.cap.common.api.execution.IExecutionCallback) ValueHolder(org.jowidgets.util.ValueHolder)

Example 2 with ValueHolder

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());
}
Also used : IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult) ValueHolder(org.jowidgets.util.ValueHolder) IExternalBeanValidator(org.jowidgets.cap.ui.api.bean.IExternalBeanValidator) IBeanValidationResultListBuilder(org.jowidgets.cap.common.api.validation.IBeanValidationResultListBuilder) LinkedList(java.util.LinkedList)

Example 3 with ValueHolder

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());
}
Also used : IChangeListener(org.jowidgets.util.event.IChangeListener) IItemStateListener(org.jowidgets.common.widgets.controller.IItemStateListener) ValueHolder(org.jowidgets.util.ValueHolder)

Example 4 with ValueHolder

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();
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ValueHolder(org.jowidgets.util.ValueHolder)

Example 5 with ValueHolder

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();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) UserQuestionResult(org.jowidgets.cap.common.api.execution.UserQuestionResult) ValueHolder(org.jowidgets.util.ValueHolder) UserQuestionRequest(org.jowidgets.cap.remoting.common.UserQuestionRequest) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

ValueHolder (org.jowidgets.util.ValueHolder)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Condition (java.util.concurrent.locks.Condition)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 IExecutionCallback (org.jowidgets.cap.common.api.execution.IExecutionCallback)1 UserQuestionResult (org.jowidgets.cap.common.api.execution.UserQuestionResult)1 IBeanValidationResult (org.jowidgets.cap.common.api.validation.IBeanValidationResult)1 IBeanValidationResultListBuilder (org.jowidgets.cap.common.api.validation.IBeanValidationResultListBuilder)1 Progress (org.jowidgets.cap.remoting.common.Progress)1 UserQuestionRequest (org.jowidgets.cap.remoting.common.UserQuestionRequest)1 IExternalBeanValidator (org.jowidgets.cap.ui.api.bean.IExternalBeanValidator)1 IItemStateListener (org.jowidgets.common.widgets.controller.IItemStateListener)1 IChangeListener (org.jowidgets.util.event.IChangeListener)1 Test (org.junit.Test)1