Use JVx Swing controls without JVx UI

Contains useful source code for specific use cases.

Use JVx Swing controls without JVx UI

Postby Development@SIB » Thu Jan 05, 2012 3:18 pm

JVx's Swing controls are independent of JVx UI. It is no problem to use a table that shows some database or in-memory records. It is also possible to use 3-tier or 2-tier architecture.

In-Memory data

Use JVxTable and integrate it in your Swing application. Use it like a standard JTable.

Code: Select all
public class JVxTableTest extends JFrame
{
   public static void main(String[] pArgs) throws Throwable
   {
      new JVxTableTest();
   }
   
   JVxTableTest() throws Throwable
   {
      //--------------------------------
      // Data
      //--------------------------------

      MemDataBook mdbData = new MemDataBook();
      mdbData.setName("person");
      mdbData.getRowDefinition().addColumnDefinition(new ColumnDefinition("FIRSTNAME"));
      mdbData.getRowDefinition().addColumnDefinition(new ColumnDefinition("LASTNAME"));
      mdbData.getRowDefinition().addColumnDefinition(new ColumnDefinition("PHONE"));
      mdbData.open();
      
      mdbData.insert(true);
      mdbData.setValues(new String[] {"FIRSTNAME", "LASTNAME", "PHONE"},
                        new String[] {"JVx", "rocks", "+43 000 / 1234 567"});

      mdbData.saveAllRows();

      //--------------------------------
      // Swing
      //--------------------------------
      
      JVxTable table = new JVxTable();
      table.setDataBook(mdbData);

      setLayout(new BorderLayout());
      
      add(table, BorderLayout.CENTER);
      
      setPreferredSize(new Dimension(500, 400));
      pack();
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
   }
   
}   // JVxTableTest

You have all JVx features like link cell editors, image choice editors - in your Swing application!


2-tier data (database)

Replace the MemDataBook with following code:

Code: Select all
//--------------------------------
// Database handling
//--------------------------------

//DB Connection
DBAccess dba = DBAccess.getDBAccess("jdbc:hsqldb:hsql://localhost/db");
dba.setUsername("sa");
dba.setPassword("");
dba.open();
      
//Table access
DBStorage dsFiles = dba.createStorage();
dsFiles.setWritebackTable("FILES");
dsFiles.setAutoLinkReference(false);
dsFiles.open();
      
//--------------------------------
// Communication
//--------------------------------

//Connection handling
DirectObjectConnection con = new DirectObjectConnection();
con.put("files", dsFiles);
      
MasterConnection macon = new MasterConnection(con);
macon.open();
      
//Connect to the "remote" table
RemoteDataSource rds = new RemoteDataSource(macon);
rds.open();

RemoteDataBook rdbData = new RemoteDataBook();
rdbData.setDataSource(rds);
rdbData.setName("files");
rdbData.open();


3-tier data (database)

Remote DBAccess, DBStorage and DirectObjectConnection and replace the MasterConnection with following code:

Code: Select all
HttpConnection con = new HttpConnection("http://server/app/services/Server");      
      
MasterConnection macon = new MasterConnection(con);
macon.setApplicationName("showcase");
macon.setUserName("admin");
macon.setPassword("admin");
macon.open();
User avatar
Development@SIB
 
Posts: 311
Joined: Mon Sep 28, 2009 1:54 pm

Return to Code snippets