KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > forms > FormDialog


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.forms;
12
13 import org.eclipse.jface.dialogs.TrayDialog;
14 import org.eclipse.jface.window.IShellProvider;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.swt.widgets.Shell;
21 import org.eclipse.ui.forms.widgets.FormToolkit;
22 import org.eclipse.ui.forms.widgets.ScrolledForm;
23 import org.eclipse.ui.internal.forms.Messages;
24
25 /**
26  * A general-purpose dialog that hosts a form. Clients should extend the class
27  * and override <code>createFormContent(IManagedForm)</code> protected method.
28  * <p>
29  * Since forms with wrapped text typically don't have a preferred size, it is
30  * important to set the initial dialog size upon creation:
31  * <p>
32  *
33  * <pre>
34  * MyFormDialog dialog = new MyFormDialog(shell);
35  * dialog.create();
36  * dialog.getShell().setSize(500, 500);
37  * dialog.open();
38  * </pre>
39  *
40  * <p>
41  * Otherwise, the dialog may open very wide.
42  * <p>
43  *
44  * @since 3.3
45  */

46
47 public class FormDialog extends TrayDialog {
48     private FormToolkit toolkit;
49
50     /**
51      * Creates a new form dialog for a provided parent shell.
52      *
53      * @param shell
54      * the parent shell
55      */

56     public FormDialog(Shell shell) {
57         super(shell);
58         setShellStyle(getShellStyle() | SWT.RESIZE);
59     }
60
61     /**
62      * Creates a new form dialog for a provided parent shell provider.
63      *
64      * @param parentShellProvider
65      * the parent shell provider
66      */

67     public FormDialog(IShellProvider parentShellProvider) {
68         super(parentShellProvider);
69     }
70
71     /*
72      * (non-Javadoc)
73      *
74      * @see org.eclipse.jface.dialogs.TrayDialog#close()
75      */

76     public boolean close() {
77         boolean rcode = super.close();
78         toolkit.dispose();
79         return rcode;
80     }
81
82     /*
83      * (non-Javadoc)
84      *
85      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
86      */

87     protected Control createDialogArea(Composite parent) {
88         toolkit = new FormToolkit(parent.getDisplay());
89         ScrolledForm sform = toolkit.createScrolledForm(parent);
90         sform.setLayoutData(new GridData(GridData.FILL_BOTH));
91         ManagedForm mform = new ManagedForm(toolkit, sform);
92         createFormContent(mform);
93         applyDialogFont(sform.getBody());
94         return sform;
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see org.eclipse.jface.dialogs.TrayDialog#createButtonBar(org.eclipse.swt.widgets.Composite)
101      */

102     protected Control createButtonBar(Composite parent) {
103         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
104         //Composite sep = new Composite(parent, SWT.NULL);
105
//sep.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
106
//gd.heightHint = 1;
107
Label sep = new Label(parent, SWT.HORIZONTAL|SWT.SEPARATOR);
108         sep.setLayoutData(gd);
109         Control bar = super.createButtonBar(parent);
110         return bar;
111     }
112
113     /**
114      * Configures the dialog form and creates form content. Clients should
115      * override this method.
116      *
117      * @param mform
118      * the dialog form
119      */

120     protected void createFormContent(IManagedForm mform) {
121         mform.getForm().setText(Messages.FormDialog_defaultTitle);
122     }
123 }
124
Popular Tags