Search in sources :

Example 46 with ComponentState

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Example 47 with ComponentState

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));
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) ComponentState(com.qcadoo.view.api.ComponentState)

Example 48 with ComponentState

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);
    }
}
Also used : ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Service(org.springframework.stereotype.Service) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Set(java.util.Set) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 49 with ComponentState

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);
            }
        }
    }
}
Also used : ComponentState(com.qcadoo.view.api.ComponentState) SelectComponentState(com.qcadoo.view.internal.components.select.SelectComponentState)

Example 50 with ComponentState

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");
}
Also used : PlannedEventDetailsHooks(com.qcadoo.mes.cmmsMachineParts.hooks.PlannedEventDetailsHooks) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) EventHooks(com.qcadoo.mes.cmmsMachineParts.hooks.EventHooks) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CmmsMachinePartsConstants(com.qcadoo.mes.cmmsMachineParts.constants.CmmsMachinePartsConstants) Maps(com.google.common.collect.Maps) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponent(com.qcadoo.view.api.components.GridComponent) PlannedEventFields(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventFields) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) JSONException(org.json.JSONException) List(java.util.List) Lists(com.google.common.collect.Lists) LookupUtils(com.qcadoo.mes.basic.LookupUtils) JSONObject(org.json.JSONObject) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Map(java.util.Map) Optional(java.util.Optional) ActionForPlannedEventFields(com.qcadoo.mes.cmmsMachineParts.constants.ActionForPlannedEventFields) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent)

Aggregations

ComponentState (com.qcadoo.view.api.ComponentState)68 Entity (com.qcadoo.model.api.Entity)33 FormComponent (com.qcadoo.view.api.components.FormComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)23 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)21 Autowired (org.springframework.beans.factory.annotation.Autowired)17 FieldComponent (com.qcadoo.view.api.components.FieldComponent)16 Test (org.junit.Test)16 Service (org.springframework.stereotype.Service)16 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)15 Collectors (java.util.stream.Collectors)14 List (java.util.List)13 DataDefinition (com.qcadoo.model.api.DataDefinition)12 Lists (com.google.common.collect.Lists)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)11 Map (java.util.Map)11 BigDecimal (java.math.BigDecimal)10 Maps (com.google.common.collect.Maps)8 LookupComponent (com.qcadoo.view.api.components.LookupComponent)8 Transactional (org.springframework.transaction.annotation.Transactional)8