use of org.jowidgets.api.command.IEnabledChecker 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