1 11 package org.eclipse.pde.internal.ui.editor.text; 12 13 import org.eclipse.jface.preference.IPreferenceStore; 14 import org.eclipse.jface.text.AbstractInformationControlManager; 15 import org.eclipse.jface.text.DefaultInformationControl; 16 import org.eclipse.jface.text.IInformationControl; 17 import org.eclipse.jface.text.IInformationControlCreator; 18 import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; 19 import org.eclipse.jface.text.information.IInformationPresenter; 20 import org.eclipse.jface.text.information.IInformationProvider; 21 import org.eclipse.jface.text.information.InformationPresenter; 22 import org.eclipse.jface.text.reconciler.IReconciler; 23 import org.eclipse.jface.text.reconciler.MonoReconciler; 24 import org.eclipse.jface.text.source.ISourceViewer; 25 import org.eclipse.jface.util.PropertyChangeEvent; 26 import org.eclipse.pde.core.IBaseModel; 27 import org.eclipse.pde.internal.core.text.IReconcilingParticipant; 28 import org.eclipse.pde.internal.ui.PDEPlugin; 29 import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage; 30 import org.eclipse.pde.internal.ui.editor.PDESourcePage; 31 import org.eclipse.pde.internal.ui.editor.actions.PDEActionConstants; 32 import org.eclipse.pde.internal.ui.editor.contentassist.display.HTMLTextPresenter; 33 import org.eclipse.pde.internal.ui.editor.outline.QuickOutlinePopupDialog; 34 import org.eclipse.swt.SWT; 35 import org.eclipse.swt.widgets.Shell; 36 import org.eclipse.ui.editors.text.EditorsUI; 37 import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; 38 import org.eclipse.ui.texteditor.ChainedPreferenceStore; 39 40 public abstract class ChangeAwareSourceViewerConfiguration extends TextSourceViewerConfiguration { 41 42 protected PDESourcePage fSourcePage; 43 protected IColorManager fColorManager; 44 private MonoReconciler fReconciler; 45 private InformationPresenter fInfoPresenter; 46 private InformationPresenter fOutlinePresenter; 47 48 53 public ChangeAwareSourceViewerConfiguration(PDESourcePage page, IColorManager manager, IPreferenceStore store) { 54 super(store); 55 fColorManager = manager; 56 fSourcePage = page; 57 } 58 59 public ChangeAwareSourceViewerConfiguration(PDESourcePage page, IColorManager manager) { 60 this(page, manager, new ChainedPreferenceStore(new IPreferenceStore[] { 61 PDEPlugin.getDefault().getPreferenceStore(), 62 EditorsUI.getPreferenceStore() })); 64 } 65 66 public IReconciler getReconciler(ISourceViewer sourceViewer) { 67 if (fSourcePage != null && fReconciler == null) { 68 IBaseModel model = fSourcePage.getInputContext().getModel(); 69 if (model instanceof IReconcilingParticipant) { 70 ReconcilingStrategy strategy = new ReconcilingStrategy(); 71 strategy.addParticipant((IReconcilingParticipant)model); 72 ISortableContentOutlinePage outline = fSourcePage.getContentOutline(); 73 if (outline instanceof IReconcilingParticipant) 74 strategy.addParticipant((IReconcilingParticipant)outline); 75 fReconciler = new MonoReconciler(strategy, false); 76 fReconciler.setDelay(500); 77 } 78 } 79 return fReconciler; 80 } 81 82 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) { 83 if (fSourcePage == null) 84 return null; 85 if (fInfoPresenter == null && getInfoImplementationType() != SourceInformationProvider.F_NO_IMP) { 86 IInformationControlCreator icc = getInformationControlCreator(false); 87 fInfoPresenter = new InformationPresenter(icc); 88 fInfoPresenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); 89 90 IInformationProvider provider = new SourceInformationProvider(fSourcePage, icc, getInfoImplementationType()); 92 String [] contentTypes = getConfiguredContentTypes(sourceViewer); 93 for (int i= 0; i < contentTypes.length; i++) 94 fInfoPresenter.setInformationProvider(provider, contentTypes[i]); 95 96 fInfoPresenter.setSizeConstraints(60, 10, true, true); 97 } 98 return fInfoPresenter; 99 } 100 101 105 public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer) { 106 if (fSourcePage == null) { 108 return null; 109 } 110 if (fOutlinePresenter != null) { 112 return fOutlinePresenter; 113 } 114 fOutlinePresenter = 116 new InformationPresenter(getOutlinePresenterControlCreator( 117 sourceViewer, PDEActionConstants.COMMAND_ID_QUICK_OUTLINE)); 118 fOutlinePresenter.setDocumentPartitioning( 119 getConfiguredDocumentPartitioning(sourceViewer)); 120 fOutlinePresenter.setAnchor( 121 AbstractInformationControlManager.ANCHOR_GLOBAL); 122 IInformationProvider provider = new PDESourceInfoProvider(fSourcePage); 124 String [] contentTypes = getConfiguredContentTypes(sourceViewer); 126 for (int i= 0; i < contentTypes.length; i++) { 127 fOutlinePresenter.setInformationProvider(provider, contentTypes[i]); 128 } 129 fOutlinePresenter.setSizeConstraints(50, 20, true, false); 131 132 return fOutlinePresenter; 133 } 134 135 143 private IInformationControlCreator getOutlinePresenterControlCreator( 144 ISourceViewer sourceViewer, final String commandId) { 145 return new IInformationControlCreator() { 146 public IInformationControl createInformationControl(Shell parent) { 147 int shellStyle = SWT.RESIZE; 148 QuickOutlinePopupDialog dialog = new QuickOutlinePopupDialog( 149 parent, shellStyle, fSourcePage, fSourcePage); 150 return dialog; 151 } 152 }; 153 } 154 155 protected int getInfoImplementationType() { 156 return SourceInformationProvider.F_NO_IMP; 157 } 158 159 protected IInformationControlCreator getInformationControlCreator(final boolean cutDown) { 160 return new IInformationControlCreator() { 161 public IInformationControl createInformationControl(Shell parent) { 162 int style = cutDown ? SWT.RESIZE : (SWT.V_SCROLL | SWT.H_SCROLL | SWT.RESIZE); 163 return new DefaultInformationControl(parent, style, new HTMLTextPresenter(cutDown)); 164 } 165 }; 166 } 167 168 public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { 169 if (fSourcePage != null) 170 return new IHyperlinkDetector[] { (IHyperlinkDetector)fSourcePage.getAdapter(IHyperlinkDetector.class) }; 171 return super.getHyperlinkDetectors(sourceViewer); 172 } 173 174 public abstract boolean affectsTextPresentation(PropertyChangeEvent event); 175 176 public abstract boolean affectsColorPresentation(PropertyChangeEvent event); 177 178 public abstract void adaptToPreferenceChange(PropertyChangeEvent event); 179 180 public abstract void dispose(); 181 182 } 183 | Popular Tags |