use of eu.ggnet.dwoss.receipt.product.SimpleView in project dwoss by gg-net.
the class UiProductSupport method createOrEditPart.
// DesktopBundleView and internal.
/**
* Creates or edits Product with partNo.
* <p/>
* @param manufacturer the manufacturer.
* @param partNo the partNo
* @param allowedEditGroup if not null and there exist a Product with the partNo, the ProductGroup of that product must be like the parameter.
* @param selectedBrand if not null the brand is assumed as selected and may not be changed.
* @param parent the parent window for localisation
* @return the created or edited ProductSpec
* @throws UserInfoException if not ok
*/
public static ProductSpec createOrEditPart(TradeName manufacturer, String partNo, TradeName selectedBrand, ProductGroup allowedEditGroup, Window parent) throws UserInfoException {
validatePartNo(manufacturer, partNo);
ProductSpec productSpec = Dl.remote().lookup(SpecAgent.class).findProductSpecByPartNoEager(partNo);
boolean edit = false;
if (productSpec != null) {
edit = true;
if (allowedEditGroup != null && selectedBrand != null) {
if (productSpec.getModel().getFamily().getSeries().getGroup() != allowedEditGroup) {
throw new UserInfoException("Erlaubte Warengruppe ist " + allowedEditGroup + ", Artikel ist aber " + SpecFormater.toDetailedName(productSpec));
} else if (productSpec.getModel().getFamily().getSeries().getBrand() != selectedBrand) {
throw new UserInfoException("Ausgewählte Marke ist " + selectedBrand + ", Artikel ist aber " + SpecFormater.toDetailedName(productSpec));
}
}
}
SimpleView simpleView;
if (edit)
simpleView = new SimpleView(productSpec);
else if (allowedEditGroup != null && selectedBrand != null)
simpleView = new SimpleView(partNo, selectedBrand, allowedEditGroup);
else
simpleView = new SimpleView(manufacturer, partNo);
OkCancelDialog<SimpleView> simpleDialog = new OkCancelDialog<>(parent, "Artikelkonfiguration", simpleView);
simpleDialog.setVisible(true);
if (simpleDialog.isCancel())
return null;
ProductSpec spec = simpleView.getProductSpec();
if (edit)
spec = Dl.remote().lookup(ProductProcessor.class).refresh(spec, simpleView.getSelectedModel().get());
AbstractView productView = AbstractView.newView(spec, simpleView.getSelectedModel().get().getFamily().getSeries().getBrand());
if (edit)
productView.setGtin(Dl.remote().lookup(UniqueUnitAgent.class).findById(Product.class, spec.getProductId()).getGtin());
OkCancelDialog productDialog = new OkCancelDialog(parent, "Artikeldetailkonfiguration", productView);
productDialog.setVisible(true);
if (productDialog.isCancel())
return null;
validate(simpleView.getSelectedModel().get());
validate(productView.getSpec());
if (edit)
return Dl.remote().lookup(ProductProcessor.class).update(productView.getSpec(), productView.getGtin());
else
// TODO: In Case of a Bundle autoupdate the name of the model.
return Dl.remote().lookup(ProductProcessor.class).create(productView.getSpec(), simpleView.getSelectedModel().get(), productView.getGtin());
}
Aggregations