KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > comp > details > CompCSTaskGroupDetails


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.comp.details;
13
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants;
16 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskGroup;
17 import org.eclipse.pde.internal.ui.PDEUIMessages;
18 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
19 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
20 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails;
21 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster;
22 import org.eclipse.pde.internal.ui.editor.cheatsheet.comp.CompCSInputContext;
23 import org.eclipse.pde.internal.ui.parts.ComboPart;
24 import org.eclipse.pde.internal.ui.parts.FormEntry;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.SelectionAdapter;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.graphics.Color;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.ui.forms.IFormColors;
34 import org.eclipse.ui.forms.IFormPart;
35 import org.eclipse.ui.forms.IManagedForm;
36 import org.eclipse.ui.forms.widgets.ExpandableComposite;
37 import org.eclipse.ui.forms.widgets.Section;
38
39 /**
40  * CompCSTaskGroupDetails
41  *
42  */

43 public class CompCSTaskGroupDetails extends CSAbstractDetails {
44
45     private Section fDefinitionSection;
46     
47     private FormEntry fNameEntry;
48     
49     private ComboPart fKindCombo;
50     
51     private Button fSkip;
52     
53     private ICompCSTaskGroup fDataTaskGroup;
54     
55     private CompCSEnclosingTextDetails fEnclosingTextSection;
56     
57     private static final String JavaDoc F_KIND_VALUE_SET = PDEUIMessages.CompCSTaskGroupDetails_Set;
58     
59     private static final String JavaDoc F_KIND_VALUE_CHOICE = PDEUIMessages.CompCSTaskGroupDetails_Choice;
60
61     private static final String JavaDoc F_KIND_VALUE_SEQUENCE = PDEUIMessages.CompCSTaskGroupDetails_Sequence;
62     
63     /**
64      * @param section
65      */

66     public CompCSTaskGroupDetails(ICSMaster section) {
67         super(section, CompCSInputContext.CONTEXT_ID);
68         fDataTaskGroup = null;
69
70         fNameEntry = null;
71         fKindCombo = null;
72         fSkip = null;
73
74         fDefinitionSection = null;
75         fEnclosingTextSection =
76             new CompCSEnclosingTextDetails(ICompCSConstants.TYPE_TASKGROUP, section);
77     }
78     
79     /**
80      * @param object
81      */

82     public void setData(ICompCSTaskGroup object) {
83         // Set data
84
fDataTaskGroup = object;
85         // Set data on the enclosing text section
86
fEnclosingTextSection.setData(object);
87     }
88     
89     /* (non-Javadoc)
90      * @see org.eclipse.ui.forms.AbstractFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
91      */

92     public void initialize(IManagedForm form) {
93         super.initialize(form);
94         // Unfortunately this has to be explicitly called for sub detail
95
// sections through its main section parent; since, it never is
96
// registered directly.
97
// Initialize managed form for enclosing text section
98
fEnclosingTextSection.initialize(form);
99     }
100     
101     /* (non-Javadoc)
102      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#createDetails(org.eclipse.swt.widgets.Composite)
103      */

104     public void createDetails(Composite parent) {
105         
106         // Create the main section
107
int style = Section.DESCRIPTION | ExpandableComposite.TITLE_BAR;
108         fDefinitionSection = getPage().createUISection(parent, PDEUIMessages.SimpleCSDetails_3,
109             PDEUIMessages.CompCSTaskGroupDetails_SectionDescription, style);
110         // Align the master and details section headers (misalignment caused
111
// by section toolbar icons)
112
getPage().alignSectionHeaders(getMasterSection().getSection(),
113                 fDefinitionSection);
114         // Create the container for the main section
115
Composite sectionClient = getPage().createUISectionContainer(fDefinitionSection, 2);
116         // Create the name entry
117
createUINameEntry(sectionClient);
118         // Create the kind label
119
createUIKindLabel(sectionClient);
120         // Create the kind combo
121
createUIKindCombo(sectionClient);
122         // Create the skip button
123
createUISkipButton(sectionClient);
124         // Create the enclosing text section
125
fEnclosingTextSection.createDetails(parent);
126         // Bind widgets
127
getManagedForm().getToolkit().paintBordersFor(sectionClient);
128         fDefinitionSection.setClient(sectionClient);
129         markDetailsPart(fDefinitionSection);
130
131     }
132
133     /**
134      * @param parent
135      */

136     private void createUISkipButton(Composite parent) {
137         Color foreground = getToolkit().getColors().getColor(IFormColors.TITLE);
138         fSkip = getToolkit().createButton(parent, PDEUIMessages.CompCSTaskGroupDetails_SkipLabel, SWT.CHECK);
139         GridData data = new GridData(GridData.FILL_HORIZONTAL);
140         data.horizontalSpan = 2;
141         fSkip.setLayoutData(data);
142         fSkip.setForeground(foreground);
143     }
144
145     /**
146      * @param parent
147      */

148     private void createUIKindLabel(Composite parent) {
149         Color foreground = getToolkit().getColors().getColor(IFormColors.TITLE);
150         Label label = getToolkit().createLabel(parent,
151                 PDEUIMessages.CompCSTaskGroupDetails_Type, SWT.WRAP);
152         label.setForeground(foreground);
153         label.setToolTipText(PDEUIMessages.CompCSTaskGroupDetails_KindToolTip);
154     }
155     
156     /**
157      * @param parent
158      */

159     private void createUIKindCombo(Composite parent) {
160         fKindCombo = new ComboPart();
161         fKindCombo.createControl(parent, getToolkit(), SWT.READ_ONLY);
162         GridData data = new GridData(GridData.FILL_HORIZONTAL);
163         // Needed to align vertically with form entry field and allow space
164
// for a possible field decoration
165
data.horizontalIndent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT;
166         fKindCombo.getControl().setLayoutData(data);
167         fKindCombo.add(F_KIND_VALUE_SET);
168         fKindCombo.add(F_KIND_VALUE_SEQUENCE);
169         fKindCombo.add(F_KIND_VALUE_CHOICE);
170         fKindCombo.setText(F_KIND_VALUE_SET);
171         fKindCombo.getControl().setToolTipText(
172                 PDEUIMessages.CompCSTaskGroupDetails_KindToolTip);
173     }
174
175     /**
176      * @param parent
177      */

178     private void createUINameEntry(Composite parent) {
179         fNameEntry = new FormEntry(parent, getManagedForm().getToolkit(),
180                 PDEUIMessages.CompCSTaskGroupDetails_Name, SWT.NONE);
181     }
182
183     /* (non-Javadoc)
184      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#hookListeners()
185      */

186     public void hookListeners() {
187         // Create listeners for the name entry
188
createListenersNameEntry();
189         // Create listeners for the kind combo
190
createListenersKindCombo();
191         // Create listeners for the skip button
192
createListenersSkipButton();
193         // Create listeners within the enclosing text section
194
fEnclosingTextSection.hookListeners();
195     }
196
197     /**
198      *
199      */

200     private void createListenersNameEntry() {
201         fNameEntry.setFormEntryListener(new FormEntryAdapter(this) {
202             public void textValueChanged(FormEntry entry) {
203                 // Ensure data object is defined
204
if (fDataTaskGroup == null) {
205                     return;
206                 }
207                 fDataTaskGroup.setFieldName(fNameEntry.getValue());
208             }
209         });
210     }
211
212     /**
213      *
214      */

215     private void createListenersKindCombo() {
216         fKindCombo.addSelectionListener(new SelectionAdapter() {
217             public void widgetSelected(SelectionEvent e) {
218                 // Ensure data object is defined
219
if (fDataTaskGroup == null) {
220                     return;
221                 }
222                 String JavaDoc selection = fKindCombo.getSelection();
223                 if (selection.equals(F_KIND_VALUE_CHOICE)) {
224                     fDataTaskGroup.setFieldKind(
225                             ICompCSConstants.ATTRIBUTE_VALUE_CHOICE);
226                 } else if (selection.equals(F_KIND_VALUE_SEQUENCE)) {
227                     fDataTaskGroup.setFieldKind(
228                             ICompCSConstants.ATTRIBUTE_VALUE_SEQUENCE);
229                 } else if (selection.equals(F_KIND_VALUE_SET)) {
230                     fDataTaskGroup.setFieldKind(
231                             ICompCSConstants.ATTRIBUTE_VALUE_SET);
232                 }
233             }
234         });
235     }
236
237     /**
238      *
239      */

240     private void createListenersSkipButton() {
241         fSkip.addSelectionListener(new SelectionAdapter() {
242             public void widgetSelected(SelectionEvent e) {
243                 // Ensure data object is defined
244
if (fDataTaskGroup == null) {
245                     return;
246                 }
247                 fDataTaskGroup.setFieldSkip(fSkip.getSelection());
248             }
249         });
250     }
251     
252     /* (non-Javadoc)
253      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#updateFields()
254      */

255     public void updateFields() {
256         // Ensure data object is defined
257
if (fDataTaskGroup == null) {
258             return;
259         }
260         boolean editable = isEditableElement();
261         // Update name entry
262
updateNameEntry(editable);
263         // Update kind combo
264
updateKindCombo(editable);
265         // Update skip button
266
updateSkipButton(editable);
267         // Update fields within enclosing text section
268
fEnclosingTextSection.updateFields();
269     }
270
271     /**
272      * @param editable
273      */

274     private void updateNameEntry(boolean editable) {
275         fNameEntry.setValue(fDataTaskGroup.getFieldName(), true);
276         fNameEntry.setEditable(editable);
277     }
278
279     /**
280      * @param editable
281      */

282     private void updateKindCombo(boolean editable) {
283         String JavaDoc kind = fDataTaskGroup.getFieldKind();
284         
285         if (kind == null) {
286             // NO-OP
287
} else if (kind.compareTo(ICompCSConstants.ATTRIBUTE_VALUE_SEQUENCE) == 0) {
288             fKindCombo.setText(F_KIND_VALUE_SEQUENCE);
289         } else if (kind.compareTo(ICompCSConstants.ATTRIBUTE_VALUE_CHOICE) == 0) {
290             fKindCombo.setText(F_KIND_VALUE_CHOICE);
291         } else {
292             fKindCombo.setText(F_KIND_VALUE_SET);
293         }
294         
295         fKindCombo.setEnabled(editable);
296     }
297
298     /**
299      * @param editable
300      */

301     private void updateSkipButton(boolean editable) {
302         fSkip.setSelection(fDataTaskGroup.getFieldSkip());
303         fSkip.setEnabled(editable);
304     }
305     
306     /* (non-Javadoc)
307      * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
308      */

309     public void commit(boolean onSave) {
310         super.commit(onSave);
311         // Only required for form entries
312
fNameEntry.commit();
313         // No need to call for sub details, because they contain no form entries
314
}
315
316     /* (non-Javadoc)
317      * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
318      */

319     public void selectionChanged(IFormPart part, ISelection selection) {
320         // Get the first selected object
321
Object JavaDoc object = getFirstSelectedObject(selection);
322         // Ensure we have the right type
323
if ((object == null) ||
324                 (object instanceof ICompCSTaskGroup) == false) {
325             return;
326         }
327         // Set data
328
setData((ICompCSTaskGroup)object);
329         // Update the UI given the new data
330
updateFields();
331     }
332     
333     /* (non-Javadoc)
334      * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
335      */

336     public void dispose() {
337         // Dispose of the enclosing text section
338
if (fEnclosingTextSection != null) {
339             fEnclosingTextSection.dispose();
340             fEnclosingTextSection = null;
341         }
342         super.dispose();
343     }
344     
345 }
346
Popular Tags