Multi-Dimensional "View Output as Table" Example

 

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

 

/**

*

* A simple method that will display multi-dimension results in a tabular format.

*

* @param result set generated from reading a information map using multi-dimension data.

*

* @throws Exception

*/

private void DisplayOLAPTableExample(com.sas.iquery.execution2.ResultSetInterface resultSet) throws Exception

{         

          // Use result set to setup OLAPDataSetInterface that is used to visually display OLAP data

com.sas.storage.olap.OLAPDataSetInterface olapDataSet = null;

olapDataSet = (com.sas.storage.olap.OLAPDataSetInterface)resultSet.getResultSet();

 

// Set up a Java Frame to display Simple Table

Object obj = olapDataSet;

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 FlowLayout(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 BorderLayout() );

if ( obj instanceof com.sas.storage.olap.OLAPDataSetInterface )

{        table.setLayout(new AutoSizingGridLayout(0, 1, 5, 5, true, true, true));

com.sas.swing.models.OLAPTableModelAdapter adapter = new com.sas.swing.models.OLAPTableModelAdapter((com.sas.storage.olap.OLAPDataSetInterface)obj);

com.sas.swing.visuals.olaptableview.OLAPTableView olapData = new OLAPTableView();

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

olapData.setModel( adapter );

javax.swing.JScrollPane olapPane = new javax.swing.JScrollPane(olapData);

table.add(BorderLayout.CENTER, olapPane);

tableWidth = olapData.getPreferredSize().width ;

tableHeight = (olapData.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 BorderLayout() );

m_testDialog.setContentPane( panel );

ButtonPanel.add( closeButton );

closeButton.addActionListener( new ActionListener()

{ public void actionPerformed(ActionEvent event)

{ }

});

panel.add( BorderLayout.CENTER, table );

panel.add( 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 );

}

}