Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2dc49d9fe018d8b4dce063745335ddfeea02576e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package org.eclipse.ui.externaltools.internal.ant.editor;

/**********************************************************************
This file is made available under the terms of the Common Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/cpl-v10.html
**********************************************************************/
//
// Copyright:
// GEBIT Gesellschaft fuer EDV-Beratung
// und Informatik-Technologien mbH, 
// Berlin, Duesseldorf, Frankfurt (Germany) 2002
// All rights reserved.
//

import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;

import org.eclipse.ui.externaltools.internal.ant.editor.derived.HTMLTextPresenter;
import org.eclipse.ui.externaltools.internal.ant.editor.text.XMLAnnotationHover;
import org.eclipse.ui.externaltools.internal.ant.editor.text.XMLTextHover;
import org.eclipse.ui.externaltools.internal.ant.editor.text.NonRuleBasedDamagerRepairer;
import org.eclipse.ui.externaltools.internal.ant.editor.text.IAntEditorColorConstants;
import org.eclipse.ui.externaltools.internal.ant.editor.text.NotifyingReconciler;
import org.eclipse.ui.externaltools.internal.ant.editor.text.PlantyPartitionScanner;
import org.eclipse.ui.externaltools.internal.ant.editor.text.PlantyProcInstrScanner;
import org.eclipse.ui.externaltools.internal.ant.editor.text.PlantyTagScanner;
import org.eclipse.ui.externaltools.internal.ant.editor.text.XMLReconcilingStrategy;



/**
 * The source viewer configuration for Planty.
 * 
 * @version 24.09.2002
 * @author Alf Schiefelbein
 */
public class PlantySourceViewerConfiguration extends SourceViewerConfiguration {

    private PlantyTagScanner tagScanner;
    private PlantyProcInstrScanner instructionScanner;
	private NonRuleBasedDamagerRepairer damageRepairer;
        
    private PlantyEditor fEditor;

    private XMLTextHover fTextHover;
    
    /**
     * Creates an instance with the specified color manager.
     */
    public PlantySourceViewerConfiguration(PlantyEditor editor) {
	    super();
	    fEditor= editor;
    }    

    /* (non-Javadoc)
     * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(ISourceViewer)
     */
    public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
        ContentAssistant assistant= new ContentAssistant();
        PlantyCompletionProcessor tempProcessor = new PlantyCompletionProcessor(); 
        assistant.setContentAssistProcessor(tempProcessor, IDocument.DEFAULT_CONTENT_TYPE);
        assistant.setContentAssistProcessor(tempProcessor, PlantyPartitionScanner.XML_TAG);
		assistant.enableAutoActivation(true);
		
        IInformationControlCreator creator = getInformationControlCreator(true);
        assistant.setInformationControlCreator(creator);

        return assistant;
    }


    protected IInformationControlCreator getInformationControlCreator(final boolean cutDown) {
        return new IInformationControlCreator() {
            public IInformationControl createInformationControl(Shell parent) {
                int style= cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
                return new DefaultInformationControl(parent, style, new HTMLTextPresenter(cutDown));
            }
        };
    }

    /* (non-Javadoc)
     * Method declared on SourceViewerConfiguration
     */
    public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
        return new String[] {
            IDocument.DEFAULT_CONTENT_TYPE,
            PlantyPartitionScanner.XML_COMMENT,
            PlantyPartitionScanner.XML_TAG };
    }
    
    /**
     * @return TAB_WIDTH
     * @see SourceViewerConfiguration#getTabWidth(org.eclipse.jface.text.source.ISourceViewer)
     */
    public int getTabWidth(ISourceViewer sourceViewer) {
        return PlantyEditor.TAB_WIDTH;
    }
    
    private PlantyProcInstrScanner getDefaultScanner() {
        if (instructionScanner == null) {
            instructionScanner = new PlantyProcInstrScanner();
            instructionScanner.setDefaultReturnToken(
                new Token(
                    new TextAttribute(ExternalToolsPlugin.getPreferenceColor(IAntEditorColorConstants.P_DEFAULT))));
        }
        return instructionScanner;
    }
    
	private PlantyTagScanner getTagScanner() {
        if (tagScanner == null) {
            tagScanner = new PlantyTagScanner();
            tagScanner.setDefaultReturnToken(
                new Token(new TextAttribute(ExternalToolsPlugin.getPreferenceColor(IAntEditorColorConstants.P_TAG))));
        }
        return tagScanner;
    }
    
    
    public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
        PresentationReconciler reconciler = new PresentationReconciler();

        DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getDefaultScanner());
        reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
        reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);

        dr = new DefaultDamagerRepairer(getTagScanner());
        reconciler.setDamager(dr, PlantyPartitionScanner.XML_TAG);
        reconciler.setRepairer(dr, PlantyPartitionScanner.XML_TAG);

		damageRepairer= new NonRuleBasedDamagerRepairer(
                new TextAttribute(ExternalToolsPlugin.getPreferenceColor(IAntEditorColorConstants.P_XML_COMMENT)));
        reconciler.setDamager(damageRepairer, PlantyPartitionScanner.XML_COMMENT);
        reconciler.setRepairer(damageRepairer, PlantyPartitionScanner.XML_COMMENT);

        return reconciler;
    }


	/**
	 * Preference colors have changed.  
	 * Update the default tokens of the scanners.
	 */
	public void updateScanners() {
		tagScanner.setDefaultReturnToken(
				new Token(new TextAttribute(ExternalToolsPlugin.getPreferenceColor(IAntEditorColorConstants.P_TAG))));
				
		instructionScanner.setDefaultReturnToken(
			   new Token(
				   new TextAttribute(ExternalToolsPlugin.getPreferenceColor(IAntEditorColorConstants.P_DEFAULT))));
				   
		damageRepairer.setDefaultTextAttribute(new TextAttribute(ExternalToolsPlugin.getPreferenceColor(IAntEditorColorConstants.P_XML_COMMENT)));				  
	}

    /*
     * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
     */
    public IReconciler getReconciler(ISourceViewer sourceViewer) {
	    NotifyingReconciler reconciler= new NotifyingReconciler(new XMLReconcilingStrategy(fEditor), false);
	    reconciler.setDelay(500);
	    return reconciler;
    }

	/*
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAnnotationHover(org.eclipse.jface.text.source.ISourceViewer)
	 */
	public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
		return new XMLAnnotationHover();
	}

	/*
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getInformationControlCreator(org.eclipse.jface.text.source.ISourceViewer)
	 */
	public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
		return getInformationControlCreator(true);
	}

	/*
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getTextHover(org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
	 */
	public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
		if (fTextHover == null) {
			fTextHover= new XMLTextHover();
		}
		return fTextHover;
	}

}

Back to the top