XMLEditor.java
上传用户:fanxing
上传日期:2017-01-19
资源大小:36k
文件大小:3k
源码类别:

PlugIns编程

开发平台:

Java

  1. /*******************************************************************************
  2.  * Copyright (c) 2005 Prashant Deva.
  3.  
  4.  * All rights reserved. This program and the accompanying materials 
  5.  * are made available under the terms of the Eclipse Public License - v 1.0
  6.  * which is available at http://www.eclipse.org/legal/epl-v10.html
  7. *******************************************************************************/
  8. package projection_test.editors;
  9. import java.util.ArrayList;
  10. import java.util.HashMap;
  11. import org.eclipse.jface.text.Position;
  12. import org.eclipse.jface.text.source.Annotation;
  13. import org.eclipse.jface.text.source.IAnnotationModel;
  14. import org.eclipse.jface.text.source.ISourceViewer;
  15. import org.eclipse.jface.text.source.IVerticalRuler;
  16. import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
  17. import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
  18. import org.eclipse.jface.text.source.projection.ProjectionSupport;
  19. import org.eclipse.jface.text.source.projection.ProjectionViewer;
  20. import org.eclipse.swt.widgets.Composite;
  21. import org.eclipse.ui.editors.text.TextEditor;
  22. public class XMLEditor extends TextEditor {
  23.     private ProjectionSupport projectionSupport;
  24.     
  25. private ColorManager colorManager;
  26. public XMLEditor() {
  27. super();
  28. colorManager = new ColorManager();
  29. setSourceViewerConfiguration(new XMLConfiguration(colorManager,this));
  30. setDocumentProvider(new XMLDocumentProvider());
  31. }
  32. public void dispose() {
  33. colorManager.dispose();
  34. super.dispose();
  35. }
  36.     /* (non-Javadoc)
  37.      * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
  38.      */
  39.     public void createPartControl(Composite parent)
  40.     {
  41.         super.createPartControl(parent);
  42.         ProjectionViewer viewer =(ProjectionViewer)getSourceViewer();
  43.         
  44.         projectionSupport = new ProjectionSupport(viewer,getAnnotationAccess(),getSharedColors());
  45. projectionSupport.install();
  46. //turn projection mode on
  47. viewer.doOperation(ProjectionViewer.TOGGLE);
  48. annotationModel = viewer.getProjectionAnnotationModel();
  49.     }
  50. private Annotation[] oldAnnotations;
  51. private ProjectionAnnotationModel annotationModel;
  52. public void updateFoldingStructure(ArrayList positions)
  53. {
  54. Annotation[] annotations = new Annotation[positions.size()];
  55. //this will hold the new annotations along
  56. //with their corresponding positions
  57. HashMap newAnnotations = new HashMap();
  58. for(int i =0;i<positions.size();i++)
  59. {
  60. ProjectionAnnotation annotation = new ProjectionAnnotation();
  61. newAnnotations.put(annotation,positions.get(i));
  62. annotations[i]=annotation;
  63. }
  64. annotationModel.modifyAnnotations(oldAnnotations,newAnnotations,null);
  65. oldAnnotations=annotations;
  66. }
  67.     /* (non-Javadoc)
  68.      * @see org.eclipse.ui.texteditor.AbstractTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int)
  69.      */
  70.     protected ISourceViewer createSourceViewer(Composite parent,
  71.             IVerticalRuler ruler, int styles)
  72.     {
  73.         ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
  74.      // ensure decoration support has been created and configured.
  75.      getSourceViewerDecorationSupport(viewer);
  76.     
  77.      return viewer;
  78.     }
  79. }