use of org.jowidgets.api.command.IEnabledState in project jo-client-platform by jo-source.
the class AbstractDataModelCommand method checkEnabledState.
private void checkEnabledState() {
if (dataModels.size() == 0) {
enabledChecker.setEnabledState(NO_DATA_NODE_STATE.get());
return;
} else {
for (final IDataModel dataModel : dataModels) {
final IEnabledState vetoEnabledState = getVetoEnabledState(dataModel);
if (!vetoEnabledState.isEnabled()) {
enabledChecker.setEnabledState(vetoEnabledState);
return;
}
}
for (final IDataModel dataModel : dataModels) {
final IEnabledState enabledState = getEnabledState(dataModel);
if (enabledState.isEnabled()) {
enabledChecker.setEnabledState(EnabledState.ENABLED);
return;
}
enabledChecker.setEnabledState(enabledState);
}
}
}
use of org.jowidgets.api.command.IEnabledState in project jo-client-platform by jo-source.
the class BeanSelectionProviderEnabledChecker method getEnabledState.
@Override
public IEnabledState getEnabledState() {
// TODO MG enabled checks must be done better performance
if (BeanSelectionPolicy.SINGLE_SELECTION == beanSelectionPolicy && lastSelection.size() != 1) {
return SINGLE_SELECTION_STATE.get();
} else if (BeanSelectionPolicy.MULTI_SELECTION == beanSelectionPolicy && lastSelection.size() < 1) {
return MULTI_SELECTION_STATE.get();
} else if (BeanSelectionPolicy.NO_SELECTION == beanSelectionPolicy && lastSelection.size() > 0) {
return NO_SELECTION_STATE.get();
}
for (final IEnabledChecker enabledChecker : enabledCheckers) {
final IEnabledState result = enabledChecker.getEnabledState();
if (!result.isEnabled()) {
return result;
}
}
if (!ignoreSelectedBeansState) {
for (final IBeanProxy bean : lastSelection) {
if (bean == null) {
return UNLOADED_DATA_STATE.get();
}
if (bean.isDummy() || bean.isLastRowDummy()) {
return EnabledState.DISABLED;
}
final IBeanMessage worstMessage = bean.getFirstWorstMessage();
final IBeanMessage worstMandatoryMessage = bean.getFirstWorstMandatoryMessage();
if (bean.getExecutionTask() != null) {
return IS_IN_PROGRESS_STATE.get();
} else if (BeanMessageStatePolicy.NO_MESSAGE == beanMessageStatePolicy && worstMessage != null) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanMessageStatePolicy.NO_MESSAGE_MANDATORY == beanMessageStatePolicy && worstMandatoryMessage != null) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanModificationStatePolicy.NO_MODIFICATION == beanModificationStatePolicy && bean.hasModifications() && !bean.isTransient()) {
return UNSAVED_DATA_STATE.get();
} else if (BeanMessageStatePolicy.NO_WARNING_OR_ERROR == beanMessageStatePolicy && worstMessage != null && worstMessage.getType().equalOrWorse(BeanMessageType.WARNING)) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanMessageStatePolicy.NO_WARNING_OR_ERROR_MANDATORY == beanMessageStatePolicy && worstMandatoryMessage != null && worstMandatoryMessage.getType().equalOrWorse(BeanMessageType.WARNING)) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanMessageStatePolicy.NO_ERROR == beanMessageStatePolicy && worstMessage != null && worstMessage.getType() == BeanMessageType.ERROR) {
return UNHANDLED_MESSAGES_STATE.get();
} else if (BeanMessageStatePolicy.NO_ERROR_MANDATORY == beanMessageStatePolicy && worstMandatoryMessage != null && worstMandatoryMessage.getType() == BeanMessageType.ERROR) {
return UNHANDLED_MESSAGES_STATE.get();
}
for (final IExecutableChecker executableChecker : executableCheckers) {
final IExecutableState result = executableChecker.getExecutableState(bean.getBean());
if (!result.isExecutable()) {
return EnabledState.disabled(result.getReason());
}
}
}
}
return EnabledState.ENABLED;
}
Aggregations