1 11 package org.eclipse.pde.internal.ui.editor; 12 13 import org.eclipse.jface.action.IAction; 14 import org.eclipse.jface.action.IMenuManager; 15 import org.eclipse.jface.preference.IPreferenceStore; 16 import org.eclipse.jface.text.reconciler.IReconciler; 17 import org.eclipse.jface.text.reconciler.IReconcilingStrategy; 18 import org.eclipse.jface.text.source.ISourceViewer; 19 import org.eclipse.jface.text.source.IVerticalRuler; 20 import org.eclipse.jface.text.source.projection.IProjectionListener; 21 import org.eclipse.jface.text.source.projection.ProjectionSupport; 22 import org.eclipse.jface.text.source.projection.ProjectionViewer; 23 import org.eclipse.jface.util.PropertyChangeEvent; 24 import org.eclipse.pde.core.IBaseModel; 25 import org.eclipse.pde.internal.core.text.IEditingModel; 26 import org.eclipse.pde.internal.ui.IPreferenceConstants; 27 import org.eclipse.pde.internal.ui.PDEPlugin; 28 import org.eclipse.pde.internal.ui.editor.actions.PDEActionConstants; 29 import org.eclipse.pde.internal.ui.editor.text.ChangeAwareSourceViewerConfiguration; 30 import org.eclipse.pde.internal.ui.editor.text.ColorManager; 31 import org.eclipse.pde.internal.ui.editor.text.IColorManager; 32 import org.eclipse.pde.internal.ui.editor.text.ReconcilingStrategy; 33 import org.eclipse.swt.widgets.Composite; 34 35 36 public abstract class PDEProjectionSourcePage extends PDESourcePage implements IProjectionListener { 37 38 private ProjectionSupport fProjectionSupport; 39 private IFoldingStructureProvider fFoldingStructureProvider; 40 private IColorManager fColorManager; 41 private ChangeAwareSourceViewerConfiguration fConfiguration; 42 43 public PDEProjectionSourcePage(PDEFormEditor editor, String id, String title) { 44 super(editor, id, title); 45 fColorManager = ColorManager.getDefault(); 46 fConfiguration = 47 SourceViewerConfigurationFactory.createSourceViewerConfiguration(this, fColorManager); 48 if (fConfiguration != null) 49 setSourceViewerConfiguration(fConfiguration); 50 } 51 52 public void createPartControl(Composite parent) { 53 super.createPartControl(parent); 54 55 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer(); 56 createFoldingSupport(projectionViewer); 57 58 if (isFoldingEnabled()) { 59 projectionViewer.doOperation(ProjectionViewer.TOGGLE); 60 } 61 } 62 63 protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { 64 ISourceViewer viewer = new PDEProjectionViewer( 65 parent, 66 ruler, 67 getOverviewRuler(), 68 isOverviewRulerVisible(), 69 styles, 70 isQuickOutlineEnabled()); 71 getSourceViewerDecorationSupport(viewer); 72 return viewer; 73 } 74 75 78 public abstract boolean isQuickOutlineEnabled(); 79 80 public void dispose() { 81 ((ProjectionViewer) getSourceViewer()).removeProjectionListener(this); 82 if (fProjectionSupport != null) { 83 fProjectionSupport.dispose(); 84 fProjectionSupport = null; 85 } 86 fColorManager.dispose(); 87 if (fConfiguration != null) 88 fConfiguration.dispose(); 89 super.dispose(); 90 } 91 92 private void createFoldingSupport(ProjectionViewer projectionViewer) { 93 fProjectionSupport = new ProjectionSupport( 94 projectionViewer, 95 getAnnotationAccess(), 96 getSharedColors()); 97 98 fProjectionSupport.install(); 99 ((ProjectionViewer)getSourceViewer()).addProjectionListener(this); 100 101 } 102 103 public void projectionEnabled() { 104 IBaseModel model = getInputContext().getModel(); 105 if(model instanceof IEditingModel) { 106 fFoldingStructureProvider = 107 FoldingStructureProviderFactory.createProvider(this, (IEditingModel) model); 108 if(fFoldingStructureProvider != null) { 109 fFoldingStructureProvider.initialize(); 110 IReconciler rec = getSourceViewerConfiguration().getReconciler(getSourceViewer()); 111 IReconcilingStrategy startegy = rec.getReconcilingStrategy(new String ()); 112 if (startegy instanceof ReconcilingStrategy) { 113 ((ReconcilingStrategy)startegy).addParticipant(fFoldingStructureProvider); 114 } 115 } 116 } 117 } 118 119 public void projectionDisabled() { 120 fFoldingStructureProvider = null; 121 } 122 123 private boolean isFoldingEnabled() { 124 IPreferenceStore store = PDEPlugin.getDefault().getPreferenceStore(); 125 return store.getBoolean(IPreferenceConstants.EDITOR_FOLDING_ENABLED); 126 } 127 128 protected boolean affectsTextPresentation(PropertyChangeEvent event) { 129 if (fConfiguration == null) 130 return false; 131 return fConfiguration.affectsTextPresentation(event) || super.affectsTextPresentation(event); 132 } 133 134 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { 135 try { 136 if (fConfiguration != null) { 137 ISourceViewer sourceViewer = getSourceViewer(); 138 if (sourceViewer != null) 139 fConfiguration.adaptToPreferenceChange(event); 140 } 141 } finally { 142 super.handlePreferenceStoreChanged(event); 143 } 144 } 145 146 public Object getAdapter(Class key) { 147 if (fProjectionSupport != null) { 148 Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), key); 149 if (adapter != null) { 150 return adapter; 151 } 152 } 153 return super.getAdapter(key); 154 } 155 156 159 protected void editorContextMenuAboutToShow(IMenuManager menu) { 160 addQuickOutlineMenuEntry(menu); 162 super.editorContextMenuAboutToShow(menu); 164 } 165 166 169 private void addQuickOutlineMenuEntry(IMenuManager menu) { 170 if (isQuickOutlineEnabled() == false) { 172 return; 173 } 174 IAction quickOutlineAction = getAction( 177 PDEActionConstants.COMMAND_ID_QUICK_OUTLINE); 178 if (quickOutlineAction == null) { 180 return; 181 } 182 menu.add(quickOutlineAction); 184 } 185 186 } 187 | Popular Tags |