KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > simple > details > SimpleCSHelpDetails


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
12 package org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details;
13
14 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSHelpObject;
15 import org.eclipse.pde.internal.core.util.PDETextHelper;
16 import org.eclipse.pde.internal.ui.PDEUIMessages;
17 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
18 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractSubDetails;
19 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster;
20 import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSInputContext;
21 import org.eclipse.pde.internal.ui.parts.ComboPart;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.ModifyEvent;
24 import org.eclipse.swt.events.ModifyListener;
25 import org.eclipse.swt.events.SelectionAdapter;
26 import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.graphics.Color;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.swt.widgets.Text;
32 import org.eclipse.ui.forms.IFormColors;
33 import org.eclipse.ui.forms.widgets.ExpandableComposite;
34 import org.eclipse.ui.forms.widgets.FormToolkit;
35 import org.eclipse.ui.forms.widgets.Section;
36
37 /**
38  * SimpleCSHelpDetailsSection
39  *
40  */

41 public class SimpleCSHelpDetails extends CSAbstractSubDetails {
42
43     private Text fHelpText;
44     
45     private ComboPart fHelpCombo;
46     
47     private Label fHelpLabel;
48     
49     private ISimpleCSHelpObject fHelpObject;
50     
51     private Section fHelpSection;
52     
53     private boolean fBlockListeners;
54
55     private static final String JavaDoc F_NO_HELP = PDEUIMessages.SimpleCSCommandDetails_6;
56     
57     private static final String JavaDoc F_HELP_CONTEXT_ID = PDEUIMessages.SimpleCSHelpDetails_HelpContextID;
58
59     private static final String JavaDoc F_HELP_DOCUMENT_LINK = PDEUIMessages.SimpleCSHelpDetails_HelpDocumentLink;
60     
61     /**
62      * @param section
63      */

64     public SimpleCSHelpDetails(ICSMaster section) {
65         super(section, SimpleCSInputContext.CONTEXT_ID);
66         fHelpObject = null;
67         fBlockListeners = false;
68         
69         fHelpText = null;
70         fHelpCombo = null;
71         fHelpLabel = null;
72         
73         fHelpSection = null;
74     }
75     
76     /* (non-Javadoc)
77      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#setData(java.lang.Object)
78      */

79     public void setData(ISimpleCSHelpObject object) {
80         // Set data
81
fHelpObject = object;
82     }
83     
84     /* (non-Javadoc)
85      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.ISimpleCSDetails#createDetails(org.eclipse.swt.widgets.Composite)
86      */

87     public void createDetails(Composite parent) {
88
89         int columnSpan = 2;
90         FormToolkit toolkit = getToolkit();
91         
92         GridData data = null;
93         Label label = null;
94         Color foreground = toolkit.getColors().getColor(IFormColors.TITLE);
95         
96         // Create help section
97
fHelpSection = toolkit.createSection(parent, Section.DESCRIPTION
98                 | ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE);
99         fHelpSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
100         fHelpSection.setText(PDEUIMessages.SimpleCSSharedUIFactory_1);
101         fHelpSection.setDescription(PDEUIMessages.SimpleCSSharedUIFactory_2);
102         fHelpSection.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
103         data = new GridData(GridData.FILL_HORIZONTAL);
104         fHelpSection.setLayoutData(data);
105         
106         // Create container for help section
107
Composite helpSectionClient = toolkit.createComposite(fHelpSection);
108         helpSectionClient.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, columnSpan));
109
110         // Attribute: href
111
// Attribute: contextId
112
label = toolkit.createLabel(helpSectionClient,
113                 PDEUIMessages.SimpleCSHelpDetails_Type, SWT.WRAP);
114         label.setForeground(foreground);
115
116         // Attribute: href
117
// Attribute: contextId
118
fHelpCombo = new ComboPart();
119         fHelpCombo.createControl(helpSectionClient, toolkit, SWT.READ_ONLY);
120         fHelpCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
121         fHelpCombo.add(F_NO_HELP);
122         fHelpCombo.add(F_HELP_CONTEXT_ID);
123         fHelpCombo.add(F_HELP_DOCUMENT_LINK);
124         fHelpCombo.setText(F_NO_HELP);
125         
126         // Attribute: href
127
// Attribute: contextId
128
fHelpLabel = toolkit.createLabel(helpSectionClient,
129                 PDEUIMessages.SimpleCSHelpDetails_Value, SWT.WRAP);
130         fHelpLabel.setForeground(foreground);
131         
132         // Attribute: href
133
// Attribute: contextId
134
fHelpText = toolkit.createText(helpSectionClient, null);
135         data = new GridData(GridData.FILL_HORIZONTAL);
136         fHelpText.setLayoutData(data);
137     
138         // Bind widgets
139
toolkit.paintBordersFor(helpSectionClient);
140         fHelpSection.setClient(helpSectionClient);
141         // Mark as a details part to enable cut, copy, paste, etc.
142
markDetailsPart(fHelpSection);
143     }
144
145     /* (non-Javadoc)
146      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.ISimpleCSDetails#hookListeners()
147      */

