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.ITextSelection;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.information.IInformationProvider;
import org.eclipse.jface.text.information.IInformationProviderExtension;
import de.innovationgate.eclipse.editors.Plugin;
public class TMLInformationProvider implements IInformationProvider, IInformationProviderExtension {
public String getInformation(ITextViewer textViewer, IRegion subject) {
return null;
}
public IRegion getSubject(ITextViewer textViewer, int offset) {
if (textViewer.getSelectionProvider().getSelection() instanceof ITextSelection) {
ITextSelection selection = (ITextSelection)textViewer.getSelectionProvider().getSelection();
return new Region(selection.getOffset(),0);
}
return new Region(offset, 0);
}
public Object getInformation2(ITextViewer textViewer, IRegion region) {
try {
ITypedRegion partition = textViewer.getDocument().getPartition(region.getOffset());
if (partition.getType().equals(TMLPartitionScanner.TML_TAG_START)) {
TMLRegion tmlInfo = TMLRegion.parse(partition, textViewer.getDocument(), region.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;
}
}