Relational "View Output as Table" Example

 

The following coding example presents a tabular display of any result set that used relational data.

 

/**

*

* A simple method that will display data selection using relational data in a tabular format.

*

* @param result set generated from reading a information map using relational data.

*

* @throws Exception

*/

private void DisplayRelationalTableExample(com.sas.iquery.metadata.business.DataSelection dataSelection) throws Exception

{         

          // Use result set to setup table adapter that is used to visually display relational data

com.sas.storage.iquery.BusinessQueryToTableModelAdapter adapter = new com.sas.storage.iquery.BusinessQueryToTableModelAdapter();

adapter.setModel(dataSelection);

 

// Set up a Java Frame to display Simple Table

javax.swing.JDialog m_testDialog;

javax.swing.JFrame m_mainFrame = null;

 

// Create the panel to hold the results of 

javax.swing.JPanel ButtonPanel = new javax.swing.JPanel( new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 10) );

javax.swing.JButton closeButton = new javax.swing.JButton("Close");

java.awt.Container table = new java.awt.Container();

int tableWidth = 0, tableHeight = 0;

table.setLayout( new java.awt.BorderLayout() );

table.setLayout(new com.sas.visuals.AutoSizingGridLayout(0, 1, 5, 5, true, true, true));

com.sas.swing.visuals.tableview.TableView rtable= new com.sas.swing.visuals.tableview.TableView();
rtable.setColumnSelectionAllowed(true);
rtable.setCellSelectionEnabled(true);
rtable.setModel(adapter);

rtable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);

javax.swing.JScrollPane relationPane = new javax.swing.JScrollPane(rtable);

table.add(java.awt.BorderLayout.CENTER, relationPane);

tableWidth = rtable.getPreferredSize().width ;

tableHeight = rtable.getPreferredSize().height + 75 ;

 

// Fill in the dialog

String resultTitle = "Testing Dialog";

m_testDialog = new javax.swing.JDialog( m_mainFrame, resultTitle, true );

javax.swing.JPanel panel = new javax.swing.JPanel();

panel.setLayout( new java.awt.BorderLayout() );

m_testDialog.setContentPane( panel );

ButtonPanel.add( closeButton );

closeButton.addActionListener( new java.awt.event.ActionListener()

{ public void actionPerformed(java.awt.event.ActionEvent event)

{ }

});

panel.add( java.awt.BorderLayout.CENTER, table );

panel.add( java.awt.BorderLayout.SOUTH, ButtonPanel );

tableHeight += ButtonPanel.getPreferredSize().height;

if ( tableHeight < 200 ) tableHeight = 200;

if ( tableWidth > 500 ) tableWidth = 500;

else if ( tableWidth < 300 ) tableWidth = 300;

if ( tableHeight > 600 ) tableHeight = 600;

m_testDialog.pack();

m_testDialog.setSize(tableWidth, tableHeight);

m_testDialog.setResizable( true );

m_testDialog.setVisible( true );

}