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.ISimpleCSSubItem; 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.events.SelectionAdapter; 25 import org.eclipse.swt.events.SelectionEvent; 26 import org.eclipse.swt.layout.GridData; 27 import org.eclipse.swt.widgets.Button; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.ui.forms.IFormPart; 30 import org.eclipse.ui.forms.IManagedForm; 31 import org.eclipse.ui.forms.widgets.ExpandableComposite; 32 import org.eclipse.ui.forms.widgets.Section; 33 34 38 public class SimpleCSSubItemDetails extends CSAbstractDetails { 39 40 private ISimpleCSSubItem fSubItem; 41 42 private FormEntry fLabel; 43 44 private Button fSkip; 45 46 private Section fMainSection; 47 48 private SimpleCSCommandDetails fCommandSection; 49 50 53 public SimpleCSSubItemDetails(ICSMaster masterTreeSection) { 54 super(masterTreeSection, SimpleCSInputContext.CONTEXT_ID); 55 fSubItem = null; 56 57 fLabel = null; 58 fSkip = null; 59 fMainSection = null; 60 fCommandSection = new SimpleCSCommandDetails(masterTreeSection); 61 } 62 63 66 public void setData(ISimpleCSSubItem object) { 67 fSubItem = object; 69 fCommandSection.setData(object); 71 } 72 73 76 public void selectionChanged(IFormPart part, ISelection selection) { 77 Object object = getFirstSelectedObject(selection); 79 if ((object == null) || 81 (object instanceof ISimpleCSSubItem) == false) { 82 return; 83 } 84 setData((ISimpleCSSubItem)object); 86 updateFields(); 88 } 89 90 93 public void initialize(IManagedForm form) { 94 super.initialize(form); 95 fCommandSection.initialize(form); 100 } 101 102 105 public void createDetails(Composite parent) { 106 107 GridData data = null; 108 109 fMainSection = getToolkit().createSection(parent, Section.DESCRIPTION | ExpandableComposite.TITLE_BAR); 111 fMainSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING; 112 fMainSection.setText(PDEUIMessages.SimpleCSSubItemDetails_10); 113 fMainSection.setDescription(PDEUIMessages.SimpleCSSubItemDetails_11); 114 fMainSection.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 115 data = new GridData(GridData.FILL_HORIZONTAL); 116 fMainSection.setLayoutData(data); 117 118 getPage().alignSectionHeaders(getMasterSection().getSection(), 121 fMainSection); 122 123 Composite mainSectionClient = getToolkit().createComposite(fMainSection); 125 mainSectionClient.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2)); 126 127 fLabel = new FormEntry(mainSectionClient, getToolkit(), PDEUIMessages.SimpleCSSubItemDetails_0, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); 129 data = new GridData(GridData.FILL_HORIZONTAL); 130 data.heightHint = 50; 131 fLabel.getText().setLayoutData(data); 132 data = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END); 133 fLabel.getLabel().setLayoutData(data); 134 135 fSkip = getToolkit().createButton(mainSectionClient, PDEUIMessages.SimpleCSSubItemDetails_3, SWT.CHECK); 137 data = new GridData(GridData.FILL_HORIZONTAL); 138 data.horizontalSpan = 2; 139 fSkip.setLayoutData(data); 140 141 getToolkit().paintBordersFor(mainSectionClient); 143 fMainSection.setClient(mainSectionClient); 144 markDetailsPart(fMainSection); 145 146 fCommandSection.createDetails(parent); 147 } 148 149 152 public void hookListeners() { 153 fLabel.setFormEntryListener(new FormEntryAdapter(this) { 155 public void textValueChanged(FormEntry entry) { 156 if (fSubItem == null) { 158 return; 159 } 160 fSubItem.setLabel(fLabel.getValue()); 161 } 162 }); 163 fSkip.addSelectionListener(new SelectionAdapter() { 165 public void widgetSelected(SelectionEvent e) { 166 if (fSubItem == null) { 167 return; 168 } 169 fSubItem.setSkip(fSkip.getSelection()); 170 } 171 }); 172 173 fCommandSection.hookListeners(); 174 } 175 176 179 public void updateFields() { 180 181 boolean editable = isEditableElement(); 182 if (fSubItem == null) { 184 return; 185 } 186 fLabel.setValue(fSubItem.getLabel(), true); 188 fLabel.setEditable(editable); 189 190 fSkip.setSelection(fSubItem.getSkip()); 192 fSkip.setEnabled(editable); 193 194 fCommandSection.updateFields(); 195 } 196 197 200 public void commit(boolean onSave) { 201 super.commit(onSave); 202 fLabel.commit(); 204 } 206 207 } 208 | Popular Tags |