1 11 12 package org.eclipse.pde.internal.ui.editor.cheatsheet.simple.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.jface.viewers.ISelection; 18 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro; 19 import org.eclipse.pde.internal.ui.PDEUIMessages; 20 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 21 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails; 22 import org.eclipse.pde.internal.ui.editor.cheatsheet.CSSourceViewer; 23 import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster; 24 import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSInputContext; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.dnd.Clipboard; 27 import org.eclipse.swt.graphics.Color; 28 import org.eclipse.swt.layout.GridData; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.swt.widgets.Label; 31 import org.eclipse.ui.forms.IFormColors; 32 import org.eclipse.ui.forms.IFormPart; 33 import org.eclipse.ui.forms.IManagedForm; 34 import org.eclipse.ui.forms.widgets.ExpandableComposite; 35 import org.eclipse.ui.forms.widgets.Section; 36 37 41 public class SimpleCSIntroDetails extends CSAbstractDetails { 42 43 private ISimpleCSIntro fIntro; 44 45 private CSSourceViewer fContentViewer; 46 47 private Section fMainSection; 48 49 private SimpleCSHelpDetails fHelpSection; 50 51 private boolean fBlockEvents; 52 53 56 public SimpleCSIntroDetails(ICSMaster elementSection) { 57 super(elementSection, SimpleCSInputContext.CONTEXT_ID); 58 fIntro = null; 59 60 fContentViewer = null; 61 fMainSection = null; 62 fHelpSection = new SimpleCSHelpDetails(elementSection); 63 fBlockEvents = false; 64 } 65 66 69 public void setData(ISimpleCSIntro object) { 70 fIntro = object; 72 fHelpSection.setData(object); 74 } 75 76 79 public void selectionChanged(IFormPart part, ISelection selection) { 80 Object object = getFirstSelectedObject(selection); 82 if ((object == null) || 84 (object instanceof ISimpleCSIntro) == false) { 85 return; 86 } 87 setData((ISimpleCSIntro)object); 89 updateFields(); 91 } 92 93 96 public void initialize(IManagedForm form) { 97 super.initialize(form); 98 fHelpSection.initialize(form); 103 } 104 105 108 public void createDetails(Composite parent) { 109 110 GridData data = null; 111 112 fMainSection = getToolkit().createSection(parent, Section.DESCRIPTION | ExpandableComposite.TITLE_BAR); 114 fMainSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING; 115 fMainSection.setText(PDEUIMessages.SimpleCSIntroDetails_2); 116 fMainSection.setDescription(PDEUIMessages.SimpleCSIntroDetails_3); 117 fMainSection.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); 118 data = new GridData(GridData.FILL_HORIZONTAL); 119 fMainSection.setLayoutData(data); 120 121 getPage().alignSectionHeaders(getMasterSection().getSection(), 124 fMainSection); 125 126 Composite mainSectionClient = getToolkit().createComposite(fMainSection); 128 mainSectionClient.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2)); 129 130 createUIFieldContent(mainSectionClient); 132 133 getToolkit().paintBordersFor(mainSectionClient); 135 fMainSection.setClient(mainSectionClient); 136 markDetailsPart(fMainSection); 137 138 fHelpSection.createDetails(parent); 139 } 140 141 144 private void createUIFieldContent(Composite parent) { 145 GridData data = null; 146 Color foreground = getToolkit().getColors().getColor(IFormColors.TITLE); 148 Label label = 149 getToolkit().createLabel( 150 parent, 151 PDEUIMessages.SimpleCSDescriptionDetails_0, 152 SWT.WRAP); 153 label.setForeground(foreground); 154 int style = GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END; 155 data = new GridData(style); 156 label.setLayoutData(data); 157 fContentViewer = new CSSourceViewer(getPage()); 159 fContentViewer.createUI(parent, 90, 60); 160 ((GridData)fContentViewer.getViewer().getTextWidget().getLayoutData()).horizontalIndent = 163 FormLayoutFactory.CONTROL_HORIZONTAL_INDENT; 164 } 165 166 169 public boolean doGlobalAction(String actionId) { 170 return fContentViewer.doGlobalAction(actionId); 171 } 172 173 176 public void hookListeners() { 177 createUIListenersContentViewer(); 179 fHelpSection.hookListeners(); 180 } 181 182 185 private void createUIListenersContentViewer() { 186 fContentViewer.createUIListeners(); 187 fContentViewer.getDocument().addDocumentListener(new IDocumentListener() { 189 public void documentAboutToBeChanged(DocumentEvent event) { 190 } 192 public void documentChanged(DocumentEvent event) { 193 if (fBlockEvents) { 195 return; 196 } 197 if (fIntro == null) { 199 return; 200 } 201 IDocument document = event.getDocument(); 203 if (document == null) { 204 return; 205 } 206 String text = document.get().trim(); 208 209 if (fIntro.getDescription() != null) { 210 fIntro.getDescription().setContent(text); 211 } 212 } 213 }); 214 } 215 216 219 public void updateFields() { 220 if (fIntro == null) { 222 return; 223 } 224 225 fHelpSection.updateFields(); 226 227 if (fIntro.getDescription() == null) { 228 return; 229 } 230 231 fBlockEvents = true; 233 fContentViewer.getDocument().set(fIntro.getDescription().getContent()); 234 fBlockEvents = false; 235 236 boolean editable = isEditableElement(); 237 fContentViewer.getViewer().setEditable(editable); 238 } 239 240 243 public void dispose() { 244 if (fContentViewer != null) { 247 fContentViewer.unsetMenu(); 248 fContentViewer = null; 249 } 250 251 super.dispose(); 252 } 253 254 257 public boolean canPaste(Clipboard clipboard) { 258 return fContentViewer.canPaste(); 259 } 260 261 264 public void commit(boolean onSave) { 265 super.commit(onSave); 266 } 269 270 } 271 | Popular Tags |