1 11 12 package org.eclipse.pde.internal.ui.editor.cheatsheet.comp.details; 13 14 import org.eclipse.jface.text.DocumentEvent; 15 import org.eclipse.jface.text.IDocument; 16 import org.eclipse.jface.text.IDocumentListener; 17 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory; 18 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSOnCompletion; 19 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject; 20 import org.eclipse.pde.internal.core.util.PDETextHelper; 21 22 26 public class CompCSConclusionTextListener implements IDocumentListener { 27 28 private ICompCSTaskObject fDataTaskObject; 29 30 private boolean fBlockEvents; 31 32 35 public CompCSConclusionTextListener() { 36 fDataTaskObject = null; 37 fBlockEvents = false; 38 } 39 40 43 public void setBlockEvents(boolean block) { 44 fBlockEvents = block; 45 } 46 47 50 public boolean getBlockEvents() { 51 return fBlockEvents; 52 } 53 54 57 public void setData(ICompCSTaskObject object) { 58 fDataTaskObject = object; 60 } 61 62 65 public void documentAboutToBeChanged(DocumentEvent e) { 66 } 68 69 72 public void documentChanged(DocumentEvent event) { 73 if (fBlockEvents) { 75 return; 76 } 77 if (fDataTaskObject == null) { 79 return; 80 } 81 IDocument document = event.getDocument(); 83 if (document == null) { 84 return; 85 } 86 String text = document.get().trim(); 87 boolean hasText = PDETextHelper.isDefined(text); 89 if (hasText) { 90 updateConclusionText(text); 92 } else { 93 removeConclusionText(text); 95 } 96 } 97 98 101 private void updateConclusionText(String text) { 102 if (fDataTaskObject.getFieldOnCompletion() == null) { 103 addConclusionText(text); 105 } else { 106 modifyConclusionText(text); 108 } 109 } 110 111 114 private void addConclusionText(String text) { 115 ICompCSModelFactory factory = 116 fDataTaskObject.getModel().getFactory(); 117 ICompCSOnCompletion conclusion = 118 factory.createCompCSOnCompletion(fDataTaskObject); 119 conclusion.setFieldContent(text); 120 fDataTaskObject.setFieldOnCompletion(conclusion); 121 } 122 123 126 private void modifyConclusionText(String text) { 127 ICompCSOnCompletion conclusion = fDataTaskObject.getFieldOnCompletion(); 128 conclusion.setFieldContent(text); 129 } 130 131 134 private void removeConclusionText(String text) { 135 ICompCSOnCompletion conclusion = fDataTaskObject.getFieldOnCompletion(); 136 if (conclusion != null) { 137 fDataTaskObject.setFieldOnCompletion(null); 138 } 139 } 140 141 } 142 | Popular Tags |