001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details;
011:
012: import org.eclipse.jface.viewers.ISelection;
013: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSSubItem;
014: import org.eclipse.pde.internal.ui.PDEUIMessages;
015: import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
016: import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
017: import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails;
018: import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster;
019: import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSInputContext;
020: import org.eclipse.pde.internal.ui.parts.FormEntry;
021: import org.eclipse.swt.SWT;
022: import org.eclipse.swt.events.SelectionAdapter;
023: import org.eclipse.swt.events.SelectionEvent;
024: import org.eclipse.swt.layout.GridData;
025: import org.eclipse.swt.widgets.Button;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.ui.forms.IFormPart;
028: import org.eclipse.ui.forms.IManagedForm;
029: import org.eclipse.ui.forms.widgets.ExpandableComposite;
030: import org.eclipse.ui.forms.widgets.Section;
031:
032: /**
033: * SimpleCSSubItemDetails
034: *
035: */
036: public class SimpleCSSubItemDetails extends CSAbstractDetails {
037:
038: private ISimpleCSSubItem fSubItem;
039:
040: private FormEntry fLabel;
041:
042: private Button fSkip;
043:
044: private Section fMainSection;
045:
046: private SimpleCSCommandDetails fCommandSection;
047:
048: /**
049: * @param elementSection
050: */
051: public SimpleCSSubItemDetails(ICSMaster masterTreeSection) {
052: super (masterTreeSection, SimpleCSInputContext.CONTEXT_ID);
053: fSubItem = null;
054:
055: fLabel = null;
056: fSkip = null;
057: fMainSection = null;
058: fCommandSection = new SimpleCSCommandDetails(masterTreeSection);
059: }
060:
061: /**
062: * @param object
063: */
064: public void setData(ISimpleCSSubItem object) {
065: // Set data
066: fSubItem = object;
067: // Set data on command section
068: fCommandSection.setData(object);
069: }
070:
071: /* (non-Javadoc)
072: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
073: */
074: public void selectionChanged(IFormPart part, ISelection selection) {
075: // Get the first selected object
076: Object object = getFirstSelectedObject(selection);
077: // Ensure we have the right type
078: if ((object == null)
079: || (object instanceof ISimpleCSSubItem) == false) {
080: return;
081: }
082: // Set data
083: setData((ISimpleCSSubItem) object);
084: // Update the UI given the new data
085: updateFields();
086: }
087:
088: /* (non-Javadoc)
089: * @see org.eclipse.ui.forms.AbstractFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
090: */
091: public void initialize(IManagedForm form) {
092: super .initialize(form);
093: // Unfortunately this has to be explicitly called for sub detail
094: // sections through its main section parent; since, it never is
095: // registered directly.
096: // Initialize managed form for command section
097: fCommandSection.initialize(form);
098: }
099:
100: /* (non-Javadoc)
101: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#createDetails(org.eclipse.swt.widgets.Composite)
102: */
103: public void createDetails(Composite parent) {
104:
105: GridData data = null;
106:
107: // Create main section
108: fMainSection = getToolkit().createSection(parent,
109: Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
110: fMainSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
111: fMainSection.setText(PDEUIMessages.SimpleCSSubItemDetails_10);
112: fMainSection
113: .setDescription(PDEUIMessages.SimpleCSSubItemDetails_11);
114: fMainSection.setLayout(FormLayoutFactory.createClearGridLayout(
115: false, 1));
116: data = new GridData(GridData.FILL_HORIZONTAL);
117: fMainSection.setLayoutData(data);
118:
119: // Align the master and details section headers (misalignment caused
120: // by section toolbar icons)
121: getPage().alignSectionHeaders(getMasterSection().getSection(),
122: fMainSection);
123:
124: // Create container for main section
125: Composite mainSectionClient = getToolkit().createComposite(
126: fMainSection);
127: mainSectionClient.setLayout(FormLayoutFactory
128: .createSectionClientGridLayout(false, 2));
129:
130: // Attribute: label
131: fLabel = new FormEntry(mainSectionClient, getToolkit(),
132: PDEUIMessages.SimpleCSSubItemDetails_0, SWT.MULTI
133: | SWT.WRAP | SWT.V_SCROLL);
134: data = new GridData(GridData.FILL_HORIZONTAL);
135: data.heightHint = 50;
136: fLabel.getText().setLayoutData(data);
137: data = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
138: | GridData.HORIZONTAL_ALIGN_END);
139: fLabel.getLabel().setLayoutData(data);
140:
141: // Attribute: skip
142: fSkip = getToolkit().createButton(mainSectionClient,
143: PDEUIMessages.SimpleCSSubItemDetails_3, SWT.CHECK);
144: data = new GridData(GridData.FILL_HORIZONTAL);
145: data.horizontalSpan = 2;
146: fSkip.setLayoutData(data);
147:
148: // Bind widgets
149: getToolkit().paintBordersFor(mainSectionClient);
150: fMainSection.setClient(mainSectionClient);
151: markDetailsPart(fMainSection);
152:
153: fCommandSection.createDetails(parent);
154: }
155:
156: /* (non-Javadoc)
157: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#hookListeners()
158: */
159: public void hookListeners() {
160: // Attribute: label
161: fLabel.setFormEntryListener(new FormEntryAdapter(this ) {
162: public void textValueChanged(FormEntry entry) {
163: // Ensure data object is defined
164: if (fSubItem == null) {
165: return;
166: }
167: fSubItem.setLabel(fLabel.getValue());
168: }
169: });
170: // Attribute: skip
171: fSkip.addSelectionListener(new SelectionAdapter() {
172: public void widgetSelected(SelectionEvent e) {
173: if (fSubItem == null) {
174: return;
175: }
176: fSubItem.setSkip(fSkip.getSelection());
177: }
178: });
179:
180: fCommandSection.hookListeners();
181: }
182:
183: /* (non-Javadoc)
184: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#updateFields()
185: */
186: public void updateFields() {
187:
188: boolean editable = isEditableElement();
189: // Ensure data object is defined
190: if (fSubItem == null) {
191: return;
192: }
193: // Attribute: label
194: fLabel.setValue(fSubItem.getLabel(), true);
195: fLabel.setEditable(editable);
196:
197: // Attribute: skip
198: fSkip.setSelection(fSubItem.getSkip());
199: fSkip.setEnabled(editable);
200:
201: fCommandSection.updateFields();
202: }
203:
204: /* (non-Javadoc)
205: * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
206: */
207: public void commit(boolean onSave) {
208: super .commit(onSave);
209: // Only required for form entries
210: fLabel.commit();
211: // No need to call for sub details, because they contain no form entries
212: }
213:
214: }
|