Package com.nexirius.jnex.example.dataeditor

Source Code of com.nexirius.jnex.example.dataeditor.ProductEditor

package com.nexirius.jnex.example.dataeditor;

import javax.swing.*;

import com.nexirius.jnex.example.datamodel.*;
import com.nexirius.framework.gadgets.*;
import com.nexirius.framework.dataeditor.*;
import com.nexirius.framework.dataviewer.*;
import com.nexirius.framework.layout.*;
import com.nexirius.framework.datamodel.DataModel;
import com.nexirius.util.resource.ClientResource;

public class ProductEditor extends StructEditor
{
  /**
  Creates an instance and initialises its associated data model
  */
  public ProductEditor(ProductModel model)
  {
    super(model);
  }

  public void update()
  {
    SnapGridLayout layout = new SnapGridLayout(10, 10, 500, 200);
    ClientResource cr = getFactory().getClientResource();

    if (isCreated()) {
      getJPanel().removeAll();
      getJPanel().setLayout(layout);

      DataModel dm;
      JComponent comp;
      JLabel label;

      MultiplePropertyEntry numberColumnProps = new MultiplePropertyEntry();

      numberColumnProps.append(new SinglePropertyEntry("Font", "Courier-BOLDITALIC-14"));
      numberColumnProps.append(new SinglePropertyEntry("Foreground", "pink"));
      numberColumnProps.append(new SinglePropertyEntry("Background", "blue"));
      numberColumnProps.append(new SinglePropertyEntry("Alignment", "1"));

      try {
        int y = 0;
        int xfield = 4;
        int wfield = 6;
        int wlabel = 4;

        dm = getModel().getChild("productNumber");
        comp = createFieldValue(dm);
        numberColumnProps.change(comp, this.getFactory());
        label = new JLabel(cr.getLabel("productNumber"));
        layout.addLayoutComponent(label, 0, y, wlabel, 1);
        layout.addLayoutComponent(comp, xfield, y, wfield, 1);
        getJPanel().add(label);
        getJPanel().add(comp);
        ++y;
        dm = getModel().getChild("name");
        comp = createFieldValue(dm);
        label = new JLabel(cr.getLabel("name"));
        layout.addLayoutComponent(label, 0, y, wlabel, 1);
        layout.addLayoutComponent(comp, xfield, y, wfield, 1);
        getJPanel().add(label);
        getJPanel().add(comp);
        ++y;
        dm = getModel().getChild("description");
        comp = createFieldValue(dm);
        label = new JLabel(cr.getLabel("description"));
        layout.addLayoutComponent(label, 0, y, wlabel, 1);
        layout.addLayoutComponent(comp, xfield, y, wfield, 2);
        getJPanel().add(label);
        getJPanel().add(comp);
        y+=2;
        dm = getModel().getChild("stock");
        comp = createFieldValue(dm);
        label = new JLabel(cr.getLabel("stock"));
        layout.addLayoutComponent(label, 0, y, wlabel, 1);
        layout.addLayoutComponent(comp, xfield, y, wfield, 1);
        getJPanel().add(label);
        getJPanel().add(comp);
        ++y;
        dm = getModel().getChild("Features");
        comp = createFieldValue(dm);
        layout.addLayoutComponent(comp, 0, y, wlabel + wfield, 4);
        getJPanel().add(comp);
        y += 4;
        comp = getFactory().createDefaultEditor(getModel().getMethod("newFeature")).getJComponent();
        layout.addLayoutComponent(comp, 3, y, 4, 1);
        getJPanel().add(comp);
        y += 1;
      }
      catch (Exception ex)
      {
        //FIX
        ex.printStackTrace();
      }

      updateUI();
    }
  }

}
TOP

Related Classes of com.nexirius.jnex.example.dataeditor.ProductEditor

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.