JMinor Application Framework

As simple as possible but not simpler

User Tools

Site Tools


documentation:tutorials:petstore

Pet Store: Application tutorial

Data

Define the domain model

File: org/jminor/framework/demos/petstore/domain/Petstore.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.domain;
 
import org.jminor.framework.domain.Domain;
 
import java.sql.Types;
 
import static org.jminor.framework.domain.Properties.*;
 
public final class Petstore extends Domain {
 
  public Petstore() {
    address();
    category();
    product();
    sellerContactInfo();
    item();
    tag();
    tagItem();
  }
 
  public static final String T_ADDRESS = "address";
  public static final String ADDRESS_ID = "Address id";
  public static final String ADDRESS_STREET_1 = "Street 1";
  public static final String ADDRESS_STREET_2 = "Street 2";
  public static final String ADDRESS_CITY = "City";
  public static final String ADDRESS_STATE = "State";
  public static final String ADDRESS_ZIP = "Zip";
  public static final String ADDRESS_LATITUDE = "Latitude";
  public static final String ADDRESS_LONGITUDE = "Longitude";
 
  void address() {
    define(T_ADDRESS, "petstore.address",
            primaryKeyProperty(ADDRESS_ID)
                    .setColumnName("addressid"),
            columnProperty(ADDRESS_STREET_1, Types.VARCHAR, ADDRESS_STREET_1)
                    .setColumnName("street1").setMaxLength(55).setNullable(false),
            columnProperty(ADDRESS_STREET_2, Types.VARCHAR, ADDRESS_STREET_2)
                    .setColumnName("street2").setMaxLength(55),
            columnProperty(ADDRESS_CITY, Types.VARCHAR, ADDRESS_CITY)
                    .setColumnName("city").setMaxLength(55).setNullable(false),
            columnProperty(ADDRESS_STATE, Types.VARCHAR, ADDRESS_STATE)
                    .setColumnName("state").setMaxLength(25).setNullable(false),
            columnProperty(ADDRESS_ZIP, Types.INTEGER, ADDRESS_ZIP)
                    .setColumnName("zip").setNullable(false),
            columnProperty(ADDRESS_LATITUDE, Types.DOUBLE, ADDRESS_LATITUDE)
                    .setColumnName("latitude").setNullable(false).setMaximumFractionDigits(2),
            columnProperty(ADDRESS_LONGITUDE, Types.DOUBLE, ADDRESS_LONGITUDE)
                    .setColumnName("longitude").setNullable(false).setMaximumFractionDigits(2))
            .setKeyGenerator(incrementKeyGenerator("petstore.address", "addressid"))
            .setOrderBy(orderBy().ascending(ADDRESS_CITY, ADDRESS_STREET_1, ADDRESS_STREET_2))
            .setStringProvider(new StringProvider(ADDRESS_STREET_1).addText(" ")
                    .addValue(ADDRESS_STREET_2).addText(", ").addValue(ADDRESS_CITY).addText(" ")
                    .addValue(ADDRESS_ZIP).addText(", ").addValue(ADDRESS_STATE))
            .setCaption("Addresses");
  }
 
  public static final String T_CATEGORY = "category";
  public static final String CATEGORY_ID = "Category id";
  public static final String CATEGORY_NAME = "Name";
  public static final String CATEGORY_DESCRIPTION = "Description";
  public static final String CATEGORY_IMAGE_URL = "Image URL";
 
  void category() {
    define(T_CATEGORY, "petstore.category",
            primaryKeyProperty(CATEGORY_ID)
                    .setColumnName("categoryid"),
            columnProperty(CATEGORY_NAME, Types.VARCHAR, CATEGORY_NAME)
                    .setColumnName("name").setMaxLength(25).setNullable(false),
            columnProperty(CATEGORY_DESCRIPTION, Types.VARCHAR, CATEGORY_DESCRIPTION)
                    .setColumnName("description").setMaxLength(255).setNullable(false),
            columnProperty(CATEGORY_IMAGE_URL, Types.VARCHAR, CATEGORY_IMAGE_URL)
                    .setColumnName("imageurl").setHidden(true))
            .setKeyGenerator(incrementKeyGenerator("petstore.category", "categoryid"))
            .setOrderBy(orderBy().ascending(CATEGORY_NAME))
            .setStringProvider(new StringProvider(CATEGORY_NAME))
            .setCaption("Categories");
  }
 
