KickJava   Java API By Example, From Geeks To Geeks.

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


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.ICompCS;
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.cheatsheet.CSAbstractDetails;
19 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster;
20 import org.eclipse.pde.internal.ui.editor.cheatsheet.comp.CompCSInputContext;
21 import org.eclipse.pde.internal.ui.parts.FormEntry;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.ui.forms.IFormPart;
25 import org.eclipse.ui.forms.widgets.ExpandableComposite;
26 import org.eclipse.ui.forms.widgets.Section;
27
28 /**
29  * CompCSDetails
30  *
31  */

32 public class CompCSDetails extends CSAbstractDetails {
33
34     private ICompCS fDataCheatSheet;
35     
36     private Section fMainSection;
37     
38     private FormEntry fNameEntry;
39     
40     /**
41      * @param masterSection
42      */

43     public CompCSDetails(ICSMaster masterSection) {
44         super(masterSection, CompCSInputContext.CONTEXT_ID);
45         fDataCheatSheet = null;
46
47         fNameEntry = null;
48         fMainSection = null;
49     }
50     
51     /**
52      * @param object
53      */

54     public void setData(ICompCS object) {
55         // Set data
56
fDataCheatSheet = object;
57     }
58     
59     /* (non-Javadoc)
60      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#createDetails(org.eclipse.swt.widgets.Composite)
61      */

62     public void createDetails(Composite parent) {
63         // Create the main section
64
int style = Section.DESCRIPTION | ExpandableComposite.TITLE_BAR;
65         fMainSection = getPage().createUISection(parent, PDEUIMessages.SimpleCSDetails_3,
66             PDEUIMessages.CompCSDetails_sectionDescription, style);
67         // Align the master and details section headers (misalignment caused
68
// by section toolbar icons)
69
getPage().alignSectionHeaders(getMasterSection().getSection(),
70                 fMainSection);
71         // Create the container for the main section
72
Composite sectionClient = getPage().createUISectionContainer(fMainSection, 2);
73         // Create the name widget
74
createUINameEntry(sectionClient);
75         // Bind widgets
76
getManagedForm().getToolkit().paintBordersFor(sectionClient);
77         fMainSection.setClient(sectionClient);
78         markDetailsPart(fMainSection);
79     }
80     
81     /**
82      * @param parent
83      */

84     private void createUINameEntry(Composite parent) {
85         fNameEntry = new FormEntry(parent, getManagedForm().getToolkit(),
86                 PDEUIMessages.CompCSDetails_Name, SWT.NONE);
87     }
88
89     /* (non-Javadoc)
90      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#hookListeners()
91      */

92     public void hookListeners() {
93         // Create the listeners for the name entry
94
createListenersNameEntry();
95     }
96
97     /**
98      *
99      */

100     private void createListenersNameEntry() {
101         fNameEntry.setFormEntryListener(new FormEntryAdapter(this) {
102             public void textValueChanged(FormEntry entry) {
103                 // Ensure data object is defined
104
if (fDataCheatSheet == null) {
105                     return;
106                 }
107                 fDataCheatSheet.setFieldName(fNameEntry.getValue());
108             }
109         });
110     }
111
112     /* (non-Javadoc)
113      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#updateFields()
114      */

115     public void updateFields() {
116         // Ensure data object is defined
117
if (fDataCheatSheet == null) {
118             return;
119         }
120         // Update name entry
121
updateNameEntry(isEditableElement());
122     }
123
124     /**
125      * @param editable
126      */

127     private void updateNameEntry(boolean editable) {
128         fNameEntry.setValue(fDataCheatSheet.getFieldName(), true);
129         fNameEntry.setEditable(editable);
130     }
131     
132     /* (non-Javadoc)
133      * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
134      */

135     public void commit(boolean onSave) {
136         super.commit(onSave);
137         // Only required for form entries
138
fNameEntry.commit();
139         // No need to call for sub details, because they contain no form entries
140
}
141
142     /* (non-Javadoc)
143      * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
144      */

145     public void selectionChanged(IFormPart part, ISelection selection) {
146         // Get the first selected object
147
Object JavaDoc object = getFirstSelectedObject(selection);
148         // Ensure we have the right type
149
if ((object == null) ||
150                 (object instanceof ICompCS) == false) {
151             return;
152         }
153         // Set data
154
setData((ICompCS)object);
155         // Update the UI given the new data
156
updateFields();
157     }
158
159 }
160
Popular Tags