/*
 * Copyright 2000-2010 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.lang.properties.projectView;

import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.move.MoveHandlerDelegate;
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesHandler;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Set;

public class ResourceBundleMoveProvider extends MoveHandlerDelegate {
  private static final Logger LOG = Logger.getInstance(ResourceBundleMoveProvider.class);

  @Override
  public boolean canMove(DataContext dataContext) {
    return ResourceBundle.ARRAY_DATA_KEY.getData(dataContext) != null;
  }

  @Override
  public boolean canMove(PsiElement[] elements, @Nullable final PsiElement targetContainer) {
    return false;
  }

  @Override
  public boolean isValidTarget(PsiElement psiElement, PsiElement[] sources) {
    return MoveFilesOrDirectoriesHandler.isValidTarget(psiElement);
  }

  @Override
  public void collectFilesOrDirsFromContext(DataContext dataContext, Set<PsiElement> filesOrDirs) {

    final ResourceBundle[] bundles = ResourceBundle.ARRAY_DATA_KEY.getData(dataContext);
    LOG.assertTrue(bundles != null);
    for (ResourceBundle bundle : bundles) {
      List<PropertiesFile> propertiesFiles = bundle.getPropertiesFiles();
      for (PropertiesFile propertiesFile : propertiesFiles) {
        filesOrDirs.add(propertiesFile.getContainingFile());
      }
    }
  }

  @Override
  public boolean isMoveRedundant(PsiElement source, PsiElement target) {
    if (source instanceof PropertiesFile && target instanceof PsiDirectory) {
      return source.getParent() == target;
    }
    return super.isMoveRedundant(source, target);
  }
}

@@ -1,13 +1,10 @@
 /
-*%0A *
+/
  Copyrig
@@ -14,17 +14,17 @@
 2000-201
-0
+7
  JetBrai
@@ -37,565 +37,114 @@
 .o.%0A
- *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */
+// Use of this source code is governed by the Apache 2.0 license that can be%0A// found in the LICENSE file.
 %0Apac
@@ -396,24 +396,69 @@
 tic.Logger;%0A
+import com.intellij.openapi.project.Project;%0A
 import com.i
@@ -519,16 +519,67 @@
 lement;%0A
+import com.intellij.refactoring.move.MoveCallback;%0A
 import c
@@ -1339,16 +1339,84 @@
   return
+ (psiElement == null && (sources == null %7C%7C sources.length == 0)) %7C%7C
  MoveFil
@@ -2177,24 +2177,24 @@
 rget;%0A    %7D%0A
-
     return s
@@ -2234,11 +2234,289 @@
 et);%0A  %7D
+%0A%0A  @Override%0A  public void doMove(Project project,%0A                     PsiElement%5B%5D elements,%0A                     @Nullable PsiElement targetContainer,%0A                     @Nullable MoveCallback callback) %7B%0A    super.doMove(project, elements, targetContainer, callback);%0A  %7D
 %0A%7D%0A

make move resource bundle available with f6 (IDEA-179376)