  public static final String T_PRODUCT = "product";
  public static final String PRODUCT_ID = "Product id";
  public static final String PRODUCT_CATEGORY_ID = "Category id";
  public static final String PRODUCT_CATEGORY_FK = "Category";
  public static final String PRODUCT_NAME = "Name";
  public static final String PRODUCT_DESCRIPTION = "Description";
  public static final String PRODUCT_IMAGE_URL = "Image URL";
 
  void product() {
    define(T_PRODUCT, "petstore.product",
            primaryKeyProperty(PRODUCT_ID)
                    .setColumnName("productid"),
            foreignKeyProperty(PRODUCT_CATEGORY_FK, PRODUCT_CATEGORY_FK, T_CATEGORY,
                    columnProperty(PRODUCT_CATEGORY_ID)
                            .setColumnName("categoryid")).setNullable(false),
            columnProperty(PRODUCT_NAME, Types.VARCHAR, PRODUCT_NAME)
                    .setColumnName("name").setMaxLength(25).setNullable(false),
            columnProperty(PRODUCT_DESCRIPTION, Types.VARCHAR, PRODUCT_DESCRIPTION)
                    .setColumnName("description").setMaxLength(255).setNullable(false),
            columnProperty(PRODUCT_IMAGE_URL, Types.VARCHAR, PRODUCT_IMAGE_URL)
                    .setColumnName("imageurl").setMaxLength(55).setHidden(true))
            .setKeyGenerator(incrementKeyGenerator("petstore.product", "productid"))
            .setOrderBy(orderBy().ascending(PRODUCT_NAME))
            .setStringProvider(new StringProvider(PRODUCT_CATEGORY_FK)
                    .addText(" - ").addValue(PRODUCT_NAME))
            .setCaption("Products");
  }
 
  public static final String T_SELLER_CONTACT_INFO = "sellercontactinfo";
  public static final String SELLER_CONTACT_INFO_ID = "Contactinfo id";
  public static final String SELLER_CONTACT_INFO_FIRST_NAME = "First name";
  public static final String SELLER_CONTACT_INFO_LAST_NAME = "Last name";
  public static final String SELLER_CONTACT_INFO_EMAIL = "Email";
 
  void sellerContactInfo() {
    define(T_SELLER_CONTACT_INFO, "petstore.sellercontactinfo",
            primaryKeyProperty(SELLER_CONTACT_INFO_ID)
                    .setColumnName("contactinfoid"),
            columnProperty(SELLER_CONTACT_INFO_FIRST_NAME, Types.VARCHAR, SELLER_CONTACT_INFO_FIRST_NAME)
                    .setColumnName("firstname").setMaxLength(24).setNullable(false),
            columnProperty(SELLER_CONTACT_INFO_LAST_NAME, Types.VARCHAR, SELLER_CONTACT_INFO_LAST_NAME)
                    .setColumnName("lastname").setMaxLength(24).setNullable(false),
            columnProperty(SELLER_CONTACT_INFO_EMAIL, Types.VARCHAR, SELLER_CONTACT_INFO_EMAIL)
                    .setColumnName("email").setMaxLength(24).setNullable(false))
            .setKeyGenerator(incrementKeyGenerator("petstore.sellercontactinfo", "contactinfoid"))
            .setOrderBy(orderBy()
                    .ascending(SELLER_CONTACT_INFO_LAST_NAME, SELLER_CONTACT_INFO_FIRST_NAME))
            .setStringProvider(new StringProvider(SELLER_CONTACT_INFO_LAST_NAME)
                    .addText(", ").addValue(SELLER_CONTACT_INFO_FIRST_NAME))
            .setCaption("Seller info");
  }
 
