KickJava   Java API By Example, From Geeks To Geeks.

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


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.ISimpleCS;
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.layout.GridData;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.ui.forms.IFormPart;
27 import org.eclipse.ui.forms.widgets.ExpandableComposite;
28 import org.eclipse.ui.forms.widgets.FormToolkit;
29 import org.eclipse.ui.forms.widgets.Section;
30
31 /**
32  * SimpleCSDetails
33  *
34  */

35 public class SimpleCSDetails extends CSAbstractDetails {
36
37     private ISimpleCS fCheatSheet;
38     
39     private FormEntry fTitle;
40     
41     private Section fMainSection;
42     
43     /**
44      * @param section
45      */

46     public SimpleCSDetails(ICSMaster section) {
47         super(section, SimpleCSInputContext.CONTEXT_ID);
48         fCheatSheet = null;
49         
50         fTitle = null;
51         fMainSection = null;
52     }
53
54     /**
55      * @param object
56      */

57     public void setData(ISimpleCS object) {
58         // Set data
59
fCheatSheet = object;
60     }
61     
62     /* (non-Javadoc)
63      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
64      */

65     public void selectionChanged(IFormPart part, ISelection selection) {
66         // Get the first selected object
67
Object JavaDoc object = getFirstSelectedObject(selection);
68         // Ensure we have the right type
69
if ((object == null) ||
70                 (object instanceof ISimpleCS) == false) {
71             return;
72         }
73         // Set data
74
setData((ISimpleCS)object);
75         // Update the UI given the new data
76
updateFields();
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#createDetails(org.eclipse.swt.widgets.Composite)
81      */

82     public void createDetails(Composite parent) {
83
84         FormToolkit toolkit = getManagedForm().getToolkit();
85         GridData data = null;
86         
87         // Create main section
88
fMainSection = toolkit.createSection(parent, Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
89         fMainSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
90         fMainSection.setText(PDEUIMessages.SimpleCSDetails_3);
91         fMainSection.setDescription(PDEUIMessages.SimpleCSDetails_2);
92         fMainSection.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
93         data = new GridData(GridData.FILL_HORIZONTAL);
94         fMainSection.setLayoutData(data);
95         // Align the master and details section headers (misalignment caused
96
// by section toolbar icons)
97
getPage().alignSectionHeaders(getMasterSection().getSection(),
98                 fMainSection);
99         
100         // Create container for main section
101
Composite mainSectionClient = toolkit.createComposite(fMainSection);
102         mainSectionClient.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2));
103
104         // Attribute: title
105
fTitle = new FormEntry(mainSectionClient, toolkit, PDEUIMessages.SimpleCSDetails_0, SWT.NONE);
106
107         // Bind widgets
108
toolkit.paintBordersFor(mainSectionClient);
109         fMainSection.setClient(mainSectionClient);
110         markDetailsPart(fMainSection);
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#hookListeners()
115      */

116     public void hookListeners() {
117         // Attribute: title
118
fTitle.setFormEntryListener(new FormEntryAdapter(this) {
119             public void textValueChanged(FormEntry entry) {
120                 // Ensure data object is defined
121
if (fCheatSheet == null) {
122                     return;
123                 }
124                 fCheatSheet.setTitle(fTitle.getValue());
125             }
126         });
127     }
128
129     /* (non-Javadoc)
130      * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#updateFields()
131      */

132     public void updateFields() {
133         // Ensure data object is defined
134
if (fCheatSheet == null) {
135             return;
136         }
137         
138         boolean editable = isEditableElement();
139         // Attribute: title
140
fTitle.setValue(fCheatSheet.getTitle(), true);
141         fTitle.setEditable(editable);
142     }
143
144     /* (non-Javadoc)
145      * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
146      */

147     public void commit(boolean onSave) {
148         super.commit(onSave);
149         // Only required for form entries
150
fTitle.commit();
151         // No need to call for sub details, because they contain no form entries
152
}
153
154 }
155
Popular Tags