blob: 15e0a3edc397748a51250917224adeb3b0015465 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.editor.text.light.vtcl;
import java.util.Iterator;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.viatra2.editor.text.Activator;
import org.eclipse.viatra2.editor.text.light.IVTEConstants;
import org.eclipse.viatra2.editor.text.light.VTEAutoIndentStrategy;
import org.eclipse.viatra2.editor.text.light.VTEColorProvider;
import org.eclipse.viatra2.editor.text.light.VTEColorToken;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
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.ui.texteditor.MarkerAnnotation;
public class VTCLConfiguration extends SourceViewerConfiguration
{
private VTCLCodeScanner iCodeScanner = null;
private VTEColorProvider iColorProvider = null;
private VTEColorToken iColorToken = null;
@SuppressWarnings("static-access")
public VTCLConfiguration(VTEColorProvider cm)
{
iColorProvider = cm;
iColorProvider.initializeDefaults(Activator.getDefault().getPreferenceStore());
iColorToken = new VTEColorToken();
iColorToken.COMMENT = new Token(new TextAttribute(iColorProvider.getColor(IVTEConstants.COMMENT),null,SWT.ITALIC));
iColorToken.KEYWORD = new Token(new TextAttribute(iColorProvider.getColor(IVTEConstants.KEYWORD),null,SWT.BOLD));
iColorToken.STRING = new Token(new TextAttribute(iColorProvider.getColor(IVTEConstants.STRING)));
iColorToken.OTHER = new Token(new TextAttribute(iColorProvider.getColor(IVTEConstants.DEFAULT)));
iCodeScanner = new VTCLCodeScanner(iColorProvider,iColorToken);
}
/**
* Define reconciler for VTMLEditor
*/
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(iCodeScanner);
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
return reconciler;
}
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType)
{
return new IAutoEditStrategy[]{new VTEAutoIndentStrategy()};
}
@Override
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer)
{
return new IAnnotationHover() {
public String getHoverInfo(ISourceViewer sourceViewer,int lineNumber) {
String r = "Problems:\n";
Iterator<?> it = sourceViewer.getAnnotationModel().getAnnotationIterator();
while (it.hasNext())
{
Object o = it.next();
if (o instanceof MarkerAnnotation)
{
MarkerAnnotation ann = (MarkerAnnotation)o;
try
{
int line = (Integer) ann.getMarker().getAttribute(IMarker.LINE_NUMBER);
if (line == lineNumber || line == lineNumber-1 || line == lineNumber+1) // no comment...
{
r+=" - "+ann.getText()+"\n";
}
}
catch (CoreException e) { }
}
}
return r;
}
};
}
}