  public static final String T_ITEM = "item";
  public static final String ITEM_ID = "Item id";
  public static final String ITEM_PRODUCT_ID = "Product id";
  public static final String ITEM_PRODUCT_FK = "Product";
  public static final String ITEM_NAME = "Name";
  public static final String ITEM_DESCRIPTION = "Description";
  public static final String ITEM_IMAGE_URL = "Image URL";
  public static final String ITEM_IMAGE_THUMB_URL = "Image thumbnail URL";
  public static final String ITEM_PRICE = "Price";
  public static final String ITEM_C0NTACT_INFO_ID = "Contactinfo id";
  public static final String ITEM_C0NTACT_INFO_FK = "Contact info";
  public static final String ITEM_ADDRESS_ID = "Address id";
  public static final String ITEM_ADDRESS_FK = "Address";
  public static final String ITEM_DISABLED = "Disabled";
 
  void item() {
    define(T_ITEM, "petstore.item",
            primaryKeyProperty(ITEM_ID)
                    .setColumnName("itemid"),
            foreignKeyProperty(ITEM_PRODUCT_FK, ITEM_PRODUCT_FK, T_PRODUCT,
                    columnProperty(ITEM_PRODUCT_ID)
                            .setColumnName("productid"))
                    .setFetchDepth(2).setNullable(false),
            columnProperty(ITEM_NAME, Types.VARCHAR, ITEM_NAME)
                    .setColumnName("name").setMaxLength(30).setNullable(false),
            columnProperty(ITEM_DESCRIPTION, Types.VARCHAR, ITEM_DESCRIPTION)
                    .setColumnName("description").setMaxLength(500).setNullable(false),
            columnProperty(ITEM_IMAGE_URL, Types.VARCHAR, ITEM_IMAGE_URL)
                    .setColumnName("imageurl").setMaxLength(55).setHidden(true),
            columnProperty(ITEM_IMAGE_THUMB_URL, Types.VARCHAR, ITEM_IMAGE_THUMB_URL)
                    .setColumnName("imagethumburl").setMaxLength(55).setHidden(true),
            columnProperty(ITEM_PRICE, Types.DECIMAL, ITEM_PRICE)
                    .setColumnName("price").setNullable(false).setMaximumFractionDigits(2),
            foreignKeyProperty(ITEM_C0NTACT_INFO_FK, ITEM_C0NTACT_INFO_FK, T_SELLER_CONTACT_INFO,
                    columnProperty(ITEM_C0NTACT_INFO_ID).setColumnName("contactinfo_contactinfoid"))
                    .setNullable(false),
            foreignKeyProperty(ITEM_ADDRESS_FK, "Address", T_ADDRESS,
                    columnProperty(ITEM_ADDRESS_ID).setColumnName("address_addressid"))
                    .setNullable(false),
            booleanProperty(ITEM_DISABLED, Types.INTEGER, ITEM_DISABLED, 1, 0)
                    .setColumnName("disabled").setDefaultValue(false))
            .setKeyGenerator(incrementKeyGenerator("petstore.item", "itemid"))
            .setOrderBy(orderBy().ascending(ITEM_NAME))
            .setStringProvider(new StringProvider(ITEM_PRODUCT_FK)
                    .addText(" - ").addValue(ITEM_NAME))
            .setCaption("Items");
  }
 
  public static final String T_TAG = "tag";
  public static final String TAG_ID = "Tag id";
  public static final String TAG_TAG = "Tag";
  public static final String TAG_REFCOUNT = "Reference count";
 
  void tag() {
    define(T_TAG, "petstore.tag",
            primaryKeyProperty(TAG_ID)
                    .setColumnName("tagid"),
            columnProperty(TAG_TAG, Types.VARCHAR, TAG_TAG)
                    .setColumnName("tag").setMaxLength(30).setNullable(false),
            subqueryProperty(TAG_REFCOUNT, Types.INTEGER, TAG_REFCOUNT,
                    "select count(*) from petstore.tag_item where tagid = tag.tagid")
                    .setColumnName("refcount"))
            .setKeyGenerator(incrementKeyGenerator("petstore.tag", "tagid"))
            .setOrderBy(orderBy().ascending(TAG_TAG))
            .setSelectTableName("petstore.tag tag")
            .setStringProvider(new StringProvider(TAG_TAG))
            .setCaption("Tags");
  }
 
  public static final String T_TAG_ITEM = "tag_item";
  public static final String TAG_ITEM_ITEM_ID = "Item id";
  public static final String TAG_ITEM_ITEM_FK = "Item";
  public static final String TAG_ITEM_TAG_ID = "Tag id";
  public static final String TAG_ITEM_TAG_FK = "Tag";
 
