1 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 35 public class SimpleCSDetails extends CSAbstractDetails { 36 37 private ISimpleCS fCheatSheet; 38 39 private FormEntry fTitle; 40 41 private Section fMainSection; 42 43 46 public SimpleCSDetails(ICSMaster section) { 47 super(section, SimpleCSInputContext.CONTEXT_ID); 48 fCheatSheet = null; 49 50 fTitle = null; 51 fMainSection = null; 52 } 53 54 57 public void setData(ISimpleCS object) { 58 fCheatSheet = object; 60 } 61 62 65 public void selectionChanged(IFormPart part, ISelection selection) { 66 Object object = getFirstSelectedObject(selection); 68 if ((object == null) || 70 (object instanceof ISimpleCS) == false) { 71 return; 72 } 73 setData((ISimpleCS)object); 75 updateFields(); 77 } 78 79 82 public void createDetails(Composite parent) { 83 84 FormToolkit toolkit = getManagedForm().getToolkit(); 85 GridData data = null; 86 87 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 getPage().alignSectionHeaders(getMasterSection().getSection(), 98 fMainSection); 99 100 Composite mainSectionClient = toolkit.createComposite(fMainSection); 102 mainSectionClient.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2)); 103 104 fTitle = new FormEntry(mainSectionClient, toolkit, PDEUIMessages.SimpleCSDetails_0, SWT.NONE); 106 107 toolkit.paintBordersFor(mainSectionClient); 109 fMainSection.setClient(mainSectionClient); 110 markDetailsPart(fMainSection); 111 } 112 113 116 public void hookListeners() { 117 fTitle.setFormEntryListener(new FormEntryAdapter(this) { 119 public void textValueChanged(FormEntry entry) { 120 if (fCheatSheet == null) { 122 return; 123 } 124 fCheatSheet.setTitle(fTitle.getValue()); 125 } 126 }); 127 } 128 129 132 public void updateFields() { 133 if (fCheatSheet == null) { 135 return; 136 } 137 138 boolean editable = isEditableElement(); 139 fTitle.setValue(fCheatSheet.getTitle(), true); 141 fTitle.setEditable(editable); 142 } 143 144 147 public void commit(boolean onSave) { 148 super.commit(onSave); 149 fTitle.commit(); 151 } 153 154 } 155 | Popular Tags |