use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class AdvancedGenealogyTreeViewListenersTest method shouldGenerateUsedToProduceTree.
@SuppressWarnings("unchecked")
@Test
public void shouldGenerateUsedToProduceTree() {
// given
Entity batch = mock(Entity.class);
when(batch.getId()).thenReturn(1L);
when(batch.getField("parent")).thenReturn(null);
when(batch.getField("priority")).thenReturn(1);
when(batch.getField("entityType")).thenReturn("batch");
ComponentState includeDraftComponent = mock(ComponentState.class);
ComponentState treeTypeComponent = mock(ComponentState.class);
when(batchLookup.getFieldValue()).thenReturn(1L);
when(dataDefinition.get(1L)).thenReturn(batch);
when(view.getComponentByReference("includeDrafts")).thenReturn(includeDraftComponent);
String includeDraftsString = "0";
when(includeDraftComponent.getFieldValue()).thenReturn(includeDraftsString);
boolean includeDrafts = "1".equals(includeDraftsString);
when(view.getComponentByReference("treeType")).thenReturn(treeTypeComponent);
when(treeTypeComponent.getFieldValue()).thenReturn("02usedToProduce");
List<Entity> tree = mock(List.class);
when(advancedGenealogyTreeService.getUsedToProduceTree(batch, includeDrafts, true)).thenReturn(tree);
Iterator<Entity> treeIterator = mock(Iterator.class);
when(treeIterator.hasNext()).thenReturn(true, false);
when(treeIterator.next()).thenReturn(batch);
when(tree.iterator()).thenReturn(treeIterator);
ComponentState genealogyTree = mock(ComponentState.class);
when(view.getComponentByReference("genealogyTree")).thenReturn(genealogyTree);
// when
viewListeners.generateFormEntity(view, state);
// then
verify(advancedGenealogyTreeService).getUsedToProduceTree(batch, includeDrafts, true);
verify(formEntity).setField("producedBatch", batch);
verify(formEntity).setField(eq("genealogyTree"), any(EntityTree.class));
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class AdvancedGenealogyTreeViewListenersTest method shouldGenerateProducedFromTree.
@SuppressWarnings("unchecked")
@Test
public void shouldGenerateProducedFromTree() {
// given
Entity batch = mock(Entity.class);
when(batch.getId()).thenReturn(1L);
when(batch.getField("parent")).thenReturn(null);
when(batch.getField("priority")).thenReturn(1);
when(batch.getField("entityType")).thenReturn("batch");
ComponentState includeDraftComponent = mock(ComponentState.class);
ComponentState treeTypeComponent = mock(ComponentState.class);
when(batchLookup.getFieldValue()).thenReturn(1L);
when(dataDefinition.get(1L)).thenReturn(batch);
when(view.getComponentByReference("includeDrafts")).thenReturn(includeDraftComponent);
String includeDraftsString = "0";
when(includeDraftComponent.getFieldValue()).thenReturn(includeDraftsString);
boolean includeDrafts = "1".equals(includeDraftsString);
when(view.getComponentByReference("treeType")).thenReturn(treeTypeComponent);
when(treeTypeComponent.getFieldValue()).thenReturn("01producedFrom");
List<Entity> tree = mock(List.class);
when(advancedGenealogyTreeService.getProducedFromTree(batch, includeDrafts, true)).thenReturn(tree);
Iterator<Entity> treeIterator = mock(Iterator.class);
when(treeIterator.hasNext()).thenReturn(true, false);
when(treeIterator.next()).thenReturn(batch);
when(tree.iterator()).thenReturn(treeIterator);
ComponentState genealogyTree = mock(ComponentState.class);
when(view.getComponentByReference("genealogyTree")).thenReturn(genealogyTree);
// when
viewListeners.generateFormEntity(view, state);
// then
verify(advancedGenealogyTreeService).getProducedFromTree(batch, includeDrafts, true);
verify(formEntity).setField("producedBatch", batch);
verify(formEntity).setField(eq("genealogyTree"), any(EntityTree.class));
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class ProductionCountingQuantityAdvancedDetailsHooks method hideFieldsDependsOfState.
private void hideFieldsDependsOfState(final ViewDefinitionState view) {
FormComponent productionCountingQuantityForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
ComponentState usedQuantityGridLayout = view.getComponentByReference(L_USED_QUANTITY_GRID_LAYOUT);
ComponentState producedQuantityGridLayout = view.getComponentByReference(L_PRODUCED_QUANTITY_GRID_LAYOUT);
FieldComponent roleField = (FieldComponent) view.getComponentByReference(ProductionCountingQuantityFields.ROLE);
Long productionCountingQuantityId = productionCountingQuantityForm.getEntityId();
boolean isEnabled = (productionCountingQuantityId != null);
boolean isUsed = checkIfIsUsed((String) roleField.getFieldValue());
boolean isProduced = checkIfIsProduced((String) roleField.getFieldValue());
updateComponentState(usedQuantityGridLayout, isEnabled && isUsed);
updateComponentState(producedQuantityGridLayout, isEnabled && isProduced);
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class AdvancedGenealogyTreeViewListenersTest method shouldStopGeneratingTreeAndAddCertainMessageIfNoTreeTypeIsSelected.
@Test(expected = FormValidationException.class)
public void shouldStopGeneratingTreeAndAddCertainMessageIfNoTreeTypeIsSelected() {
// given
Entity batch = mock(Entity.class);
ComponentState includeDraftComponent = mock(ComponentState.class);
ComponentState treeTypeComponent = mock(ComponentState.class);
when(batchLookup.getFieldValue()).thenReturn(1L);
when(dataDefinition.get(1L)).thenReturn(batch);
when(view.getComponentByReference("includeDrafts")).thenReturn(includeDraftComponent);
when(includeDraftComponent.getFieldValue()).thenReturn("0");
when(view.getComponentByReference("treeType")).thenReturn(treeTypeComponent);
when(treeTypeComponent.getFieldValue()).thenReturn(null);
// when
viewListeners.generateFormEntity(view, state);
// then
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class ProductDetailsHooks method enableCharacteristicsTabForExternalItems.
public void enableCharacteristicsTabForExternalItems(final ViewDefinitionState view) {
FormComponent productForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Long productId = productForm.getEntityId();
if (Objects.isNull(productId)) {
return;
}
Entity product = getProductDD().get(productId);
if (Objects.isNull(product)) {
return;
}
String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER);
if (!StringUtils.isEmpty(externalNumber)) {
for (String componentName : innerComponents) {
ComponentState characteristicsTab = view.getComponentByReference(componentName);
characteristicsTab.setEnabled(true);
}
}
}
Aggregations