package com.sibvisions.apps.javafx.db;
import javax.rad.application.IContent;
import javax.rad.application.genui.Application;
import javax.rad.application.genui.UILauncher;
import javax.rad.genui.celleditor.UIDateCellEditor;
import javax.rad.genui.celleditor.UIImageViewer;
import javax.rad.genui.celleditor.UINumberCellEditor;
import javax.rad.genui.component.UILabel;
import javax.rad.genui.container.UIGroupPanel;
import javax.rad.genui.container.UIPanel;
import javax.rad.genui.container.UISplitPanel;
import javax.rad.genui.control.UIEditor;
import javax.rad.genui.layout.UIBorderLayout;
import javax.rad.genui.layout.UIFormLayout;
import javax.rad.model.ModelException;
import javax.rad.ui.IContainer;
import javax.rad.util.event.IExceptionListener;
import com.sibvisions.apps.components.FilterEditor;
import com.sibvisions.apps.components.NavigationTable;
import com.sibvisions.rad.persist.StorageDataBook;
import com.sibvisions.rad.persist.jdbc.DBAccess;
import com.sibvisions.rad.persist.jdbc.DBStorage;
public class SimpleDBApplication extends Application
implements IExceptionListener
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Class members
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private static final String NO_IMAGE =
"/com/sibvisions/apps/vxdemo/images/nobody.gif";
private static final UIImageViewer IMAGE_VIEWER =
new UIImageViewer(NO_IMAGE);
private StorageDataBook sdbContacts;
private UIBorderLayout blThis = new UIBorderLayout();
private UISplitPanel splitMain = new UISplitPanel();
private NavigationTable navContacts = new NavigationTable();
private UIFormLayout flDetails = new UIFormLayout();
private UIFormLayout layoutDetails = new UIFormLayout();
private UIPanel panDetails = new UIPanel();
private UIGroupPanel gpanDedails = new UIGroupPanel("Contact");
private UIBorderLayout blContacts = new UIBorderLayout();
private UIPanel panContacts = new UIPanel();
private UIFormLayout layoutSearch = new UIFormLayout();
private UIPanel panSearch = new UIPanel();
private UILabel lblSalutation = new UILabel("Salutation");
private UILabel lblAcademicTitle = new UILabel("Academic title");
private UILabel lblFirstName = new UILabel("First name");
private UILabel lblLastName = new UILabel("Last name");
private UILabel lblStreet = new UILabel("Street");
private UILabel lblNr = new UILabel("Nr");
private UILabel lblZip = new UILabel("ZIP");
private UILabel lblTown = new UILabel("Town");
private UILabel lblBirthday = new UILabel("DoB");
private UILabel lblHealthInsurance = new UILabel("Health insurance");
private UILabel lblSearch = new UILabel("Search");
private UIEditor edtSalutation = new UIEditor();
private UIEditor edtAcademicTitle = new UIEditor();
private UIEditor edtFirstName = new UIEditor();
private UIEditor edtLastName = new UIEditor();
private UIEditor edtStreet = new UIEditor();
private UIEditor editNr = new UIEditor();
private UIEditor edtZip = new UIEditor();
private UIEditor edtTown = new UIEditor();
private UIEditor edtCountry = new UIEditor();
private UIEditor edtBirthday = new UIEditor();
private UIEditor edtHealthInsurance = new UIEditor();
private FilterEditor edtSearch = new FilterEditor();
private UIEditor icoImage = new UIEditor();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Initialization
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Creates a new instance of <code>Showcase</code>.
*
* @param pLauncher the launcher
* @throws Throwable if the initialization failed
*/
public SimpleDBApplication(UILauncher pLauncher) throws Throwable
{
super(pLauncher);
setName("Simple DB application");
initModel();
initUI();
}
/**
* Initializes model.
*
* @throws ModelException
*/
private void initModel() throws ModelException
{
DBAccess dba = DBAccess.getDBAccess("jdbc:oracle:thin:@localhost:1521:xe");
dba.setUsername("vxdemo");
dba.setPassword("vxdemo");
dba.open();
DBStorage dbsContacts = new DBStorage();
dbsContacts.setDBAccess(dba);
dbsContacts.setWritebackTable("CONTACTS");
dbsContacts.open();
sdbContacts = new StorageDataBook(dbsContacts);
sdbContacts.open();
sdbContacts.getRowDefinition().getColumnDefinition("IMAGE").
getDataType().setCellEditor(IMAGE_VIEWER);
sdbContacts.getRowDefinition().getColumnDefinition("SOCIALSECNR").
getDataType().setCellEditor(new UINumberCellEditor("0000"));
sdbContacts.getRowDefinition().getColumnDefinition("BIRTHDAY").
getDataType().setCellEditor(new UIDateCellEditor("dd.MM.yyyy"));
}
/**
* Initializes UI.
*
* @throws Throwable if the initialization failed
*/
private void initUI() throws Throwable
{
navContacts.setDataBook(sdbContacts);
navContacts.setAutoResize(false);
icoImage.setDataRow(sdbContacts);
icoImage.setColumnName("IMAGE");
icoImage.setPreferredSize(200, 140);
edtSearch.setDataRow(sdbContacts);
edtSalutation.setDataRow(sdbContacts);
edtSalutation.setColumnName("SALU_SALUTATION");
edtAcademicTitle.setDataRow(sdbContacts);
edtAcademicTitle.setColumnName("ACTI_ACADEMIC_TITLE");
edtFirstName.setDataRow(sdbContacts);
edtFirstName.setColumnName("FIRSTNAME");
edtLastName.setDataRow(sdbContacts);
edtLastName.setColumnName("LASTNAME");
edtStreet.setDataRow(sdbContacts);
edtStreet.setColumnName("STREET");
editNr.setDataRow(sdbContacts);
editNr.setColumnName("NR");
edtZip.setDataRow(sdbContacts);
edtZip.setColumnName("ZIP");
edtTown.setDataRow(sdbContacts);
edtTown.setColumnName("TOWN");
edtCountry.setDataRow(sdbContacts);
edtCountry.setColumnName("CTRY_COUNTRY");
edtBirthday.setDataRow(sdbContacts);
edtBirthday.setColumnName("BIRTHDAY");
edtHealthInsurance.setDataRow(sdbContacts);
edtHealthInsurance.setColumnName("HEIN_HEALTH_INSURANCE");
panSearch.setLayout(layoutSearch);
panSearch.add(lblSearch, layoutSearch.getConstraints(0, 0));
panSearch.add(edtSearch, layoutSearch.getConstraints(1, 0, -1, 0));
panContacts.setLayout(blContacts);
panContacts.add(panSearch, UIBorderLayout.NORTH);
panContacts.add(navContacts, UIBorderLayout.CENTER);
gpanDedails.setLayout(flDetails);
gpanDedails.add(icoImage, flDetails.getConstraints(0, 0, 1, 7));
flDetails.setHorizontalGap(15);
gpanDedails.add(edtSalutation, flDetails.getConstraints(3, 0));
flDetails.setHorizontalGap(5);
gpanDedails.add(edtAcademicTitle, flDetails.getConstraints(3, 1));
flDetails.setHorizontalGap(15);
gpanDedails.add(lblSalutation, flDetails.getConstraints(2, 0));
flDetails.setHorizontalGap(5);
gpanDedails.add(lblAcademicTitle, flDetails.getConstraints(2, 1));
gpanDedails.add(lblFirstName, flDetails.getConstraints(2, 2));
gpanDedails.add(edtFirstName, flDetails.getConstraints(3, 2, -1, 2));
gpanDedails.add(lblLastName, flDetails.getConstraints(2, 3));
gpanDedails.add(edtLastName, flDetails.getConstraints(3, 3, -1, 3));
gpanDedails.add(lblBirthday, flDetails.getConstraints(2, 4));
gpanDedails.add(edtBirthday, flDetails.getConstraints(3, 4, 3, 4));
gpanDedails.add(lblHealthInsurance,
flDetails.getConstraints(2, 5));
gpanDedails.add(edtHealthInsurance,
flDetails.getConstraints(3, 5, -1, 5));
gpanDedails.add(lblStreet, flDetails.getConstraints(2, 6));
gpanDedails.add(edtStreet, flDetails.getConstraints(3, 6, -3, 6));
gpanDedails.add(lblNr, flDetails.getConstraints(-2, 6));
gpanDedails.add(editNr, flDetails.getConstraints(-1, 6));
gpanDedails.add(lblZip, flDetails.getConstraints(2, 7));
gpanDedails.add(edtZip, flDetails.getConstraints(3, 7));
gpanDedails.add(lblTown, flDetails.getConstraints(4, 7));
gpanDedails.add(edtTown, flDetails.getConstraints(5, 7, -1, 7));
panDetails.setLayout(layoutDetails);
panDetails.add(gpanDedails,
layoutDetails.getConstraints(0, 0, -1, 0));
splitMain.setDividerPosition(250);
splitMain.setDividerAlignment(UISplitPanel.DIVIDER_TOP_LEFT);
splitMain.setFirstComponent(panContacts);
splitMain.setSecondComponent(panDetails);
setLayout(blThis);
add(splitMain, UIBorderLayout.CENTER);
setPreferredSize(1024, 768);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Interface implementation
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public IContainer getContentPane()
{
return this;
}
public <OP> IContent showMessage(OP pOpener, int pIconType,
int pButtonType, String pMessage,
String pOkAction, String pCancelAction)
throws Throwable
{
System.out.println(pMessage);
return null;
}
public void handleException(Throwable pThrowable)
{
pThrowable.printStackTrace();
}
}