use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class TechnologyOperCompDetailsListenersTNFO method copyTimeNormsFromOperation.
public void copyTimeNormsFromOperation(final ViewDefinitionState view, final ComponentState operationLookupState, final String[] args) {
ComponentState operationLookup = view.getComponentByReference(OPERATION);
if (operationLookup.getFieldValue() == null) {
if (!OPERATION.equals(operationLookupState.getName())) {
view.getComponentByReference(QcadooViewConstants.L_FORM).addMessage("productionTimeNorms.messages.info.missingOperationReference", INFO);
}
return;
}
Entity operation = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION).get((Long) operationLookup.getFieldValue());
FormComponent formComponent = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
if (formComponent.getEntityId() != null) {
Entity toc = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).get(formComponent.getEntityId());
copyOperationWorkstationTimes(toc, operation);
}
applyTimeNormsFromGivenSource(view, operation, FIELDS_OPERATION);
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class EventHooks method fetchNumberFromDatabase.
private void fetchNumberFromDatabase(final ViewDefinitionState view) {
FormComponent formComponent = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
if (formComponent.getEntityId() != null) {
ComponentState numberField = view.getComponentByReference(MaintenanceEventFields.NUMBER);
String numberFieldValue = (String) numberField.getFieldValue();
if (Strings.isNullOrEmpty(numberFieldValue)) {
DataDefinition maintenanceEventDD = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT);
Entity maintenanceEvent = maintenanceEventDD.get(formComponent.getEntityId());
numberField.setFieldValue(maintenanceEvent.getField(MaintenanceEventFields.NUMBER));
}
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class StaffsListListeners method printStaffLabels.
public void printStaffLabels(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent staffsGrid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
Set<Long> staffIds = staffsGrid.getSelectedEntitiesIds();
if (staffIds.isEmpty()) {
view.addMessage("basic.staffsList.error.notSelected", ComponentState.MessageType.INFO);
} else {
String redirectUrl = new StringBuilder("/basic/staffLabelsReport.pdf?").append(staffIds.stream().map(staffId -> "ids=" + staffId.toString()).collect(Collectors.joining("&"))).toString();
view.redirectTo(redirectUrl, true, false);
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class PlannedEventDetailsHooks method hideFields.
public void hideFields(final ViewDefinitionState view, final Entity plannedEvent, final FieldsForType fieldsForType) {
Set<String> allFields = plannedEvent.getDataDefinition().getFields().keySet();
List<String> hiddenFields = fieldsForType.getHiddenFields();
for (String fieldName : allFields) {
Optional<ComponentState> maybeFieldComponent = view.tryFindComponentByReference(fieldName);
if (maybeFieldComponent.isPresent() && !PlannedEventFields.STATE.equals(fieldName)) {
ComponentState fieldComponent = maybeFieldComponent.get();
if (hiddenFields.contains(fieldName)) {
fieldComponent.setVisible(false);
} else {
fieldComponent.setVisible(true);
}
}
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class PlannedEventDetailsListeners method onRemoveRelatedEvents.
public void onRemoveRelatedEvents(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent relatedEventsGrid = (GridComponent) view.getComponentByReference(PlannedEventFields.RELATED_EVENTS);
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity currentEvent = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_PLANNED_EVENT).get(form.getEntityId());
List<Entity> relatedEventsForCurrentEvent = Lists.newArrayList(currentEvent.getManyToManyField(PlannedEventFields.RELATED_EVENTS));
List<Entity> relatedEventsToDelete = relatedEventsGrid.getSelectedEntities();
for (Entity relatedEventToDelete : relatedEventsToDelete) {
List<Entity> relatedEvents = Lists.newArrayList(relatedEventToDelete.getManyToManyField(PlannedEventFields.RELATED_EVENTS));
Optional<Entity> eventToDelete = relatedEvents.stream().filter(event -> event.getId().compareTo(currentEvent.getId()) == 0).findFirst();
if (eventToDelete.isPresent()) {
relatedEvents.remove(eventToDelete.get());
relatedEventToDelete.setField(PlannedEventFields.RELATED_EVENTS, relatedEvents);
relatedEventToDelete.getDataDefinition().save(relatedEventToDelete);
}
Optional<Entity> eventToDeleteFromCurrent = relatedEventsForCurrentEvent.stream().filter(event -> event.getId().compareTo(relatedEventToDelete.getId()) == 0).findFirst();
if (eventToDeleteFromCurrent.isPresent()) {
relatedEventsForCurrentEvent.remove(eventToDeleteFromCurrent.get());
}
}
currentEvent.setField(PlannedEventFields.RELATED_EVENTS, relatedEventsForCurrentEvent);
currentEvent.getDataDefinition().save(currentEvent);
Entity formEntity = form.getEntity();
formEntity = formEntity.getDataDefinition().get(formEntity.getId());
form.setEntity(formEntity);
view.performEvent(view, "refresh");
}
Aggregations