Package com.nexirius.jnex.example.datamodel

Source Code of com.nexirius.jnex.example.datamodel.ProductModel

package com.nexirius.jnex.example.datamodel;

import com.nexirius.util.CopyPairs;
import com.nexirius.framework.datamodel.*;
import com.nexirius.framework.dataviewer.ViewerFactory;
import com.nexirius.framework.application.DataModelPopupEditor;


public class ProductModel extends StructModel
{
    static int instanceName = 1000;
    IntModel productNumber;
  StringModel name;
  TextModel description;
  BooleanModel needOrder;
  CurrencyWithSelectorModel price;
  FileNameModel imageFile;
  ImageModel image;
  IntModel stock;
  FeatureArrayModel features;
    private InstanceNameComboBoxModel featureSelector;

    public ProductModel()
    {
        super("Product");
        init();
    }

  private void init()
  {
    productNumber = new IntModel(0, "productNumber");
    name = new StringModel("", "name");
    stock = new IntModel(0, "stock");
    description = new TextModel("", "description");
    needOrder = new BooleanModel(false, "needOrder");
    price = new CurrencyWithSelectorModel(0.0, "CHF", "price");
        imageFile = new FileNameModel("", "imageFile");
    image = new ImageModel("", "image");
    imageFile.addDataModelListener(new FileNameListener());
    features = new FeatureArrayModel();
        featureSelector = new InstanceNameComboBoxModel("", features, "featureSelector");

        appendMethod(new DefaultDataModelCommand("newFeature"));

    append(productNumber);
    append(name);
    append(description);
    append(needOrder);
    append(price);
    append(imageFile);
    append(image);
    append(stock);
    append(features);
        append(featureSelector);
    }

  public synchronized DataModel duplicate(DataModel instance, CopyPairs copyPairs)
  {
    if (instance == null) {
      instance = new ProductModel();
    }
 
    return super.duplicate(instance, copyPairs);
  }

  public void newFeature()
  {
    ProductFeatureModel feature = new ProductFeatureModel();
    DataModelPopupEditor ed = new DataModelPopupEditor(feature, ViewerFactory.getInstance());

    if (ed.popup()) {
            addFeature(feature);
        }
  }

    private void addFeature(ProductFeatureModel feature) {
        ++instanceName;
        feature.setInstanceName(Integer.toString(instanceName));
        features.append(feature);
    }

    public void addFeature(String s) {
        addFeature(new ProductFeatureModel(s));
    }

    class FileNameListener extends DataModelAdaptor
    {
        public void dataModelChangeValue(DataModelEvent p0)
        {
            image.setText(imageFile.getText());
        }
    }
}
TOP

Related Classes of com.nexirius.jnex.example.datamodel.ProductModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.