use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.
the class ReplacementsListeners method addManyReplacements.
public final void addManyReplacements(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
JSONObject obj = view.getJsonContext();
if (obj.has("window.mainTab.product.productId")) {
GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
Long productId = obj.getLong("window.mainTab.product.productId");
for (Long sub : grid.getSelectedEntitiesIds()) {
Entity substituteComponent = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE_COMPONENT).create();
substituteComponent.setField(SubstituteComponentFields.BASE_PRODUCT, productId);
substituteComponent.setField(SubstituteComponentFields.PRODUCT, sub);
substituteComponent.setField(SubstituteComponentFields.QUANTITY, 1);
substituteComponent.getDataDefinition().save(substituteComponent);
}
CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
generated.setChecked(true);
}
}
use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.
the class MachinePartDetailsHooks method setMachinePartCheckbox.
public void setMachinePartCheckbox(final ViewDefinitionState view) {
CheckBoxComponent machinePartCheckbox = (CheckBoxComponent) view.getComponentByReference(ProductFields.MACHINE_PART);
machinePartCheckbox.setChecked(true);
machinePartCheckbox.requestComponentUpdateState();
}
use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.
the class CostCalculationReportService method generateCostCalculationReport.
public void generateCostCalculationReport(final ViewDefinitionState view, final ComponentState state, final String[] args) {
if (state instanceof FormComponent) {
FieldComponent dateField = (FieldComponent) view.getComponentByReference(CostCalculationFields.DATE);
CheckBoxComponent generatedField = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.GENERATED);
Entity costCalculation = getCostCalculation((Long) state.getFieldValue());
if (costCalculation == null) {
state.addMessage("qcadooView.message.entityNotFound", MessageType.FAILURE);
return;
} else if (StringUtils.hasText(costCalculation.getStringField(CostCalculationFields.FILE_NAME))) {
state.addMessage("qcadooReport.errorMessage.documentsWasNotGenerated", MessageType.FAILURE);
return;
}
if (!generatedField.isChecked()) {
dateField.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, view.getLocale()).format(new Date()));
generatedField.setChecked(true);
}
state.performEvent(view, "save");
if (state.isHasError()) {
return;
}
if (state.getFieldValue() == null || !((FormComponent) state).isValid()) {
dateField.setFieldValue(null);
generatedField.setChecked(false);
return;
}
costCalculation = getCostCalculation((Long) state.getFieldValue());
try {
Entity costCalculationWithFileName = fileService.updateReportFileName(costCalculation, CostCalculationFields.DATE, "costCalculation.costCalculation.report.fileName");
costCalculationXlsService.generateDocument(costCalculationWithFileName, state.getLocale());
state.performEvent(view, "reset");
view.getComponentByReference(QcadooViewConstants.L_FORM).addMessage("costCalculation.messages.success.calculationComplete", MessageType.SUCCESS);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
}
use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.
the class CostCalculationDetailsHooks method setFieldsEnabled.
public void setFieldsEnabled(final ViewDefinitionState view) {
Set<String> referenceNames = Sets.newHashSet(CostCalculationFields.QUANTITY, CostCalculationFields.NUMBER, CostCalculationFields.DESCRIPTION, CostCalculationFields.MATERIAL_COSTS_USED, CostCalculationFields.AVERAGE_LABOR_HOURLY_COST, CostCalculationFields.STANDARD_LABOR_COST, CostCalculationFields.PRODUCTION_COST_MARGIN, CostCalculationFields.AVERAGE_MACHINE_HOURLY_COST, CostCalculationFields.MATERIAL_COST_MARGIN, CostCalculationFields.ADDITIONAL_OVERHEAD, CostCalculationFields.INCLUDE_TPZ, CostCalculationFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED, CostCalculationFields.INCLUDE_ADDITIONAL_TIME, CostCalculationFields.SOURCE_OF_OPERATION_COSTS, CostCalculationFields.REGISTRATION_PRICE_OVERHEAD, CostCalculationFields.TECHNICAL_PRODUCTION_COST_OVERHEAD, CostCalculationFields.PROFIT);
Map<String, FieldComponent> componentsMap = Maps.newHashMap();
for (String referenceName : referenceNames) {
FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(referenceName);
componentsMap.put(referenceName, fieldComponent);
}
CheckBoxComponent generatedField = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.GENERATED);
boolean isGenerated = generatedField.isChecked();
for (Entry<String, FieldComponent> entry : componentsMap.entrySet()) {
entry.getValue().setEnabled(!isGenerated);
}
if (isGenerated) {
view.getComponentByReference(CostCalculationFields.TECHNOLOGIES).setEnabled(false);
}
if (!isGenerated) {
FieldComponent sourceOfOperationCosts = (FieldComponent) view.getComponentByReference(CostCalculationFields.SOURCE_OF_OPERATION_COSTS);
FieldComponent standardLaborCost = (FieldComponent) view.getComponentByReference(CostCalculationFields.STANDARD_LABOR_COST);
CheckBoxComponent includeTPZ = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.INCLUDE_TPZ);
CheckBoxComponent includeAdditionalTime = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.INCLUDE_ADDITIONAL_TIME);
FieldComponent averageMachineHourlyCost = (FieldComponent) view.getComponentByReference(CostCalculationFields.AVERAGE_MACHINE_HOURLY_COST);
FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(CostCalculationFields.AVERAGE_LABOR_HOURLY_COST);
standardLaborCost.setEnabled(SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
standardLaborCost.setRequired(SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
if (!SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue())) {
standardLaborCost.setFieldValue(null);
}
standardLaborCost.requestComponentUpdateState();
includeTPZ.setEnabled(!SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
includeAdditionalTime.setEnabled(!SourceOfOperationCosts.STANDARD_LABOR_COSTS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
averageMachineHourlyCost.setEnabled(SourceOfOperationCosts.PARAMETERS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
averageLaborHourlyCost.setEnabled(SourceOfOperationCosts.PARAMETERS.getStringValue().equals(sourceOfOperationCosts.getFieldValue()));
}
}
use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.
the class CostCalculationDetailsHooks method setButtonsEnabled.
private void setButtonsEnabled(ViewDefinitionState view) {
WindowComponent window = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
RibbonActionItem saveNominalCosts = window.getRibbon().getGroupByName(CostCalculationFields.SAVE_COSTS).getItemByName(CostCalculationFields.NOMINAL_COSTS);
RibbonActionItem generate = window.getRibbon().getGroupByName("generate").getItemByName("generate");
RibbonActionItem pdfButton = window.getRibbon().getGroupByName("export").getItemByName("pdf");
RibbonActionItem xlsButton = window.getRibbon().getGroupByName("export").getItemByName("xls");
RibbonActionItem save = window.getRibbon().getGroupByName(ACTIONS).getItemByName("save");
RibbonActionItem saveBack = window.getRibbon().getGroupByName(ACTIONS).getItemByName("saveBack");
RibbonActionItem saveNew = window.getRibbon().getGroupByName(ACTIONS).getItemByName("saveNew");
RibbonActionItem copy = window.getRibbon().getGroupByName(ACTIONS).getItemByName("copy");
RibbonActionItem cancel = window.getRibbon().getGroupByName(ACTIONS).getItemByName("cancel");
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
boolean pdf = form.getPersistedEntityWithIncludedFormValues().getBooleanField(CostCalculationFields.PDF);
boolean entityExists = form.getEntityId() != null;
if (entityExists) {
CheckBoxComponent generatedField = (CheckBoxComponent) view.getComponentByReference(CostCalculationFields.GENERATED);
int technologiesCount = ((GridComponent) view.getComponentByReference(CostCalculationFields.TECHNOLOGIES)).getEntities().size();
generate.setEnabled(technologiesCount > 0);
generate.requestUpdate(true);
saveNominalCosts.setEnabled(generatedField.isChecked());
saveNominalCosts.requestUpdate(true);
if (generatedField.isChecked()) {
if (pdf) {
pdfButton.setEnabled(true);
pdfButton.requestUpdate(true);
} else {
xlsButton.setEnabled(true);
xlsButton.requestUpdate(true);
}
generate.setEnabled(false);
generate.requestUpdate(true);
save.setEnabled(false);
save.setMessage(COST_CALCULATION_RIBBON_MESSAGE_RECORD_ALREADY_GENERATED);
save.requestUpdate(true);
saveNew.setEnabled(false);
saveNew.setMessage(COST_CALCULATION_RIBBON_MESSAGE_RECORD_ALREADY_GENERATED);
saveNew.requestUpdate(true);
saveBack.setEnabled(false);
saveBack.setMessage(COST_CALCULATION_RIBBON_MESSAGE_RECORD_ALREADY_GENERATED);
saveBack.requestUpdate(true);
cancel.setEnabled(false);
cancel.setMessage(COST_CALCULATION_RIBBON_MESSAGE_RECORD_ALREADY_GENERATED);
} else {
pdfButton.setEnabled(false);
pdfButton.setMessage("costCalculation.ribbon.message.recordNotGenerated");
pdfButton.requestUpdate(true);
xlsButton.setEnabled(false);
xlsButton.setMessage("costCalculation.ribbon.message.recordNotGenerated");
xlsButton.requestUpdate(true);
save.setEnabled(true);
save.requestUpdate(true);
cancel.setEnabled(true);
}
} else {
copy.setEnabled(false);
copy.setMessage(RECORD_NOT_CREATED);
copy.requestUpdate(true);
pdfButton.setEnabled(false);
pdfButton.setMessage(RECORD_NOT_CREATED);
pdfButton.requestUpdate(true);
xlsButton.setEnabled(false);
xlsButton.setMessage(RECORD_NOT_CREATED);
xlsButton.requestUpdate(true);
save.setEnabled(true);
save.requestUpdate(true);
cancel.setEnabled(true);
}
cancel.requestUpdate(true);
}
Aggregations