The Form Designer gives you an object-oriented, visual environment for creating graphical forms and other user interface elements. You can create a form using either the Form Wizard or the Form Designer without the wizard. You can also create subforms to include in your forms.
Without SilverStream, building an interface to your application can be laborious and time-consuming. SilverStream makes it easy with a powerful Form Designer and Property Inspector.
You should understand the following concepts before you use the Form Designer.
A form is an interface between the user and the data the user wants to access. There are basically two kinds of forms:
Database forms
Forms are attached to one or more database tables, depending on the table relationships. Only the primary table associated with the form is updateable. The Form Designer enables you to select not only the table you want your form to use, but also the data fields to include in the form. These data fields are data-bound to database columns and changes the user makes can be updated in the database. The Form Designer lets you arrange the data fields and labels as needed.
Your form can also get its data from a data source business object (DSO). For more information, see the chapter on DSOs in the Programmer's Guide.
Dialog/message box forms
A dialog box is a form that requires a response from the user before the user can continue with the application. For example, you could design a form that asks the user to respond to a prompt before continuing on to another activity. The way you display the form determines whether it is a dialog box.
A form that you include within another form is called a subform. Using subforms allows you to design reusable interface components. A subform can be content that you want to repeat on all your forms, like a footer or a menu bar, or it can be associated with another database table, enabling you to update multiple tables in the form.
To learn more about subforms in forms, see
Including subforms and views in your form.
The Form Designer HTML Edit control is a Java-based HTML editor that enables you to include rich text and structured data on the same form. The HTML Edit control and the Page Designer are similar in that you do not have to know HTML to be able to use them. The HTML Edit control contains a toolbar that enables you to graphically apply formatting instead of coding HTML tags, although you can insert raw HTML into the document if you want. You can also insert GIF or JPEG files into the rich text field and create image maps.
To learn more about what the control can do, see
Inserting HTML Edit controls. To include the control in your form, see
The HTML Edit control.
When you embed a view in a form, the Form Designer automatically creates a link clause that links the data in the view to the form. One form can contain several views or one view that contains data hierarchies.
To learn more about embedded views, see
Including subforms and views in your form.
Link clauses join information from different sources together. For example, you can embed a view created with data from one table inside a form that takes its data from another table. You can also create or modify a Link clause using the Property Inspector.
The Form Designer has two kinds of objects that you can include in your form:
Pre-defined objects are controls that SilverStream provides automatically, such as an input field or combo box. You can use these controls as part of the form you are creating. You can also bind them to data.
User-defined objects are objects that you have created or defined. These objects can include Java Beans, image files, and existing forms and views.
The Form Wizard enables you to generate a form in a few easy steps. After you've created the form, you use the toolbars and gallery to add controls to the form; the Property Inspector to set initial values for the form and the controls; and the Programming Editor to write code for events.
NOTE If you want to create a blank form, click Cancel. You can add controls to the form and use the Relational Data Palette later to choose a database table for the form, if you want. To use the Form Wizard for selecting data and style settings, continue with these steps.
NOTE For more information, see the chapter on DSOs in the Programmer's Guide.
You can select the columns in any order you want. To select individual columns, highlight the column and click >. To select all the columns, highlight the table name, and click >>. To remove the column or columns, click < or << respectively.
The form page appears in the Form Designer.
NOTE The General Reference has more information about naming conventions.
What happens
SilverStream generates a form with fields corresponding to the data you specified. Also, SilverStream adds buttons to the form, allowing users to navigate through the data and update the data (if the data source is updatable). SilverStream specifies appearance settings according to the form style you select. For some styles, the buttons are on subforms stored in the SilverMaster database.
If you chose a DSO as the primary data source, SilverStream also adds an AgcData control to the form. The AgcData control specifies the DSO the form uses to load data.
Refining the query
By default, all rows will be retrieved from the database and sent to the client. If you have large tables, you will want to specify a query that restricts which rows are retrieved. For more information, see Building queries.
The Property Inspector is available throughout SilverStream. It displays information about the selected object. Sometimes the information is read-only, but in the Form Designer, you use the Property Inspector to specify initial values for the form and its controls.
To open the Property Inspector from the Form Designer, you can:
The Property Inspector has one or more tabs depending on the containment hierarchy of the currently selected object. For example, if a field is selected, there are tabs for the Form and the field. Choose a different tab to display the property sheet for another object in the containment hierarchy, as needed.
While the Property Inspector is open, you can display properties for different objects by selecting the objects in the form. The tabs change according to the current selection.
You can also display the Programming Editor to write code for events of the form and its controls. For more information, see Programming Editor.
Forms are saved in the database. It's a good idea to save periodically while you are designing your form and before you test it.
If the server happens to be down when you try to save your form, you haven't lost anything. You will be able to save when the server comes back up.
Once you are finished adding data, controls, and buttons to your form, you are ready to test it to make sure everything works the way it should.
The compiled Java version of your form appears. If there are compilation errors, the Programming Editor displays the problematic code.
SilverStream contains an executable file called SilverJRunner that allows you to view a form without having to either launch a browser or put your form in a Web page. SilverJRunner runs from the MS-DOS prompt instead of the SilverStream Designer environment, although it still connects to the SilverStream Application Server to download the form and the necessary Java classes. You install SilverJRunner separately from SilverStream.
For more information see the deployment chapter in the Programmer's Guide.
To view a form in SilverJRunner:
silverjrunner hostname databasename formname
The name of the server where the database you want to use is located. | |
NOTE Before you can run SilverJRunner successfully against a SQL Anywhere database, you must access the ODBC settings for your database, and specify the -c and 4m flags in the Startup Options dialog box.
The Form Designer provides two facilities for adding components to a form:
The Component Gallery, which appears on the left side of the Form Designer, lets you add components from the Relational Data Palette, the Media Store, the Forms gallery, and the Views gallery. The list of available components is determined by the currently selected database. You can hide the Component Gallery to increase the amount of space available for displaying your form.
The Component Palette is an alternative to the Component Gallery that uses less screen space. When the Component Gallery is hidden, you can use the Component Palette to add components to a form. The Component Palette gives you access to all of the items in the Component Gallery, except the Relational Data Palette, which you can display separately.
NOTE To display the Relational Data Palette, select View>Relational Data Palette.
NOTE You can hide the Component Gallery by selecting View>Hide Component Gallery.
A list of resources in your current database appears.
A list of resources in your current database appears.
Here are some of the things you can do with form controls:
Beginning with Version 3.0, SilverStream supports both Swing and AWT controls. Swing controls were introduced in Java 2 (JDK 1.2.1) and provide several benefits over AWT controls, such as more flexible cross-platform support and control over the look and feel of your application, improved screen painting, data models for separating data and its presentation, and support for access by disabled users.
In the Form Designer, use the Common and Other toolbars to add Swing-based controls to your form. Many of the controls are extensions of the standard Swing controls; they provide support for data binding. The toolbars include some standard Swing controls, such as JProgressBar. Class names for Swing-based controls in SilverStream begin with the prefix AgcJ.
The Version 2 toolbar contains AWT-based controls. Use these controls for maintaining existing applications. Class names for AWT-based controls in SilverStream begin with the prefix Agc. In general, you should not mix controls based on AWT (Version 2 toolbar) with those based on Swing. If you mix both types, your form may not paint correctly. For more information, see the Java documentation from Sun.
The controls discussed in the rest of this chapter are Swing-based controls.
For more information about the Form Designer controls and what you can do with them, see Working with Swing and AWT controls in the Programming Forms chapter of the Programmer's Guide. There are many examples of using controls in the Java Client section of Application Techniques.
When you name objects you define in SilverStream, you will make your code easier to understand if you use a naming convention that identifies the object type. The General Reference provides a a list of suggested prefixes that you can use as a starting point for your naming conventions.
The Form Designer lets you incorporate the following types of text edit controls into your form:
You can restrict the kind of data users can enter into text fields. With single-line text fields, you can also format the data displayed in the form. The Form Designer provides several named display styles, plus it allows you to specify patterns of characters.
For information on characters in display patterns and named display styles, see Formatting Patterns and Styles in the online General Reference.
You can include any number of controls in your form. While this section describes adding a tab panel control, the procedure is basically the same for adding any control to a form. Tab panels are useful for organizing your user interface. You can use the tab panel control to group other controls such as radio buttons, and database navigation buttons. The tab panel also supports several events that are fired when the user navigates through the panels in your form.
NOTE You must select the tab panel before you can place other controls on it. Use Cut and Paste on the Edit menu to move controls from one tab panel to another.
AgcView is a programmable control that enables you to create views that you can adjust at runtime. This is a useful feature if you are creating a form but you do not know what the data structure underlying the form will be. For example, you could be creating a form that users are going to populate with data from classes they create. You can also use the AgcView control to hide sensitive data from unauthorized users.
AgoHeaderRowClick h = (AgoHeaderRowClick) evt.getArgument();
boolean shift = h.shiftDown();
int idx = h.getColumnIndex();
try
{
viewname.sort(idx, shift);
}
catch (Exception e) {}
where viewname is the name you gave the AgcView control.
The HTML Edit Control is a WYSIWYG editor that you can use to create and maintain HTML content on a form in SilverStream. Using the Form Designer and the HTML Edit Control, you can combine structured data with a rich text field.
The Page Designer and the HTML Edit Control are similar in that you do not have to know HTML to use either one of them. The HTML Edit Control contains a toolbar that allows you to select text formatting icons instead of coding HTML tags, although you can insert raw HTML if you want to.
To learn about how the user interacts with the control, see
Using the HTML Edit Control.
To add an HTML Edit Control to your form:
For information on how the user interacts with the HTML Edit Control include how to interact with it in Test Mode, see
Using the HTML Edit Control.
The file attachment control is a data-bound control that allows you to upload a file to a database table. When you are testing your form or running a SilverJRunner application, you can also download the file from a database to your local drive and edit the file contents. You can bind the file attachment control to a field with any data type, but the size of the file you can store is limited by the database unless you bind it to a field with the longvarbinary or longvarchar type.
You can see the file attachment control on your form when you are in Design mode. The control becomes invisible when you look at the form in Test Mode.
NOTE You cannot view file attachments from a browser unless the user adjusts the browser's security settings.
In order to use a file attachment control, you must write Java code in the Programming Editor. You'll need to decide when the code should run. You may, for example, wish to put Upload and Download buttons on your form so that the user controls when the file is uploaded or downloaded. When you upload a file, you can specify that the local copy of the file is deleted. When you download a file from the database to the local drive, you can specify that it be opened in a local editor.
To associate a File Attachment control with a database column:
To upload a file from your local drive to the database:
fileattachment1.upload(new File("c:\\temp\\file.txt"), false);
When you test the form and click the Upload button, a message appears telling you that SilverStream is uploading the file from the location you specified. When the file is uploaded and the boolean flag is true, SilverStream deletes the local copy of the file after it has been uploaded.
To download a file attachment from a database table column to your local disk:
fileattachment1.download(new File("c:\\temp\\file.txt"), false);
When you test the form and click the Download button, a message appears telling you that SilverStream is downloading the file to the path you specified. If the boolean flag were true, SilverStream would launch a local editor for the file based on the registry entry for the file extension.
The controls on your form can display data from database tables. You can set up data binding in the Property Inspector without writing any code. When the form is displayed, you can choose to have data from the database automatically displayed. Data the user enters or selects in fields bound to the form's primary table are updated when you call the update method.
For more information about displaying data in a form, see the data access information in the discussion of form basics in the Programmer's Guide.
To bind a control to a database column:
or
If you do not know the exact name of the column you want to include:
There are two ways to align controls. You can align individual controls to a grid when you add or move them. Grid alignment is on by default. After placing controls on your form, you can align groups of controls with each other with the alignment buttons or the Edit menu options Distribute and Align.
To enable or disable automatic grid alignment:
You can specify the way focus changes when the user presses the tab key. The default order is the order the fields were created.
or
Click the number for the first control you want to change. Then click the controls that will follow it, in sequence.
or
Right-click the number that you want to change and enter a new number in the dialog box. Click the controls that will follow it, in sequence.
As you change the tab order, the order number of other controls will change to avoid conflicts.
To remove a control from the tab order:
You can also set tab order programmatically by calling the setUserDefinedTabOrder() method. SilverStream calls this method in the code it generates for init()
. If you call it in the formActivate event, your tab-order array will override the tab order set in the Designer.
There are two ways to load a list of values into a list control:
Lists have two types of values: a display value and a storage value. The user sees the display value, but the associated storage value is the value passed to the database. This allows you display user-recognizable text while storing keys or other types of codes in the database. For example, if you entered the words "apples," "oranges," and "pears", these words would appear in the display list. However, selecting "apples" might return the value "1," "oranges" could return "2," and so on. In form expressions and Java code, you can refer to the storage value to find out which list item is currently selected.
A list control is usually associated with two tables:
When the form is first displayed, the value in the data-bound column determines the initial selection in the list control. The value the user selects in the list is used to update this column.
NOTE Tree controls can display a multilevel hierarchy of values. In the Property Inspector, you can specify a first level of values. You must write code to add additional levels. Application Techniques has a topic on populating tree controls.
To load the list from a table:
For help using the Expression Builder, see
Expression Builder.
A form that you include within another form is called a subform. You create the subform in the Designer, just as you would any form. A subform can be content that you want to repeat on all your forms, like a footer or a menu bar, or it can be associated with another database table, enabling you to update multiple tables in the form.
In addition to being able to include subforms in your form, you can also include views to give users a more detailed look at data. You create views in the View Designer.
For both subforms and views, if the data in the subform or view is related to the data in the form, SilverStream automatically links the two together.
NOTE If your application design requires many subforms, you might choose to load them dynamically, instead of adding them in the Designer. For information, see the information on child forms in the Programmer's Guide.
To include a subform in a form:
NOTE To select a form in a different database, see Using objects from a different database.
For more information, see
Relationship Designer and
Link clauses.
NOTE To select an view in a different database, see Using objects from a different database.
For more information, see
Relationship Designer and
Link clauses.
NOTE If a Link clause is specified, SilverStream ignores the setting for Automatic Query on the View tab; SilverStream will retrieve the view's data whenever the linked data on the form is retrieved, regardless of the Automatic Query setting.
You can use an image as the background for your form, or you can place a static image on your form. You can also create a button that displays as an images that change according to the user's actions.
In all the controls that display images, you use the Edit Property dialog box to choose the image. The file you choose can be in a SilverStream database, stored in the local file system, or accessed from a web server. Whatever you pick, the file is added to the current SilverStream database.
The image you select appears in the Preview field.
To use an image as the background for your form:
When you return to the Form Designer, the image you selected appears as the background of your form.
Swing buttons can display several images, depending on the user's actions. You can specify an image for these button states:
You don't need to specify images for all of these. For example, Disabled may be handled automatically by Swing's look-and-feel support. For more information, see the documentation for Swing controls from Sun.
The Swing buttons available on the Common tab of the toolbar are JButton and JToggleButton.
To create a button on your form that displays an image:
The JLabel control lets you display an image with an optional text label. The text can be positioned above, below, beside, or over the image. There are two ways to create the control. You can create the control and then select an image; or, if the image is already in a SilverStream database, you can select the image in the Media Store and a JLabel control is created for it on the form.
To create a control and select an image from a database, file, or URL:
The image appears in the JLabel control.
To select an image from the Media Store:
NOTE To select an image in a different database, see Using objects from a different database.
or
Select the image and drag it to a specific position on the form.
The size of the new JLabel control is set to the size of the image.
To set properties for the JLabel control:
You can display part of a larger image in an image control by specifying the pixel coordinates of a portion of the image in the Property Inspector. You might do this because:
Keeping several small images in a single file is useful because one large file compresses better and loads faster than a lot of little files. Having one large image file also removes clutter from the Media Store and enables you to load your forms and views faster. For example, instead of having a separate file for each toolbar button that you want to use, you can have one large file that contains all the toolbar buttons.
If you do not know the pixel coordinates for the image area that you want to use, use an image editing program to determine the values.
You can specify cropping coordinates anywhere in SilverStream that you can use images.
To create smaller images from a larger one:
x y width height
The coordinates are pixel measurements that define the area of the image that you want to include in your form. For example, to display an area of 20x20 pixels with the upper left corner at 10 pixels from the left edge and 5 pixels from the top, you would specify the file name and coordinates like this:
calendar.gif 10 5 20 20
You can include JavaBeans in your form. JavaBeans is a specification for third party reusable software components. Before you can include JavaBeans in your form, however, you have to import them into your database. This section describes:
JavaBeans are contained in .JAR files. Each .JAR file can contain several beans.
To upload beans to the SilverStream Media Store:
Status messages appear as SilverStream analyzes the JAR and uploads it to the server. The JAR file appears in the database's Media Store. To see the beans the JAR contains, see the next procedure.
NOTE SilverStream only supports Java Beans that use JDK 1.1 events.
NOTE You should be careful when deleting beans from the Media Store. When you delete a Bean, you also delete the .JAR file associated with it, as well as any other Beans that were included in the .JAR file.
To use JavaBeans in your form:
NOTE To select a bean in a different database, see Using objects from a different database.
You can include objects in your form that reside on a different database from the one you originally specified.
To use objects from a different database:
Use the Property Inspector and the Expression Builder to ensure data integrity by creating validation rules for the fields on your form.
For more information about specifying expressions, see
Expression Builder.
Use the special value _newValue to refer to the value that the user just entered; use the special value _lastValue to refer to the previous value in the form.
For example, if you want to prevent someone from entering a value less than zero in a field, specify the following validation rule for the field:
_newValue >= 0
Validation expressions can also refer to other fields in the form. The Expression Builder shows other fields in the form with this icon:
. For example, if you want to make sure that the date a user enters in the shipDate field is later than the value entered in orderDate, specify this rule for the shipDate field:
_newValue > orderdate
You can also refer to values in the database for the current row by selecting database columns, which are listed last in the Variables pane. The primary table is listed at the top level in the Variables pane. Click + to expand the table and display its columns. Also, tables related to the primary table are listed. You can pick columns from these tables to include in your validation rule.
For more information about relationships between tables, see
Relationship Designer.
What happens
When a user changes the value in the field, then changes focus from the field, the validation rule will be triggered. If the new entry doesn't pass validation, a dialog will display with the message you specified.
Programmatic validation checking
You can perform more complex validation testing, notification, and processing by writing code in validation-related events. For information, see the Programmer's Guide.
SilverStream provides the ability for you to provide full-text search in your forms.
For more information, see
Full Text Search.
This section describes how to use the HTML Edit Control in Test Mode. The users of your application will also use these procedures to edit HTML in the control.
The HTML Edit Control enables you to apply formatting to text in the same way that standard word processing packages do. Simply type in text, highlight it, and select the appropriate formatting button from the toolbar. The toolbar buttons take the place of inserting HTML tags into the text. For example, if you are coding raw HTML and want to make a word bold, you would have to enter:
<B>WARNING</B>
To bold text in the HTML Edit Control, all you have to do is select the Bold button.
The HTML Edit Control toolbar has tools for formatting text, creating links to other web pages, incorporating images into the HTML, and creating image maps. Place your mouse pointer over a button in the toolbar to see what the button does.
There is also a popup menu for changing the text. (Right-click in the editing area to display the menu.) The menu options vary based on the current selection or the location of the insertion point. The first option is always Properties, which displays a Property Inspector for the current editing object.
There are some text styles that are not on the toolbar but can be applied in the Property Inspector. They are:
The HTML Edit Control is for entering HTML for purposes of storing it in a database. It does not format HTML tags that you paste.
You can use the Raw HTML window to enter HTML tags that are not supported on the formatting toolbar. The HTML is not formatted, but appears as an icon in the editing area.
You can specify that words or phrases in your HTML Edit control link to web pages.
You can change the colors for text, active links, and visited links in the Property Inspector.
When the HTML Edit Control is read-only, you can follow the links by clicking on them. When it allows editing, you must press the right mouse button to follow the link.
You can specify different colors for the background or the text of your HTML Edit control.
You can also set text and link colors. Your changes appear immediately.
You must convert bitmaps or graphics created using other graphic packages (such as PowerPoint or Visio) into web-compatible formats such as .GIF or .JPG. Once you convert your image to the appropriate format, you can include it in the HTML Edit control and an inline or background image.
or
To specify a background image, open the Property Inspector, select the Page tab, expand the Background and colors section, and click the ellipses beside the Image field.
A dialog box appears.
Image maps are descriptions of areas on an image. You can create an image map by selecting parts of a graphic file and specifying the URL that you want it to link to.
The Layout Region control lets you create a layout area with absolute positioning for other controls.
NOTE Once you place a control inside a layout region, you cannot move it to an area outside the region unless you cut and paste it.
On the dropdown near the right end of the toolbar, there are buttons for:
To include a component in your HTML Edit control: