/** * Stores the current PriceConfig. Prior to saving it will show the user which other ProductTypes * are affected by this change and give him the possibility to cancel this action. * * @return Whether the PriceConfig was saved or not. */ public boolean submit() { // ProductType packageProductType = productTypeSelector.getPackageProductType(); if (packageProductType == null) return false; ProductTypeID productTypeID = (ProductTypeID) JDOHelper.getObjectId(packageProductType); // PriceConfigID innerPriceConfigID = (PriceConfigID) // JDOHelper.getObjectId(packageProductType.getInnerPriceConfig()); // This doesn't work, if the // PC is new! IInnerPriceConfig ipc = packageProductType.getInnerPriceConfig(); PriceConfigID innerPriceConfigID = ipc == null ? null : PriceConfigID.create(ipc.getOrganisationID(), ipc.getPriceConfigID()); String localOrganisationID; try { localOrganisationID = Login.getLogin().getOrganisationID(); } catch (LoginException e) { throw new RuntimeException(e); } // collect all price configurations Set<GridPriceConfig> priceConfigs; Set<PriceConfigID> priceConfigIDs; Map<GridPriceConfig, List<ProductTypeSelector.Item>> priceConfig2ProductTypeSelectorItemList = null; if (packageProductType.getPackageNature() == ProductType.PACKAGE_NATURE_INNER) { priceConfigs = new HashSet<GridPriceConfig>(1); priceConfigs.add((GridPriceConfig) packageProductType.getInnerPriceConfig()); } else { if (packageProductType.getInnerPriceConfig() == null) { priceConfigs = new HashSet<GridPriceConfig>(0); } else { priceConfig2ProductTypeSelectorItemList = new HashMap<GridPriceConfig, List<ProductTypeSelector.Item>>( productTypeSelector.getProductTypeItems().size()); for (ProductTypeSelector.Item item : productTypeSelector.getProductTypeItems()) { if (!localOrganisationID.equals( item.getProductType() .getOrganisationID())) // ignore partner-ProductTypes as we must not modify their // prices continue; GridPriceConfig priceConfig = item.getPriceConfig(); if (priceConfig != null) { List<ProductTypeSelector.Item> items = priceConfig2ProductTypeSelectorItemList.get(priceConfig); if (items == null) { items = new ArrayList<ProductTypeSelector.Item>(); priceConfig2ProductTypeSelectorItemList.put(priceConfig, items); } items.add(item); } } priceConfigs = new HashSet<GridPriceConfig>( priceConfig2ProductTypeSelectorItemList .keySet()); // we copy the set, because the keySet is not serializable and // cannot be sent to the server } } // remove null values - maybe not every product type has a price config assigned while (priceConfigs.remove(null)) ; priceConfigIDs = NLJDOHelper.getObjectIDSet(priceConfigs); priceConfigIDs = new HashSet<PriceConfigID>(priceConfigIDs); // if there are priceConfigs which have never been stored (i.e. no ID assigned), we ignore them // silently. while (priceConfigIDs.remove(null)) ; // Kai: 2009-11-13 // Check to see if there are STILL any more errors contained in the price configs; i.e. dont // save if errors persist. if (priceCalculator != null) { try { priceCalculator.calculatePrices(); } catch (PriceCalculationException e) { throw new RuntimeException( "Invalid or incomplete formula in the price configuration(s): " + e.getShortenedErrorMessage()); } } if (!priceConfigIDs.isEmpty()) { // show the consequences and ask the user whether he really wants to save Shell shell = null; try { shell = getShell(); } catch (SWTException e) { // the composite might be disposed already, try to get another shell shell = Display.getDefault().getActiveShell(); } StorePriceConfigsConfirmationDialog dialog = new StorePriceConfigsConfirmationDialog( shell, priceConfigIDs, productTypeID, innerPriceConfigID); if (dialog.open() != Window.OK) return false; } // store the price configs to the server (it will recalculate all affected product types) Collection<GridPriceConfig> newPCs = storePriceConfigs( priceConfigs, new AssignInnerPriceConfigCommand( productTypeID, innerPriceConfigID, packageProductType .getFieldMetaData(ProductType.FieldName.innerPriceConfig) .isValueInherited())); // and replace the local price configs by the new ones (freshly detached from the server) if (priceConfig2ProductTypeSelectorItemList != null) { for (GridPriceConfig priceConfig : newPCs) { List<ProductTypeSelector.Item> items = priceConfig2ProductTypeSelectorItemList.get(priceConfig); for (ProductTypeSelector.Item item : items) item.setPriceConfig(priceConfig); } } // In case the new price configs have not all data that's necessary now // (e.g. that's the case with DynamicTradePriceConfig, which does not store // packagingResultPriceConfigs), // we ensure this now: if (packageProductType.getInnerPriceConfig() != null) { priceCalculator.preparePriceCalculation(); try { // We must actually recalculate as well, because otherwise the TransientStablePriceConfig // contains only 0.00 // in every cell (which will be shown in the UI as soon as a dimension-value is modified). // See: https://www.jfire.org/modules/bugs/view.php?id=1084 priceCalculator.calculatePrices(); } catch (PriceCalculationException e) { throw new RuntimeException(e); } } return true; }
public void _setPackageProductType(ProductType packageProductType) // throws ModuleException { if (productTypeSelector != null) productTypeSelector.setPackageProductType(null); if (dimensionValueSelector != null) dimensionValueSelector.setGridPriceConfig(null); if (priceConfigInInnerProductTypeNotEditableComposite != null) priceConfigInInnerProductTypeNotEditableComposite.setPackageProductType(null); priceCalculator = null; this.packageProductType = packageProductType; if (packageProductType == null) { stackLayout.topControl = productTypeNotSetComposite; } else { if (packageProductType.getInnerPriceConfig() == null) { stackLayout.topControl = getNoPriceConfigAssignedComposite(); } else { if (packageProductType.getPackageNature() == ProductType.PACKAGE_NATURE_INNER) { stackLayout.topControl = getPriceConfigInInnerProductTypeNotEditableComposite(); getPriceConfigInInnerProductTypeNotEditableComposite() .setPackageProductType(packageProductType); } else { // package nature outer // show price config comp stackLayout.topControl = getPriceConfigEditComposite(); // if (packageProductType.getInnerPriceConfig() != null || // packageProductType.getPackagePriceConfig() != null) { priceCalculator = createPriceCalculator(packageProductType); priceCalculator.preparePriceCalculation(); try { priceCalculator.calculatePrices(); } catch (PriceCalculationException e) { throw new RuntimeException(e); } // The packagePriceConfig defines all parameters (dimension values) we need to know. // When the packagePriceConfig comes from the server (after preparePriceCalculation hase // been called) // it has the same parameters (except PriceFragmentTypes) as the innerPriceConfig. // The PriceFragmentTypes have already been collected from all the packaged PriceConfigs. GridPriceConfig gridPriceConfig = (GridPriceConfig) packageProductType.getPackagePriceConfig(); if (gridPriceConfig == null) { // if the package priceConfig is null in the prodcut-type we // take the one created by the PriceCalculator (this might be a non-persistent temporal // one) gridPriceConfig = (GridPriceConfig) priceCalculator.getPackagePriceConfig(); } if (gridPriceConfig == null) throw new IllegalStateException( "packageProductType.getPackagePriceConfig() and priceCalculator.getPackagePriceConfig() both returned null!"); //$NON-NLS-1$ // gridPriceConfig = (GridPriceConfig) packageProductType.getInnerPriceConfig(); dimensionValueSelector.setGridPriceConfig(gridPriceConfig); productTypeSelector.setPackageProductType(packageProductType); // } } // package nature outer } // if (packageProductType.getInnerPriceConfig() != null) { } // if (packageProductType != null) { stackWrapper.layout(true, true); if (priceConfigGrid != null) priceConfigGrid.setPriceCalculator(priceCalculator); }