KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > site > BaseNewDialog


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

11 package org.eclipse.pde.internal.ui.editor.site;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.jface.dialogs.*;
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.pde.internal.core.isite.*;
17 import org.eclipse.pde.internal.ui.*;
18 import org.eclipse.pde.internal.ui.parts.*;
19 import org.eclipse.swt.*;
20 import org.eclipse.swt.events.*;
21 import org.eclipse.swt.layout.*;
22 import org.eclipse.swt.widgets.*;
23 import org.eclipse.ui.help.*;
24
25 public abstract class BaseNewDialog extends StatusDialog {
26     private Button okButton;
27     private ISiteModel siteModel;
28     private ISiteObject siteObject;
29     private IStatus errorStatus;
30     private IStatus okStatus;
31
32     public BaseNewDialog(
33         Shell shell,
34         ISiteModel siteModel,
35         ISiteObject siteObject) {
36         super(shell);
37         this.siteModel = siteModel;
38         this.siteObject = siteObject;
39     }
40
41     protected void createButtonsForButtonBar(Composite parent) {
42         super.createButtonsForButtonBar(parent);
43         dialogChanged();
44     }
45
46     public ISiteObject getSiteObject() {
47         return siteObject;
48     }
49
50     public ISiteModel getSiteModel() {
51         return siteModel;
52     }
53     
54     protected IDialogSettings getDialogSettings(String JavaDoc sectionName) {
55         IDialogSettings master = PDEPlugin.getDefault().getDialogSettings();
56         IDialogSettings section = master.getSection(sectionName);
57         if (section==null)
58             section = master.addNewSection(sectionName);
59         return section;
60     }
61
62     protected Control createDialogArea(Composite parent) {
63         Composite container = new Composite(parent, SWT.NULL);
64         GridLayout layout = new GridLayout();
65         layout.numColumns = 2;
66         layout.marginHeight = layout.marginWidth = 10;
67         container.setLayout(layout);
68         GridData gd = new GridData(GridData.FILL_BOTH);
69         container.setLayoutData(gd);
70
71         createEntries(container);
72
73         if (siteObject != null)
74             initializeFields();
75         ModifyListener listener = new ModifyListener() {
76             public void modifyText(ModifyEvent e) {
77                 dialogChanged();
78             }
79         };
80         hookListeners(listener);
81         setTitle(getDialogTitle());
82         Dialog.applyDialogFont(container);
83         WorkbenchHelp.setHelp(container, getHelpId());
84         return container;
85     }
86
87     protected abstract String JavaDoc getDialogTitle();
88     protected abstract String JavaDoc getHelpId();
89     protected abstract void createEntries(Composite container);
90     protected abstract void hookListeners(ModifyListener listener);
91     protected abstract void dialogChanged();
92     protected abstract String JavaDoc getEmptyErrorMessage();
93
94     protected void initializeFields() {
95         if (siteModel.isEditable() == false) {
96             okButton.setEnabled(false);
97         }
98     }
99
100     protected void setIfDefined(Text text, String JavaDoc value) {
101         if (value != null)
102             text.setText(value);
103     }
104
105     protected IStatus getEmptyErrorStatus() {
106         if (errorStatus == null)
107             errorStatus = createErrorStatus(getEmptyErrorMessage());
108         return errorStatus;
109     }
110
111     protected IStatus getOKStatus() {
112         if (okStatus == null)
113             okStatus =
114                 new Status(
115                     IStatus.OK,
116                     PDEPlugin.getPluginId(),
117                     IStatus.OK,
118                     "", //$NON-NLS-1$
119
null);
120         return okStatus;
121     }
122
123     protected IStatus createErrorStatus(String JavaDoc message) {
124         return new Status(
125             IStatus.ERROR,
126             PDEPlugin.getPluginId(),
127             IStatus.OK,
128             message,
129             null);
130     }
131
132     protected void okPressed() {
133         execute();
134         super.okPressed();
135     }
136
137     protected abstract void execute();
138 }
139
Popular Tags