KickJava   Java API By Example, From Geeks To Geeks.

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


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.jface.viewers.ISelection;
15 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSSubItem;
16 import org.eclipse.pde.internal.ui.PDEUIMessages;
17 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
18 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
19 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails;
20 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster;
21 import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSInputContext;
22 import org.eclipse.pde.internal.ui.parts.FormEntry;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.SelectionAdapter;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.widgets.Button;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.ui.forms.IFormPart;
30 import org.eclipse.ui.forms.IManagedForm;
31 import org.eclipse.ui.forms.widgets.ExpandableComposite;
32 import org.eclipse.ui.forms.widgets.Section;
33
34 /**
35  * SimpleCSSubItemDetails
36  *
37  */

38 public class SimpleCSSubItemDetails extends CSAbstractDetails {
39
40     private ISimpleCSSubItem fSubItem;
41     
42     private FormEntry fLabel;
43     
44     private Button fSkip;
45     
46     private Section fMainSection;
47
48     private SimpleCSCommandDetails fCommandSection;
49     
50     /**
51      * @param elementSection
52      */

53     public SimpleCSSubItemDetails(ICSMaster masterTreeSection) {
54         super(masterTreeSection, SimpleCSInputContext.CONTEXT_ID);
55         fSubItem = null;
56
57         fLabel = null;
58         fSkip = null;
59         fMainSection = null;
60         fCommandSection = new SimpleCSCommandDetails(masterTreeSection);
61     }
62
63     /**
64      * @param object
65      */

66     public void setData(ISimpleCSSubItem object) {
67         // Set data
68
fSubItem = object;
69         // Set data on command section
70
fCommandSection.setData(object);
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
75      */

76     public void selectionChanged(IFormPart part, ISelection selection) {
77         // Get the first selected object
78
Object JavaDoc object = getFirstSelectedObject(selection);
79         // Ensure we have the right type
80
if ((object == null) ||
81                 (object instanceof ISimpleCSSubItem) == false) {
82             return;
83         }
84         // Set data
85
setData((ISimpleCSSubItem)object);
86         // Update the UI given the new data
87
updateFields();
88     }
89     
90     /* (non-Javadoc)
91      * @see org.eclipse.ui.forms.AbstractFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
92      */

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

105     public void createDetails(Composite parent) {
106
107         GridData data = null;
108         
109         // Create main section
110
fMainSection = getToolkit().createSection(parent, Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
111         fMainSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
112         fMainSection.setText(PDEUIMessages.SimpleCSSubItemDetails_10);
113         fMainSection.setDescription(PDEUIMessages.SimpleCSSubItemDetails_11);
114         fMainSection.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
115         data = new GridData(GridData.FILL_HORIZONTAL);
116         fMainSection.setLayoutData(data);
117         
118         // Align the master and details section headers (misalignment caused
119
// by section toolbar icons)
120
getPage().alignSectionHeaders(getMasterSection().getSection(),
121                 fMainSection);
122         
123         // Create container for main section
124
Composite mainSectionClient = getToolkit().createComposite(fMainSection);
125         mainSectionClient.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2));
126         
127         // Attribute: label
128
fLabel = new FormEntry(mainSectionClient, getToolkit(), PDEUIMessages.SimpleCSSubItemDetails_0, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
129         data = new GridData(GridData.FILL_HORIZONTAL);
130         data.heightHint = 50;
131         fLabel.getText().setLayoutData(data);
132         data = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
133         fLabel.getLabel().setLayoutData(data);
134
135         // Attribute: skip
136
fSkip = getToolkit().createButton(mainSectionClient, PDEUIMessages.SimpleCSSubItemDetails_3, SWT.CHECK);
137         data = new GridData(GridData.FILL_HORIZONTAL);
138         data.horizontalSpan = 2;
139         fSkip.setLayoutData(data);
140
141         // Bind widgets
142
getToolkit().paintBordersFor(mainSectionClient);
143         fMainSection.setClient(mainSectionClient);
144         markDetailsPart(fMainSection);
145
146         fCommandSection.createDetails(parent);
147     }
148     
149     /* (non-Javadoc)
150      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#hookListeners()
151      */

152     public void hookListeners() {
153         // Attribute: label
154
fLabel.setFormEntryListener(new FormEntryAdapter(this) {
155             public void textValueChanged(FormEntry entry) {
156                 // Ensure data object is defined
157
if (fSubItem == null) {
158                     return;
159                 }
160                 fSubItem.setLabel(fLabel.getValue());
161             }
162         });
163         // Attribute: skip
164
fSkip.addSelectionListener(new SelectionAdapter() {
165             public void widgetSelected(SelectionEvent e) {
166                 if (fSubItem == null) {
167                     return;
168                 }
169                 fSubItem.setSkip(fSkip.getSelection());
170             }
171         });
172         
173         fCommandSection.hookListeners();
174     }
175     
176     /* (non-Javadoc)
177      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#updateFields()
178      */

179     public void updateFields() {
180
181         boolean editable = isEditableElement();
182         // Ensure data object is defined
183
if (fSubItem == null) {
184             return;
185         }
186         // Attribute: label
187
fLabel.setValue(fSubItem.getLabel(), true);
188         fLabel.setEditable(editable);
189         
190         // Attribute: skip
191
fSkip.setSelection(fSubItem.getSkip());
192         fSkip.setEnabled(editable);
193         
194         fCommandSection.updateFields();
195     }
196
197     /* (non-Javadoc)
198      * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
199      */

200     public void commit(boolean onSave) {
201         super.commit(onSave);
202         // Only required for form entries
203
fLabel.commit();
204         // No need to call for sub details, because they contain no form entries
205
}
206
207 }
208
Popular Tags