Commit 68c0e845 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Initial implementation of MarkerHoverInfoControl


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 7019f68c
......@@ -13,46 +13,32 @@ import java.util.List;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.IAnnotationHoverExtension;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.ILineRange;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.LineRange;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.editors.controls.MarkerHoverInfoControl;
import org.eclipse.ui.texteditor.MarkerAnnotation;
/**
* @author Kristof Szabados
* @author Arpad Lovassy
* @author Miklos Magyari
*/
public final class AnnotationHover implements IAnnotationHover {
public final class AnnotationHover implements IAnnotationHover, IAnnotationHoverExtension {
@Override
@Deprecated
public String getHoverInfo(final ISourceViewer sourceViewer, final int lineNumber) {
final List<IMarker> markers = getMarkerForLine(sourceViewer, lineNumber);
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < markers.size(); i++) {
String message = markers.get(i).getAttribute(IMarker.MESSAGE, (String) null);
if ( message != null ) {
message = message.trim();
if ( message.length() > 0 ) {
// Marker error text hover (or tooltip in other words) handles error message
// in HTML format, and there can be situation, when the message contains
// < and > characters, which are handled as HTML control tags, so they
// are not visible. So these < and > characters are removed.
// Example: ANTLR sends the following error message during parsing:
// "mismatched input 'control' expecting <EOF>"
message = message.replaceAll( "\\<([A-Z]+)\\>", "$1" );
if (i != 0) {
// Perfect newline for TextHoverControl
// builder.append('\n');
// DefaultInformationControl needs html
// like newline
builder.append("<BR></BR>");
}
builder.append( message );
}
}
}
return builder.toString();
return null;
}
/**
......@@ -92,4 +78,43 @@ public final class AnnotationHover implements IAnnotationHover {
}
return markers;
}
@Override
public IInformationControlCreator getHoverControlCreator() {
return new IInformationControlCreator() {
@Override
public IInformationControl createInformationControl(Shell parent) {
return new MarkerHoverInfoControl(parent, true);
}
};
}
@Override
public boolean canHandleMouseCursor() {
// TODO Auto-generated method stub
return false;
}
@Override
public Object getHoverInfo(ISourceViewer sourceViewer, ILineRange lineRange, int visibleNumberOfLines) {
final List<IMarker> markers = getMarkerForLine(sourceViewer, lineRange.getStartLine());
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < markers.size(); i++) {
String message = markers.get(i).getAttribute(IMarker.MESSAGE, (String) null);
if ( message != null ) {
message = message.trim();
if ( message.length() > 0 ) {
builder.append( message );
}
}
}
IDocument document = new Document(builder.toString());
return document;
}
@Override
public ILineRange getHoverLineRange(ISourceViewer viewer, int lineNumber) {
// FIXME calculate real range
return new LineRange(lineNumber, 1);
}
}
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.designer.editors.controls;
import org.eclipse.jface.text.AbstractInformationControl;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControlExtension2;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
/**
* Control for handling ttcn3 editor error marker hovers
*
* @author Miklos Magyari
*
*/
public class MarkerHoverInfoControl extends AbstractInformationControl implements IInformationControlExtension2 {
private Shell fShell;
private TextViewer viewer;
private IDocument content;
public MarkerHoverInfoControl(Shell parentShell, boolean isResizable) {
super(parentShell, isResizable);
create();
}
@Override
public boolean hasContents() {
return content != null;
}
@Override
public void setInput(Object input) {
if (input instanceof IDocument) {
content = (IDocument)input;
}
viewer.setDocument(content);
}
@Override
protected void createContent(Composite parent) {
fShell = parent.getShell();
viewer = new TextViewer(fShell, 0);
viewer.setEditable(false);
}
}
......@@ -9,7 +9,6 @@ package org.eclipse.titan.designer.editors.ttcn3editor;
import java.util.Iterator;
import org.eclipse.core.internal.resources.MarkerInfo;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment