Permalink
Browse files

add image hover

  • Loading branch information...
nittka committed Aug 29, 2018
1 parent 309b5f7 commit 269c292342fa2589594322c3fab463755b39bb68
@@ -1,7 +1,11 @@
package de.nittka.tooling.jtag.ui;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.common.util.URI;
import de.nittka.tooling.jtag.jtag.File;
import de.nittka.tooling.jtag.jtag.FileName;
public class JtagFileURIs {
@@ -15,6 +19,17 @@ public static URI getReferencedResourceURI(FileName file){
}
}
public static String getImageLocation(File file){
IResource wsFile = ResourcesPlugin.getWorkspace().getRoot().findMember(file.eResource().getURI().toPlatformString(true));
if(wsFile.exists()){
FileName name = file.getFileName();
IPath folder = wsFile.getLocation().removeLastSegments(1);
IPath fileLocation = folder.append(name.getFileName()).addFileExtension(name.getExtension());
return fileLocation.toString();
}
return null;
}
// public static IFile getJtagFile(IFile file){
// if("jtag".equals(file.getFileExtension())){
// throw new IllegalArgumentException(file+" is already an Jtag file");
@@ -7,8 +7,12 @@
import org.eclipse.xtext.resource.ILocationInFileProvider;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.findrefs.FindReferencesHandler;
import org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider;
import org.eclipse.xtext.ui.editor.hover.html.IEObjectHoverDocumentationProvider;
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper;
import de.nittka.tooling.jtag.ui.hover.JTagEObjectHover;
import de.nittka.tooling.jtag.ui.hover.JtagHoverProvider;
import de.nittka.tooling.jtag.ui.linking.JtagFindReferencesHandler;
import de.nittka.tooling.jtag.ui.linking.JtagHyperlinkHelper;
import de.nittka.tooling.jtag.ui.linking.JtagLocationInFileProvider;
@@ -55,6 +59,14 @@ public JtagUiModule(AbstractUIPlugin plugin) {
return JtagFindReferencesHandler.class;
}
public Class<? extends DefaultEObjectHoverProvider> bindEHoverProvider(){
return JtagHoverProvider.class;
}
public Class<? extends IEObjectHoverDocumentationProvider> bindEObjectHover(){
return JTagEObjectHover.class;
}
// public Class<? extends XtextTemplateContextType> bindTemplateContextType() {
// return XarchiveTemplateContextType.class;
//}
@@ -0,0 +1,25 @@
package de.nittka.tooling.jtag.ui.hover;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ui.editor.hover.html.DefaultHoverDocumentationProvider;
import de.nittka.tooling.jtag.jtag.File;
import de.nittka.tooling.jtag.jtag.FileName;
import de.nittka.tooling.jtag.ui.JtagFileURIs;
public class JTagEObjectHover extends DefaultHoverDocumentationProvider {
private static String SPACING_POSTFIX="<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>";
@Override
public String getDocumentation(EObject object) {
if(object instanceof FileName){
String location=JtagFileURIs.getImageLocation((File)object.eContainer());
if(location!=null){
String folder=new java.io.File(location).getParent();
return "<img src=\"file://"+location+"\" height=120px><br>"+folder+SPACING_POSTFIX;
}
}
return super.getDocumentation(object);
}
}
@@ -0,0 +1,25 @@
package de.nittka.tooling.jtag.ui.hover;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider;
import de.nittka.tooling.jtag.jtag.FileName;
public class JtagHoverProvider extends DefaultEObjectHoverProvider {
@Override
protected boolean hasHover(EObject o) {
if(o instanceof FileName){
return true;
}
return super.hasHover(o);
}
@Override
protected String getFirstLine(EObject o) {
if(o instanceof FileName){
return "<b>"+getLabel(o)+"</b>";
}
return super.getFirstLine(o);
}
}

0 comments on commit 269c292

Please sign in to comment.