Search in sources :

Example 1 with SimpleView

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());
}
Also used : AbstractView(eu.ggnet.dwoss.receipt.product.AbstractView) SpecAgent(eu.ggnet.dwoss.spec.ee.SpecAgent) SimpleView(eu.ggnet.dwoss.receipt.product.SimpleView) OkCancelDialog(eu.ggnet.dwoss.util.OkCancelDialog) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) ProductProcessor(eu.ggnet.dwoss.receipt.ee.ProductProcessor)

Aggregations

ProductProcessor (eu.ggnet.dwoss.receipt.ee.ProductProcessor)1 AbstractView (eu.ggnet.dwoss.receipt.product.AbstractView)1 SimpleView (eu.ggnet.dwoss.receipt.product.SimpleView)1 SpecAgent (eu.ggnet.dwoss.spec.ee.SpecAgent)1 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)1 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)1 OkCancelDialog (eu.ggnet.dwoss.util.OkCancelDialog)1 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)1