1 11 12 package org.eclipse.pde.internal.ui.editor.cheatsheet.comp.details; 13 14 import org.eclipse.osgi.util.NLS; 15 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants; 16 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSIntro; 17 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSOnCompletion; 18 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject; 19 import org.eclipse.pde.internal.core.util.PDETextHelper; 20 import org.eclipse.pde.internal.ui.PDEPlugin; 21 import org.eclipse.pde.internal.ui.PDEPluginImages; 22 import org.eclipse.pde.internal.ui.PDEUIMessages; 23 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractSubDetails; 24 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSSourceViewer; 25 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster; 26 import org.eclipse.pde.internal.ui.editor.cheatsheet.comp.CompCSInputContext; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.custom.CTabFolder; 29 import org.eclipse.swt.custom.CTabItem; 30 import org.eclipse.swt.custom.StackLayout; 31 import org.eclipse.swt.dnd.Clipboard; 32 import org.eclipse.swt.events.SelectionAdapter; 33 import org.eclipse.swt.events.SelectionEvent; 34 import org.eclipse.swt.graphics.Color; 35 import org.eclipse.swt.layout.GridData; 36 import org.eclipse.swt.layout.GridLayout; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Control; 39 import org.eclipse.swt.widgets.Label; 40 import org.eclipse.ui.forms.FormColors; 41 import org.eclipse.ui.forms.IFormColors; 42 import org.eclipse.ui.forms.widgets.ExpandableComposite; 43 import org.eclipse.ui.forms.widgets.Section; 44 45 49 public class CompCSEnclosingTextDetails extends CSAbstractSubDetails { 50 51 private ICompCSTaskObject fDataTaskObject; 52 53 private Section fEnclosingTextSection; 54 55 private CSSourceViewer fIntroductionViewer; 56 57 private CSSourceViewer fConclusionViewer; 58 59 private CTabFolder fTabFolder; 60 61 private final static int F_INTRODUCTION_TAB = 0; 62 63 private final static int F_CONCLUSION_TAB = 1; 64 65 private final static int F_NO_TAB = -1; 66 67 private Composite fNotebookComposite; 68 69 private StackLayout fNotebookLayout; 70 71 private Composite fIntroductionComposite; 72 73 private Composite fConclusionComposite; 74 75 private String fTaskObjectLabelName; 76 77 private CompCSIntroductionTextListener fIntroductionListener; 78 79 private CompCSConclusionTextListener fConclusionListener; 80 81 84 public CompCSEnclosingTextDetails(int type, 85 ICSMaster section) { 86 super(section, CompCSInputContext.CONTEXT_ID); 87 88 fDataTaskObject = null; 89 90 fEnclosingTextSection = null; 91 92 fIntroductionViewer = null; 93 fConclusionViewer = null; 94 95 fTabFolder = null; 96 fNotebookComposite = null; 97 fNotebookLayout = null; 98 99 fIntroductionComposite = null; 100 fConclusionComposite = null; 101 102 fIntroductionListener = new CompCSIntroductionTextListener(); 103 fConclusionListener = new CompCSConclusionTextListener(); 104 105 defineTaskObjectLabelName(type); 106 } 107 108 111 public void setData(ICompCSTaskObject object) { 112 fDataTaskObject = object; 114 fIntroductionListener.setData(object); 116 fConclusionListener.setData(object); 118 } 119 120 123 public void commit(boolean onSave) { 124 super.commit(onSave); 125 } 127 128 131 private void defineTaskObjectLabelName(int type) { 132 if (type == ICompCSConstants.TYPE_TASK) { 133 fTaskObjectLabelName = PDEUIMessages.CompCSDependenciesDetails_task; 134 } else { 135 fTaskObjectLabelName = PDEUIMessages.CompCSDependenciesDetails_group; 136 } 137 } 138 139 142 public void createDetails(Composite parent) { 143 int style = Section.DESCRIPTION | ExpandableComposite.TITLE_BAR; 145 String description = NLS.bind( 146 PDEUIMessages.CompCSEnclosingTextDetails_SectionDescription, 147 fTaskObjectLabelName); 148 fEnclosingTextSection = getPage().createUISection(parent, 149 PDEUIMessages.CompCSEnclosingTextDetails_EnclosingText, 150 description, style); 151 GridData data = new GridData(GridData.FILL_BOTH); 156 fEnclosingTextSection.setLayoutData(data); 157 Composite sectionClient = getPage().createUISectionContainer( 159 fEnclosingTextSection, 1); 160 createUITabFolder(sectionClient); 162 createUIIntroductionTab(); 164 createUIConclusionTab(); 166 createUINotebookComposite(sectionClient); 168 createUIIntroductionViewer(); 170 createUIConclusionViewer(); 172 getToolkit().paintBordersFor(sectionClient); 174 fEnclosingTextSection.setClient(sectionClient); 175 markDetailsPart(fEnclosingTextSection); 177 } 178 179 182 private void createUITabFolder(Composite parent) { 183 fTabFolder = new CTabFolder(parent, SWT.FLAT | SWT.TOP); 184 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 185 data.heightHint = 2; 186 fTabFolder.setLayoutData(data); 187 188 getToolkit().adapt(fTabFolder, true, true); 189 190 FormColors colors = getToolkit().getColors(); 191 colors.initializeSectionToolBarColors(); 192 Color selectedColor = colors.getColor(IFormColors.TB_BG); 193 fTabFolder.setSelectionBackground(new Color[] { selectedColor, 194 colors.getBackground() }, 195 new int[] { 100 }, true); 196 } 197 198 201 private void createUIIntroductionTab() { 202 CTabItem item = new CTabItem(fTabFolder, SWT.NULL); 203 item.setText(PDEUIMessages.CompCSEnclosingTextDetails_Introduction); 204 item.setImage(PDEPlugin.getDefault().getLabelProvider().get( 205 PDEPluginImages.DESC_CSINTRO_OBJ)); 206 } 207 208 211 private void createUIConclusionTab() { 212 CTabItem item = new CTabItem(fTabFolder, SWT.NULL); 213 item.setText(PDEUIMessages.CompCSEnclosingTextDetails_Conclusion); 214 item.setImage(PDEPlugin.getDefault().getLabelProvider().get( 215 PDEPluginImages.DESC_CSCONCLUSION_OBJ)); 216 } 217 218 221 private void createUINotebookComposite(Composite parent) { 222 fNotebookComposite = getToolkit().createComposite(parent); 223 GridData data = new GridData(GridData.FILL_HORIZONTAL); 224 fNotebookComposite.setLayoutData(data); 225 fNotebookLayout = new StackLayout(); 226 fNotebookComposite.setLayout(fNotebookLayout); 227 } 228 229 232 private void createUIIntroductionViewer() { 233 fIntroductionComposite = createUIContainer(fNotebookComposite, 1); 235 String description = NLS.bind( 237 PDEUIMessages.CompCSEnclosingTextDetails_IntroductionDescription, 238 fTaskObjectLabelName); 239 final Label label = getToolkit().createLabel( 240 fIntroductionComposite, description, SWT.WRAP); 241 GridData data = new GridData(GridData.FILL_HORIZONTAL); 242 label.setLayoutData(data); 243 fIntroductionViewer = new CSSourceViewer(getPage()); 245 fIntroductionViewer.createUI(fIntroductionComposite, 60, 60); 246 getToolkit().paintBordersFor(fIntroductionComposite); 250 } 251 252 255 public boolean doGlobalAction(String actionId) { 256 int index = fTabFolder.getSelectionIndex(); 258 CSSourceViewer viewer = null; 260 261 if (index == F_INTRODUCTION_TAB) { 262 viewer = fIntroductionViewer; 263 } else if (index == F_CONCLUSION_TAB) { 264 viewer = fConclusionViewer; 265 } 266 267 return viewer.doGlobalAction(actionId); 268 } 269 270 273 private void createUIConclusionViewer() { 274 fConclusionComposite = createUIContainer(fNotebookComposite, 1); 276 String description = NLS.bind( 278 PDEUIMessages.CompCSEnclosingTextDetails_ConclusionDescription, 279 fTaskObjectLabelName); 280 final Label label = getToolkit().createLabel( 281 fConclusionComposite, description, SWT.WRAP); 282 GridData data = new GridData(GridData.FILL_HORIZONTAL); 283 label.setLayoutData(data); 284 fConclusionViewer = new CSSourceViewer(getPage()); 286 fConclusionViewer.createUI(fConclusionComposite, 60, 60); 287 getToolkit().paintBordersFor(fConclusionComposite); 291 } 292 293 298 private Composite createUIContainer(Composite parent, int columns) { 299 Composite container = getToolkit().createComposite(parent); 300 GridLayout layout = new GridLayout(); 301 layout.marginWidth = 2; 302 layout.marginHeight = 2; 303 layout.numColumns = columns; 304 container.setLayout(layout); 305 return container; 306 } 307 308 311 public void hookListeners() { 312 createListenersIntroductionViewer(); 314 createListenersConclusionViewer(); 316 createListenersTabFolder(); 318 } 319 320 323 private void createListenersIntroductionViewer() { 324 fIntroductionViewer.createUIListeners(); 325 fIntroductionViewer.getDocument().addDocumentListener(fIntroductionListener); 327 } 328 329 332 private void createListenersConclusionViewer() { 333 fConclusionViewer.createUIListeners(); 334 fConclusionViewer.getDocument().addDocumentListener(fConclusionListener); 336 } 337 338 341 private void createListenersTabFolder() { 342 fTabFolder.addSelectionListener(new SelectionAdapter() { 343 public void widgetSelected(SelectionEvent e) { 344 updateTabFolder(); 345 } 346 }); 347 } 348 349 352 private void updateTabFolder() { 353 354 int index = fTabFolder.getSelectionIndex(); 355 Control oldControl = fNotebookLayout.topControl; 356 357 if (index == F_NO_TAB) { 358 fNotebookLayout.topControl = fIntroductionComposite; 360 fTabFolder.setSelection(F_INTRODUCTION_TAB); 363 } else if (index == F_INTRODUCTION_TAB) { 364 fNotebookLayout.topControl = fIntroductionComposite; 365 } else if (index == F_CONCLUSION_TAB) { 366 fNotebookLayout.topControl = fConclusionComposite; 367 } 368 369 if (oldControl != fNotebookLayout.topControl) { 370 fNotebookComposite.layout(); 371 } 372 373 } 374 375 378 public void updateFields() { 379 if (fDataTaskObject == null) { 381 return; 382 } 383 boolean editable = isEditableElement(); 384 updateTabFolder(); 386 updateIntroductionViewer(editable); 388 updateConclusionViewer(editable); 390 } 391 392 395 private void updateIntroductionViewer(boolean editable) { 396 ICompCSIntro intro = fDataTaskObject.getFieldIntro(); 397 398 fIntroductionListener.setBlockEvents(true); 400 if ((intro != null) && 401 PDETextHelper.isDefined(intro.getFieldContent())) { 402 fIntroductionViewer.getDocument().set(intro.getFieldContent()); 403 } else { 404 fIntroductionViewer.getDocument().set(""); } 406 fIntroductionListener.setBlockEvents(false); 408 409 fIntroductionViewer.getViewer().setEditable(editable); 410 } 411 412 415 private void updateConclusionViewer(boolean editable) { 416 ICompCSOnCompletion conclusion = fDataTaskObject.getFieldOnCompletion(); 417 418 fConclusionListener.setBlockEvents(true); 420 if ((conclusion != null) && 421 PDETextHelper.isDefined(conclusion.getFieldContent())) { 422 fConclusionViewer.getDocument().set(conclusion.getFieldContent()); 423 } else { 424 fConclusionViewer.getDocument().set(""); } 426 fConclusionListener.setBlockEvents(false); 428 429 fConclusionViewer.getViewer().setEditable(editable); 430 } 431 432 435 public void dispose() { 436 if (fIntroductionViewer != null) { 439 fIntroductionViewer.unsetMenu(); 440 fIntroductionViewer = null; 441 } 442 if (fConclusionViewer != null) { 443 fConclusionViewer.unsetMenu(); 444 fConclusionViewer = null; 445 } 446 super.dispose(); 447 } 448 449 452 public boolean canPaste(Clipboard clipboard) { 453 int index = fTabFolder.getSelectionIndex(); 455 CSSourceViewer viewer = null; 457 458 if (index == F_INTRODUCTION_TAB) { 459 viewer = fIntroductionViewer; 460 } else if (index == F_CONCLUSION_TAB) { 461 viewer = fConclusionViewer; 462 } 463 464 return viewer.canPaste(); 465 } 466 } 467 | Popular Tags |