Before you display the persistence object chooser, you can customize it in the following ways.
Method | Customization |
---|---|
addPersistenceObjectFilter |
Adds an object type to the list of types to which users can limit their search. |
resetPersistenceObjectFilter |
Removes all items in the list of types, except "all objects" |
getPersistenceObjectFilter |
Rearranges the object types in the list. This method returns an array of filters. You rearrange the array to rearrange the items in the combo box. |
setAttributesToDisplay |
Determines which attributes appear in a list of attributes to display for each object, when a detailed list appears. Note that the persistence object chooser always displays the object name. You do not need to call the method if all you want to display is the object name. |
setSelectedObjectName |
Sets a default name for an object. |
setLocale |
Changes the locale for the dialog box. The persistence object chooser uses the default locale by default. Call this method if you want to set the locale for the dialog box only. |
The following code adds a filter to the persistence object chooser, identifies a default component to open, and specifies the attributes that appear in a detailed list of files. This example assumes an InitialPersistenceManager
named pmRoot
.
// create the persistence object chooser // pmRoot is the InitialPersistenceManager PersistenceObjectChooser dialog = new PersistenceObjectChooser(pmRoot); create a frame for the dialog JFrame frame = new JFrame(); // create a filter PersistenceObjectFilter filter = new BasicPersistenceObjectFilter(PSRConstants.GRAPH, "Graph"); // add the filter to the persistence object chooser dialog.addPersistenceObjectFilter(filter); // set a file to be selected for opening by default dialog.setSelectedObjectName("SalesGraph"); // create an array of attributes to display String[] attrs = new String[]{PSRConstants.Attributes.OBJECT_TYPE, PSRConstants.Attributes.DESCRIPTION, PSRConstants.Attributes.TIME_DATE_MODIFIED}; // create an array for the column headings String[] headings = new String[]{"Object Type", "Description", "Time/Date"}; // create an array of widths for each column int[] widths = new int[]{100, 200, 100}; dialog.setAttributesToDisplay(attrs, headings, widths); // display the dialog box int result = dialog.showOpenDialog(frame);