mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed creating project/global library without name
This commit is contained in:
+3
-2
@@ -25,6 +25,7 @@ import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.CreateNewLibraryDialog;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -61,13 +62,13 @@ class NewLibraryChooser implements ClasspathElementChooser<Library> {
|
||||
List<LibraryTable> tables = Arrays.asList(myRootModel.getModuleLibraryTable(),
|
||||
registrar.getLibraryTable(myProject),
|
||||
registrar.getLibraryTable());
|
||||
CreateNewLibraryDialog dialog = CreateNewLibraryDialog.createDialog(myParentComponent, myProject, tables, 1);
|
||||
CreateNewLibraryDialog dialog = new CreateNewLibraryDialog(myParentComponent, myContext, new NewLibraryEditor(), tables, 1);
|
||||
final Module contextModule = DataKeys.MODULE_CONTEXT.getData(DataManager.getInstance().getDataContext(myParentComponent));
|
||||
dialog.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, contextModule);
|
||||
dialog.show();
|
||||
myIsOk = dialog.isOK();
|
||||
if (myIsOk) {
|
||||
myChosenLibrary = dialog.createLibrary(myContext.getModifiableLibraryTable(dialog.getSelectedTable()));
|
||||
myChosenLibrary = dialog.createLibrary();
|
||||
}
|
||||
else {
|
||||
myChosenLibrary = null;
|
||||
|
||||
+2
-2
@@ -64,10 +64,10 @@ public class CreateCustomLibraryAction extends CustomLibraryActionBase {
|
||||
LibraryTablesRegistrar registrar = LibraryTablesRegistrar.getInstance();
|
||||
final Project project = myContext.getProject();
|
||||
final List<LibraryTable> tables = Arrays.asList(registrar.getLibraryTable(project), registrar.getLibraryTable());
|
||||
final CreateNewLibraryDialog dialog = new CreateNewLibraryDialog(myModuleStructureConfigurable.getTree(), project, libraryEditor, tables, 0);
|
||||
final CreateNewLibraryDialog dialog = new CreateNewLibraryDialog(myModuleStructureConfigurable.getTree(), myContext, libraryEditor, tables, 0);
|
||||
dialog.show();
|
||||
if (dialog.isOK()) {
|
||||
final Library library = dialog.createLibrary(myContext.getModifiableLibraryTable(dialog.getSelectedTable()));
|
||||
final Library library = dialog.createLibrary();
|
||||
final ModifiableRootModel rootModel = myContext.getModulesConfigurator().getOrCreateModuleEditor(myModule).getModifiableRootModelProxy();
|
||||
if (!askAndRemoveDuplicatedLibraryEntry(myCreator.getDescription(), rootModel)) {
|
||||
return;
|
||||
|
||||
+15
-13
@@ -17,13 +17,12 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -33,18 +32,14 @@ import java.util.List;
|
||||
* @author nik
|
||||
*/
|
||||
public class CreateNewLibraryDialog extends LibraryEditorDialogBase {
|
||||
private final StructureConfigurableContext myContext;
|
||||
private NewLibraryEditor myLibraryEditor;
|
||||
private ComboBox myLibraryLevelCombobox;
|
||||
|
||||
public static CreateNewLibraryDialog createDialog(JComponent parent, @Nullable Project project,
|
||||
@NotNull List<LibraryTable> libraryTables,
|
||||
int selectedTable) {
|
||||
return new CreateNewLibraryDialog(parent, project, new NewLibraryEditor(), libraryTables, selectedTable);
|
||||
}
|
||||
|
||||
public CreateNewLibraryDialog(@NotNull JComponent parent, @Nullable Project project, @NotNull NewLibraryEditor libraryEditor,
|
||||
public CreateNewLibraryDialog(@NotNull JComponent parent, @NotNull StructureConfigurableContext context, @NotNull NewLibraryEditor libraryEditor,
|
||||
@NotNull List<LibraryTable> libraryTables, int selectedTable) {
|
||||
super(parent, new LibraryRootsComponent(project, libraryEditor));
|
||||
super(parent, new LibraryRootsComponent(context.getProject(), libraryEditor));
|
||||
myContext = context;
|
||||
myLibraryEditor = libraryEditor;
|
||||
final DefaultComboBoxModel model = new DefaultComboBoxModel();
|
||||
for (LibraryTable table : libraryTables) {
|
||||
@@ -65,11 +60,14 @@ public class CreateNewLibraryDialog extends LibraryEditorDialogBase {
|
||||
init();
|
||||
}
|
||||
|
||||
public LibraryTable getSelectedTable() {
|
||||
return (LibraryTable)myLibraryLevelCombobox.getSelectedItem();
|
||||
@NotNull @Override
|
||||
protected LibraryTable.ModifiableModel getTableModifiableModel() {
|
||||
final LibraryTable selectedTable = (LibraryTable)myLibraryLevelCombobox.getSelectedItem();
|
||||
return myContext.getModifiableLibraryTable(selectedTable);
|
||||
}
|
||||
|
||||
public Library createLibrary(final @NotNull LibraryTable.ModifiableModel modifiableModel) {
|
||||
public Library createLibrary() {
|
||||
final LibraryTable.ModifiableModel modifiableModel = getTableModifiableModel();
|
||||
final Library library = modifiableModel.createLibrary(myLibraryEditor.getName());
|
||||
final Library.ModifiableModel model = library.getModifiableModel();
|
||||
myLibraryEditor.apply(model);
|
||||
@@ -85,4 +83,8 @@ public class CreateNewLibraryDialog extends LibraryEditorDialogBase {
|
||||
protected void addNorthComponents(FormBuilder formBuilder) {
|
||||
formBuilder.addLabeledComponent("Level:", myLibraryLevelCombobox);
|
||||
}
|
||||
|
||||
protected boolean shouldCheckName(String newName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -20,6 +20,7 @@ import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -79,4 +80,8 @@ public class EditExistingLibraryDialog extends LibraryEditorDialogBase {
|
||||
protected LibraryTable.ModifiableModel getTableModifiableModel() {
|
||||
return myTableModifiableModel;
|
||||
}
|
||||
|
||||
protected boolean shouldCheckName(String newName) {
|
||||
return !Comparing.equal(newName, getLibraryRootsComponent().getLibraryEditor().getName());
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -22,7 +22,6 @@ import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryEditingUtil;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -65,12 +64,11 @@ public abstract class LibraryEditorDialogBase extends DialogWrapper {
|
||||
}
|
||||
|
||||
protected boolean validateAndApply() {
|
||||
final String currentName = myLibraryRootsComponent.getLibraryEditor().getName();
|
||||
String newName = myNameField.getText().trim();
|
||||
if (newName.length() == 0) {
|
||||
newName = null;
|
||||
}
|
||||
if (!Comparing.equal(newName, currentName)) {
|
||||
if (shouldCheckName(newName)) {
|
||||
final LibraryTable.ModifiableModel tableModifiableModel = getTableModifiableModel();
|
||||
if (tableModifiableModel != null && !(tableModifiableModel instanceof ModuleLibraryTable)) {
|
||||
if (newName == null) {
|
||||
@@ -88,11 +86,17 @@ public abstract class LibraryEditorDialogBase extends DialogWrapper {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract boolean shouldCheckName(String newName);
|
||||
|
||||
@Nullable
|
||||
protected LibraryTable.ModifiableModel getTableModifiableModel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected LibraryRootsComponent getLibraryRootsComponent() {
|
||||
return myLibraryRootsComponent;
|
||||
}
|
||||
|
||||
protected JComponent createNorthPanel() {
|
||||
FormBuilder formBuilder = new FormBuilder();
|
||||
String currentName = myLibraryRootsComponent.getLibraryEditor().getName();
|
||||
|
||||
Reference in New Issue
Block a user