148     public void hookListeners() {
149
150         // Attribute: href
151
// Attribute: contextId
152
fHelpCombo.addSelectionListener(new SelectionAdapter() {
153             public void widgetSelected(SelectionEvent e) {
154                 // Ensure data object is defined
155
if (fHelpObject == null) {
156                     return;
157                 }
158                 String JavaDoc selection = fHelpCombo.getSelection();
159                 if (selection.equals(F_NO_HELP) == false) {
160                     // Help was selected
161
if (selection.equals(F_HELP_CONTEXT_ID)) {
162                         // Help context ID was selected, clear the help
163
// document link value
164
fHelpObject.setHref(null);
165                     } else {
166                         // Help document link was selected, clear the help
167
// context ID value
168
fHelpObject.setContextId(null);
169                     }
170                     // Make the label and text field visible
171
fHelpLabel.setVisible(true);
172                     fHelpText.setVisible(true);
173                     // Set the focus on the text field
174
fHelpText.setFocus();
175                     // Clear the previous contents of the text field
176
// (Will cause field to become dirty)
177
fHelpText.setText(""); //$NON-NLS-1$
178
} else {
179                     // No help was selected
180
// Make the label and text field invisible
181
fHelpLabel.setVisible(false);
182                     fHelpText.setVisible(false);
183                     // Clear values for help in model
184
fHelpObject.setContextId(null);
185                     fHelpObject.setHref(null);
186                 }
187             }
188         });
189         // Attribute: href
190
// Attribute: contextId
191
fHelpText.addModifyListener(new ModifyListener() {
192             public void modifyText(ModifyEvent e) {
193                 // Block UI updates
194
if (fBlockListeners) {
195                     return;
196                 }
197                 // Ensure data object is defined
198
if (fHelpObject == null) {
199                     return;
200                 }
201                 String JavaDoc selection = fHelpCombo.getSelection();
202                 if (selection.equals(F_HELP_CONTEXT_ID)) {
203                     // Help context ID was selected, save the field contents
204
// as such
205
fHelpObject.setContextId(fHelpText.getText());
206                 } else {
207                     // Help document link was selected, save the field contents
208
// as such
209
fHelpObject.setHref(fHelpText.getText());
210                 }
211             }
212         });
213     
214     }
215
216     /* (non-Javadoc)
217      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details.ISimpleCSDetails#updateFields()
218      */

219     public void updateFields() {
220         // Ensure data object is defined
221
if (fHelpObject == null) {
222             return;
223         }
224
225         boolean editable = isEditableElement();
226         boolean expanded = false;
227         
228         // Block model updates
229
fBlockListeners = true;
230         // Attribute: contextId
231
// Attribute: href
232
if (PDETextHelper.isDefined(fHelpObject.getContextId())) {
233             fHelpText.setText(fHelpObject.getContextId());
234             fHelpCombo.setText(F_HELP_CONTEXT_ID);
235             expanded = true;
236         } else if (PDETextHelper.isDefined(fHelpObject.getHref())) {
237             fHelpText.setText(fHelpObject.getHref());
238             fHelpCombo.setText(F_HELP_DOCUMENT_LINK);
239             expanded = true;
240         } else {
241             fHelpCombo.setText(F_NO_HELP);
242         }
243         // Unblock model updates
244
fBlockListeners = false;
245
246         fHelpSection.setExpanded(expanded);
247         fHelpText.setEnabled(editable);
248         fHelpText.setVisible(expanded);
249         fHelpLabel.setVisible(expanded);
250         fHelpCombo.setEnabled(editable);
251     }
252
253
254     /* (non-Javadoc)
255      * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
256      */

257     public void commit(boolean onSave) {
258         super.commit(onSave);
259         // NO-OP
260
// No form entries
261
}
262     
263 }
264
Popular Tags