private void doDeleteDirectory() { if (myResourceDir == null) { return; } final int selectedIndex = myDirectoriesList.getSelectedIndex(); if (selectedIndex < 0) { return; } final String selectedDirName = myDirNames[selectedIndex]; final VirtualFile selectedDir = myResourceDir.findChild(selectedDirName); if (selectedDir == null) { return; } final VirtualFileDeleteProvider provider = new VirtualFileDeleteProvider(); provider.deleteElement( new DataContext() { @Override public Object getData(@NonNls String dataId) { if (PlatformDataKeys.VIRTUAL_FILE_ARRAY.getName().equals(dataId)) { return new VirtualFile[] {selectedDir}; } else { return null; } } }); updateDirectories(false); }
protected void toggleSelection() { int index = _list.getSelectedIndex(); toggleSelection(index); }
private void updateDirectories(boolean updateFileCombo) { final Module module = getModule(); List<VirtualFile> valuesDirs = Collections.emptyList(); if (module != null) { final AndroidFacet facet = AndroidFacet.getInstance(module); if (facet != null) { myResourceDir = AndroidRootUtil.getResourceDir(facet); if (myResourceDir != null) { valuesDirs = AndroidResourceUtil.getResourceSubdirs( ResourceFolderType.VALUES.getName(), new VirtualFile[] {myResourceDir}); } } } Collections.sort( valuesDirs, new Comparator<VirtualFile>() { @Override public int compare(VirtualFile f1, VirtualFile f2) { return f1.getName().compareTo(f2.getName()); } }); final Map<String, JCheckBox> oldCheckBoxes = myCheckBoxes; final int selectedIndex = myDirectoriesList.getSelectedIndex(); final String selectedDirName = selectedIndex >= 0 ? myDirNames[selectedIndex] : null; final List<JCheckBox> checkBoxList = new ArrayList<JCheckBox>(); myCheckBoxes = new HashMap<String, JCheckBox>(); myDirNames = new String[valuesDirs.size()]; int newSelectedIndex = -1; int i = 0; for (VirtualFile dir : valuesDirs) { final String dirName = dir.getName(); final JCheckBox oldCheckBox = oldCheckBoxes.get(dirName); final boolean selected = oldCheckBox != null && oldCheckBox.isSelected(); final JCheckBox checkBox = new JCheckBox(dirName, selected); checkBoxList.add(checkBox); myCheckBoxes.put(dirName, checkBox); myDirNames[i] = dirName; if (dirName.equals(selectedDirName)) { newSelectedIndex = i; } i++; } myDirectoriesList.setModel(new CollectionListModel<JCheckBox>(checkBoxList)); if (newSelectedIndex >= 0) { myDirectoriesList.setSelectedIndex(newSelectedIndex); } if (checkBoxList.size() == 1) { checkBoxList.get(0).setSelected(true); } if (updateFileCombo) { final Object oldItem = myFileNameCombo.getEditor().getItem(); final Set<String> fileNameSet = new HashSet<String>(); for (VirtualFile valuesDir : valuesDirs) { for (VirtualFile file : valuesDir.getChildren()) { fileNameSet.add(file.getName()); } } final List<String> fileNames = new ArrayList<String>(fileNameSet); Collections.sort(fileNames); myFileNameCombo.setModel(new DefaultComboBoxModel(fileNames.toArray())); myFileNameCombo.getEditor().setItem(oldItem); } }