  void tagItem() {
    define(T_TAG_ITEM, "petstore.tag_item",
            foreignKeyProperty(TAG_ITEM_ITEM_FK, TAG_ITEM_ITEM_FK, T_ITEM,
                    primaryKeyProperty(TAG_ITEM_ITEM_ID)
                            .setColumnName("itemid").setPrimaryKeyIndex(0))
                    .setNullable(false),
            foreignKeyProperty(TAG_ITEM_TAG_FK, TAG_ITEM_TAG_FK, T_TAG,
                    primaryKeyProperty(TAG_ITEM_TAG_ID)
                            .setColumnName("tagid").setPrimaryKeyIndex(1))
                    .setNullable(false))
            .setStringProvider(new StringProvider(TAG_ITEM_ITEM_FK)
                    .addText(" - ").addValue(TAG_ITEM_TAG_FK))
            .setCaption("Item tags");
  }
}

Unit testing the domain model

File: org/jminor/framework/demos/petstore/domain/PetstoreTest.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.domain;
 
import org.jminor.common.User;
import org.jminor.common.model.CancelException;
import org.jminor.framework.domain.test.EntityTestUnit;
 
import org.junit.jupiter.api.Test;
 
import static org.jminor.framework.demos.petstore.domain.Petstore.*;
 
public class PetstoreTest extends EntityTestUnit {
 
  private static final User UNIT_TEST_USER = new User(
          System.getProperty("jminor.unittest.username", "scott"),
          System.getProperty("jminor.unittest.password", "tiger").toCharArray());
 
  public PetstoreTest() {
    super(Petstore.class.getName());
  }
 
  @Test
  public void address() throws Exception {
    testEntity(T_ADDRESS);
  }
 
  @Test
  public void category() throws Exception {
    testEntity(T_CATEGORY);
  }
 
  @Test
  public void item() throws Exception {
    testEntity(T_ITEM);
  }
 
  @Test
  public void product() throws Exception {
    testEntity(T_PRODUCT);
  }
 
  @Test
  public void sellerInfo() throws Exception {
    testEntity(T_SELLER_CONTACT_INFO);
  }
 
  @Test
  public void tag() throws Exception {
    testEntity(T_TAG);
  }
 
  @Test
  public void tagItem() throws Exception {
    testEntity(T_TAG_ITEM);
  }
 
  @Override
  protected User getTestUser() throws CancelException {
    return UNIT_TEST_USER;
  }
}

CRUD UI layer

File: org/jminor/framework/demos/petstore/beans/ui/AddressEditPanel.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.beans.ui;
 
import org.jminor.swing.common.ui.layout.FlexibleGridLayout;
import org.jminor.swing.framework.model.SwingEntityEditModel;
import org.jminor.swing.framework.ui.EntityEditPanel;
 
import javax.swing.JLabel;
 
import static org.jminor.framework.demos.petstore.domain.Petstore.*;
 
public class AddressEditPanel extends EntityEditPanel {
 
  public AddressEditPanel(final SwingEntityEditModel model) {
    super(model);
  }
 
  @Override
  protected void initializeUI() {
    setInitialFocusProperty(ADDRESS_CITY);
 
    createTextField(ADDRESS_CITY).setColumns(12);
    createTextField(ADDRESS_STATE).setColumns(12);
    createTextField(ADDRESS_ZIP).setColumns(12);
    createTextField(ADDRESS_STREET_1).setColumns(12);
    createTextField(ADDRESS_STREET_2).setColumns(12);
    createTextField(ADDRESS_LATITUDE);
    createTextField(ADDRESS_LONGITUDE);
 
    setLayout(new FlexibleGridLayout(4, 2, 5, 5));
    addPropertyPanel(ADDRESS_CITY);
    addPropertyPanel(ADDRESS_STATE);
    add(new JLabel());
    addPropertyPanel(ADDRESS_ZIP);
    addPropertyPanel(ADDRESS_STREET_1);
    addPropertyPanel(ADDRESS_STREET_2);
    addPropertyPanel(ADDRESS_LATITUDE);
    addPropertyPanel(ADDRESS_LONGITUDE);
  }
}

File: org/jminor/framework/demos/petstore/beans/ui/CategoryEditPanel.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.beans.ui;
 
