View Javadoc

1   /********************************************************************************
2    * Copyright (c) 2005 Prashant Deva.
3    *               2006 Ontotext Lab. / Sirma Group
4   
5    * All rights reserved. This program and the accompanying materials 
6    * are made available under the terms of the Eclipse Public License - v 1.0
7    * which is available at http://www.eclipse.org/legal/epl-v10.html
8    *******************************************************************************/
9   
10  package org.wsmostudio.grounding.sawsdl.ui.text;
11  
12  import java.util.ArrayList;
13  import java.util.HashMap;
14  
15  import org.eclipse.jface.text.source.*;
16  import org.eclipse.jface.text.source.projection.*;
17  import org.eclipse.swt.widgets.Composite;
18  import org.eclipse.ui.editors.text.TextEditor;
19  
20  public class SAWSDLTextEditor extends TextEditor {
21  
22      private ProjectionSupport projectionSupport;
23  
24      private ColorManager colorManager;
25  
26      public SAWSDLTextEditor() {
27          super();
28          colorManager = new ColorManager();
29          setSourceViewerConfiguration(new XMLConfiguration(colorManager, this));
30          setDocumentProvider(new XMLDocumentProvider());
31      }
32  
33      public void doUpdateView() {
34          ((XMLConfiguration) getSourceViewerConfiguration()).updateColors();
35          this.getSourceViewer().invalidateTextPresentation();
36      }
37  
38      public void dispose() {
39          colorManager.dispose();
40          super.dispose();
41      }
42  
43      /*
44       * (non-Javadoc)
45       * 
46       * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
47       */
48      public void createPartControl(Composite parent) {
49          super.createPartControl(parent);
50          ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
51  
52          projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors());
53          projectionSupport.install();
54  
55          // turn projection mode on
56          viewer.doOperation(ProjectionViewer.TOGGLE);
57  
58          annotationModel = viewer.getProjectionAnnotationModel();
59  
60      }
61  
62      private Annotation[] oldAnnotations;
63  
64      private ProjectionAnnotationModel annotationModel;
65  
66      @SuppressWarnings("unchecked")
67      public void updateFoldingStructure(ArrayList positions) {
68          Annotation[] annotations = new Annotation[positions.size()];
69  
70          // this will hold the new annotations along
71          // with their corresponding positions
72          HashMap newAnnotations = new HashMap();
73  
74          for (int i = 0; i < positions.size(); i++) {
75              ProjectionAnnotation annotation = new ProjectionAnnotation();
76  
77              newAnnotations.put(annotation, positions.get(i));
78  
79              annotations[i] = annotation;
80          }
81  
82          annotationModel.modifyAnnotations(oldAnnotations, newAnnotations, null);
83  
84          oldAnnotations = annotations;
85      }
86  
87      /*
88       * (non-Javadoc)
89       * 
90       * @see org.eclipse.ui.texteditor.AbstractTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite,
91       *      org.eclipse.jface.text.source.IVerticalRuler, int)
92       */
93      protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
94          ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(),
95                  isOverviewRulerVisible(), styles);
96  
97          // ensure decoration support has been created and configured.
98          getSourceViewerDecorationSupport(viewer);
99  
100         return viewer;
101     }
102 }
103 
104 /*
105  * $Log$
106  * Revision 1.2  2006/10/27 08:41:08  alex_simov
107  * no message
108  * 
109  * Revision 1.1 2006/10/26 13:55:07 alex_simov
110  * SA-WSDL Text Editor with syntax highlighting added
111  * 
112  */