mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-58921: Not disposed after using project wizard + framework support, download libs via maven
This commit is contained in:
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.intellij.facet.impl.ui.libraries;
|
||||
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryRootsComponent;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
@@ -39,9 +37,7 @@ public class EditLibraryDialog extends DialogWrapper {
|
||||
public EditLibraryDialog(Component parent, LibraryCompositionSettings settings) {
|
||||
super(parent, true);
|
||||
mySettings = settings;
|
||||
final Library library = settings.getOrCreateLibrary();
|
||||
|
||||
myLibraryRootsComponent = LibraryRootsComponent.createComponent(new ExistingLibraryEditor(library, null));
|
||||
myLibraryRootsComponent = LibraryRootsComponent.createComponent(settings.getOrCreateLibrary());
|
||||
|
||||
Disposer.register(getDisposable(), myLibraryRootsComponent);
|
||||
|
||||
|
||||
+12
-26
@@ -18,11 +18,10 @@ package com.intellij.facet.impl.ui.libraries;
|
||||
import com.intellij.facet.ui.libraries.LibraryDownloadInfo;
|
||||
import com.intellij.facet.ui.libraries.LibraryInfo;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.impl.libraries.ApplicationLibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
@@ -52,7 +51,7 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
private final Icon myIcon;
|
||||
private boolean myDownloadSources = true;
|
||||
private boolean myDownloadJavadocs = true;
|
||||
private Library myLibrary;
|
||||
private NewLibraryEditor myLibraryEditor;
|
||||
|
||||
public LibraryCompositionSettings(final @NotNull LibraryInfo[] libraryInfos,
|
||||
final @NotNull String defaultLibraryName,
|
||||
@@ -66,16 +65,10 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
}
|
||||
|
||||
public void addFilesToLibrary(VirtualFile[] files, OrderRootType orderRootType) {
|
||||
final Library.ModifiableModel modifiableModel = getOrCreateLibrary().getModifiableModel();
|
||||
final NewLibraryEditor libraryEditor = getOrCreateLibrary();
|
||||
for (VirtualFile file : files) {
|
||||
modifiableModel.addRoot(file, orderRootType);
|
||||
libraryEditor.addRoot(file, orderRootType);
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
modifiableModel.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -156,9 +149,8 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
|
||||
@Nullable
|
||||
private Library createLibrary(final ModifiableRootModel rootModel, @Nullable LibrariesContainer additionalContainer) {
|
||||
if (myLibrary != null) {
|
||||
VirtualFile[] roots = myLibrary.getFiles(OrderRootType.CLASSES);
|
||||
myLibrary.dispose();
|
||||
if (myLibraryEditor != null) {
|
||||
VirtualFile[] roots = myLibraryEditor.getFiles(OrderRootType.CLASSES);
|
||||
return LibrariesContainerFactory.createLibrary(additionalContainer, LibrariesContainerFactory.createContainer(rootModel),
|
||||
myLibraryName, myLibraryLevel, roots, VirtualFile.EMPTY_ARRAY);
|
||||
}
|
||||
@@ -217,25 +209,19 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Library getLibrary() {
|
||||
return myLibrary;
|
||||
public NewLibraryEditor getLibraryEditor() {
|
||||
return myLibraryEditor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Library getOrCreateLibrary() {
|
||||
if (myLibrary == null) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myLibrary = new ApplicationLibraryTable().createLibrary();
|
||||
}
|
||||
});
|
||||
public NewLibraryEditor getOrCreateLibrary() {
|
||||
if (myLibraryEditor == null) {
|
||||
myLibraryEditor = new NewLibraryEditor();
|
||||
}
|
||||
return myLibrary;
|
||||
return myLibraryEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
System.out.println("I'm disposed!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
@@ -93,7 +94,7 @@ public class LibraryOptionsPanel {
|
||||
showDialog(new DownloadingOptionsDialog(myConfigureButton, mySettings));
|
||||
break;
|
||||
case PICK_FILES:
|
||||
if (mySettings.getLibrary() == null) {
|
||||
if (mySettings.getLibraryEditor() == null) {
|
||||
VirtualFile[] files = showFileChooser();
|
||||
mySettings.addFilesToLibrary(files, OrderRootType.CLASSES);
|
||||
}
|
||||
@@ -175,8 +176,8 @@ public class LibraryOptionsPanel {
|
||||
mySettings.getLibraryName());
|
||||
break;
|
||||
case PICK_FILES:
|
||||
Library library = mySettings.getLibrary();
|
||||
if (library == null) {
|
||||
NewLibraryEditor libraryEditor = mySettings.getLibraryEditor();
|
||||
if (libraryEditor == null) {
|
||||
myMessage.setForeground(Color.red);
|
||||
message = "Press Configure button to add classes to the library";
|
||||
}
|
||||
@@ -185,7 +186,7 @@ public class LibraryOptionsPanel {
|
||||
" with {2} file(s) will be created",
|
||||
mySettings.getLibraryLevel(),
|
||||
mySettings.getLibraryName(),
|
||||
library.getFiles(OrderRootType.CLASSES).length);
|
||||
libraryEditor.getFiles(OrderRootType.CLASSES).length);
|
||||
}
|
||||
break;
|
||||
case DO_NOT_CREATE:
|
||||
|
||||
-2
@@ -77,8 +77,6 @@ public class CreateCustomLibraryAction extends DumbAwareAction {
|
||||
final LibraryOrderEntry orderEntry = rootModel.addLibraryEntry(library);
|
||||
myModuleStructureConfigurable.selectOrderEntry(myModule, orderEntry);
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<AnAction> getActions(StructureConfigurableContext context, ModuleStructureConfigurable moduleStructureConfigurable) {
|
||||
|
||||
+1
-4
@@ -102,7 +102,7 @@ public class LibraryRootsComponent implements Disposable {
|
||||
private final Map<DataKey, Object> myFileChooserUserData = new HashMap<DataKey, Object>();
|
||||
private final LibraryEditor myLibraryEditor;
|
||||
|
||||
private LibraryRootsComponent(Project project, LibraryEditor libraryEditor) {
|
||||
private LibraryRootsComponent(@Nullable Project project, @NotNull LibraryEditor libraryEditor) {
|
||||
myProject = project;
|
||||
myLibraryEditor = libraryEditor;
|
||||
updateProperties();
|
||||
@@ -122,9 +122,6 @@ public class LibraryRootsComponent implements Disposable {
|
||||
public static LibraryRootsComponent createComponent(final @Nullable Project project, @NotNull LibraryEditor libraryEditor) {
|
||||
LibraryRootsComponent rootsComponent = new LibraryRootsComponent(project, libraryEditor);
|
||||
rootsComponent.init(new LibraryTreeStructure(rootsComponent));
|
||||
if (project != null) {
|
||||
Disposer.register(project, rootsComponent);
|
||||
}
|
||||
return rootsComponent;
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -26,6 +26,7 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryRootsComponent;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -85,7 +86,10 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
|
||||
}
|
||||
|
||||
public void disposeUIResources() {
|
||||
myLibraryEditor = null;
|
||||
if (myLibraryEditor != null) {
|
||||
Disposer.dispose(myLibraryEditor);
|
||||
myLibraryEditor = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDisplayName(final String name) {
|
||||
|
||||
Reference in New Issue
Block a user