import org.jminor.swing.common.ui.layout.FlexibleGridLayout;
import org.jminor.swing.framework.model.SwingEntityEditModel;
import org.jminor.swing.framework.ui.EntityEditPanel;
 
import static org.jminor.framework.demos.petstore.domain.Petstore.*;
 
public class CategoryEditPanel extends EntityEditPanel {
 
  public CategoryEditPanel(final SwingEntityEditModel model) {
    super(model);
  }
 
  @Override
  protected void initializeUI() {
    setInitialFocusProperty(CATEGORY_NAME);
 
    createTextField(CATEGORY_NAME).setColumns(10);
    createTextField(CATEGORY_DESCRIPTION).setColumns(18);
    createTextField(CATEGORY_IMAGE_URL);
 
    setLayout(new FlexibleGridLayout(2, 2, 5, 5));
    addPropertyPanel(CATEGORY_NAME);
    addPropertyPanel(CATEGORY_DESCRIPTION);
    addPropertyPanel(CATEGORY_IMAGE_URL);
  }
}

File: org/jminor/framework/demos/petstore/beans/ui/ContactInfoEditPanel.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.beans.ui;
 
import org.jminor.swing.common.ui.layout.FlexibleGridLayout;
import org.jminor.swing.framework.model.SwingEntityEditModel;
import org.jminor.swing.framework.ui.EntityEditPanel;
 
import static org.jminor.framework.demos.petstore.domain.Petstore.*;
 
public class ContactInfoEditPanel extends EntityEditPanel {
 
  public ContactInfoEditPanel(final SwingEntityEditModel model) {
    super(model);
  }
 
  @Override
  protected void initializeUI() {
    setInitialFocusProperty(SELLER_CONTACT_INFO_LAST_NAME);
 
    createTextField(SELLER_CONTACT_INFO_LAST_NAME).setColumns(10);
    createTextField(SELLER_CONTACT_INFO_FIRST_NAME);
    createTextField(SELLER_CONTACT_INFO_EMAIL);
 
    setLayout(new FlexibleGridLayout(3, 1, 5, 5));
    addPropertyPanel(SELLER_CONTACT_INFO_LAST_NAME);
    addPropertyPanel(SELLER_CONTACT_INFO_FIRST_NAME);
    addPropertyPanel(SELLER_CONTACT_INFO_EMAIL);
  }
}

File: org/jminor/framework/demos/petstore/beans/ui/ItemEditPanel.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.beans.ui;
 
import org.jminor.framework.demos.petstore.domain.Petstore;
import org.jminor.swing.common.ui.TextInputPanel;
import org.jminor.swing.common.ui.UiUtil;
import org.jminor.swing.common.ui.layout.FlexibleGridLayout;
import org.jminor.swing.framework.model.SwingEntityEditModel;
import org.jminor.swing.framework.ui.EntityComboBox;
import org.jminor.swing.framework.ui.EntityEditPanel;
import org.jminor.swing.framework.ui.EntityPanelProvider;
 
import static org.jminor.framework.demos.petstore.domain.Petstore.*;
 
public class ItemEditPanel extends EntityEditPanel {
 
  public ItemEditPanel(final SwingEntityEditModel model) {
    super(model);
  }
 
