/*******************************************************************************
* * Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.tml;
import java.text.ParseException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextHoverExtension2;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.Region;
import de.innovationgate.eclipse.editors.Plugin;
public class TMLTextHover implements ITextHover, ITextHoverExtension2 {
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
try {
ITypedRegion partition = textViewer.getDocument().getPartition(hoverRegion.getOffset());
if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
TMLRegion tmlInfo = TMLRegion.parse(partition, textViewer.getDocument(), hoverRegion.getOffset());
if (tmlInfo.getAttributeAtCursor() != null) {
String attributeName = tmlInfo.getAttributeAtCursor();
String attributeValue = tmlInfo.getAttributeValue(attributeName);
return Plugin.getDefault().getContextInformationProvider().getAttributeInformation(tmlInfo.getTagName(), attributeName, attributeValue, Plugin.getDefault().getActiveFile());
} else {
return Plugin.getDefault().getContextInformationProvider().getTagInformation(tmlInfo.getTagName(), Plugin.getDefault().getActiveFile());
}
}
} catch (BadLocationException e) {
} catch (ParseException e) {
}
return null;
}
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
return null;
}
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
return new Region(offset, 0);
}
}