mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-59669 AE at LibraryImpl.getFiles() on removing just created library (third case)
This commit is contained in:
+58
-6
@@ -27,9 +27,9 @@ import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.UsageInArtifact;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.CreateNewLibraryAction;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.*;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.NamedConfigurable;
|
||||
@@ -186,13 +186,65 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
|
||||
|
||||
public abstract BaseLibrariesConfigurable getOppositeGroup();
|
||||
|
||||
protected void removeLibrary(final Library library) {
|
||||
protected boolean removeLibrary(final Library library) {
|
||||
final LibraryTable table = library.getTable();
|
||||
if (table != null) {
|
||||
getModelProvider().getModifiableModel().removeLibrary(library);
|
||||
myContext.getDaemonAnalyzer().removeElement(new LibraryProjectStructureElement(myContext, library));
|
||||
// TODO: myContext.invalidateModules(myContext.myLibraryDependencyCache.get(library.getName()));
|
||||
final Collection<ProjectStructureElementUsage> usages = myContext.getDaemonAnalyzer().getUsages(getSelectedElement());
|
||||
if (usages.size() > 0) {
|
||||
final List<String> modules = new ArrayList<String>();
|
||||
final List<String> artifacts = new ArrayList<String>();
|
||||
for (final ProjectStructureElementUsage usage : usages) {
|
||||
if (usage instanceof UsageInModuleClasspath) {
|
||||
modules.add(usage.getPresentableName());
|
||||
} else if (usage instanceof UsageInArtifact) {
|
||||
artifacts.add(usage.getPresentableName());
|
||||
} else {
|
||||
LOG.error("Unknown usage: " + usage.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
final StringBuilder sb = new StringBuilder("Library \"");
|
||||
sb.append(library.getName()).append("\" is used in ");
|
||||
if (modules.size() > 0) {
|
||||
if (modules.size() == 1) {
|
||||
sb.append("module ").append("\"").append(modules.get(0)).append("\"");
|
||||
} else {
|
||||
sb.append(modules.size()).append(" modules");
|
||||
}
|
||||
}
|
||||
|
||||
if (artifacts.size() > 0) {
|
||||
sb.append(modules.size() > 0 ? " and in " : ".");
|
||||
|
||||
if (modules.size() == 1) {
|
||||
sb.append("artifact ").append("\"").append(artifacts.get(0)).append("\".");
|
||||
} else {
|
||||
sb.append(artifacts.size()).append(" artifacts.");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("\n\nAre you sure you want to delete this library?");
|
||||
|
||||
if (DialogWrapper.OK_EXIT_CODE == Messages.showOkCancelDialog(myProject, sb.toString(),
|
||||
"Confirm library deletion", Messages.getQuestionIcon())) {
|
||||
|
||||
final ModuleStructureConfigurable rootConfigurable = ModuleStructureConfigurable.getInstance(myProject);
|
||||
for (final ProjectStructureElementUsage usage : usages) {
|
||||
if (usage instanceof UsageInModuleClasspath) {
|
||||
rootConfigurable.removeLibraryOrderEntry(((ModuleProjectStructureElement)usage.getContainingElement()).getModule(), library);
|
||||
} else if (usage instanceof UsageInArtifact) {
|
||||
// TODO[nik] implement me
|
||||
}
|
||||
}
|
||||
|
||||
getModelProvider().getModifiableModel().removeLibrary(library);
|
||||
myContext.getDaemonAnalyzer().removeElement(new LibraryProjectStructureElement(myContext, library));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected
|
||||
|
||||
+3
-3
@@ -403,7 +403,7 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i
|
||||
if (removeFacet((Facet)editableObject).isEmpty()) return false;
|
||||
}
|
||||
else if (editableObject instanceof Library) {
|
||||
removeLibrary((Library)editableObject);
|
||||
if (!removeLibrary((Library)editableObject)) return false;
|
||||
}
|
||||
else if (editableObject instanceof Artifact) {
|
||||
removeArtifact((Artifact)editableObject);
|
||||
@@ -416,8 +416,8 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i
|
||||
}
|
||||
|
||||
|
||||
protected void removeLibrary(Library library) {
|
||||
|
||||
protected boolean removeLibrary(Library library) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void removeFacetNodes(@NotNull List<Facet> facets) {
|
||||
|
||||
+16
@@ -417,6 +417,22 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
|
||||
}
|
||||
}
|
||||
|
||||
public void removeLibraryOrderEntry(final Module module, final Library library) {
|
||||
final ModuleEditor moduleEditor = myContext.myModulesConfigurator.getModuleEditor(module);
|
||||
LOG.assertTrue(moduleEditor != null, "Current module editor was not initialized");
|
||||
final ModifiableRootModel modelProxy = moduleEditor.getModifiableRootModelProxy();
|
||||
final OrderEntry[] entries = modelProxy.getOrderEntries();
|
||||
for (OrderEntry entry : entries) {
|
||||
if (entry instanceof LibraryOrderEntry && Comparing.strEqual(entry.getPresentableName(), library.getName())) {
|
||||
modelProxy.removeOrderEntry(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
myContext.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(myContext, module));
|
||||
myTree.repaint();
|
||||
}
|
||||
|
||||
public void addLibraryOrderEntry(final Module module, final Library library) {
|
||||
Component parent = WindowManager.getInstance().suggestParentWindow(module.getProject());
|
||||
|
||||
|
||||
@@ -678,12 +678,34 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom
|
||||
namedConfigurable.disposeUIResources();
|
||||
}
|
||||
|
||||
if (parentNode != null && idx != -1) {
|
||||
TreeUtil
|
||||
.selectInTree((DefaultMutableTreeNode)(idx < parentNode.getChildCount() ? parentNode.getChildAt(idx) : parentNode), true, myTree);
|
||||
}
|
||||
else {
|
||||
TreeUtil.selectFirstNode(myTree);
|
||||
if (paths.length > 0) {
|
||||
if (parentNode != null && idx != -1) {
|
||||
DefaultMutableTreeNode toSelect = null;
|
||||
if (idx < parentNode.getChildCount()) {
|
||||
toSelect = (DefaultMutableTreeNode) parentNode.getChildAt(idx);
|
||||
} else {
|
||||
if (idx > 0 && parentNode.getChildCount() > 0) {
|
||||
if (idx - 1 < parentNode.getChildCount()) {
|
||||
toSelect = (DefaultMutableTreeNode) parentNode.getChildAt(idx - 1);
|
||||
} else {
|
||||
toSelect = (DefaultMutableTreeNode) parentNode.getFirstChild();
|
||||
}
|
||||
} else {
|
||||
if (parentNode.isRoot() && myTree.isRootVisible()) {
|
||||
toSelect = parentNode;
|
||||
} else if (parentNode.getChildCount() > 0) {
|
||||
toSelect = (DefaultMutableTreeNode) parentNode.getFirstChild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toSelect != null) {
|
||||
TreeUtil.selectInTree(toSelect, true, myTree);
|
||||
}
|
||||
}
|
||||
else {
|
||||
TreeUtil.selectFirstNode(myTree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user