  @Override
  protected void initializeUI() {
    setInitialFocusProperty(ITEM_PRODUCT_FK);
 
    createForeignKeyComboBox(ITEM_PRODUCT_FK);
    createTextField(ITEM_NAME).setColumns(12);
    final TextInputPanel descriptionPanel = createTextInputPanel(ITEM_DESCRIPTION);
    descriptionPanel.getTextField().setColumns(14);
    descriptionPanel.getButton().setFocusable(false);
    createTextField(ITEM_PRICE);
    final EntityComboBox contactInfoBox = createForeignKeyComboBox(ITEM_C0NTACT_INFO_FK);
    UiUtil.setPreferredWidth(contactInfoBox, 140);
    contactInfoBox.setPopupWidth(200);
    final EntityComboBox addressBox = createForeignKeyComboBox(ITEM_ADDRESS_FK);
    UiUtil.setPreferredWidth(addressBox, 140);
    addressBox.setPopupWidth(200);
    addressBox.setPreferredSize(UiUtil.getPreferredTextFieldSize());
    createTextField(ITEM_IMAGE_URL).setColumns(14);
    createTextField(ITEM_IMAGE_THUMB_URL).setColumns(14);
    createTristateCheckBox(ITEM_DISABLED, null, false);
 
    setLayout(new FlexibleGridLayout(3, 3, 5, 5));
    addPropertyPanel(ITEM_PRODUCT_FK);
    addPropertyPanel(ITEM_NAME);
    add(createPropertyPanel(ITEM_DESCRIPTION, descriptionPanel));
    addPropertyPanel(ITEM_PRICE);
    add(createPropertyPanel(ITEM_C0NTACT_INFO_FK, UiUtil.createEastButtonPanel(contactInfoBox,
            createEditPanelAction(contactInfoBox, new EntityPanelProvider(Petstore.T_SELLER_CONTACT_INFO)
                    .setEditPanelClass(ContactInfoEditPanel.class)), false)));
    add(createPropertyPanel(ITEM_ADDRESS_FK, UiUtil.createEastButtonPanel(addressBox,
            createEditPanelAction(addressBox, new EntityPanelProvider(Petstore.T_ADDRESS)
                    .setEditPanelClass(AddressEditPanel.class)), false)));
    addPropertyPanel(ITEM_IMAGE_URL);
    addPropertyPanel(ITEM_IMAGE_THUMB_URL);
    addPropertyPanel(ITEM_DISABLED);
  }
}

File: org/jminor/framework/demos/petstore/beans/ui/ProductEditPanel.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.beans.ui;
 
import org.jminor.swing.common.ui.layout.FlexibleGridLayout;
import org.jminor.swing.framework.model.SwingEntityEditModel;
import org.jminor.swing.framework.ui.EntityEditPanel;
 
import static org.jminor.framework.demos.petstore.domain.Petstore.*;
 
public class ProductEditPanel extends EntityEditPanel {
 
  public ProductEditPanel(final SwingEntityEditModel model) {
    super(model);
  }
 
  @Override
  protected void initializeUI() {
    setInitialFocusProperty(PRODUCT_CATEGORY_FK);
 
    createForeignKeyComboBox(PRODUCT_CATEGORY_FK);
    createTextField(PRODUCT_NAME);
    createTextField(PRODUCT_DESCRIPTION).setColumns(16);
 
    setLayout(new FlexibleGridLayout(3, 1, 5, 5));
    addPropertyPanel(PRODUCT_CATEGORY_FK);
    addPropertyPanel(PRODUCT_NAME);
    addPropertyPanel(PRODUCT_DESCRIPTION);
  }
}

File: org/jminor/framework/demos/petstore/beans/ui/TagItemEditPanel.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.beans.ui;
 
import org.jminor.framework.demos.petstore.domain.Petstore;
import org.jminor.swing.common.ui.UiUtil;
import org.jminor.swing.common.ui.layout.FlexibleGridLayout;
import org.jminor.swing.framework.model.SwingEntityEditModel;
import org.jminor.swing.framework.ui.EntityComboBox;
import org.jminor.swing.framework.ui.EntityEditPanel;
import org.jminor.swing.framework.ui.EntityPanelProvider;
 
import static org.jminor.framework.demos.petstore.domain.Petstore.TAG_ITEM_ITEM_FK;
import static org.jminor.framework.demos.petstore.domain.Petstore.TAG_ITEM_TAG_FK;
 
public class TagItemEditPanel extends EntityEditPanel {
 
  public TagItemEditPanel(final SwingEntityEditModel model) {
    super(model);
  }
 
  @Override
  protected void initializeUI() {
    setLayout(new FlexibleGridLayout(2, 1, 5, 5));
    final EntityComboBox itemBox = createForeignKeyComboBox(TAG_ITEM_ITEM_FK);
    setInitialFocusComponent(itemBox);
    itemBox.setPopupWidth(240);
    UiUtil.setPreferredWidth(itemBox, 180);
    addPropertyPanel(TAG_ITEM_ITEM_FK);
    final EntityComboBox itemTagBox = createForeignKeyComboBox(TAG_ITEM_TAG_FK);
    add(createPropertyPanel(TAG_ITEM_TAG_FK, UiUtil.createEastButtonPanel(itemTagBox,
            createEditPanelAction(itemTagBox, new EntityPanelProvider(Petstore.T_TAG)
                    .setEditPanelClass(TagEditPanel.class)), false)));
  }
}

