I am making a plugin and when I right click on a Package Explorer class, my handler would get the class reference clicked.
When I right click on a class in the Package explorer opens the menu, in this menu I created a new function (line), when I click on it it is treated in the handler which is a class, and in that handler I would like how do I get an instance (reference) of the class that I right clicked.
The interface part is implemented in plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="br.usp.each.saeg.badua.dataflow.handler"
label="Dataflow Coverage"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="activeMenuSelection">
<iterate
ifEmpty="false"
operator="or">
<adapt
type="org.eclipse.jdt.core.ICompilationUnit">
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="DataflowHandler"
id="br.usp.each.saeg.badua.dataflow.handler"
name="DataflowViewHandler">
</command>
</extension>
</plugin>
I have a class DataflowHandler.java that is Handler
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.PlatformUI;
public class DataflowHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
#codigo para conseguir a instancia da classe selecionada
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Basically what I need is that when I click this button I get a reference to the Main.java class, which is the class I clicked with the right mouse button.