package no.uio.ifi.refaktor.handlers; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ITreeSelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; public class TreeSelectionInfoHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); String title = "Tree Selection Info"; if (!(selection instanceof ITreeSelection)) { MessageDialog.openInformation(window.getShell(), title, "Selection is not of type " + ITreeSelection.class.getCanonicalName()); return null; } ITreeSelection treeSelection = (ITreeSelection) selection; String message = "Selection type: " + treeSelection.getClass().getCanonicalName() + "\n\nType of selected element: " + treeSelection.getFirstElement().getClass().getCanonicalName() + "\nInterface type(s) for element:\n" + getAdditionalTypeInfoForElement(treeSelection.getFirstElement()); MessageDialog.openInformation(window.getShell(), title, message); return null; } private String getAdditionalTypeInfoForElement(Object element) { String interfaces = ""; for (Class iface: element.getClass().getInterfaces()) interfaces += iface.getCanonicalName() + "\n"; return interfaces; } }