File: org/jminor/framework/demos/petstore/beans/ui/TagEditPanel.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.beans.ui;
 
import org.jminor.swing.common.ui.layout.FlexibleGridLayout;
import org.jminor.swing.framework.model.SwingEntityEditModel;
import org.jminor.swing.framework.ui.EntityEditPanel;
 
import static org.jminor.framework.demos.petstore.domain.Petstore.TAG_TAG;
 
public class TagEditPanel extends EntityEditPanel {
 
  public TagEditPanel(final SwingEntityEditModel model) {
    super(model);
  }
 
  @Override
  protected void initializeUI() {
    setInitialFocusProperty(TAG_TAG);
 
    createTextField(TAG_TAG).setColumns(16);
 
    setLayout(new FlexibleGridLayout(1, 1, 5, 5));
    addPropertyPanel(TAG_TAG);
  }
}

Main application panel

File: org/jminor/framework/demos/petstore/client/ui/PetstoreAppPanel.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.client.ui;
 
import org.jminor.common.User;
import org.jminor.common.model.CancelException;
import org.jminor.framework.db.EntityConnectionProvider;
import org.jminor.framework.demos.petstore.beans.ui.AddressEditPanel;
import org.jminor.framework.demos.petstore.beans.ui.CategoryEditPanel;
import org.jminor.framework.demos.petstore.beans.ui.ContactInfoEditPanel;
import org.jminor.framework.demos.petstore.beans.ui.ItemEditPanel;
import org.jminor.framework.demos.petstore.beans.ui.ProductEditPanel;
import org.jminor.framework.demos.petstore.beans.ui.TagEditPanel;
import org.jminor.framework.demos.petstore.beans.ui.TagItemEditPanel;
import org.jminor.framework.demos.petstore.client.PetstoreAppModel;
import org.jminor.swing.common.ui.UiUtil;
import org.jminor.swing.framework.ui.EntityApplicationPanel;
import org.jminor.swing.framework.ui.EntityPanel;
import org.jminor.swing.framework.ui.EntityPanelProvider;
 
import java.util.Locale;
 
import static org.jminor.framework.demos.petstore.domain.Petstore.*;
 
public final class PetstoreAppPanel extends EntityApplicationPanel<PetstoreAppModel> {
 
  @Override
  protected void setupEntityPanelProviders() {
    /* CATEGORY
     *   PRODUCT
     *     ITEM
     *       ITEMTAG
     */
    final EntityPanelProvider tagItemProvider = new EntityPanelProvider(T_TAG_ITEM)
            .setEditPanelClass(TagItemEditPanel.class);
    final EntityPanelProvider itemProvider = new EntityPanelProvider(T_ITEM)
            .setEditPanelClass(ItemEditPanel.class);
    itemProvider.addDetailPanelProvider(tagItemProvider).setDetailPanelState(EntityPanel.PanelState.HIDDEN);
    final EntityPanelProvider productProvider = new EntityPanelProvider(T_PRODUCT)
            .setEditPanelClass(ProductEditPanel.class);
    productProvider.addDetailPanelProvider(itemProvider).setDetailSplitPanelResizeWeight(0.3);
    final EntityPanelProvider categoryProvider = new EntityPanelProvider(T_CATEGORY)
            .setEditPanelClass(CategoryEditPanel.class);
    categoryProvider.addDetailPanelProvider(productProvider).setDetailSplitPanelResizeWeight(0.3);
 
    addEntityPanelProvider(categoryProvider);
 
    final EntityPanelProvider addressProvider = new EntityPanelProvider(T_ADDRESS)
            .setEditPanelClass(AddressEditPanel.class);
    final EntityPanelProvider contactInfoProvider = new EntityPanelProvider(T_SELLER_CONTACT_INFO)
            .setEditPanelClass(ContactInfoEditPanel.class);
    contactInfoProvider.addDetailPanelProvider(itemProvider);
    final EntityPanelProvider tagProvider = new EntityPanelProvider(T_TAG)
            .setEditPanelClass(TagEditPanel.class);
    tagProvider.addDetailPanelProvider(tagItemProvider).setDetailPanelState(EntityPanel.PanelState.HIDDEN);
 
    addSupportPanelProviders(addressProvider, contactInfoProvider, tagProvider);
  }
 
