Search in sources :

Example 31 with ResourceBundle

use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.

the class ResourceBundleRenamerFactory method isApplicable.

@Override
public boolean isApplicable(@NotNull final PsiElement element) {
    if (!(element instanceof PsiFile)) {
        return false;
    }
    final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(element);
    if (file == null) {
        return false;
    }
    final ResourceBundle resourceBundle = file.getResourceBundle();
    return resourceBundle.getBaseDirectory() != null && resourceBundle.getPropertiesFiles().size() != 1;
}
Also used : PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Example 32 with ResourceBundle

use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.

the class ResourceBundleNode method drop.

@Override
public void drop(TreeNode[] sourceNodes, DataContext dataContext) {
    MultiMap<ResourceBundle, PropertiesFile> bundleGrouping = new MultiMap<>();
    for (TreeNode sourceNode : sourceNodes) {
        final PropertiesFile propertiesFile = extractPropertiesFileFromNode(sourceNode);
        if (propertiesFile == null)
            return;
        bundleGrouping.putValue(propertiesFile.getResourceBundle(), propertiesFile);
    }
    final ResourceBundle resourceBundle = ObjectUtils.notNull(getValue());
    bundleGrouping.remove(resourceBundle);
    final ResourceBundleManager resourceBundleManager = ResourceBundleManager.getInstance(myProject);
    final List<PropertiesFile> toAddInResourceBundle = new ArrayList<>();
    for (Map.Entry<ResourceBundle, Collection<PropertiesFile>> entry : bundleGrouping.entrySet()) {
        toAddInResourceBundle.addAll(entry.getValue());
        final ResourceBundle currentBundle = entry.getKey();
        final Collection<PropertiesFile> propertiesFilesToMove = entry.getValue();
        if (currentBundle.getPropertiesFiles().size() - propertiesFilesToMove.size() > 0) {
            final String currentBundleBaseName = currentBundle.getBaseName();
            final ArrayList<PropertiesFile> files = new ArrayList<>(currentBundle.getPropertiesFiles());
            files.removeAll(propertiesFilesToMove);
            resourceBundleManager.dissociateResourceBundle(currentBundle);
            resourceBundleManager.combineToResourceBundle(files, currentBundleBaseName);
        }
    }
    toAddInResourceBundle.addAll(resourceBundle.getPropertiesFiles());
    final String baseName = resourceBundle.getBaseName();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(getProject());
    fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(resourceBundle));
    resourceBundleManager.dissociateResourceBundle(resourceBundle);
    final ResourceBundle updatedBundle = resourceBundleManager.combineToResourceBundleAndGet(toAddInResourceBundle, baseName);
    FileEditorManager.getInstance(getProject()).openFile(new ResourceBundleAsVirtualFile(updatedBundle), true);
    ProjectView.getInstance(getProject()).refresh();
}
Also used : ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile) MultiMap(com.intellij.util.containers.MultiMap) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TreeNode(javax.swing.tree.TreeNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) MultiMap(com.intellij.util.containers.MultiMap)

Aggregations

ResourceBundle (com.intellij.lang.properties.ResourceBundle)32 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)20 Project (com.intellij.openapi.project.Project)11 NotNull (org.jetbrains.annotations.NotNull)10 PsiFile (com.intellij.psi.PsiFile)9 PsiElement (com.intellij.psi.PsiElement)7 IProperty (com.intellij.lang.properties.IProperty)6 FileEditor (com.intellij.openapi.fileEditor.FileEditor)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 HashSet (com.intellij.util.containers.HashSet)3 com.intellij.lang.properties (com.intellij.lang.properties)2 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)2 ResourceBundleNode (com.intellij.lang.properties.projectView.ResourceBundleNode)2 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)2 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)2 Logger (com.intellij.openapi.diagnostic.Logger)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2