2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.refactoring
.actions
;
19 import com
.intellij
.lang
.Language
;
20 import com
.intellij
.lang
.LanguageRefactoringSupport
;
21 import com
.intellij
.lang
.refactoring
.RefactoringSupportProvider
;
22 import com
.intellij
.openapi
.actionSystem
.DataContext
;
23 import com
.intellij
.openapi
.actionSystem
.LangDataKeys
;
24 import com
.intellij
.psi
.PsiElement
;
25 import com
.intellij
.psi
.PsiFile
;
26 import com
.intellij
.refactoring
.RefactoringActionHandler
;
27 import com
.intellij
.refactoring
.lang
.ElementsHandler
;
30 public class PushDownAction
extends BaseRefactoringAction
{
32 public PushDownAction() {
33 setInjectedContext(true);
36 public boolean isAvailableInEditorOnly() {
40 public boolean isEnabledOnElements(PsiElement
[] elements
) {
41 if (elements
.length
> 0) {
42 final Language language
= elements
[0].getLanguage();
43 final RefactoringActionHandler handler
= LanguageRefactoringSupport
.INSTANCE
.forLanguage(language
).getPushDownHandler();
44 return handler
instanceof ElementsHandler
&& ((ElementsHandler
)handler
).isEnabledOnElements(elements
);
49 public RefactoringActionHandler
getHandler(DataContext dataContext
) {
50 PsiFile file
= LangDataKeys
.PSI_FILE
.getData(dataContext
);
51 if (file
== null) return null;
52 final RefactoringSupportProvider supportProvider
= LanguageRefactoringSupport
.INSTANCE
.forLanguage(file
.getViewProvider().getBaseLanguage());
53 return supportProvider
!= null ? supportProvider
.getPushDownHandler() : null;
56 protected boolean isAvailableForLanguage(final Language language
) {
57 return LanguageRefactoringSupport
.INSTANCE
.forLanguage(language
).getPushDownHandler() != null;