  @Override
  protected PetstoreAppModel initializeApplicationModel(final EntityConnectionProvider connectionProvider)
          throws CancelException {
    return new PetstoreAppModel(connectionProvider);
  }
 
  public static void main(final String[] args) {
    Locale.setDefault(new Locale("en"));
    EntityPanel.TOOLBAR_BUTTONS.set(true);
    EntityApplicationPanel.CONFIRM_EXIT.set(true);
    EntityConnectionProvider.CLIENT_DOMAIN_CLASS.set("org.jminor.framework.demos.petstore.domain.Petstore");
    new PetstoreAppPanel().startApplication("The Pet Store", null, false,
            UiUtil.getScreenSizeRatio(0.8), new User("scott", "tiger".toCharArray()));
  }
 
}

Application load test

File: org/jminor/framework/demos/petstore/testing/PetstoreLoadTest.java -

/*
 * Copyright (c) 2004 - 2019, Björn Darri Sigurðsson. All Rights Reserved.
 */
package org.jminor.framework.demos.petstore.testing;
 
import org.jminor.common.User;
import org.jminor.common.model.CancelException;
import org.jminor.framework.db.EntityConnectionProviders;
import org.jminor.framework.demos.petstore.client.PetstoreAppModel;
import org.jminor.framework.demos.petstore.domain.Petstore;
import org.jminor.swing.common.tools.ui.LoadTestPanel;
import org.jminor.swing.framework.model.SwingEntityModel;
import org.jminor.swing.framework.tools.EntityLoadTestModel;
 
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
 
import static java.util.Collections.singletonList;
 
public final class PetstoreLoadTest extends EntityLoadTestModel<PetstoreAppModel> {
 
  private static final User UNIT_TEST_USER = new User(
          System.getProperty("jminor.unittest.username", "scott"),
          System.getProperty("jminor.unittest.password", "tiger").toCharArray());
 
  public PetstoreLoadTest() {
    super(UNIT_TEST_USER, singletonList(new AbstractUsageScenario<PetstoreAppModel>("selectRecords") {
      @Override
      protected void performScenario(final PetstoreAppModel application) {
        final SwingEntityModel categoryModel = application.getEntityModels().iterator().next();
        categoryModel.getTableModel().getSelectionModel().clearSelection();
        categoryModel.refresh();
        selectRandomRow(categoryModel.getTableModel());
        selectRandomRow(categoryModel.getDetailModels().iterator().next().getTableModel());
        selectRandomRow(categoryModel.getDetailModels().iterator().next().getDetailModels().iterator().next().getTableModel());
      }
    }));
  }
 
  @Override
  protected PetstoreAppModel initializeApplication() throws CancelException {
    final PetstoreAppModel applicationModel = new PetstoreAppModel(
            EntityConnectionProviders.connectionProvider().setDomainClassName(Petstore.class.getName())
                    .setClientTypeId(getClass().getSimpleName()).setUser(getUser()));
    final SwingEntityModel categoryModel = applicationModel.getEntityModels().iterator().next();
    categoryModel.addLinkedDetailModel(categoryModel.getDetailModels().iterator().next());
    final SwingEntityModel productModel = categoryModel.getDetailModels().iterator().next();
    productModel.addLinkedDetailModel(productModel.getDetailModels().iterator().next());
    final SwingEntityModel itemModel = productModel.getDetailModels().iterator().next();
    itemModel.addLinkedDetailModel(itemModel.getDetailModels().iterator().next());
 
    return applicationModel;
  }
 
  public static void main(final String[] args) throws Exception {
    SwingUtilities.invokeLater(new Runner());
  }
 
  private static final class Runner implements Runnable {
    @Override
    public void run() {
      try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        new LoadTestPanel(new PetstoreLoadTest()).showFrame();
      }
      catch (final Exception e) {
        e.printStackTrace();
      }
    }
  }
}
documentation/tutorials/petstore.txt · Last modified: 2015/10/29 16:25 by darri