downloadable libraries: ui fixes

This commit is contained in:
nik
2011-07-07 14:38:38 +04:00
parent c89650cf7b
commit 41387d87d1
21 changed files with 116 additions and 95 deletions
@@ -345,7 +345,7 @@ public class LibraryOptionsPanel implements Disposable {
else {
path = PathUtil.getFileName(downloadPath);
}
return MessageFormat.format("{0} jar(s) will be downloaded into <b>{1}</b> directory <br>" +
return MessageFormat.format("{0} {0, choice, 1#jar|2#jars} will be downloaded into <b>{1}</b> directory<br>" +
"{2} library <b>{3}</b> will be created",
downloadSettings.getSelectedDownloads().size(),
path,
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.framework.library;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface FrameworkSupportWithLibrary {
@NotNull
CustomLibraryDescription createLibraryDescription();
boolean isLibraryOnly();
}
@@ -25,6 +25,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent;
import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorBase;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.vfs.VirtualFile;
@@ -54,7 +55,7 @@ public class DownloadableLibraryEditor extends LibraryPropertiesEditor {
myDescription = description;
myEditorComponent = editorComponent;
myLibraryType = libraryType;
myDescriptionLabel.setText(libraryType.getDescription(editorComponent.getProperties()));
updateDescription();
myCurrentVersionString = myEditorComponent.getProperties().getVersionString();
myChangeVersionButton.addActionListener(new ActionListener() {
@Override
@@ -64,6 +65,10 @@ public class DownloadableLibraryEditor extends LibraryPropertiesEditor {
});
}
private void updateDescription() {
myDescriptionLabel.setText(myLibraryType.getDescription(myEditorComponent.getProperties()));
}
private void changeVersion() {
final ModalityState current = ModalityState.current();
myDescription.fetchLibraryVersions(new DownloadableLibraryDescription.LibraryVersionsCallback() {
@@ -91,9 +96,11 @@ public class DownloadableLibraryEditor extends LibraryPropertiesEditor {
final NewLibraryEditor editor = settings.download(myMainPanel);
if (editor != null) {
myEditorComponent.getLibraryEditor().removeAllRoots();
editor.copyRoots(myEditorComponent.getLibraryEditor());
myEditorComponent.getLibraryEditor().setName(editor.getName());
editor.applyTo((LibraryEditorBase)myEditorComponent.getLibraryEditor());
myEditorComponent.updateRootsTree();
myCurrentVersionString = settings.getVersion().getVersionString();
updateDescription();
myModified = true;
}
}
@@ -130,5 +137,6 @@ public class DownloadableLibraryEditor extends LibraryPropertiesEditor {
@Override
public void reset() {
updateDescription();
}
}
@@ -17,7 +17,7 @@ package com.intellij.ide.util.frameworkSupport;
import com.intellij.framework.library.DownloadableLibraryDescription;
import com.intellij.framework.library.DownloadableLibraryType;
import com.intellij.openapi.roots.libraries.LibraryProperties;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.roots.libraries.LibraryType;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryFilter;
import com.intellij.openapi.vfs.VirtualFile;
@@ -30,6 +30,7 @@ import java.util.List;
* @author nik
*/
public class CustomLibraryDescriptionImpl extends CustomLibraryDescriptionBase {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.frameworkSupport.CustomLibraryDescriptionImpl");
private final DownloadableLibraryType myLibraryType;
public CustomLibraryDescriptionImpl(@NotNull DownloadableLibraryType downloadableLibraryType) {
@@ -58,4 +59,10 @@ public class CustomLibraryDescriptionImpl extends CustomLibraryDescriptionBase {
}
};
}
public static CustomLibraryDescriptionImpl createDescription(Class<? extends DownloadableLibraryType> typeClass) {
final DownloadableLibraryType libraryType = LibraryType.EP_NAME.findExtension(typeClass);
LOG.assertTrue(libraryType != null, typeClass);
return new CustomLibraryDescriptionImpl(libraryType);
}
}
@@ -1,46 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.util.frameworkSupport;
import com.intellij.framework.library.DownloadableLibraryType;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.roots.libraries.LibraryType;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public class FrameworkVersionWithLibrary extends FrameworkVersion {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.frameworkSupport.FrameworkVersionWithLibrary");
private CustomLibraryDescription myLibraryDescription;
public FrameworkVersionWithLibrary(@NotNull String versionName, boolean isDefault, CustomLibraryDescription libraryDescription) {
super(versionName, isDefault);
myLibraryDescription = libraryDescription;
}
public CustomLibraryDescription getLibraryDescription() {
return myLibraryDescription;
}
public static FrameworkVersionWithLibrary createVersion(Class<? extends DownloadableLibraryType> typeClass) {
final DownloadableLibraryType libraryType = LibraryType.EP_NAME.findExtension(typeClass);
LOG.assertTrue(libraryType != null, typeClass);
CustomLibraryDescription description = new CustomLibraryDescriptionImpl(libraryType);
return new FrameworkVersionWithLibrary("latest", true, description);
}
}
@@ -17,6 +17,7 @@ package com.intellij.ide.util.newProjectWizard;
import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings;
import com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel;
import com.intellij.framework.library.FrameworkSupportWithLibrary;
import com.intellij.ide.util.frameworkSupport.*;
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase;
import com.intellij.openapi.Disposable;
@@ -77,8 +78,9 @@ public class FrameworkSupportOptionsComponent {
final CustomLibraryDescription description = createLibraryDescription();
if (description != null) {
final boolean libraryOnly = myConfigurable instanceof FrameworkSupportWithLibrary && ((FrameworkSupportWithLibrary)myConfigurable).isLibraryOnly();
myLibraryOptionsPanel = new LibraryOptionsPanel(description, myModel.getBaseDirectoryForLibrariesPath(), myConfigurable.getSelectedVersion(),
container, !myConfigurable.isLibraryOnly());
container, !libraryOnly);
Disposer.register(myConfigurable, myLibraryOptionsPanel);
if (addSeparator) {
JComponent separator1 = SeparatorFactory.createSeparator("Libraries", null);
@@ -99,13 +101,12 @@ public class FrameworkSupportOptionsComponent {
@Nullable
private CustomLibraryDescription createLibraryDescription() {
List<? extends FrameworkVersion> versions = myConfigurable.getVersions();
if (versions.isEmpty()) return null;
if (versions.get(0) instanceof FrameworkVersionWithLibrary) {
return ((FrameworkVersionWithLibrary)versions.get(0)).getLibraryDescription();
if (myConfigurable instanceof FrameworkSupportWithLibrary) {
return ((FrameworkSupportWithLibrary)myConfigurable).createLibraryDescription();
}
List<? extends FrameworkVersion> versions = myConfigurable.getVersions();
if (versions.isEmpty()) return null;
return OldCustomLibraryDescription.createByVersions(versions);
}
@@ -3,7 +3,7 @@
<grid id="e9129" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="6" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="91" y="83" width="403" height="352"/>
<xy x="97" y="50" width="403" height="352"/>
</constraints>
<properties/>
<border type="none"/>
@@ -355,7 +355,8 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
final String tableLevel = table != null ? table.getTableLevel() : LibraryTableImplUtil.MODULE_LEVEL;
final LibraryTablePresentation presentation = LibraryEditingUtil.getLibraryTablePresentation(getProject(), tableLevel);
final LibraryTableModifiableModelProvider provider = getModifiableModelProvider(tableLevel);
EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(ClasspathPanelImpl.this, provider, library, myState.getProject(), presentation);
EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(ClasspathPanelImpl.this, provider, library, myState.getProject(),
presentation, getStructureConfigurableContext());
dialog.setContextModule(getRootModel().getModule());
dialog.show();
myEntryTable.repaint();
@@ -18,6 +18,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
import com.intellij.ide.ui.ListCellRendererWrapper;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.impl.libraries.LibraryTableBase;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
@@ -68,7 +69,7 @@ public class CreateNewLibraryDialog extends LibraryEditorDialogBase {
public Library createLibrary() {
final LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx)getTableModifiableModel();
final Library library = modifiableModel.createLibrary(myLibraryEditor.getName(), myLibraryEditor.getType());
final Library.ModifiableModel model = library.getModifiableModel();
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
myLibraryEditor.apply(model);
new WriteAction() {
protected void run(final Result result) {
@@ -21,8 +21,10 @@ import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
@@ -38,7 +40,9 @@ public class EditExistingLibraryDialog extends LibraryEditorDialogBase {
public static EditExistingLibraryDialog createDialog(Component parent,
LibraryTableModifiableModelProvider modelProvider,
Library library,
@Nullable Project project, LibraryTablePresentation presentation) {
@Nullable Project project,
LibraryTablePresentation presentation,
StructureConfigurableContext context) {
LibraryTable.ModifiableModel modifiableModel = modelProvider.getModifiableModel();
boolean commitChanges = false;
ExistingLibraryEditor libraryEditor;
@@ -49,7 +53,7 @@ public class EditExistingLibraryDialog extends LibraryEditorDialogBase {
libraryEditor = new ExistingLibraryEditor(library, null);
commitChanges = true;
}
return new EditExistingLibraryDialog(parent, modifiableModel, project, libraryEditor, commitChanges, presentation);
return new EditExistingLibraryDialog(parent, modifiableModel, project, libraryEditor, commitChanges, presentation, context);
}
private EditExistingLibraryDialog(Component parent,
@@ -57,15 +61,23 @@ public class EditExistingLibraryDialog extends LibraryEditorDialogBase {
@Nullable Project project,
ExistingLibraryEditor libraryEditor,
boolean commitChanges,
LibraryTablePresentation presentation) {
LibraryTablePresentation presentation, StructureConfigurableContext context) {
super(parent, new LibraryRootsComponent(project, libraryEditor));
setTitle(presentation.getLibraryTableEditorTitle());
setTitle("Configure " + presentation.getDisplayName(false));
myTableModifiableModel = tableModifiableModel;
myLibraryEditor = libraryEditor;
myCommitChanges = commitChanges;
if (commitChanges) {
Disposer.register(getDisposable(), libraryEditor);
}
context.addLibraryEditorListener(new LibraryEditorListener() {
@Override
public void libraryRenamed(@NotNull Library library, String oldName, String newName) {
if (library.equals(myLibraryEditor.getLibrary())) {
myNameField.setText(newName);
}
}
});
init();
}
@@ -71,6 +71,7 @@ public class ExistingLibraryEditor extends LibraryEditorBase implements Disposab
return myLibraryProperties;
}
@Override
public void setProperties(LibraryProperties properties) {
myLibraryProperties = properties;
}
@@ -16,6 +16,7 @@
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.LibraryProperties;
import java.util.ArrayList;
import java.util.Collection;
@@ -42,4 +43,6 @@ public abstract class LibraryEditorBase implements LibraryEditor {
}
protected abstract Collection<OrderRootType> getOrderRootTypes();
public abstract void setProperties(LibraryProperties properties);
}
@@ -33,7 +33,7 @@ import java.awt.*;
* @author nik
*/
public abstract class LibraryEditorDialogBase extends DialogWrapper {
private JTextField myNameField;
protected JTextField myNameField;
private LibraryRootsComponent myLibraryRootsComponent;
public LibraryEditorDialogBase(final Component parent, final LibraryRootsComponent libraryRootsComponent) {
@@ -116,7 +116,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
myDescriptor = new DefaultLibraryRootsComponentDescriptor();
}
init(new LibraryTreeStructure(this, myDescriptor));
updateProperties();
updatePropertiesLabel();
}
@NotNull
@@ -125,7 +125,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
return getLibraryEditor().getProperties();
}
private void updateProperties() {
public void updatePropertiesLabel() {
StringBuilder text = new StringBuilder();
for (String description : LibraryPresentationManager.getInstance().getDescriptions(getLibraryEditor().getFiles(OrderRootType.CLASSES))) {
if (text.length() > 0) {
@@ -343,7 +343,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
}
}
});
updateProperties();
updatePropertiesLabel();
myTreeBuilder.queueUpdate();
}
return filesToAttach;
@@ -383,7 +383,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
}
protected void librariesChanged(boolean putFocusIntoTree) {
updateProperties();
updatePropertiesLabel();
myTreeBuilder.queueUpdate();
if (putFocusIntoTree) {
myTree.requestFocus();
@@ -17,8 +17,8 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.impl.libraries.JarDirectories;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryProperties;
import com.intellij.openapi.roots.libraries.LibraryType;
import com.intellij.openapi.roots.ui.LightFilePointer;
@@ -69,6 +69,11 @@ public class NewLibraryEditor extends LibraryEditorBase {
return myProperties;
}
@Override
public void setProperties(LibraryProperties properties) {
myProperties = properties;
}
@Override
public String getName() {
return myLibraryName;
@@ -168,12 +173,13 @@ public class NewLibraryEditor extends LibraryEditorBase {
return false;
}
public void apply(@NotNull Library.ModifiableModel model) {
public void apply(@NotNull LibraryEx.ModifiableModelEx model) {
model.setName(myLibraryName);
applyRoots(model);
applyTo(model);
}
public void applyRoots(Library.ModifiableModel model) {
public void applyTo(LibraryEx.ModifiableModelEx model) {
model.setProperties(myProperties);
for (OrderRootType type : myRoots.keySet()) {
for (LightFilePointer pointer : myRoots.get(type)) {
model.addRoot(pointer.getUrl(), type);
@@ -186,7 +192,8 @@ public class NewLibraryEditor extends LibraryEditorBase {
}
}
public void copyRoots(LibraryEditor editor) {
public void applyTo(LibraryEditorBase editor) {
editor.setProperties(myProperties);
for (OrderRootType type : myRoots.keySet()) {
for (LightFilePointer pointer : myRoots.get(type)) {
editor.addRoot(pointer.getUrl(), type);
@@ -30,7 +30,10 @@ import com.intellij.openapi.roots.ui.configuration.artifacts.UsageInArtifact;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryEditingUtil;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.CreateNewLibraryAction;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.*;
import com.intellij.openapi.ui.*;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.ui.NonEmptyInputValidator;
import com.intellij.openapi.util.Comparing;
import com.intellij.util.ui.tree.TreeUtil;
import org.jetbrains.annotations.NonNls;
@@ -38,7 +38,9 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author nik
@@ -85,9 +87,8 @@ public class LibrariesContainerFactory {
LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx) table.getModifiableModel();
final String name = StringUtil.isEmpty(editor.getName()) ? null : getUniqueLibraryName(editor.getName(), modifiableModel);
Library library = modifiableModel.createLibrary(name, editor.getType());
final Library.ModifiableModel model = library.getModifiableModel();
editor.applyRoots(model);
((LibraryEx.ModifiableModelEx)model).setProperties(editor.getProperties());
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
editor.applyTo(model);
model.commit();
modifiableModel.commit();
return library;
@@ -273,7 +274,7 @@ public class LibrariesContainerFactory {
Library library = model.createLibrary(getUniqueLibraryName(libraryEditor.getName(), model), libraryEditor.getType());
ExistingLibraryEditor createdLibraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library);
createdLibraryEditor.setProperties(libraryEditor.getProperties());
libraryEditor.copyRoots(createdLibraryEditor);
libraryEditor.applyTo(createdLibraryEditor);
return library;
}
@@ -150,6 +150,7 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
private void resetProperties() {
if (myLibraryEditorComponent != null) {
myLibraryEditorComponent.updatePropertiesLabel();
myLibraryEditorComponent.resetProperties();
myPropertiesLoaded = true;
}
@@ -48,10 +48,6 @@ public abstract class FrameworkSupportConfigurable implements Disposable {
return Collections.emptyList();
}
public boolean isLibraryOnly() {
return false;
}
public void onFrameworkSelectionChanged(boolean selected) {
}
@@ -33,4 +33,5 @@ public abstract class DownloadableLibraryAssistant {
@NotNull
public abstract DownloadableLibraryDescription createLibraryDescription(@NotNull String groupId, @NotNull URL... localUrls);
}
@@ -15,12 +15,13 @@
*/
package org.jetbrains.plugins.groovy.config;
import com.intellij.framework.library.FrameworkSupportWithLibrary;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable;
import com.intellij.ide.util.frameworkSupport.FrameworkVersion;
import com.intellij.ide.util.frameworkSupport.FrameworkVersionWithLibrary;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -31,18 +32,11 @@ import java.util.List;
/**
* @author peter
*/
public class GroovySupportConfigurable extends FrameworkSupportConfigurable {
private FrameworkVersion myVersion;
public GroovySupportConfigurable() {
}
public class GroovySupportConfigurable extends FrameworkSupportConfigurable implements FrameworkSupportWithLibrary {
@NotNull
@Override
public FrameworkVersion getSelectedVersion() {
if (myVersion == null) {
myVersion = new FrameworkVersionWithLibrary("", true, new GroovyLibraryDescription());
}
return myVersion;
public CustomLibraryDescription createLibraryDescription() {
return new GroovyLibraryDescription();
}
@Override