1 11 12 package org.eclipse.pde.internal.ui.editor.cheatsheet.simple.details; 13 14 import org.eclipse.jface.fieldassist.ControlDecoration; 15 import org.eclipse.jface.fieldassist.FieldDecorationRegistry; 16 import org.eclipse.jface.text.DocumentEvent; 17 import org.eclipse.jface.text.IDocument; 18 import org.eclipse.jface.text.IDocumentListener; 19 import org.eclipse.jface.viewers.ISelection; 20 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSItem; 21 import org.eclipse.pde.internal.ui.PDEUIMessages; 22 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; 23 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 24 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails; 25 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSSourceViewer; 26 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster; 27 import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSInputContext; 28 import org.eclipse.pde.internal.ui.parts.FormEntry; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.dnd.Clipboard; 31 import org.eclipse.swt.events.SelectionAdapter; 32 import org.eclipse.swt.events.SelectionEvent; 33 import org.eclipse.swt.graphics.Color; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.widgets.Button; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.swt.widgets.Label; 38 import org.eclipse.ui.forms.IFormColors; 39 import org.eclipse.ui.forms.IFormPart; 40 import org.eclipse.ui.forms.IManagedForm; 41 import org.eclipse.ui.forms.widgets.ExpandableComposite; 42 import org.eclipse.ui.forms.widgets.Section; 43 44 48 public class SimpleCSItemDetails extends CSAbstractDetails { 49 50 private ISimpleCSItem fItem; 51 52 private FormEntry fTitle; 53 54 private Button fSkip; 55 56 private CSSourceViewer fContentViewer; 57 58 private Section fMainSection; 59 60 private SimpleCSHelpDetails fHelpSection; 61 62 private SimpleCSCommandDetails fCommandSection; 63 64 private ControlDecoration fSkipInfoDecoration; 65 66 private boolean fBlockEvents; 67 68 71 public SimpleCSItemDetails(ICSMaster section) { 72 super(section, SimpleCSInputContext.CONTEXT_ID); 73 fItem = null; 74 75 fTitle = null; 76 fSkip = null; 77 fSkipInfoDecoration = null; 78 fContentViewer = null; 79 fMainSection = null; 80 fBlockEvents = false; 81 82 fHelpSection = new SimpleCSHelpDetails(section); 83 fCommandSection = new SimpleCSCommandDetails(section); 84 } 85 86 89 public void initialize(IManagedForm form) { 90 super.initialize(form); 91 fHelpSection.initialize(form); 96 fCommandSection.initialize(form); 98 } 99 100 103 public void createDetails(Composite parent) { 104 105 Color foreground = getToolkit().getColors().getColor(IFormColors.TITLE); 106 GridData data = null; 107 108 fMainSection = getToolkit().createSection(parent, 110 Section.DESCRIPTION | ExpandableComposite.TITLE_BAR); 111 fMainSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING; 112 fMainSection.setText(PDEUIMessages.SimpleCSItemDetails_11); 113 fMainSection.setDescription(PDEUIMessages.SimpleCSItemDetails_12); 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 fTitle = new FormEntry(mainSectionClient, getToolkit(), PDEUIMessages.SimpleCSItemDetails_0, SWT.NONE); 129 130 createUIFieldContent(mainSectionClient); 132 133 fSkip = getToolkit().createButton(mainSectionClient, PDEUIMessages.SimpleCSItemDetails_14, SWT.CHECK); 135 data = new GridData(GridData.FILL_HORIZONTAL); 136 data.horizontalSpan = 2; 137 fSkip.setLayoutData(data); 138 fSkip.setForeground(foreground); 139 createSkipInfoDecoration(); 140 getToolkit().paintBordersFor(mainSectionClient); 142 fMainSection.setClient(mainSectionClient); 143 markDetailsPart(fMainSection); 144 145 fCommandSection.createDetails(parent); 146 147 fHelpSection.createDetails(parent); 148 } 149 150 153 public boolean doGlobalAction(String actionId) { 154 return fContentViewer.doGlobalAction(actionId); 155 } 156 157 160 private void createUIFieldContent(Composite parent) { 161 GridData data = null; 162 Color foreground = getToolkit().getColors().getColor(IFormColors.TITLE); 164 Label label = 165 getToolkit().createLabel( 166 parent, 167 PDEUIMessages.SimpleCSDescriptionDetails_0, 168 SWT.WRAP); 169 label.setForeground(foreground); 170 int style = GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END; 171 data = new GridData(style); 172 label.setLayoutData(data); 173 fContentViewer = new CSSourceViewer(getPage()); 175 fContentViewer.createUI(parent, 90, 60); 176 ((GridData)fContentViewer.getViewer().getTextWidget().getLayoutData()).horizontalIndent = 179 FormLayoutFactory.CONTROL_HORIZONTAL_INDENT; 180 } 181 182 185 private void createSkipInfoDecoration() { 186 int bits = SWT.TOP | SWT.LEFT; 188 fSkipInfoDecoration = new ControlDecoration(fSkip, bits); 189 fSkipInfoDecoration.setMarginWidth(1); 190 fSkipInfoDecoration.setDescriptionText(PDEUIMessages.SimpleCSItemDetails_msgFieldDisabledOptional); 191 updateSkipInfoDecoration(false); 192 fSkipInfoDecoration.setImage( 193 FieldDecorationRegistry.getDefault().getFieldDecoration( 194 FieldDecorationRegistry.DEC_INFORMATION).getImage()); 195 } 196 197 200 public void hookListeners() { 201 createUIListenersContentViewer(); 203 fTitle.setFormEntryListener(new FormEntryAdapter(this) { 205 public void textValueChanged(FormEntry entry) { 206 if (fItem == null) { 208 return; 209 } 210 fItem.setTitle(fTitle.getValue()); 211 } 212 }); 213 fSkip.addSelectionListener(new SelectionAdapter() { 215 public void widgetSelected(SelectionEvent e) { 216 if (fItem == null) { 218 return; 219 } 220 fItem.setSkip(fSkip.getSelection()); 221 getMasterSection().updateButtons(); 222 } 223 }); 224 225 fHelpSection.hookListeners(); 226 227 fCommandSection.hookListeners(); 228 } 229 230 233 private void createUIListenersContentViewer() { 234 fContentViewer.createUIListeners(); 235 fContentViewer.getDocument().addDocumentListener(new IDocumentListener() { 237 public void documentAboutToBeChanged(DocumentEvent event) { 238 } 240 public void documentChanged(DocumentEvent event) { 241 if (fBlockEvents) { 243 return; 244 } 245 if (fItem == null) { 247 return; 248 } 249 IDocument document = event.getDocument(); 251 if (document == null) { 252 return; 253 } 254 String text = document.get().trim(); 256 257 if (fItem.getDescription() != null) { 258 fItem.getDescription().setContent(text); 259 } 260 } 261 }); 262 } 263 264 267 public void updateFields() { 268 269 boolean editable = isEditableElement(); 270 if (fItem == null) { 272 return; 273 } 274 fTitle.setValue(fItem.getTitle(), true); 276 fTitle.setEditable(editable); 277 278 fSkip.setSelection(fItem.getSkip()); 280 updateSkipEnablement(); 281 284 fHelpSection.updateFields(); 285 286 fCommandSection.updateFields(); 287 288 if (fItem.getDescription() == null) { 289 return; 290 } 291 292 fBlockEvents = true; 294 fContentViewer.getDocument().set(fItem.getDescription().getContent()); 295 fBlockEvents = false; 296 fContentViewer.getViewer().setEditable(editable); 297 } 298 299 302 public void dispose() { 303 if (fContentViewer != null) { 306 fContentViewer.unsetMenu(); 307 fContentViewer = null; 308 } 309 310 super.dispose(); 311 } 312 313 316 public boolean canPaste(Clipboard clipboard) { 317 return fContentViewer.canPaste(); 318 } 319 320 323 private void updateSkipEnablement() { 324 if (fItem == null) { 326 return; 327 } 328 boolean editable = isEditableElement(); 329 if (fItem.hasSubItems()) { 334 editable = false; 335 updateSkipInfoDecoration(true); 336 } else { 337 updateSkipInfoDecoration(false); 338 } 339 fSkip.setEnabled(editable); 340 } 341 342 345 private void updateSkipInfoDecoration(boolean show) { 346 if (show) { 347 fSkipInfoDecoration.show(); 348 } else { 349 fSkipInfoDecoration.hide(); 350 } 351 fSkipInfoDecoration.setShowHover(show); 352 } 353 354 357 public void commit(boolean onSave) { 358 super.commit(onSave); 359 fTitle.commit(); 361 } 363 364 367 public void selectionChanged(IFormPart part, ISelection selection) { 368 Object object = getFirstSelectedObject(selection); 370 if ((object == null) || 372 (object instanceof ISimpleCSItem) == false) { 373 return; 374 } 375 setData((ISimpleCSItem)object); 377 updateFields(); 379 } 380 381 384 public void setData(ISimpleCSItem object) { 385 fItem = object; 387 fCommandSection.setData(object); 389 fHelpSection.setData(object); 391 } 392 } 393 | Popular Tags |