update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / move / moveClassesOrPackages / MoveClassesOrPackagesHandlerBase.java
blobfce85569fe927bb823893b4827deadfbdac8e865
1 /*
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.
16 package com.intellij.refactoring.move.moveClassesOrPackages;
18 import com.intellij.refactoring.move.MoveHandlerDelegate;
19 import com.intellij.refactoring.move.MoveCallback;
20 import com.intellij.refactoring.util.CommonRefactoringUtil;
21 import com.intellij.psi.PsiElement;
22 import com.intellij.psi.PsiPackage;
23 import com.intellij.psi.PsiDirectory;
24 import com.intellij.psi.JavaDirectoryService;
25 import com.intellij.openapi.project.Project;
27 import java.util.Arrays;
29 public abstract class MoveClassesOrPackagesHandlerBase extends MoveHandlerDelegate {
30 protected static boolean isPackageOrDirectory(final PsiElement element) {
31 if (element instanceof PsiPackage) return true;
32 return element instanceof PsiDirectory && JavaDirectoryService.getInstance().getPackage((PsiDirectory)element) != null;
35 public PsiElement[] adjustForMove(final Project project, final PsiElement[] sourceElements, final PsiElement targetElement) {
36 return MoveClassesOrPackagesImpl.adjustForMove(project,sourceElements, targetElement);
39 public void doMove(final Project project, final PsiElement[] elements, final PsiElement targetContainer, final MoveCallback callback) {
40 if (tryDirectoryMove ( project, elements, targetContainer, callback)) {
41 return;
43 MoveClassesOrPackagesImpl.doMove(project, elements, targetContainer, callback);
46 private static boolean tryDirectoryMove(Project project, final PsiElement[] sourceElements, final PsiElement targetElement, final MoveCallback callback) {
47 if (targetElement instanceof PsiDirectory) {
48 final PsiElement[] adjustedElements = MoveClassesOrPackagesImpl.adjustForMove(project, sourceElements, targetElement);
49 if (adjustedElements != null) {
50 if ( CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(adjustedElements),true) ) {
51 new MoveClassesOrPackagesToNewDirectoryDialog((PsiDirectory)targetElement, adjustedElements, callback).show();
54 return true;
56 return false;