e.getPresentation().setEnabled(WicketForgeFacet.hasFacetOrIsFromLibrary(psiFile));
}
@Override
public void actionPerformed(AnActionEvent event) {
Editor editor = event.getData(DataKeys.EDITOR);
if (editor == null) {
return;
}
PsiFile psiFile = event.getData(DataKeys.PSI_FILE);
if (psiFile == null) {
return;
}
if (!WicketForgeFacet.hasFacetOrIsFromLibrary(psiFile)) {
return;
}
if (psiFile instanceof XmlFile) {
PsiClass psiClass = ClassIndex.getAssociatedClass(psiFile);
if (psiClass == null) {
HintManager.getInstance().showInformationHint(editor, "No corresponding java class found");
} else {
PsiFile classFile = psiClass.getContainingFile();
// if file alredy open just navigate to file (and not to class) so caret position gets not changed (issue 92)
if (classFile != null) {
VirtualFile vf = classFile.getVirtualFile();
if (vf != null && FileEditorManager.getInstance(psiClass.getProject()).isFileOpen(vf)) {
classFile.navigate(true);
return;
}
}
psiClass.navigate(true);
}
} else if (psiFile instanceof PsiJavaFile) {
PsiClass psiClass = null;
// look for wicket class at caret
int offset = editor.getCaretModel().getOffset();
if (offset >= 0) {
PsiElement currentElement = psiFile.findElementAt(offset);
if (currentElement != null) {
psiClass = WicketPsiUtil.getParentWicketClass(currentElement);
}