At run time, you can hide or show NavigatorControl buttons in response to user actions or application states. For example, suppose you provide a single navigator for navigating through two different data sets, one permits users to edit records, and the other is read-only. When you switch between data sets, you want to hide the navigator’s Insert, Delete, Post, Cancel, Ditto, Save, and Refresh buttons when viewing the read-only data set, but show these buttons when viewing the editable data set.
Suppose you want to prevent edits to the DEPARTMENT table by hiding the Insert, Delete, Post, Cancel, Ditto, Save, and Refresh buttons on the navigator, but you also want to allow editing for the EMPLOYEE table. By default, all possible buttons are displayed. The following sections provide an example of how you might code this application. It also provides code for allowing two data sets to share a status bar. The information displayed in the status bar depends on which data set is active.
Property name | Value |
Connection URL | jdbc:odbc:DataSet Tutorial |
Username | SYSDBA |
Password | masterkey |
The code generated by the designer for this step is:
database1.setConnection(new borland.jbcl.dataset.ConnectionDescriptor
("jdbc:odbc:DataSet Tutorial", "SYSDBA", "masterkey", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
Tip: The connection dialog includes a Test Connection button. Click this button to check that the connection properties have been correctly set. Results of the connection attempt are displayed in the gray area below the button.
The code generated by this step is:
queryDataSet1.setQuery(new borland.jbcl.dataset.QueryDescriptor(database1, "select * from department", null, true, false));
Success
, click OK to close the dialog.
The code generated by this step is:
queryDataSet1.setQuery(new borland.jbcl.dataset.QueryDescriptor(database1, "select * from employee", null, true, false));
Success
, click OK to close the dialog.
The code generated by this step is:
queryDataSet2.setMasterLink(new MasterLinkDescriptor(queryDataSet1,
new String[] {"DEPT_NO"}, new String[] {"DEPT_NO"}, false));
The code generated by this step is:
gridControl1.setDataSet(queryDataSet1);
gridControl2.setDataSet(queryDataSet2);
//define which navigator buttons to show for each data set int[] grid1EnabledFlags = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; int[] grid2EnabledFlags = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; //instantiate a listener for each data set FocusListener grid1Focus = new VisualEvents_Focus(this, queryDataSet1, grid1EnabledFlags); FocusListener grid2Focus = new VisualEvents_Focus(this, queryDataSet2, grid2EnabledFlags); //tie each listener to its grid gridControl1.addFocusListener(grid1Focus); gridControl2.addFocusListener(grid2Focus);
This class gets data members when it is constructed and passes them on when gridFocusGained happens.
package borland.samples.tutoriol.dataset.visualevents; import java.awt.*; import java.awt.event.*; import borland.jbcl.dataset.QueryDataSet; public class VisualEvents_Focus implements FocusListener { VisualEvents_Frame target; QueryDataSet qds; int[] navEnabledFlags; public VisualEvents_Focus(VisualEvents_Frame target, QueryDataSet qds, int[] navEnabledFlags) { this.target = target; this.qds = qds; this.navEnabledFlags = navEnabledFlags; } public void focusGained(FocusEvent focusEvent) { target.gridFocusGained(qds, navEnabledFlags); } public void focusLost(FocusEvent parm1) { } }
// set navigator and statusBar properties for the grid that got focus public void gridFocusGained(QueryDataSet qds, int[] navEnabledFlags) { navigatorControl1.setDataSet(qds); for (int i = 0; i < navEnabledFlags.length; ++i) navigatorControl1.setButtonEnabled(i, navEnabledFlags[i] == 1); statusBar1.setDataSet(qds); }
This concludes the re-creation of the sample application VisualEvents.jpr and the demonstration of using a single navigator for two data sets.