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.ISimpleCS;
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.layout.GridData;
023: import org.eclipse.swt.widgets.Composite;
024: import org.eclipse.ui.forms.IFormPart;
025: import org.eclipse.ui.forms.widgets.ExpandableComposite;
026: import org.eclipse.ui.forms.widgets.FormToolkit;
027: import org.eclipse.ui.forms.widgets.Section;
028:
029: /**
030: * SimpleCSDetails
031: *
032: */
033: public class SimpleCSDetails extends CSAbstractDetails {
034:
035: private ISimpleCS fCheatSheet;
036:
037: private FormEntry fTitle;
038:
039: private Section fMainSection;
040:
041: /**
042: * @param section
043: */
044: public SimpleCSDetails(ICSMaster section) {
045: super (section, SimpleCSInputContext.CONTEXT_ID);
046: fCheatSheet = null;
047:
048: fTitle = null;
049: fMainSection = null;
050: }
051:
052: /**
053: * @param object
054: */
055: public void setData(ISimpleCS object) {
056: // Set data
057: fCheatSheet = object;
058: }
059:
060: /* (non-Javadoc)
061: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
062: */
063: public void selectionChanged(IFormPart part, ISelection selection) {
064: // Get the first selected object
065: Object object = getFirstSelectedObject(selection);
066: // Ensure we have the right type
067: if ((object == null) || (object instanceof ISimpleCS) == false) {
068: return;
069: }
070: // Set data
071: setData((ISimpleCS) object);
072: // Update the UI given the new data
073: updateFields();
074: }
075:
076: /* (non-Javadoc)
077: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#createDetails(org.eclipse.swt.widgets.Composite)
078: */
079: public void createDetails(Composite parent) {
080:
081: FormToolkit toolkit = getManagedForm().getToolkit();
082: GridData data = null;
083:
084: // Create main section
085: fMainSection = toolkit.createSection(parent,
086: Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
087: fMainSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
088: fMainSection.setText(PDEUIMessages.SimpleCSDetails_3);
089: fMainSection.setDescription(PDEUIMessages.SimpleCSDetails_2);
090: fMainSection.setLayout(FormLayoutFactory.createClearGridLayout(
091: false, 1));
092: data = new GridData(GridData.FILL_HORIZONTAL);
093: fMainSection.setLayoutData(data);
094: // Align the master and details section headers (misalignment caused
095: // by section toolbar icons)
096: getPage().alignSectionHeaders(getMasterSection().getSection(),
097: fMainSection);
098:
099: // Create container for main section
100: Composite mainSectionClient = toolkit
101: .createComposite(fMainSection);
102: mainSectionClient.setLayout(FormLayoutFactory
103: .createSectionClientGridLayout(false, 2));
104:
105: // Attribute: title
106: fTitle = new FormEntry(mainSectionClient, toolkit,
107: PDEUIMessages.SimpleCSDetails_0, SWT.NONE);
108:
109: // Bind widgets
110: toolkit.paintBordersFor(mainSectionClient);
111: fMainSection.setClient(mainSectionClient);
112: markDetailsPart(fMainSection);
113: }
114:
115: /* (non-Javadoc)
116: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#hookListeners()
117: */
118: public void hookListeners() {
119: // Attribute: title
120: fTitle.setFormEntryListener(new FormEntryAdapter(this ) {
121: public void textValueChanged(FormEntry entry) {
122: // Ensure data object is defined
123: if (fCheatSheet == null) {
124: return;
125: }
126: fCheatSheet.setTitle(fTitle.getValue());
127: }
128: });
129: }
130:
131: /* (non-Javadoc)
132: * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSAbstractDetails#updateFields()
133: */
134: public void updateFields() {
135: // Ensure data object is defined
136: if (fCheatSheet == null) {
137: return;
138: }
139:
140: boolean editable = isEditableElement();
141: // Attribute: title
142: fTitle.setValue(fCheatSheet.getTitle(), true);
143: fTitle.setEditable(editable);
144: }
145:
146: /* (non-Javadoc)
147: * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
148: */
149: public void commit(boolean onSave) {
150: super .commit(onSave);
151: // Only required for form entries
152: fTitle.commit();
153: // No need to call for sub details, because they contain no form entries
154: }
155:
156: }
|