final fix for push down
[fedora-idea.git] / lang-impl / src / com / intellij / refactoring / actions / PushDownAction.java
blobf03a4737343b4c187caef0a850c70223f08b19e1
1 package com.intellij.refactoring.actions;
3 import com.intellij.lang.Language;
4 import com.intellij.lang.LanguageRefactoringSupport;
5 import com.intellij.lang.refactoring.RefactoringSupportProvider;
6 import com.intellij.openapi.actionSystem.DataContext;
7 import com.intellij.openapi.actionSystem.LangDataKeys;
8 import com.intellij.psi.PsiElement;
9 import com.intellij.psi.PsiFile;
10 import com.intellij.refactoring.RefactoringActionHandler;
11 import com.intellij.refactoring.lang.ElementsHandler;
14 public class PushDownAction extends BaseRefactoringAction {
15 public boolean isAvailableInEditorOnly() {
16 return false;
19 public boolean isEnabledOnElements(PsiElement[] elements) {
20 if (elements.length > 0) {
21 final Language language = elements[0].getLanguage();
22 final RefactoringActionHandler handler = LanguageRefactoringSupport.INSTANCE.forLanguage(language).getPushDownHandler();
23 return handler instanceof ElementsHandler && ((ElementsHandler)handler).isEnabledOnElements(elements);
25 return false;
28 public RefactoringActionHandler getHandler(DataContext dataContext) {
29 PsiFile file = LangDataKeys.PSI_FILE.getData(dataContext);
30 if (file == null) return null;
31 final RefactoringSupportProvider supportProvider = LanguageRefactoringSupport.INSTANCE.forLanguage(file.getViewProvider().getBaseLanguage());
32 return supportProvider != null ? supportProvider.getPushDownHandler() : null;
35 protected boolean isAvailableForLanguage(final Language language) {
36 return LanguageRefactoringSupport.INSTANCE.forLanguage(language).getPushDownHandler() != null;