1 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 32 public class CompCSDetails extends CSAbstractDetails { 33 34 private ICompCS fDataCheatSheet; 35 36 private Section fMainSection; 37 38 private FormEntry fNameEntry; 39 40 43 public CompCSDetails(ICSMaster masterSection) { 44 super(masterSection, CompCSInputContext.CONTEXT_ID); 45 fDataCheatSheet = null; 46 47 fNameEntry = null; 48 fMainSection = null; 49 } 50 51 54 public void setData(ICompCS object) { 55 fDataCheatSheet = object; 57 } 58 59 62 public void createDetails(Composite parent) { 63 int style = Section.DESCRIPTION | ExpandableComposite.TITLE_BAR; 65 fMainSection = getPage().createUISection(parent, PDEUIMessages.SimpleCSDetails_3, 66 PDEUIMessages.CompCSDetails_sectionDescription, style); 67 getPage().alignSectionHeaders(getMasterSection().getSection(), 70 fMainSection); 71 Composite sectionClient = getPage().createUISectionContainer(fMainSection, 2); 73 createUINameEntry(sectionClient); 75 getManagedForm().getToolkit().paintBordersFor(sectionClient); 77 fMainSection.setClient(sectionClient); 78 markDetailsPart(fMainSection); 79 } 80 81 84 private void createUINameEntry(Composite parent) { 85 fNameEntry = new FormEntry(parent, getManagedForm().getToolkit(), 86 PDEUIMessages.CompCSDetails_Name, SWT.NONE); 87 } 88 89 92 public void hookListeners() { 93 createListenersNameEntry(); 95 } 96 97 100 private void createListenersNameEntry() { 101 fNameEntry.setFormEntryListener(new FormEntryAdapter(this) { 102 public void textValueChanged(FormEntry entry) { 103 if (fDataCheatSheet == null) { 105 return; 106 } 107 fDataCheatSheet.setFieldName(fNameEntry.getValue()); 108 } 109 }); 110 } 111 112 115 public void updateFields() { 116 if (fDataCheatSheet == null) { 118 return; 119 } 120 updateNameEntry(isEditableElement()); 122 } 123 124 127 private void updateNameEntry(boolean editable) { 128 fNameEntry.setValue(fDataCheatSheet.getFieldName(), true); 129 fNameEntry.setEditable(editable); 130 } 131 132 135 public void commit(boolean onSave) { 136 super.commit(onSave); 137 fNameEntry.commit(); 139 } 141 142 145 public void selectionChanged(IFormPart part, ISelection selection) { 146 Object object = getFirstSelectedObject(selection); 148 if ((object == null) || 150 (object instanceof ICompCS) == false) { 151 return; 152 } 153 setData((ICompCS)object); 155 updateFields(); 157 } 158 159 } 160 | Popular Tags |