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.ICompCSConstants; 16 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskGroup; 17 import org.eclipse.pde.internal.ui.PDEUIMessages; 18 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; 19 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 20 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails; 21 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster; 22 import org.eclipse.pde.internal.ui.editor.cheatsheet.comp.CompCSInputContext; 23 import org.eclipse.pde.internal.ui.parts.ComboPart; 24 import org.eclipse.pde.internal.ui.parts.FormEntry; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.SelectionAdapter; 27 import org.eclipse.swt.events.SelectionEvent; 28 import org.eclipse.swt.graphics.Color; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.widgets.Button; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Label; 33 import org.eclipse.ui.forms.IFormColors; 34 import org.eclipse.ui.forms.IFormPart; 35 import org.eclipse.ui.forms.IManagedForm; 36 import org.eclipse.ui.forms.widgets.ExpandableComposite; 37 import org.eclipse.ui.forms.widgets.Section; 38 39 43 public class CompCSTaskGroupDetails extends CSAbstractDetails { 44 45 private Section fDefinitionSection; 46 47 private FormEntry fNameEntry; 48 49 private ComboPart fKindCombo; 50 51 private Button fSkip; 52 53 private ICompCSTaskGroup fDataTaskGroup; 54 55 private CompCSEnclosingTextDetails fEnclosingTextSection; 56 57 private static final String F_KIND_VALUE_SET = PDEUIMessages.CompCSTaskGroupDetails_Set; 58 59 private static final String F_KIND_VALUE_CHOICE = PDEUIMessages.CompCSTaskGroupDetails_Choice; 60 61 private static final String F_KIND_VALUE_SEQUENCE = PDEUIMessages.CompCSTaskGroupDetails_Sequence; 62 63 66 public CompCSTaskGroupDetails(ICSMaster section) { 67 super(section, CompCSInputContext.CONTEXT_ID); 68 fDataTaskGroup = null; 69 70 fNameEntry = null; 71 fKindCombo = null; 72 fSkip = null; 73 74 fDefinitionSection = null; 75 fEnclosingTextSection = 76 new CompCSEnclosingTextDetails(ICompCSConstants.TYPE_TASKGROUP, section); 77 } 78 79 82 public void setData(ICompCSTaskGroup object) { 83 fDataTaskGroup = object; 85 fEnclosingTextSection.setData(object); 87 } 88 89 92 public void initialize(IManagedForm form) { 93 super.initialize(form); 94 fEnclosingTextSection.initialize(form); 99 } 100 101 104 public void createDetails(Composite parent) { 105 106 int style = Section.DESCRIPTION | ExpandableComposite.TITLE_BAR; 108 fDefinitionSection = getPage().createUISection(parent, PDEUIMessages.SimpleCSDetails_3, 109 PDEUIMessages.CompCSTaskGroupDetails_SectionDescription, style); 110 getPage().alignSectionHeaders(getMasterSection().getSection(), 113 fDefinitionSection); 114 Composite sectionClient = getPage().createUISectionContainer(fDefinitionSection, 2); 116 createUINameEntry(sectionClient); 118 createUIKindLabel(sectionClient); 120 createUIKindCombo(sectionClient); 122 createUISkipButton(sectionClient); 124 fEnclosingTextSection.createDetails(parent); 126 getManagedForm().getToolkit().paintBordersFor(sectionClient); 128 fDefinitionSection.setClient(sectionClient); 129 markDetailsPart(fDefinitionSection); 130 131 } 132 133 136 private void createUISkipButton(Composite parent) { 137 Color foreground = getToolkit().getColors().getColor(IFormColors.TITLE); 138 fSkip = getToolkit().createButton(parent, PDEUIMessages.CompCSTaskGroupDetails_SkipLabel, SWT.CHECK); 139 GridData data = new GridData(GridData.FILL_HORIZONTAL); 140 data.horizontalSpan = 2; 141 fSkip.setLayoutData(data); 142 fSkip.setForeground(foreground); 143 } 144 145 148 private void createUIKindLabel(Composite parent) { 149 Color foreground = getToolkit().getColors().getColor(IFormColors.TITLE); 150 Label label = getToolkit().createLabel(parent, 151 PDEUIMessages.CompCSTaskGroupDetails_Type, SWT.WRAP); 152 label.setForeground(foreground); 153 label.setToolTipText(PDEUIMessages.CompCSTaskGroupDetails_KindToolTip); 154 } 155 156 159 private void createUIKindCombo(Composite parent) { 160 fKindCombo = new ComboPart(); 161 fKindCombo.createControl(parent, getToolkit(), SWT.READ_ONLY); 162 GridData data = new GridData(GridData.FILL_HORIZONTAL); 163 data.horizontalIndent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT; 166 fKindCombo.getControl().setLayoutData(data); 167 fKindCombo.add(F_KIND_VALUE_SET); 168 fKindCombo.add(F_KIND_VALUE_SEQUENCE); 169 fKindCombo.add(F_KIND_VALUE_CHOICE); 170 fKindCombo.setText(F_KIND_VALUE_SET); 171 fKindCombo.getControl().setToolTipText( 172 PDEUIMessages.CompCSTaskGroupDetails_KindToolTip); 173 } 174 175 178 private void createUINameEntry(Composite parent) { 179 fNameEntry = new FormEntry(parent, getManagedForm().getToolkit(), 180 PDEUIMessages.CompCSTaskGroupDetails_Name, SWT.NONE); 181 } 182 183 186 public void hookListeners() { 187 createListenersNameEntry(); 189 createListenersKindCombo(); 191 createListenersSkipButton(); 193 fEnclosingTextSection.hookListeners(); 195 } 196 197 200 private void createListenersNameEntry() { 201 fNameEntry.setFormEntryListener(new FormEntryAdapter(this) { 202 public void textValueChanged(FormEntry entry) { 203 if (fDataTaskGroup == null) { 205 return; 206 } 207 fDataTaskGroup.setFieldName(fNameEntry.getValue()); 208 } 209 }); 210 } 211 212 215 private void createListenersKindCombo() { 216 fKindCombo.addSelectionListener(new SelectionAdapter() { 217 public void widgetSelected(SelectionEvent e) { 218 if (fDataTaskGroup == null) { 220 return; 221 } 222 String selection = fKindCombo.getSelection(); 223 if (selection.equals(F_KIND_VALUE_CHOICE)) { 224 fDataTaskGroup.setFieldKind( 225 ICompCSConstants.ATTRIBUTE_VALUE_CHOICE); 226 } else if (selection.equals(F_KIND_VALUE_SEQUENCE)) { 227 fDataTaskGroup.setFieldKind( 228 ICompCSConstants.ATTRIBUTE_VALUE_SEQUENCE); 229 } else if (selection.equals(F_KIND_VALUE_SET)) { 230 fDataTaskGroup.setFieldKind( 231 ICompCSConstants.ATTRIBUTE_VALUE_SET); 232 } 233 } 234 }); 235 } 236 237 240 private void createListenersSkipButton() { 241 fSkip.addSelectionListener(new SelectionAdapter() { 242 public void widgetSelected(SelectionEvent e) { 243 if (fDataTaskGroup == null) { 245 return; 246 } 247 fDataTaskGroup.setFieldSkip(fSkip.getSelection()); 248 } 249 }); 250 } 251 252 255 public void updateFields() { 256 if (fDataTaskGroup == null) { 258 return; 259 } 260 boolean editable = isEditableElement(); 261 updateNameEntry(editable); 263 updateKindCombo(editable); 265 updateSkipButton(editable); 267 fEnclosingTextSection.updateFields(); 269 } 270 271 274 private void updateNameEntry(boolean editable) { 275 fNameEntry.setValue(fDataTaskGroup.getFieldName(), true); 276 fNameEntry.setEditable(editable); 277 } 278 279 282 private void updateKindCombo(boolean editable) { 283 String kind = fDataTaskGroup.getFieldKind(); 284 285 if (kind == null) { 286 } else if (kind.compareTo(ICompCSConstants.ATTRIBUTE_VALUE_SEQUENCE) == 0) { 288 fKindCombo.setText(F_KIND_VALUE_SEQUENCE); 289 } else if (kind.compareTo(ICompCSConstants.ATTRIBUTE_VALUE_CHOICE) == 0) { 290 fKindCombo.setText(F_KIND_VALUE_CHOICE); 291 } else { 292 fKindCombo.setText(F_KIND_VALUE_SET); 293 } 294 295 fKindCombo.setEnabled(editable); 296 } 297 298 301 private void updateSkipButton(boolean editable) { 302 fSkip.setSelection(fDataTaskGroup.getFieldSkip()); 303 fSkip.setEnabled(editable); 304 } 305 306 309 public void commit(boolean onSave) { 310 super.commit(onSave); 311 fNameEntry.commit(); 313 } 315 316 319 public void selectionChanged(IFormPart part, ISelection selection) { 320 Object object = getFirstSelectedObject(selection); 322 if ((object == null) || 324 (object instanceof ICompCSTaskGroup) == false) { 325 return; 326 } 327 setData((ICompCSTaskGroup)object); 329 updateFields(); 331 } 332 333 336 public void dispose() { 337 if (fEnclosingTextSection != null) { 339 fEnclosingTextSection.dispose(); 340 fEnclosingTextSection = null; 341 } 342 super.dispose(); 343 } 344 345 } 346 | Popular Tags |