Merge branch 'master' of git@git.labs.intellij.net:idea/community
authorKirill Kalishev <kirill.kalishev@jetbrains.com>
Thu, 16 Sep 2010 10:10:40 +0000 (14:10 +0400)
committerKirill Kalishev <kirill.kalishev@jetbrains.com>
Thu, 16 Sep 2010 10:10:40 +0000 (14:10 +0400)
280 files changed:
images/src/META-INF/ImagesPlugin.xml
java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryElementType.java
java/compiler/openapi/src/com/intellij/packaging/ui/ArtifactEditorContext.java
java/debugger/impl/src/com/intellij/debugger/actions/KillProcessAction.java [deleted file]
java/debugger/impl/src/com/intellij/debugger/actions/ThreadDumpAction.java
java/debugger/impl/src/com/intellij/debugger/engine/evaluation/TextWithImportsImpl.java
java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java
java/debugger/impl/src/com/intellij/debugger/settings/DebuggerSettings.java
java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java
java/debugger/impl/src/com/intellij/debugger/ui/FramesPanel.java
java/debugger/impl/src/com/intellij/debugger/ui/impl/FramesList.java
java/debugger/impl/src/com/intellij/debugger/ui/impl/FramesListRenderer.java
java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/StackFrameDescriptorImpl.java
java/idea-ui/src/com/intellij/facet/impl/ui/libraries/EditLibraryDialog.java
java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java
java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryTableEditorForm.form
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryTableModifiableModelProvider.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddItemPopupAction.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryAction.java [moved from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChooseNamedLibraryAction.java with 51% similarity]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddSingleEntryModuleLibraryAction.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChooseAndAddAction.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathElementChooser.java [moved from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathElementChooserDialog.java with 92% similarity]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryDialog.java [deleted file]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateSingleEntryModuleLibraryChooser.java [moved from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChooseModuleLibrariesDialog.java with 67% similarity]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/AbstractLibraryTreeStructure.java [deleted file]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/EditExistingLibraryDialog.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ExistingLibraryEditor.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ItemElement.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditor.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryElement.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryElementDescriptor.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryFileChooser.java [deleted file]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsData.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableEditor.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableTreeContentElement.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableTreeStructure.java [deleted file]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTreeStructure.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java [deleted file]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/BaseLibrariesConfigurable.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/GlobalLibrariesConfigurable.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesContainerFactory.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesModifiableModel.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibraryConfigurable.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ProjectLibrariesConfigurable.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureConfigurableContext.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureLibraryTableModifiableModelProvider.java [new file with mode: 0644]
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/LibraryProjectStructureElement.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java
java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java
java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureUtil.java
java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDetector.java
java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java
java/java-tests/testData/codeInsight/softwrap/SoftWrapAdditionOnTyping.txt [new file with mode: 0644]
java/java-tests/testData/refactoring/changeSignatureGesture/AddParameterFinal.java [new file with mode: 0644]
java/java-tests/testData/refactoring/changeSignatureGesture/AddParameterFinal_after.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBlankLinesTest.java
java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterWrapTest.java
java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureGestureTest.java
platform/lang-api/src/com/intellij/openapi/roots/libraries/Library.java
platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java
platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java
platform/lang-api/src/com/intellij/refactoring/changeSignature/ChangeSignatureUsageProcessor.java
platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSpacesPanel.java
platform/lang-impl/src/com/intellij/application/options/codeStyle/OptionTableWithPreviewPanel.java
platform/lang-impl/src/com/intellij/application/options/codeStyle/WrappingAndBracesPanel.java
platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficProgressPanel.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java
platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java
platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java
platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java
platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java
platform/lang-impl/src/com/intellij/codeInspection/ex/SeverityEditorDialog.java
platform/lang-impl/src/com/intellij/execution/ExecutorRegistryImpl.java
platform/lang-impl/src/com/intellij/formatting/FormatConstants.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/formatting/alignment/AlignmentInColumnsConfig.java
platform/lang-impl/src/com/intellij/formatting/alignment/AlignmentInColumnsHelper.java
platform/lang-impl/src/com/intellij/ide/actions/CreateDirectoryOrPackageHandler.java
platform/lang-impl/src/com/intellij/ide/commander/ColoredCommanderRenderer.java
platform/lang-impl/src/com/intellij/ide/commander/CommanderPanel.java
platform/lang-impl/src/com/intellij/ide/util/FileStructureDialog.java
platform/lang-impl/src/com/intellij/openapi/components/impl/ModulePathMacroManager.java
platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java
platform/lang-impl/src/com/intellij/psi/formatter/FormatterUtil.java
platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java
platform/lang-impl/src/com/intellij/psi/impl/source/tree/TreeUtil.java
platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java
platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.form
platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java
platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java
platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java [moved from platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialog.java with 58% similarity]
platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesFromTablesDialog.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/util/ui/classpath/SimpleClasspathPanel.java
platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RevisionsList.java
platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java
platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java
platform/platform-api/src/com/intellij/ui/TableScrollingUtil.java
platform/platform-api/src/com/intellij/ui/components/JBList.java
platform/platform-api/src/com/intellij/ui/table/JBTable.java
platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java
platform/platform-api/src/com/intellij/util/ui/ComponentWithEmptyText.java
platform/platform-api/src/com/intellij/util/ui/StatusText.java
platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java
platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java
platform/platform-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java
platform/platform-impl/src/com/intellij/openapi/editor/actions/ConvertIndentsActionBase.java
platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/CachingSoftWrapDataMapper.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapAwareDocumentParsingListener.java
platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindow.form
platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindow.java
platform/platform-impl/src/com/intellij/ui/SpeedSearchBase.java
platform/platform-impl/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManagerTest.java [new file with mode: 0644]
platform/platform-resources-en/src/messages/ApplicationBundle.properties
platform/platform-resources-en/src/messages/ProjectBundle.properties
platform/platform-resources/src/META-INF/XmlActions.xml
platform/platform-resources/src/idea/Keymap_Default.xml
platform/platform-resources/src/idea/Keymap_Eclipse.xml
platform/platform-resources/src/idea/Keymap_Emacs.xml
platform/platform-resources/src/idea/Keymap_KDE.xml
platform/platform-resources/src/idea/Keymap_Mac.xml
platform/platform-resources/src/idea/Keymap_MacClassic.xml
platform/platform-resources/src/idea/Keymap_Netbeans.xml
platform/platform-resources/src/idea/Keymap_VisualStudio.xml
platform/platform-resources/src/idea/LangActions.xml
platform/platform-resources/src/idea/PlatformActions.xml
platform/platform-resources/src/idea/PlatformLangActionManager.xml
platform/util/src/com/intellij/util/ArrayUtil.java
platform/util/src/com/intellij/util/BufferedListConsumer.java
platform/util/src/com/intellij/util/containers/SLRUMap.java
platform/util/src/com/intellij/util/ui/UIUtil.java
platform/vcs-api/src/com/intellij/openapi/vcs/ReadonlyListsMerger.java
platform/vcs-api/src/com/intellij/openapi/vcs/Ring.java
platform/vcs-impl/src/com/intellij/openapi/vcs/BigArray.java [new file with mode: 0644]
platform/vcs-impl/src/com/intellij/openapi/vcs/StaticReadonlyList.java [new file with mode: 0644]
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesTreeBrowser.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesViewProvider.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java
platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java
platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointPropertiesPanel.form
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointPropertiesPanel.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsPanel.form
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointsPanel.java
plugins/InspectionGadgets/src/com/siyeh/ig/performance/ManualArrayCopyInspection.java
plugins/InspectionGadgets/src/com/siyeh/ig/performance/ManualArrayToCollectionCopyInspection.java
plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java
plugins/InspectionGadgets/src/com/siyeh/ig/serialization/SerializableHasSerialVersionUIDFieldInspection.java
plugins/InspectionGadgets/test/com/siyeh/igtest/performance/manual_array_copy/ManualArrayCopy.java
plugins/commander/src/com/intellij/ide/commander/Commander.java
plugins/git4idea/src/META-INF/plugin.xml
plugins/git4idea/src/git4idea/history/GitHistoryUtils.java
plugins/git4idea/src/git4idea/history/browser/GitCommit.java
plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java
plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java
plugins/git4idea/src/git4idea/history/browser/Portion.java
plugins/git4idea/src/git4idea/history/wholeTree/BigTableTableModel.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/CommitIdsHolder.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/FictiveAction.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/GitLogLongPanel.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/Join.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/LinesCache.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/LinesProxy.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/Loader.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/LoaderImpl.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/SkeletonBuilder.java
plugins/git4idea/src/git4idea/history/wholeTree/Speedometer.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/TreeComposite.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/TreeNavigation.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/TreeSkeleton.java
plugins/git4idea/src/git4idea/history/wholeTree/TreeSkeletonImpl.java
plugins/git4idea/src/git4idea/history/wholeTree/VisibleLine.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/wholeTree/WiresIndex.java [new file with mode: 0644]
plugins/git4idea/tests/git4idea/tests/CommitIdsTest.java [new file with mode: 0644]
plugins/git4idea/tests/git4idea/tests/SkeletonBuilderTest.java
plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties
plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyUnusedImportPass.java
plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java
plugins/groovy/src/org/jetbrains/plugins/groovy/config/AbstractGroovyLibraryManager.java
plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovySupportConfigurable.java
plugins/groovy/src/org/jetbrains/plugins/groovy/config/LibraryManager.java
plugins/groovy/src/org/jetbrains/plugins/groovy/config/ui/GroovyFacetEditor.java
plugins/groovy/src/org/jetbrains/plugins/groovy/config/ui/GroovyFacetTab.form [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/config/ui/GroovyFacetTab.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/config/ui/ManagedLibrariesEditor.form [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/config/ui/ManagedLibrariesEditor.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties
plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertClosureToMethodIntention.java
plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertMethodToClosureIntention.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionContributor.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/handlers/NamedArgumentInsertHandler.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyImportOptimizer.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/parsing/statements/typeDefinitions/typeDef/ClassDefinition.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrField.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrNamedArgumentSearchVisitor.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrReferenceExpression.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/members/GrMethod.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrAnnotationMethodImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrClosureSignatureUtil.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrFieldStub.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrMethodStub.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrEnumConstantElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrFieldElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrMethodElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrStubFileElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrFieldStubImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrMethodStubImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureUsageProcessor.java
plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertMethodToClosureTest.java
plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/TypesParsingTest.java
plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages.groovy [new file with mode: 0644]
plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureToMethodWithFieldUsages_after.groovy [new file with mode: 0644]
plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer.groovy [new file with mode: 0644]
plugins/groovy/testdata/intentions/convertMethodToClosure/MethodToClosureWithMemberPointer_after.groovy [new file with mode: 0644]
plugins/groovy/testdata/parsing/groovy/types/newlineBeforeClassBrace.test [new file with mode: 0644]
plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenUIModifiableModelsProvider.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectImportProvider.java
plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnAuthenticationTest.java
plugins/ui-designer/src/META-INF/plugin.xml
plugins/ui-designer/src/com/intellij/uiDesigner/wizard/FormPropertyTableCellRenderer.java
plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/intentions/ReplaceWithXslAttribute.java
resources-en/src/messages/DebuggerBundle.properties
resources/src/idea/IdeaActions.xml
resources/src/idea/JBuilderKeymap.xml
samples/conditionalOperatorConvertor/META-INF/plugin.xml
samples/conditionalOperatorConvertor/conditionalOperatorConvertor.iml
samples/conditionalOperatorConvertor/conditionalOperatorConvertor.ipr
samples/conditionalOperatorConvertor/source/com/intellij/codeInsight/intention/ConditionalOperatorConvertor.java
samples/conditionalOperatorConvertor/source/intentionDescriptions/ConditionalOperatorConvertor/after.java.template [moved from samples/conditionalOperatorConvertor/source/intentionDescriptions/Convert ternary operator to if statement/after.java.template with 100% similarity]
samples/conditionalOperatorConvertor/source/intentionDescriptions/ConditionalOperatorConvertor/before.java.template [moved from samples/conditionalOperatorConvertor/source/intentionDescriptions/Convert ternary operator to if statement/before.java.template with 100% similarity]
samples/conditionalOperatorConvertor/source/intentionDescriptions/ConditionalOperatorConvertor/description.html [new file with mode: 0644]
samples/conditionalOperatorConvertor/source/intentionDescriptions/Convert ternary operator to if statement/description.html [deleted file]
samples/conditionalOperatorConvertor/testData/before.template.after.java [new file with mode: 0644]
samples/conditionalOperatorConvertor/testData/before.template.java [new file with mode: 0644]
samples/conditionalOperatorConvertor/testSource/testPlugin/YourTest.java [new file with mode: 0644]
samples/conditionalOperatorConvertor/testSrc/com/intellij/codeInsight/ConditionalToIfTest.java [deleted file]
xml/dom-impl/src/com/intellij/util/xml/highlighting/DomHighlightingHelperImpl.java
xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java
xml/impl/src/com/intellij/codeInsight/completion/XmlCompletionContributor.java
xml/impl/src/com/intellij/codeInsight/completion/XmlSmartCompletionProvider.java [new file with mode: 0644]
xml/impl/src/com/intellij/codeInsight/completion/XmlTagInsertHandler.java
xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/URLReference.java
xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java
xml/impl/src/com/intellij/xml/actions/GenerateXmlTagAction.java [new file with mode: 0644]
xml/impl/src/com/intellij/xml/impl/XmlElementsGroupModel.java [new file with mode: 0644]
xml/impl/src/com/intellij/xml/impl/schema/ComplexTypeDescriptor.java
xml/impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java
xml/impl/src/com/intellij/xml/impl/schema/XmlElementsGroupBase.java
xml/impl/src/com/intellij/xml/impl/schema/XmlElementsGroupImpl.java
xml/impl/src/com/intellij/xml/impl/schema/XmlElementsGroupLeaf.java
xml/impl/src/com/intellij/xml/impl/schema/XmlElementsGroupProcessor.java [new file with mode: 0644]
xml/impl/src/com/intellij/xml/impl/schema/XmlSchemaTagsProcessor.java
xml/impl/src/com/intellij/xml/util/XmlUtil.java
xml/openapi/src/com/intellij/psi/xml/XmlTag.java
xml/openapi/src/com/intellij/xml/XmlElementDescriptor.java
xml/openapi/src/com/intellij/xml/XmlElementsGroup.java

index b6b12669da7faa586ab9c04e3d295f6f8680fb2e..8ff4e61b7beaffb75f1c15f834e129904059a113 100644 (file)
       <action class="org.intellij.images.editor.actions.ZoomOutAction"
               id="Images.Editor.ZoomOut"
               icon="/org/intellij/images/icons/ZoomOut.png"
-              text="Zoom Out">
-        <keyboard-shortcut first-keystroke="control SUBTRACT" keymap="$default"/>
-        <keyboard-shortcut first-keystroke="control MINUS" keymap="$default"/>
-      </action>
+              text="Zoom Out"
+              use-shortcut-of="CollapseAll"/>
       <action class="org.intellij.images.editor.actions.ActualSizeAction"
               id="Images.Editor.ActualSize"
               icon="/org/intellij/images/icons/ActualSize.png"
       <separator/>
       <action class="org.intellij.images.thumbnail.actions.HideThumbnailsAction"
               id="Images.Thumbnails.Hide"
-              icon="/actions/cancel.png">
-        <keyboard-shortcut first-keystroke="control F4" keymap="$default"/>
-      </action>
+              icon="/actions/cancel.png" use-shortcut-of="CloseContent"/>
     </group>
     <group id="Images.ThumbnailsPopupMenu">
       <reference id="CutCopyPasteGroup"/>
index b93546665a69b60d4db65bbfd23ab1cc2dee0559..33a691563521b00f2b7a7233102633e34573fde1 100644 (file)
@@ -55,7 +55,7 @@ public class LibraryElementType extends ComplexPackagingElementType<LibraryPacka
   @NotNull
   public List<? extends LibraryPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
                                                                   @NotNull CompositePackagingElement<?> parent) {
-    final List<Library> selected = context.chooseLibraries(getAllLibraries(context), ProjectBundle.message("dialog.title.packaging.choose.library"));
+    final List<Library> selected = context.chooseLibraries(ProjectBundle.message("dialog.title.packaging.choose.library"));
     final List<LibraryPackagingElement> elements = new ArrayList<LibraryPackagingElement>();
     for (Library library : selected) {
       elements.add(new LibraryPackagingElement(library.getTable().getTableLevel(), library.getName(), null));
index d5fe39d67bf4229cf7ce2e5cecfd96581d35d3b5..7ede5bedb2f992555943a5aac4b01353b07c4a37 100644 (file)
@@ -74,7 +74,7 @@ public interface ArtifactEditorContext extends PackagingElementResolvingContext
 
   List<Module> chooseModules(List<Module> modules, final String title);
 
-  List<Library> chooseLibraries(List<Library> libraries, String title);
+  List<Library> chooseLibraries(String title);
 
   Artifact getArtifact();
 }
diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/KillProcessAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/KillProcessAction.java
deleted file mode 100644 (file)
index acda5e3..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2000-2009 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.
- */
-
-/**
- * class ExportThreadsAction
- * @author Jeka
- */
-package com.intellij.debugger.actions;
-
-import com.intellij.debugger.DebuggerBundle;
-import com.intellij.debugger.impl.DebuggerContextImpl;
-import com.intellij.debugger.impl.DebuggerSession;
-import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.Presentation;
-import com.intellij.openapi.util.IconLoader;
-
-public class KillProcessAction extends AnAction {
-  public KillProcessAction() {
-    super(DebuggerBundle.message("action.kill.process.text"), DebuggerBundle.message("action.kill.process.description"), IconLoader.getIcon("/debugger/killProcess.png"));
-  }
-
-  public void actionPerformed(AnActionEvent e) {
-    final DebuggerContextImpl context = DebuggerAction.getDebuggerContext(e.getDataContext());
-    if (DebuggerContextImpl.EMPTY_CONTEXT.equals(context)) {
-      return;
-    }
-
-    final DebuggerSession session = context.getDebuggerSession();
-    if (session != null) {
-      session.getProcess().stop(true);
-    }
-  }
-
-  public void update(AnActionEvent event) {
-    Presentation presentation = event.getPresentation();
-    final DebuggerContextImpl context = DebuggerAction.getDebuggerContext(event.getDataContext());
-    if (DebuggerContextImpl.EMPTY_CONTEXT.equals(context)) {
-      presentation.setEnabled(false);
-      return;
-    }
-    DebuggerSession debuggerSession = context.getDebuggerSession();
-    presentation.setEnabled(debuggerSession != null && debuggerSession.isAttached());
-  }
-}
\ No newline at end of file
index cf181a9af1c9ee62f7b5f4ca44a360bb18eb5126..70e0413abaae6254318bce72751435109887608f 100644 (file)
@@ -16,7 +16,8 @@
 
 /**
  * class ExportThreadsAction
- * @author Jeka
+ * @author Eugene Zhuravlev
+ * @author Sascha Weinreuter
  */
 package com.intellij.debugger.actions;
 
@@ -38,7 +39,9 @@ import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.project.Project;
 import com.intellij.unscramble.ThreadDumpParser;
 import com.intellij.unscramble.ThreadState;
+import com.intellij.util.SmartList;
 import com.sun.jdi.*;
+import gnu.trove.TIntObjectHashMap;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -133,6 +136,9 @@ public class ThreadDumpAction extends AnAction implements AnAction.TransparentUp
         if (vmProxy.canGetOwnedMonitorInfo() && vmProxy.canGetMonitorInfo()) {
           List<ObjectReference> list = threadReference.ownedMonitors();
           for (ObjectReference reference : list) {
+            if (!vmProxy.canGetMonitorFrameInfo()) { // java 5 and earlier
+              buffer.append("\n\t ").append(renderLockedObject(reference));
+            }
             final List<ThreadReference> waiting = reference.waitingThreads();
             for (ThreadReference thread : waiting) {
               final String waitingThreadName = threadName(thread);
@@ -150,16 +156,37 @@ public class ThreadDumpAction extends AnAction implements AnAction.TransparentUp
               final String monitorOwningThreadName = threadName(waitedMonitorOwner);
               waitingMap.put(threadName, monitorOwningThreadName);
               buffer.append("\n\t ")
-                .append(DebuggerBundle.message("threads.export.attribute.label.waiting.for.thread", monitorOwningThreadName));
+                .append(DebuggerBundle.message("threads.export.attribute.label.waiting.for.thread", monitorOwningThreadName, renderObject(waitedMonitor)));
             }
           }
         }
 
         final List<StackFrame> frames = threadReference.frames();
         hasEmptyStack = frames.size() == 0;
-        for (StackFrame stackFrame : frames) {
+
+        final TIntObjectHashMap<List<ObjectReference>> lockedAt = new TIntObjectHashMap<List<ObjectReference>>();
+        if (vmProxy.canGetMonitorFrameInfo()) {
+          for (MonitorInfo info : threadReference.ownedMonitorsAndFrames()) {
+            final int stackDepth = info.stackDepth();
+            List<ObjectReference> monitors;
+            if ((monitors = lockedAt.get(stackDepth)) == null) {
+              lockedAt.put(stackDepth, monitors = new SmartList<ObjectReference>());
+            }
+            monitors.add(info.monitor());
+          }
+        }
+
+        for (int i = 0, framesSize = frames.size(); i < framesSize; i++) {
+          final StackFrame stackFrame = frames.get(i);
           final Location location = stackFrame.location();
           buffer.append("\n\t  ").append(renderLocation(location));
+
+          final List<ObjectReference> monitors = lockedAt.get(i);
+          if (monitors != null) {
+            for (ObjectReference monitor : monitors) {
+              buffer.append("\n\t  - ").append(renderLockedObject(monitor));
+            }
+          }
         }
       }
       catch (IncompatibleThreadStateException e) {
@@ -189,6 +216,14 @@ public class ThreadDumpAction extends AnAction implements AnAction.TransparentUp
     return result;
   }
 
+  private static String renderLockedObject(ObjectReference monitor) {
+    return DebuggerBundle.message("threads.export.attribute.label.locked", renderObject(monitor));
+  }
+
+  private static String renderObject(ObjectReference monitor) {
+    return DebuggerBundle.message("threads.export.attribute.label.object-id", Long.toHexString(monitor.uniqueID()), monitor.referenceType().name());
+  }
+
   private static String threadStatusToJavaThreadState(int status) {
     switch (status) {
       case ThreadReference.THREAD_STATUS_MONITOR:
@@ -262,4 +297,4 @@ public class ThreadDumpAction extends AnAction implements AnAction.TransparentUp
     DebuggerSession debuggerSession = (DebuggerManagerEx.getInstanceEx(project)).getContext().getDebuggerSession();
     presentation.setEnabled(debuggerSession != null);
   }
-}
\ No newline at end of file
+}
index 321efab2f5a9ee0e75e271808990ca1334a4584c..87ee0491bfbe2c948a0c0cde0eebc523b7b45131 100644 (file)
@@ -92,9 +92,9 @@ public class TextWithImportsImpl implements TextWithImports{
   }
 
   public String toString() {
-    return getText();
+    return "".equals(myImports) ? myText : myText + DebuggerEditorImpl.SEPARATOR + myImports;
   }
-
+  
   public int hashCode() {
     return myText.hashCode();
   }
index 42ba1f06407bfcd96c6c1d4bbcd2d40ad54ebc87..60215e2b7da4594701526ca8d35f416092768293 100644 (file)
@@ -354,6 +354,15 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy {
     return myGetOwnedMonitorInfo.isAvailable();
   }
 
+  private final Capability myGetMonitorFrameInfo = new Capability() {
+    protected boolean calcValue() {
+      return myVirtualMachine.canGetMonitorFrameInfo();
+    }
+  };
+  public boolean canGetMonitorFrameInfo() {
+      return myGetMonitorFrameInfo.isAvailable();
+  }
+  
   private final Capability myGetCurrentContendedMonitor = new Capability() {
     protected boolean calcValue() {
       return myVirtualMachine.canGetCurrentContendedMonitor();
index a731f69c5199b2962cb6a1bc043514039e9bc10f..a2adb38219ebd3677fe38cb604b73722be920051 100644 (file)
@@ -67,6 +67,7 @@ public class DebuggerSettings implements JDOMExternalizable, ApplicationComponen
 
   public volatile boolean WATCH_RETURN_VALUES = false;
   public volatile boolean AUTO_VARIABLES_MODE = false;
+  public volatile boolean SHOW_LIBRARY_STACKFRAMES = true;
 
 
   private ClassFilter[] mySteppingFilters = ClassFilter.EMPTY_ARRAY;
index 152176247a7755204b9eb9a7b80bd5b318d751d8..03ca33faf10d94c061143b7ec01c5ac3efeff254 100644 (file)
@@ -76,6 +76,7 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos
   private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.DebuggerSessionTab");
 
   private static final Icon WATCH_RETURN_VALUES_ICON = IconLoader.getIcon("/debugger/watchLastReturnValue.png");
+  private static final Icon FILTER_STACK_FRAMES_ICON = IconLoader.getIcon("/debugger/class_filter.png");
   private static final Icon AUTO_VARS_ICONS = IconLoader.getIcon("/debugger/autoVariablesMode.png");
 
   private final VariablesPanel myVariablesPanel;
@@ -178,6 +179,7 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos
     CommonActionsManager actionsManager = CommonActionsManager.getInstance();
     framesGroup.add(actionsManager.createPrevOccurenceAction(myFramesPanel.getOccurenceNavigator()));
     framesGroup.add(actionsManager.createNextOccurenceAction(myFramesPanel.getOccurenceNavigator()));
+    framesGroup.add(new ShowLibraryFramesAction());
 
     framesContent.setActions(framesGroup, ActionPlaces.DEBUGGER_TOOLBAR, myFramesPanel.getFramesList());
     myUi.addContent(framesContent, 0, PlaceInGrid.left, false);
@@ -591,6 +593,34 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos
     }
   }
 
+  private class ShowLibraryFramesAction extends ToggleAction {
+    private volatile boolean myShouldShow;
+    private static final String ourTextWhenShowIsOn = "Hide Frames from Libraries";
+    private static final String ourTextWhenShowIsOff = "Show All Frames";
+
+    public ShowLibraryFramesAction() {
+      super("", "", FILTER_STACK_FRAMES_ICON);
+      myShouldShow = DebuggerSettings.getInstance().SHOW_LIBRARY_STACKFRAMES;
+    }
+
+    public void update(final AnActionEvent e) {
+      super.update(e);
+      final Presentation presentation = e.getPresentation();
+      final boolean shouldShow = !(Boolean)presentation.getClientProperty(SELECTED_PROPERTY);
+      presentation.setText(shouldShow ? ourTextWhenShowIsOn : ourTextWhenShowIsOff);
+    }
+
+    public boolean isSelected(AnActionEvent e) {
+      return !myShouldShow;
+    }
+
+    public void setSelected(AnActionEvent e, boolean enabled) {
+      myShouldShow = !enabled;
+      DebuggerSettings.getInstance().SHOW_LIBRARY_STACKFRAMES = myShouldShow;
+      myFramesPanel.setShowLibraryFrames(myShouldShow);
+    }
+  }
+
   private class WatchLastMethodReturnValueAction extends ToggleAction {
     private volatile boolean myWatchesReturnValues;
     private final String myTextEnable;
index b05540efb1d1f348aa3b98bc53e7a56b390c78d8..6dbd6353983794a2f1ee1f8da7cd49f51ccf0e9a 100644 (file)
@@ -33,6 +33,7 @@ import com.intellij.debugger.impl.DebuggerSession;
 import com.intellij.debugger.impl.DebuggerStateManager;
 import com.intellij.debugger.jdi.StackFrameProxyImpl;
 import com.intellij.debugger.jdi.ThreadReferenceProxyImpl;
+import com.intellij.debugger.settings.DebuggerSettings;
 import com.intellij.debugger.ui.impl.DebuggerComboBoxRenderer;
 import com.intellij.debugger.ui.impl.FramesList;
 import com.intellij.debugger.ui.impl.UpdatableDebuggerView;
@@ -69,7 +70,8 @@ public class FramesPanel extends UpdatableDebuggerView {
   private final ThreadsListener myThreadsListener;
   private final FramesListener myFramesListener;
   private final DebuggerStateManager myStateManager;
-
+  private boolean myShowLibraryFrames = DebuggerSettings.getInstance().SHOW_LIBRARY_STACKFRAMES;
+  
   public FramesPanel(Project project, DebuggerStateManager stateManager) {
     super(project, stateManager);
     myStateManager = stateManager;
@@ -183,6 +185,26 @@ public class FramesPanel extends UpdatableDebuggerView {
     }
   }
 
+  public boolean isShowLibraryFrames() {
+    return myShowLibraryFrames;
+  }
+
+  public void setShowLibraryFrames(boolean showLibraryFrames) {
+    if (myShowLibraryFrames != showLibraryFrames) {
+      myShowLibraryFrames = showLibraryFrames;
+      rebuild(DebuggerSession.EVENT_CONTEXT);
+    }
+
+  }
+
+  public long getFramesLastUpdateTime() {
+    return myFramesLastUpdateTime;
+  }
+
+  public void setFramesLastUpdateTime(long framesLastUpdateTime) {
+    myFramesLastUpdateTime = framesLastUpdateTime;
+  }
+
   private class RefreshFramePanelCommand extends DebuggerContextCommandImpl {
     private final boolean myRefreshOnly;
     private final ThreadDescriptorImpl[] myThreadDescriptorsToUpdate;
@@ -428,10 +450,20 @@ public class FramesPanel extends UpdatableDebuggerView {
       final MethodsTracker tracker = new MethodsTracker();
       final int totalFramesCount = frames.size();
       int index = 0;
-      final long timestamp = System.nanoTime();
+      final IndexCounter indexCounter = new IndexCounter(totalFramesCount);
+      final long timestamp = Math.abs(System.nanoTime());
       for (StackFrameProxyImpl stackFrameProxy : frames) {
         managerThread.schedule(
-          new AppendFrameCommand(getSuspendContext(), stackFrameProxy, evaluationContext, tracker, index++, stackFrameProxy.equals(contextFrame), totalFramesCount, timestamp)
+          new AppendFrameCommand(
+            getSuspendContext(), 
+            stackFrameProxy, 
+            evaluationContext, 
+            tracker, 
+            index++, 
+            stackFrameProxy.equals(contextFrame),
+            timestamp, 
+            indexCounter
+          )
         );
       }
     }
@@ -471,6 +503,28 @@ public class FramesPanel extends UpdatableDebuggerView {
     }
   }
 
+  private static class IndexCounter {
+    private final int[] myData;
+
+    private IndexCounter(int totalSize) {
+      myData = new int[totalSize];
+      for (int idx = 0; idx < totalSize; idx++) {
+        myData[idx] = 0;
+      }
+    }
+    
+    public void markCalculated(int idx){
+      myData[idx] = 1;
+    }
+    
+    public int getActualIndex(final int index) {
+      int result = 0;
+      for (int idx = 0; idx < index; idx++) {
+        result += myData[idx];
+      }
+      return result;
+    }
+  }
   
   private volatile long myFramesLastUpdateTime = 0L;
   private class AppendFrameCommand extends SuspendContextCommandImpl {
@@ -479,20 +533,19 @@ public class FramesPanel extends UpdatableDebuggerView {
     private final MethodsTracker myTracker;
     private final int myIndexToInsert;
     private final boolean myIsContextFrame;
-    private final int myTotalFramesCount;
     private final long myTimestamp;
+    private final IndexCounter myCounter;
 
     public AppendFrameCommand(SuspendContextImpl suspendContext, StackFrameProxyImpl frame, EvaluationContextImpl evaluationContext,
-                              MethodsTracker tracker, int indexToInsert, final boolean isContextFrame, final int totalFramesCount,
-                              final long timestamp) {
+                              MethodsTracker tracker, int indexToInsert, final boolean isContextFrame, final long timestamp, IndexCounter counter) {
       super(suspendContext);
       myFrame = frame;
       myEvaluationContext = evaluationContext;
       myTracker = tracker;
       myIndexToInsert = indexToInsert;
       myIsContextFrame = isContextFrame;
-      myTotalFramesCount = totalFramesCount;
       myTimestamp = timestamp;
+      myCounter = counter;
     }
 
     public void contextAction() throws Exception {
@@ -509,22 +562,18 @@ public class FramesPanel extends UpdatableDebuggerView {
               if (model.isEmpty() || myFramesLastUpdateTime < myTimestamp) {
                 myFramesLastUpdateTime = myTimestamp;
                 model.clear();
-                for (int idx = 0; idx < myTotalFramesCount; idx++) {
-                  final String label = "<frame " + idx + ">";
-                  model.addElement(new Object() {
-                    public String toString() {
-                      return label;
-                    }
-                  });
-                }
               }
               if (myTimestamp != myFramesLastUpdateTime) {
                 return;  // the command has expired
               }
-              model.removeElementAt(myIndexToInsert); // remove placeholder
-              model.insertElementAt(descriptor, myIndexToInsert);
-              if (myIsContextFrame) {
-                myFramesList.setSelectedIndex(myIndexToInsert);
+              final boolean shouldHide = !myShowLibraryFrames && !myIsContextFrame && myIndexToInsert != 0 && (descriptor.isSynthetic() || descriptor.isInLibraryContent());
+              if (!shouldHide) {
+                myCounter.markCalculated(myIndexToInsert);
+                final int actualIndex = myCounter.getActualIndex(myIndexToInsert);
+                model.insertElementAt(descriptor, actualIndex);
+                if (myIsContextFrame) {
+                  myFramesList.setSelectedIndex(actualIndex);
+                }
               }
             }
           }
index c279b01e7e108c0ebe11e2e59a1f13cccb1f5b87..9967b70eb4854b6d98bb411019c2d66d100a3506 100644 (file)
@@ -31,7 +31,7 @@ public class FramesList extends DebuggerFramesList {
   private volatile Method mySelectedMethod = null;
 
   public FramesList(Project project) {
-    super(null);
+    super(project);
     doInit();
   }
 
index 7af0e0f32f16da965b44499d4505116fcee20934..c8286431349c24368fbe09fbca834224ba50be4a 100644 (file)
  */
 package com.intellij.debugger.ui.impl;
 
-import com.intellij.debugger.SourcePosition;
 import com.intellij.debugger.ui.impl.watch.StackFrameDescriptorImpl;
-import com.intellij.debugger.ui.tree.StackFrameDescriptor;
 import com.intellij.debugger.ui.tree.ValueMarkup;
 import com.intellij.openapi.editor.colors.EditorColorsManager;
 import com.intellij.openapi.editor.colors.EditorColorsScheme;
-import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.ui.ColoredListCellRenderer;
-import com.intellij.ui.FileColorManager;
 import com.intellij.ui.SimpleTextAttributes;
 import com.intellij.util.StringBuilderSpinAllocator;
 import com.intellij.util.ui.UIUtil;
@@ -32,6 +28,7 @@ import com.intellij.xdebugger.ui.DebuggerColors;
 import com.sun.jdi.Method;
 
 import javax.swing.*;
+import javax.swing.border.MatteBorder;
 import java.awt.*;
 
 class FramesListRenderer extends ColoredListCellRenderer {
@@ -57,6 +54,17 @@ class FramesListRenderer extends ColoredListCellRenderer {
         append("["+ markup.getText() + "] ", new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, markup.getColor()));
       }
 
+      boolean needSeparator = false;
+      if (index > 0) {
+        final int currentFrameIndex = descriptor.getUiIndex();
+        final Object elementAt = list.getModel().getElementAt(index - 1);
+        if (elementAt instanceof StackFrameDescriptorImpl) {
+          StackFrameDescriptorImpl previousDescriptor = (StackFrameDescriptorImpl)elementAt;
+          final int previousFrameIndex = previousDescriptor.getUiIndex();
+          needSeparator = (currentFrameIndex - previousFrameIndex != 1);
+        }
+      }
+
       if (selected) {
         setBackground(UIUtil.getListSelectionBackground());
       }
@@ -67,6 +75,14 @@ class FramesListRenderer extends ColoredListCellRenderer {
         setBackground(bg);
       }
 
+      if (needSeparator) {
+        final MatteBorder border = BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY);
+        setBorder(border);
+      }
+      else {
+        setBorder(null);
+      }
+      
       final String label = descriptor.getLabel();
       final int openingBrace = label.indexOf("{");
       final int closingBrace = (openingBrace < 0) ? -1 : label.indexOf("}");
index b67b98f780e0849219112e4dfb36914671aab9ed..f20191aecf049ac8300a8538cfcd79166a83eaa6 100644 (file)
@@ -48,6 +48,7 @@ import java.util.Map;
  */
 public class StackFrameDescriptorImpl extends NodeDescriptorImpl implements StackFrameDescriptor{
   private final StackFrameProxyImpl myFrame;
+  private int myUiIndex;
   private String myName = null;
   private Location myLocation;
   private MethodsTracker.MethodOccurrence myMethodOccurrence;
@@ -62,6 +63,7 @@ public class StackFrameDescriptorImpl extends NodeDescriptorImpl implements Stac
   public StackFrameDescriptorImpl(StackFrameProxyImpl frame, final MethodsTracker tracker) {
     myFrame = frame;
     try {
+      myUiIndex = frame.getFrameIndex();
       myLocation = frame.location();
       myThisObject = frame.thisObject();
       myMethodOccurrence = tracker.getMethodOccurrence(myLocation.method());
@@ -98,6 +100,10 @@ public class StackFrameDescriptorImpl extends NodeDescriptorImpl implements Stac
     }
   }
 
+  public int getUiIndex() {
+    return myUiIndex;
+  }
+
   public StackFrameProxyImpl getFrameProxy() {
     return myFrame;
   }
index 33f61e2cb61e8e00f9edf70741d76d7757203ce9..3e8373fd6c0c1b0cac7cd26dd282461c91d98266 100644 (file)
@@ -16,9 +16,7 @@
 package com.intellij.facet.impl.ui.libraries;
 
 import com.intellij.openapi.roots.libraries.Library;
-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.libraryEditor.ExistingLibraryEditor;
 import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.util.Disposer;
@@ -43,28 +41,7 @@ public class EditLibraryDialog extends DialogWrapper {
     mySettings = settings;
     final Library library = settings.getOrCreateLibrary();
 
-    myLibraryTableEditor = LibraryTableEditor.editLibrary(new LibraryTableModifiableModelProvider() {
-
-      @Override
-      public LibraryTable.ModifiableModel getModifiableModel() {
-        return library.getTable().getModifiableModel();
-      }
-
-      @Override
-      public String getTableLevel() {
-        return library.getTable().getTableLevel();
-      }
-
-      @Override
-      public LibraryTablePresentation getLibraryTablePresentation() {
-        return library.getTable().getPresentation();
-      }
-
-      @Override
-      public boolean isLibraryTableEditable() {
-        return false;
-      }
-    }, library);
+    myLibraryTableEditor = LibraryTableEditor.editLibrary(new ExistingLibraryEditor(library, null));
 
     Disposer.register(getDisposable(), myLibraryTableEditor);
 
index 12381bc1682d596211eac576c8002378500946c9..33bf8a57ae562e7250d24c6180939a81d601ba69 100644 (file)
@@ -25,7 +25,6 @@ import com.intellij.openapi.roots.impl.libraries.ApplicationLibraryTable;
 import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory;
-import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.containers.ContainerUtil;
@@ -66,6 +65,19 @@ public class LibraryCompositionSettings implements Disposable {
     myIcon = icon;
   }
 
+  public void addFilesToLibrary(VirtualFile[] files, OrderRootType orderRootType) {
+    final Library.ModifiableModel modifiableModel = getOrCreateLibrary().getModifiableModel();
+    for (VirtualFile file : files) {
+      modifiableModel.addRoot(file, orderRootType);
+    }
+    ApplicationManager.getApplication().runWriteAction(new Runnable() {
+      @Override
+      public void run() {
+        modifiableModel.commit();
+      }
+    });
+  }
+
   @NotNull
   public LibraryInfo[] getLibraryInfos() {
     return myLibraryInfos;
@@ -134,16 +146,19 @@ public class LibraryCompositionSettings implements Disposable {
           if (files.length != downloadingInfos.length) {
             return false;
           }
+          addFilesToLibrary(files, OrderRootType.CLASSES);
         }
       }
     }
     return true;
   }
 
+
   @Nullable
   private Library createLibrary(final ModifiableRootModel rootModel, @Nullable LibrariesContainer additionalContainer) {
     if (myLibrary != null) {
       VirtualFile[] roots = myLibrary.getFiles(OrderRootType.CLASSES);
+      myLibrary.dispose();
       return LibrariesContainerFactory.createLibrary(additionalContainer, LibrariesContainerFactory.createContainer(rootModel),
                                                      myLibraryName, myLibraryLevel, roots, VirtualFile.EMPTY_ARRAY);
     }
@@ -213,7 +228,6 @@ public class LibraryCompositionSettings implements Disposable {
         @Override
         public void run() {
           myLibrary = new ApplicationLibraryTable().createLibrary();
-          Disposer.register(LibraryCompositionSettings.this, myLibrary);
         }
       });
     }
@@ -222,5 +236,6 @@ public class LibraryCompositionSettings implements Disposable {
 
   @Override
   public void dispose() {
+    System.out.println("I'm disposed!");
   }
 }
index deff8392b7467c633e14290b823f51902fdcc80c..a74bf9bd9806cbb7029ededf63e520403cd83d9a 100644 (file)
@@ -18,7 +18,6 @@ package com.intellij.facet.impl.ui.libraries;
 import com.intellij.facet.ui.libraries.LibraryInfo;
 import com.intellij.ide.IdeBundle;
 import com.intellij.ide.util.ElementsChooser;
-import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.fileChooser.FileChooser;
 import com.intellij.openapi.fileChooser.FileChooserDescriptor;
 import com.intellij.openapi.roots.OrderRootType;
@@ -96,16 +95,7 @@ public class LibraryOptionsPanel {
           case PICK_FILES:
             if (mySettings.getLibrary() == null) {
               VirtualFile[] files = showFileChooser();
-              final Library.ModifiableModel modifiableModel = mySettings.getOrCreateLibrary().getModifiableModel();
-              for (VirtualFile file : files) {
-                modifiableModel.addRoot(file, OrderRootType.CLASSES);
-              }
-              ApplicationManager.getApplication().runWriteAction(new Runnable() {
-                @Override
-                public void run() {
-                  modifiableModel.commit();
-                }
-              });
+              mySettings.addFilesToLibrary(files, OrderRootType.CLASSES);
             }
             EditLibraryDialog dialog = new EditLibraryDialog(myConfigureButton, mySettings);
             showDialog(dialog);
index 0ed59096fb3ab11548a84f2f1991269948dcd425..a3a2d35e1d02ae6d04b55d7a5f7209a9c3804c39 100644 (file)
@@ -8,7 +8,7 @@
     <properties/>
     <border type="none"/>
     <children>
-      <grid id="1f4da" layout-manager="GridLayoutManager" row-count="11" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="6">
+      <grid id="1f4da" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="6">
         <margin top="0" left="0" bottom="0" right="0"/>
         <constraints>
           <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
         <properties/>
         <border type="none"/>
         <children>
-          <component id="9f375" class="javax.swing.JButton" binding="myAddLibraryButton">
-            <constraints>
-              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
-            </constraints>
-            <properties>
-              <text resource-bundle="messages/ProjectBundle" key="module.libraries.add.button"/>
-            </properties>
-          </component>
           <component id="f673d" class="javax.swing.JButton" binding="myAttachClassesButton">
             <constraints>
-              <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <text resource-bundle="messages/ProjectBundle" key="module.libraries.attach.classes.button"/>
           </component>
           <vspacer id="3da7">
             <constraints>
-              <grid row="10" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+              <grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
             </constraints>
           </vspacer>
           <component id="86446" class="javax.swing.JButton" binding="myAttachSourcesButton">
             <constraints>
-              <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+              <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <text resource-bundle="messages/ProjectBundle" key="module.libraries.attach.sources.button"/>
@@ -47,7 +39,7 @@
           </component>
           <component id="733a5" class="javax.swing.JButton" binding="myAttachJavadocsButton">
             <constraints>
-              <grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+              <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <text resource-bundle="messages/ProjectBundle" key="module.libraries.javadoc.attach.button"/>
@@ -55,7 +47,7 @@
           </component>
           <component id="56f78" class="javax.swing.JButton" binding="myRemoveButton">
             <constraints>
-              <grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+              <grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <text resource-bundle="messages/ProjectBundle" key="library.detach.action"/>
           </component>
           <component id="47ce1" class="javax.swing.JButton" binding="myAttachUrlJavadocsButton">
             <constraints>
-              <grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+              <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <text resource-bundle="messages/ProjectBundle" key="module.libraries.javadoc.url.button"/>
             </properties>
           </component>
-          <component id="16495" class="javax.swing.JButton" binding="myRenameLibraryButton">
-            <constraints>
-              <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
-            </constraints>
-            <properties>
-              <text resource-bundle="messages/ProjectBundle" key="module.libraries.rename.button"/>
-            </properties>
-          </component>
           <component id="3a1fb" class="javax.swing.JButton" binding="myAttachJarDirectoriesButton">
             <constraints>
-              <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+              <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <text resource-bundle="messages/ProjectBundle" key="module.libraries.attach.jar.directories.button"/>
@@ -87,7 +71,7 @@
           </component>
           <component id="79b4b" class="javax.swing.JButton" binding="myAttachAnnotationsButton" default-binding="true">
             <constraints>
-              <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+              <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <text resource-bundle="messages/ProjectBundle" key="attach.annotations.button"/>
@@ -95,7 +79,7 @@
           </component>
           <component id="1134d" class="javax.swing.JButton" binding="myAttachMoreButton" default-binding="true">
             <constraints>
-              <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+              <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <text resource-bundle="messages/ProjectBundle" key="module.libraries.attach.more.button"/>
index a6f7561050ccebad11d10abaf595fcd53403b2cc..988ae306beb26297c9622b3bf677e06524bce7ff 100644 (file)
 package com.intellij.openapi.roots.ui.configuration;
 
 import com.intellij.openapi.roots.libraries.LibraryTable;
-import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
 
 public interface LibraryTableModifiableModelProvider {
 
   LibraryTable.ModifiableModel getModifiableModel();
 
-  String getTableLevel();
-
-  LibraryTablePresentation getLibraryTablePresentation();
-
-  boolean isLibraryTableEditable();
 }
index fe641f733c88e363309422e18fa7e259b02822e7..8af238b834d503c57981143757a5a00898bd2c76 100644 (file)
@@ -409,7 +409,7 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
     }
   }
 
-  private class LibraryTableInvocationHandler implements InvocationHandler {
+  private class LibraryTableInvocationHandler implements InvocationHandler, ProxyDelegateAccessor {
     private final LibraryTable myDelegateTable;
     @NonNls private final Set<String> myCheckedNames = new HashSet<String>(Arrays.asList("removeLibrary" /*,"createLibrary"*/));
 
@@ -450,6 +450,10 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
       }
     }
 
+    @Override
+    public Object getDelegate() {
+      return myDelegateTable;
+    }
   }
 
   private class LibraryInvocationHandler implements InvocationHandler, ProxyDelegateAccessor {
@@ -478,7 +482,7 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
     }
   }
 
-  private class LibraryModifiableModelInvocationHandler implements InvocationHandler {
+  private class LibraryModifiableModelInvocationHandler implements InvocationHandler, ProxyDelegateAccessor {
     private final Library.ModifiableModel myDelegateModel;
 
     LibraryModifiableModelInvocationHandler(Library.ModifiableModel delegateModel) {
@@ -499,9 +503,14 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
         }
       }
     }
+
+    @Override
+    public Object getDelegate() {
+      return myDelegateModel;
+    }
   }
 
-  private class LibraryTableModelInvocationHandler implements InvocationHandler {
+  private class LibraryTableModelInvocationHandler implements InvocationHandler, ProxyDelegateAccessor {
     private final LibraryTable.ModifiableModel myDelegateModel;
 
     LibraryTableModelInvocationHandler(LibraryTable.ModifiableModel delegateModel) {
@@ -537,6 +546,11 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
         }
       }
     }
+
+    @Override
+    public Object getDelegate() {
+      return myDelegateModel;
+    }
   }
 
   public interface ProxyDelegateAccessor {
index c516993ad49bd4f7ea965db9e4a4e3911710a796..866913fb8a3c82ab38bc02031a87dfafe07bb5bc 100644 (file)
@@ -30,7 +30,6 @@ import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
 import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
 import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
 import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseModulesDialog;
-import com.intellij.openapi.roots.ui.configuration.packaging.ChooseLibrariesDialog;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.artifacts.ArtifactModel;
@@ -41,6 +40,7 @@ import com.intellij.packaging.impl.ui.ChooseArtifactsDialog;
 import com.intellij.packaging.ui.ArtifactEditor;
 import com.intellij.packaging.ui.ArtifactEditorContext;
 import com.intellij.packaging.ui.ManifestFileConfiguration;
+import com.intellij.util.ui.classpath.ChooseLibrariesFromTablesDialog;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.Collections;
@@ -175,10 +175,10 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext {
     return dialog.isOK() ? selected : Collections.<Module>emptyList();
   }
 
-  public List<Library> chooseLibraries(final List<Library> libraries, final String title) {
-    ChooseLibrariesDialog dialog = new ChooseLibrariesDialog(getProject(), libraries, title, null);
+  public List<Library> chooseLibraries(final String title) {
+    final ChooseLibrariesFromTablesDialog dialog = ChooseLibrariesFromTablesDialog.createDialog(title, getProject(), false);
     dialog.show();
-    return dialog.isOK() ? dialog.getChosenElements() : Collections.<Library>emptyList();
+    return dialog.isOK() ? dialog.getSelectedLibraries() : Collections.<Library>emptyList();
   }
 
   public Artifact getArtifact() {
index 179a66d7d59ffbd6811f2bbfb0100921c65a98ff..a6aa3092a96fc4db0cacaf18643a10610586c93a 100644 (file)
  */
 package com.intellij.openapi.roots.ui.configuration.classpath;
 
-import com.intellij.openapi.util.Disposer;
-import org.jetbrains.annotations.Nullable;
-
 import javax.swing.*;
-import java.util.ArrayList;
-import java.util.List;
 
 /**
 * @author nik
 */
-abstract class AddItemPopupAction<ItemType> extends ClasspathPanelAction {
+abstract class AddItemPopupAction<ItemType> extends ChooseAndAddAction<ItemType> {
   private final String myTitle;
   private final Icon myIcon;
   private final int myIndex;
@@ -49,40 +44,4 @@ abstract class AddItemPopupAction<ItemType> extends ClasspathPanelAction {
     return myIndex;
   }
 
-  @Override
-  public void run() {
-    final ClasspathElementChooserDialog<ItemType> dialog = createChooserDialog();
-    if (dialog == null) {
-      return;
-    }
-    try {
-      dialog.doChoose();
-      if (!dialog.isOK()) {
-        return;
-      }
-      final List<ItemType> chosen = dialog.getChosenElements();
-      if (chosen.isEmpty()) {
-        return;
-      }
-      List<ClasspathTableItem> toAdd = new ArrayList<ClasspathTableItem>();
-      for (ItemType item : chosen) {
-        final ClasspathTableItem tableItem = createTableItem(item);
-        if (tableItem != null) {
-          toAdd.add(tableItem);
-        }
-      }
-      myClasspathPanel.addItems(toAdd);
-    }
-    finally {
-      if (dialog instanceof ChooseNamedLibraryAction.MyChooserDialog) {
-        Disposer.dispose(dialog);
-      }
-    }
-  }
-
-  @Nullable
-  protected abstract ClasspathTableItem createTableItem(final ItemType item);
-
-  @Nullable
-  protected abstract ClasspathElementChooserDialog<ItemType> createChooserDialog();
 }
similarity index 51%
rename from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChooseNamedLibraryAction.java
rename to java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryAction.java
index 78aa9bc6e59301b3c9f2ee95e45458b6923f8944..bdfb56a66e150415e397079376b94c4a3f5c86b7 100644 (file)
@@ -21,27 +21,52 @@ import com.intellij.openapi.roots.ModifiableRootModel;
 import com.intellij.openapi.roots.OrderEntry;
 import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
 import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
-import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
+import com.intellij.openapi.roots.libraries.LibraryTable;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
 import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.Condition;
 import com.intellij.util.Icons;
+import com.intellij.util.ui.classpath.ChooseLibrariesFromTablesDialog;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.*;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
 * @author nik
 */
-class ChooseNamedLibraryAction extends AddItemPopupAction<Library> {
-  private final LibraryTableModifiableModelProvider myLibraryTableModelProvider;
+class AddLibraryAction extends AddItemPopupAction<Library> {
+  private StructureConfigurableContext myContext;
+  private AddNewLibraryItemAction myNewLibraryAction;
 
-  public ChooseNamedLibraryAction(ClasspathPanel classpathPanel,
-                                  final int index,
-                                  final String title,
-                                  final LibraryTableModifiableModelProvider libraryTable) {
+  public AddLibraryAction(ClasspathPanel classpathPanel, final int index, final String title,
+                          final StructureConfigurableContext context) {
     super(classpathPanel, index, title, Icons.LIBRARY_ICON);
-    myLibraryTableModelProvider = libraryTable;
+    myContext = context;
+    myNewLibraryAction = new AddNewLibraryItemAction(classpathPanel, context);
+  }
+
+  @Override
+  public void run() {
+    if (hasLibraries()) {
+      super.run();
+    }
+    else {
+      myNewLibraryAction.run();
+    }
+  }
+
+  private boolean hasLibraries() {
+    final Condition<Library> condition = getNotAddedLibrariesCondition();
+    for (LibraryTable table : ChooseLibrariesFromTablesDialog.getLibraryTables(myClasspathPanel.getProject(), true)) {
+      for (Library library : table.getLibraries()) {
+        if (condition.value(library)) {
+          return true;
+        }
+      }
+    }
+    return false;
   }
 
   @Nullable
@@ -65,46 +90,51 @@ class ChooseNamedLibraryAction extends AddItemPopupAction<Library> {
     return ClasspathTableItem.createLibItem(rootModel.addLibraryEntry(item));
   }
 
-  protected ClasspathElementChooserDialog<Library> createChooserDialog() {
-    return new MyChooserDialog();
+  protected ClasspathElementChooser<Library> createChooser() {
+    return new ExistingLibraryChooser();
   }
 
-  private Collection<Library> getAlreadyAddedLibraries() {
+  private Condition<Library> getNotAddedLibrariesCondition() {
     final OrderEntry[] orderEntries = myClasspathPanel.getRootModel().getOrderEntries();
     final Set<Library> result = new HashSet<Library>(orderEntries.length);
     for (OrderEntry orderEntry : orderEntries) {
       if (orderEntry instanceof LibraryOrderEntry && orderEntry.isValid()) {
         final LibraryImpl library = (LibraryImpl)((LibraryOrderEntry)orderEntry).getLibrary();
         if (library != null) {
-          result.add(library.getSource());
+          final Library source = library.getSource();
+          result.add(source != null ? source : library);
         }
       }
     }
-    return result;
+    return new Condition<Library>() {
+      @Override
+      public boolean value(Library library) {
+        if (result.contains(library)) return false;
+        if (library instanceof LibraryImpl) {
+          final Library source = ((LibraryImpl)library).getSource();
+          if (source != null && result.contains(source)) return false;
+        }
+        return true;
+      }
+    };
   }
 
-  class MyChooserDialog implements ClasspathElementChooserDialog<Library> {
-    private final LibraryTableEditor myEditor;
-    private Library[] myLibraries;
-
-    MyChooserDialog(){
-      myEditor = LibraryTableEditor.editLibraryTable(myLibraryTableModelProvider, myClasspathPanel.getProject());
-      Disposer.register(this, myEditor);
-    }
+  class ExistingLibraryChooser implements ClasspathElementChooser<Library> {
+    private List<Library> mySelectedLibraries;
 
     public List<Library> getChosenElements() {
-      final List<Library> chosen = new ArrayList<Library>(Arrays.asList(myLibraries));
-      chosen.removeAll(getAlreadyAddedLibraries());
-      return chosen;
+      return mySelectedLibraries;
     }
 
     public void doChoose() {
-      final Iterator iter = myLibraryTableModelProvider.getModifiableModel().getLibraryIterator();
-      myLibraries = myEditor.openDialog(myClasspathPanel.getComponent(), iter.hasNext()? Collections.singleton((Library)iter.next()) : Collections.<Library>emptyList(), false);
+      ProjectStructureChooseLibrariesDialog dialog = new ProjectStructureChooseLibrariesDialog(myClasspathPanel.getComponent(), myClasspathPanel.getProject(), myContext,
+                                                                                               getNotAddedLibrariesCondition(), myNewLibraryAction);
+      dialog.show();
+      mySelectedLibraries = dialog.getSelectedLibraries();
     }
 
     public boolean isOK() {
-      return myLibraries != null;
+      return mySelectedLibraries != null && !mySelectedLibraries.isEmpty();
     }
 
     public void dispose() {
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddNewLibraryItemAction.java
new file mode 100644 (file)
index 0000000..55179b2
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.openapi.roots.ui.configuration.classpath;
+
+import com.intellij.openapi.roots.LibraryOrderEntry;
+import com.intellij.openapi.roots.OrderEntry;
+import com.intellij.openapi.roots.libraries.Library;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
+
+/**
+* @author nik
+*/
+class AddNewLibraryItemAction extends ChooseAndAddAction<Library> {
+  private final StructureConfigurableContext myContext;
+
+  public AddNewLibraryItemAction(final ClasspathPanel classpathPanel,
+                                 StructureConfigurableContext context) {
+    super(classpathPanel);
+    myContext = context;
+  }
+
+  protected ClasspathTableItem createTableItem(final Library item) {
+    final OrderEntry[] entries = myClasspathPanel.getRootModel().getOrderEntries();
+    for (OrderEntry entry : entries) {
+      if (entry instanceof LibraryOrderEntry) {
+        final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
+        if (item.equals(libraryOrderEntry.getLibrary())) {
+          return ClasspathTableItem.createLibItem(libraryOrderEntry);
+        }
+      }
+    }
+    return ClasspathTableItem.createLibItem(myClasspathPanel.getRootModel().addLibraryEntry(item));
+  }
+
+  protected ClasspathElementChooser<Library> createChooser() {
+    return new NewLibraryChooser(myClasspathPanel.getProject(), myClasspathPanel.getRootModel(), myContext, myClasspathPanel.getComponent());
+  }
+}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddSingleEntryModuleLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddSingleEntryModuleLibraryAction.java
new file mode 100644 (file)
index 0000000..480c5ab
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.openapi.roots.ui.configuration.classpath;
+
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.ProjectBundle;
+import com.intellij.openapi.roots.LibraryOrderEntry;
+import com.intellij.openapi.roots.OrderEntry;
+import com.intellij.openapi.roots.libraries.Library;
+import com.intellij.openapi.roots.libraries.LibraryTable;
+import com.intellij.util.Icons;
+
+/**
+* @author nik
+*/
+class AddSingleEntryModuleLibraryAction extends AddItemPopupAction<Library> {
+  private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.classpath.AddSingleEntryModuleLibraryAction");
+
+  public AddSingleEntryModuleLibraryAction(final ClasspathPanel classpathPanel, int actionIndex) {
+    super(classpathPanel, actionIndex, ProjectBundle.message("classpath.add.simple.module.library.action"), Icons.JAR_ICON);
+  }
+
+  protected ClasspathTableItem createTableItem(final Library item) {
+    final OrderEntry[] entries = myClasspathPanel.getRootModel().getOrderEntries();
+    for (OrderEntry entry : entries) {
+      if (entry instanceof LibraryOrderEntry) {
+        final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
+        if (item.equals(libraryOrderEntry.getLibrary())) {
+          return ClasspathTableItem.createLibItem(libraryOrderEntry);
+        }
+      }
+    }
+    LOG.error("Unknown library " + item);
+    return null;
+  }
+
+  protected ClasspathElementChooser<Library> createChooser() {
+    final LibraryTable.ModifiableModel moduleLibraryModel = myClasspathPanel.getRootModel().getModuleLibraryTable().getModifiableModel();
+    return new CreateSingleEntryModuleLibraryChooser(myClasspathPanel, moduleLibraryModel);
+  }
+}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChooseAndAddAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChooseAndAddAction.java
new file mode 100644 (file)
index 0000000..7cdb4f5
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.openapi.roots.ui.configuration.classpath;
+
+import com.intellij.openapi.util.Disposer;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author nik
+ */
+public abstract class ChooseAndAddAction<ItemType> extends ClasspathPanelAction {
+  public ChooseAndAddAction(ClasspathPanel classpathPanel) {
+    super(classpathPanel);
+  }
+
+  @Override
+  public void run() {
+    final ClasspathElementChooser<ItemType> dialog = createChooser();
+    if (dialog == null) {
+      return;
+    }
+    try {
+      dialog.doChoose();
+      if (!dialog.isOK()) {
+        return;
+      }
+      final List<ItemType> chosen = dialog.getChosenElements();
+      if (chosen.isEmpty()) {
+        return;
+      }
+      List<ClasspathTableItem> toAdd = new ArrayList<ClasspathTableItem>();
+      for (ItemType item : chosen) {
+        final ClasspathTableItem tableItem = createTableItem(item);
+        if (tableItem != null) {
+          toAdd.add(tableItem);
+        }
+      }
+      myClasspathPanel.addItems(toAdd);
+    }
+    finally {
+      Disposer.dispose(dialog);
+    }
+  }
+
+  @Nullable
+  protected abstract ClasspathTableItem createTableItem(final ItemType item);
+
+  @Nullable
+  protected abstract ClasspathElementChooser<ItemType> createChooser();
+}
similarity index 92%
rename from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathElementChooserDialog.java
rename to java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathElementChooser.java
index 56befffab2f7eafd7f42603a3ea206bb4332d5df..691776cec60d46285f8b629987ed1f6ab01af5c1 100644 (file)
@@ -22,7 +22,7 @@ import java.util.List;
 /**
 * @author nik
 */
-interface ClasspathElementChooserDialog<T> extends Disposable {
+interface ClasspathElementChooser<T> extends Disposable {
   List<T> getChosenElements();
   void doChoose();
   boolean isOK();
index a64350a8ffb3400c25d5d0892c96276e1aa06257..4368359e1b1bb59aee0b9dea91cf25de5e8fe063 100644 (file)
@@ -27,14 +27,13 @@ import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.roots.*;
 import com.intellij.openapi.roots.libraries.Library;
 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.ModuleConfigurationState;
 import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
 import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
 import com.intellij.openapi.roots.ui.configuration.dependencyAnalysis.AnalyzeDependenciesDialog;
 import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseModulesDialog;
-import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
+import com.intellij.openapi.roots.ui.configuration.libraryEditor.EditExistingLibraryDialog;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.FindUsagesInProjectStructureActionBase;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
@@ -53,7 +52,6 @@ import com.intellij.openapi.wm.IdeFocusManager;
 import com.intellij.ui.*;
 import com.intellij.ui.awt.RelativePoint;
 import com.intellij.util.EventDispatcher;
-import com.intellij.util.Icons;
 import com.intellij.util.ui.Table;
 import org.jetbrains.annotations.NotNull;
 
@@ -65,8 +63,10 @@ import javax.swing.table.TableCellRenderer;
 import javax.swing.table.TableColumn;
 import java.awt.*;
 import java.awt.event.*;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
   private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.classpath.ClasspathPanel");
@@ -381,25 +381,14 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
               return moduleLibraryTable.getModifiableModel();
             }
 
-            public String getTableLevel() {
-              return moduleLibraryTable.getTableLevel();
-            }
-
-            public LibraryTablePresentation getLibraryTablePresentation() {
-              return moduleLibraryTable.getPresentation();
-            }
-
-            public boolean isLibraryTableEditable() {
-              return false;
-            }
           };
         }
         else {
-          provider = ProjectStructureConfigurable.getInstance(myState.getProject()).getContext().createModifiableModelProvider(table.getTableLevel(), false);
+          provider = ProjectStructureConfigurable.getInstance(myState.getProject()).getContext().createModifiableModelProvider(table.getTableLevel());
         }
-        final LibraryTableEditor editor = LibraryTableEditor.editLibrary(provider, library, myState.getProject());
-        editor.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, getRootModel().getModule());
-        editor.openDialog(ClasspathPanelImpl.this, Collections.singletonList(library), true);
+        EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(ClasspathPanelImpl.this, provider, library, myState.getProject());
+        dialog.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, getRootModel().getModule());
+        dialog.show();
         myEntryTable.repaint();
         ModuleStructureConfigurable.getInstance(myState.getProject()).getTree().repaint();
       }
@@ -471,67 +460,20 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
       final StructureConfigurableContext context = ProjectStructureConfigurable.getInstance(myState.getProject()).getContext();
       int actionIndex = 1;
       final List<AddItemPopupAction<?>> actions = new ArrayList<AddItemPopupAction<?>>();
-      actions.add(
-        new AddItemPopupAction<Library>(this, actionIndex++, ProjectBundle.message("classpath.add.simple.module.library.action"), Icons.JAR_ICON) {
-          protected ClasspathTableItem createTableItem(final Library item) {
-            final OrderEntry[] entries = getRootModel().getOrderEntries();
-            for (OrderEntry entry : entries) {
-              if (entry instanceof LibraryOrderEntry) {
-                final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
-                if (item.equals(libraryOrderEntry.getLibrary())) {
-                  return ClasspathTableItem.createLibItem(libraryOrderEntry);
-                }
-              }
-            }
-            LOG.error("Unknown library " + item);
-            return null;
-          }
-
-          protected ClasspathElementChooserDialog<Library> createChooserDialog() {
-            return new ChooseModuleLibrariesDialog(ClasspathPanelImpl.this, getRootModel().getModuleLibraryTable(), null);
-          }
-        });
-      actions.add(
-        new AddItemPopupAction<Library>(this, actionIndex++, ProjectBundle.message("classpath.add.module.library.action"), Icons.JAR_ICON) {
-          protected ClasspathTableItem createTableItem(final Library item) {
-            final OrderEntry[] entries = getRootModel().getOrderEntries();
-            for (OrderEntry entry : entries) {
-              if (entry instanceof LibraryOrderEntry) {
-                final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
-                if (item.equals(libraryOrderEntry.getLibrary())) {
-                  return ClasspathTableItem.createLibItem(libraryOrderEntry);
-                }
-              }
-            }
-            LOG.error("Unknown library " + item);
-            return null;
-          }
-
-          protected ClasspathElementChooserDialog<Library> createChooserDialog() {
-            return new CreateModuleLibraryDialog(ClasspathPanelImpl.this, getRootModel().getModuleLibraryTable());
-          }
-        });
-      actions.add(new ChooseNamedLibraryAction(this, actionIndex++, ProjectBundle.message("classpath.add.project.library.action"),
-                                               context.getProjectLibrariesProvider(true)));
-      actions.add(new ChooseNamedLibraryAction(this, actionIndex++, ProjectBundle.message("classpath.add.global.library.action"),
-                                               context.getGlobalLibrariesProvider(true)));
-
-      for (final LibraryTableModifiableModelProvider provider : context.getCustomLibrariesProviders(true)) {
-        actions.add(new ChooseNamedLibraryAction(this, actionIndex++, provider.getLibraryTablePresentation().getDisplayName(false) + "...", provider));
-      }
-
+      actions.add(new AddSingleEntryModuleLibraryAction(this, actionIndex++));
+      actions.add(new AddLibraryAction(this, actionIndex++, ProjectBundle.message("classpath.add.library.action"), context));
       actions.add(new AddItemPopupAction<Module>(this, actionIndex, ProjectBundle.message("classpath.add.module.dependency.action"),
                                                  StdModuleTypes.JAVA.getNodeIcon(false)) {
           protected ClasspathTableItem createTableItem(final Module item) {
             return ClasspathTableItem.createItem(getRootModel().addModuleOrderEntry(item));
           }
-          protected ClasspathElementChooserDialog<Module> createChooserDialog() {
+          protected ClasspathElementChooser<Module> createChooser() {
             final List<Module> chooseItems = getDependencyModules();
             if (chooseItems.isEmpty()) {
               Messages.showMessageDialog(ClasspathPanelImpl.this, ProjectBundle.message("message.no.module.dependency.candidates"), getTitle(), Messages.getInformationIcon());
               return null;
             }
-            return new ChooseModulesToAddDialog(chooseItems, ProjectBundle.message("classpath.chooser.title.add.module.dependency"));
+            return new ModuleChooser(chooseItems, ProjectBundle.message("classpath.chooser.title.add.module.dependency"));
           }
         }
       );
@@ -694,8 +636,8 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
     }
   }
 
-  private class ChooseModulesToAddDialog extends ChooseModulesDialog implements ClasspathElementChooserDialog<Module> {
-    public ChooseModulesToAddDialog(final List<Module> items, final String title) {
+  private class ModuleChooser extends ChooseModulesDialog implements ClasspathElementChooser<Module> {
+    public ModuleChooser(final List<Module> items, final String title) {
       super(ClasspathPanelImpl.this, items, title);
     }
 
@@ -751,4 +693,5 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
       return new RelativePoint(myEntryTable, location);
     }
   }
+
 }
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateModuleLibraryDialog.java
deleted file mode 100644 (file)
index 5640df0..0000000
+++ /dev/null
@@ -1,88 +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.openapi.roots.ui.configuration.classpath;
-
-import com.intellij.ide.DataManager;
-import com.intellij.openapi.actionSystem.DataKeys;
-import com.intellij.openapi.actionSystem.LangDataKeys;
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.roots.libraries.Library;
-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.libraryEditor.LibraryTableEditor;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
-* @author nik
-*/
-class CreateModuleLibraryDialog implements ClasspathElementChooserDialog<Library> {
-  private boolean myIsOk;
-  private final ClasspathPanel myClasspathPanel;
-  private final LibraryTable myLibraryTable;
-  private Library myChosenLibrary;
-
-  public CreateModuleLibraryDialog(ClasspathPanel classpathPanel, final LibraryTable libraryTable) {
-    myClasspathPanel = classpathPanel;
-    myLibraryTable = libraryTable;
-  }
-
-  public List<Library> getChosenElements() {
-    return myChosenLibrary == null? Collections.<Library>emptyList() : Collections.singletonList(myChosenLibrary);
-  }
-
-  public void doChoose() {
-    final LibraryTable.ModifiableModel libraryModifiableModel = myLibraryTable.getModifiableModel();
-    final LibraryTableModifiableModelProvider provider = new LibraryTableModifiableModelProvider() {
-      public LibraryTable.ModifiableModel getModifiableModel() {
-        return libraryModifiableModel;
-      }
-
-      public String getTableLevel() {
-        return myLibraryTable.getTableLevel();
-      }
-
-      public LibraryTablePresentation getLibraryTablePresentation() {
-        return myLibraryTable.getPresentation();
-      }
-
-      public boolean isLibraryTableEditable() {
-        return false;
-      }
-    };
-    final Library library = myLibraryTable.createLibrary();
-    final LibraryTableEditor editor = LibraryTableEditor.editLibrary(provider, library, myClasspathPanel.getProject());
-    final Module contextModule = DataKeys.MODULE_CONTEXT.getData(DataManager.getInstance().getDataContext(myClasspathPanel.getComponent()));
-    editor.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, contextModule);
-    myIsOk = editor.openDialog(myClasspathPanel.getComponent(), Collections.singletonList(library), true) != null;
-    if (myIsOk) {
-      myChosenLibrary = library;
-    }
-    else {
-      myChosenLibrary = null;
-      libraryModifiableModel.removeLibrary(library);
-    }
-  }
-
-  public boolean isOK() {
-    return myIsOk;
-  }
-
-  public void dispose() {
-  }
-}
similarity index 67%
rename from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ChooseModuleLibrariesDialog.java
rename to java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/CreateSingleEntryModuleLibraryChooser.java
index e4b7970fc954324ce40d5e9e604438366d8db40b..60e251a2903c343d5933162652ac7d96f4f2fe74 100644 (file)
@@ -17,34 +17,33 @@ package com.intellij.openapi.roots.ui.configuration.classpath;
 
 import com.intellij.ide.DataManager;
 import com.intellij.openapi.actionSystem.LangDataKeys;
+import com.intellij.openapi.fileChooser.FileChooser;
 import com.intellij.openapi.fileChooser.FileChooserDescriptor;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.roots.OrderRootType;
 import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.roots.libraries.LibraryTable;
-import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryFileChooser;
-import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.containers.ContainerUtil;
-import org.jetbrains.annotations.Nullable;
 
+import javax.swing.*;
 import java.awt.*;
-import java.awt.List;
 import java.util.*;
+import java.util.List;
 
 /**
 * @author nik
 */
-class ChooseModuleLibrariesDialog extends LibraryFileChooser implements ClasspathElementChooserDialog<Library> {
-  private Pair<String, VirtualFile[]> myLastChosen;
-  private final LibraryTable myLibraryTable;
-  @Nullable private final VirtualFile myFileToSelect;
+class CreateSingleEntryModuleLibraryChooser implements ClasspathElementChooser<Library> {
+  private ClasspathPanel myClasspathPanel;
+  private final LibraryTable.ModifiableModel myModuleLibrariesModel;
+  private VirtualFile[] myChosenFiles;
 
-  public ChooseModuleLibrariesDialog(Component parent, final LibraryTable libraryTable, final VirtualFile fileToSelect) {
-    super(createFileChooserDescriptor(parent), parent, false, null);
-    myLibraryTable = libraryTable;
-    myFileToSelect = fileToSelect;
+  public CreateSingleEntryModuleLibraryChooser(ClasspathPanel classpathPanel,
+                                              final LibraryTable.ModifiableModel moduleLibrariesModel) {
+    myClasspathPanel = classpathPanel;
+    myModuleLibrariesModel = moduleLibrariesModel;
   }
 
   private static FileChooserDescriptor createFileChooserDescriptor(Component parent) {
@@ -54,18 +53,17 @@ class ChooseModuleLibrariesDialog extends LibraryFileChooser implements Classpat
     return descriptor;
   }
 
-  public java.util.List<Library> getChosenElements() {
-    if (myLastChosen == null) {
+  public List<Library> getChosenElements() {
+    if (myChosenFiles == null) {
       return Collections.emptyList();
     }
-    final VirtualFile[] files = filterAlreadyAdded(myLastChosen.getSecond());
+    final VirtualFile[] files = filterAlreadyAdded(myChosenFiles);
     if (files.length == 0) {
       return Collections.emptyList();
     }
-    final LibraryTable.ModifiableModel modifiableModel = myLibraryTable.getModifiableModel();
-    final java.util.List<Library> addedLibraries = new ArrayList<Library>(files.length);
+    final List<Library> addedLibraries = new ArrayList<Library>(files.length);
     for (VirtualFile file : files) {
-      final Library library = modifiableModel.createLibrary(null);
+      final Library library = myModuleLibrariesModel.createLibrary(null);
       final Library.ModifiableModel libModel = library.getModifiableModel();
       libModel.addRoot(file, OrderRootType.CLASSES);
       libModel.commit();
@@ -80,7 +78,7 @@ class ChooseModuleLibrariesDialog extends LibraryFileChooser implements Classpat
     }
     final Set<VirtualFile> chosenFilesSet = new HashSet<VirtualFile>(Arrays.asList(files));
     final Set<VirtualFile> alreadyAdded = new HashSet<VirtualFile>();
-    final Library[] libraries = myLibraryTable.getLibraries();
+    final Library[] libraries = myModuleLibrariesModel.getLibraries();
     for (Library library : libraries) {
       ContainerUtil.addAll(alreadyAdded, library.getFiles(OrderRootType.CLASSES));
     }
@@ -89,6 +87,16 @@ class ChooseModuleLibrariesDialog extends LibraryFileChooser implements Classpat
   }
 
   public void doChoose() {
-    myLastChosen = chooseNameAndFiles(myFileToSelect);
+    final JComponent parent = myClasspathPanel.getComponent();
+    myChosenFiles = FileChooser.chooseFiles(parent, createFileChooserDescriptor(parent));
+  }
+
+  @Override
+  public boolean isOK() {
+    return myChosenFiles != null && myChosenFiles.length > 0;
+  }
+
+  @Override
+  public void dispose() {
   }
 }
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/NewLibraryChooser.java
new file mode 100644 (file)
index 0000000..9ded4cc
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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.openapi.roots.ui.configuration.classpath;
+
+import com.intellij.ide.DataManager;
+import com.intellij.openapi.actionSystem.DataKeys;
+import com.intellij.openapi.actionSystem.LangDataKeys;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.ModifiableRootModel;
+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.projectRoot.StructureConfigurableContext;
+
+import javax.swing.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+* @author nik
+*/
+class NewLibraryChooser implements ClasspathElementChooser<Library> {
+  private boolean myIsOk;
+  private final ModifiableRootModel myRootModel;
+  private Library myChosenLibrary;
+  private StructureConfigurableContext myContext;
+  private final JComponent myParentComponent;
+  private final Project myProject;
+
+  public NewLibraryChooser(final Project project,
+                             final ModifiableRootModel rootModel,
+                             StructureConfigurableContext context, final JComponent parentComponent) {
+    myRootModel = rootModel;
+    myContext = context;
+    myParentComponent = parentComponent;
+    myProject = project;
+  }
+
+  public List<Library> getChosenElements() {
+    return myChosenLibrary == null? Collections.<Library>emptyList() : Collections.singletonList(myChosenLibrary);
+  }
+
+  public void doChoose() {
+    final LibraryTablesRegistrar registrar = LibraryTablesRegistrar.getInstance();
+    List<LibraryTable> tables = Arrays.asList(myRootModel.getModuleLibraryTable(),
+                                              registrar.getLibraryTable(myProject),
+                                              registrar.getLibraryTable());
+    CreateNewLibraryDialog dialog = CreateNewLibraryDialog.createDialog(myParentComponent, myProject, this, 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()));
+    }
+    else {
+      myChosenLibrary = null;
+    }
+  }
+
+  public boolean isOK() {
+    return myIsOk;
+  }
+
+  public void dispose() {
+  }
+}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ProjectStructureChooseLibrariesDialog.java
new file mode 100644 (file)
index 0000000..5079e27
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * 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.openapi.roots.ui.configuration.classpath;
+
+import com.intellij.ide.projectView.PresentationData;
+import com.intellij.ide.util.treeView.NodeDescriptor;
+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.LibrariesModifiableModel;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
+import com.intellij.openapi.util.Condition;
+import com.intellij.ui.SimpleTextAttributes;
+import com.intellij.util.Icons;
+import com.intellij.util.ui.classpath.ChooseLibrariesFromTablesDialog;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
+/**
+ * @author nik
+ */
+public class ProjectStructureChooseLibrariesDialog extends ChooseLibrariesFromTablesDialog {
+  private StructureConfigurableContext myContext;
+  private Condition<Library> myAcceptedLibraries;
+  private AddNewLibraryItemAction myNewLibraryAction;
+
+  public ProjectStructureChooseLibrariesDialog(JComponent parentComponent,
+                                               @Nullable Project project,
+                                               StructureConfigurableContext context,
+                                               Condition<Library> acceptedLibraries, AddNewLibraryItemAction newLibraryAction) {
+    super(parentComponent, "Choose Libraries", project, true);
+    myContext = context;
+    myAcceptedLibraries = acceptedLibraries;
+    myNewLibraryAction = newLibraryAction;
+    setOKButtonText("Add Selected");
+    init();
+  }
+
+  @NotNull
+  @Override
+  protected Library[] getLibraries(@NotNull LibraryTable table) {
+    final LibrariesModifiableModel model = getLibrariesModifiableModel(table);
+    if (model == null) return Library.EMPTY_ARRAY;
+    return model.getLibraries();
+  }
+
+  private LibrariesModifiableModel getLibrariesModifiableModel(LibraryTable table) {
+    return myContext.myLevel2Providers.get(table.getTableLevel());
+  }
+
+  @Override
+  protected boolean acceptsElement(Object element) {
+    if (element instanceof Library) {
+      final Library library = (Library)element;
+      return myAcceptedLibraries.value(library);
+    }
+    return true;
+  }
+
+  @NotNull
+  private String getLibraryName(@NotNull Library library) {
+    final LibrariesModifiableModel model = getLibrariesModifiableModel(library.getTable());
+    if (model != null) {
+      if (model.hasLibraryEditor(library)) {
+        return model.getLibraryEditor(library).getName();
+      }
+    }
+    return library.getName();
+  }
+
+  @Override
+  protected Action[] createActions() {
+    return new Action[]{getCancelAction()};
+  }
+
+  @Override
+  protected Action[] createLeftSideActions() {
+    return new Action[]{getOKAction(), new CreateNewLibraryAction()};
+  }
+
+  @Override
+  protected LibrariesTreeNodeBase<Library> createLibraryDescriptor(NodeDescriptor parentDescriptor,
+                                                                   Library library) {
+    final String libraryName = getLibraryName(library);
+    return new LibraryEditorDescriptor(getProject(), parentDescriptor, library, libraryName);
+  }
+
+  private static class LibraryEditorDescriptor extends LibrariesTreeNodeBase<Library> {
+    protected LibraryEditorDescriptor(final Project project, final NodeDescriptor parentDescriptor, final Library element,
+                                      String libraryName) {
+      super(project, parentDescriptor, element);
+      final PresentationData templatePresentation = getTemplatePresentation();
+      templatePresentation.setIcons(Icons.LIBRARY_ICON);
+      templatePresentation.addText(libraryName, SimpleTextAttributes.REGULAR_ATTRIBUTES);
+    }
+  }
+
+  private class CreateNewLibraryAction extends DialogWrapperAction {
+    private CreateNewLibraryAction() {
+      super("New Library...");
+      putValue(MNEMONIC_KEY, KeyEvent.VK_N);
+    }
+
+    @Override
+    protected void doAction(ActionEvent e) {
+      close(CANCEL_EXIT_CODE);
+      myNewLibraryAction.execute();
+    }
+  }
+}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/AbstractLibraryTreeStructure.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/AbstractLibraryTreeStructure.java
deleted file mode 100644 (file)
index 5bdea37..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2000-2009 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.openapi.roots.ui.configuration.libraryEditor;
-
-import com.intellij.ide.util.treeView.AbstractTreeStructure;
-import com.intellij.ide.util.treeView.NodeDescriptor;
-import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.libraries.Library;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-/**
- * @author nik
- */
-public abstract class AbstractLibraryTreeStructure extends AbstractTreeStructure {
-  protected NodeDescriptor myRootElementDescriptor;
-  protected final LibraryTableEditor myParentEditor;
-
-  public AbstractLibraryTreeStructure(LibraryTableEditor parentElement) {
-    myParentEditor = parentElement;
-  }
-
-  public void commit() {
-  }
-
-  public boolean hasSomethingToCommit() {
-    return false;
-  }
-
-  protected Object[] buildItems(LibraryTableTreeContentElement parent, Library library, OrderRootType orderRootType) {
-    ArrayList<ItemElement> items = new ArrayList<ItemElement>();
-    final LibraryEditor libraryEditor = myParentEditor.getLibraryEditor(library);
-    final String[] urls = libraryEditor.getUrls(orderRootType).clone();
-    Arrays.sort(urls, LibraryTableEditor.ourUrlComparator);
-    for (String url : urls) {
-      items.add(new ItemElement(parent, library, url, orderRootType, libraryEditor.isJarDirectory(url), libraryEditor.isValid(url, orderRootType)));
-    }
-    return items.toArray();
-  }
-
-  public Object getParentElement(Object element) {
-    Object rootElement = getRootElement();
-    if (element == rootElement) {
-      return null;
-    }
-    if (element instanceof LibraryTableTreeContentElement) {
-      return ((LibraryTableTreeContentElement)element).getParent();
-    }
-    return rootElement;
-  }
-
-  @NotNull
-  public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
-    if (element == getRootElement()) {
-      return myRootElementDescriptor;
-    }
-    if (element instanceof LibraryTableTreeContentElement) {
-      return ((LibraryTableTreeContentElement)element).createDescriptor(parentDescriptor, myParentEditor);
-    }
-    return null;
-  }
-}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryAction.java
new file mode 100644 (file)
index 0000000..8a8f2a0
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * 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.openapi.roots.ui.configuration.libraryEditor;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.project.ProjectBundle;
+import com.intellij.openapi.roots.libraries.Library;
+import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.BaseLibrariesConfigurable;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureLibraryTableModifiableModelProvider;
+import com.intellij.openapi.ui.InputValidator;
+import com.intellij.openapi.ui.MasterDetailsComponent;
+import com.intellij.openapi.ui.Messages;
+import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.ui.UIUtil;
+
+import javax.swing.*;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreeNode;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+* @author nik
+*/
+public class CreateNewLibraryAction extends AnAction {
+  private StructureLibraryTableModifiableModelProvider myModelProvider;
+  private Project myProject;
+
+  public CreateNewLibraryAction(String text, StructureLibraryTableModifiableModelProvider modelProvider, final Project project) {
+    super(text);
+    myModelProvider = modelProvider;
+    myProject = project;
+  }
+
+  @Override
+  public void actionPerformed(AnActionEvent e) {
+    final LibrariesModifiableModel modifiableModel = myModelProvider.getModifiableModel();
+    final String initial = LibraryTableEditor.suggestNewLibraryName(modifiableModel);
+    final String prompt = ProjectBundle.message("library.name.prompt");
+    final String title = ProjectBundle.message("library.create.library.action").replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
+    final Icon icon = Messages.getQuestionIcon();
+    final String libraryName = Messages.showInputDialog(myProject, prompt, title, icon, initial, new InputValidator() {
+      public boolean checkInput(final String inputString) {
+        return true;
+      }
+      public boolean canClose(final String inputString) {
+        if (inputString.length() == 0)  {
+          Messages.showErrorDialog(ProjectBundle.message("library.name.not.specified.error"), ProjectBundle.message("library.name.not.specified.title"));
+          return false;
+        }
+        if (LibraryTableEditor.libraryAlreadyExists(modifiableModel, inputString)) {
+          Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", inputString), ProjectBundle.message("library.name.already.exists.title"));
+          return false;
+        }
+        return true;
+      }
+    });
+    if (libraryName == null) return;
+    final Library library = modifiableModel.createLibrary(libraryName);
+    if (myProject != null){
+      final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library);
+      final ExistingLibraryEditor libraryEditor = modifiableModel.getLibraryEditor(library);
+      if (libraryEditor.hasChanges()) {
+        ApplicationManager.getApplication().runWriteAction(new Runnable(){
+          public void run() {
+            libraryEditor.commit();  //update lib node
+          }
+        });
+      }
+      final DefaultMutableTreeNode
+        libraryNode = MasterDetailsComponent.findNodeByObject((TreeNode)rootConfigurable.getTree().getModel().getRoot(), library);
+      rootConfigurable.selectNodeInTree(libraryNode);
+      appendLibraryToModules(ModuleStructureConfigurable.getInstance(myProject), library);
+    }
+  }
+
+  private void appendLibraryToModules(final ModuleStructureConfigurable rootConfigurable, final Library libraryToSelect) {
+    final List<Module> modules = new ArrayList<Module>();
+    ContainerUtil.addAll(modules, rootConfigurable.getModules());
+    final ChooseModulesDialog dlg = new ChooseModulesDialog(myProject,
+                                                            modules, ProjectBundle.message("choose.modules.dialog.title"),
+                                                            ProjectBundle
+                                                              .message("choose.modules.dialog.description", libraryToSelect.getName()));
+    dlg.show();
+    if (dlg.isOK()) {
+      final List<Module> choosenModules = dlg.getChosenElements();
+      for (Module module : choosenModules) {
+        rootConfigurable.addLibraryOrderEntry(module, libraryToSelect);
+      }
+    }
+  }
+}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/CreateNewLibraryDialog.java
new file mode 100644 (file)
index 0000000..c5ab576
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * 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.openapi.roots.ui.configuration.libraryEditor;
+
+import com.intellij.openapi.Disposable;
+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.ui.ComboBox;
+import com.intellij.openapi.util.Disposer;
+import com.intellij.util.ui.FormBuilder;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.List;
+
+/**
+ * @author nik
+ */
+public class CreateNewLibraryDialog extends LibraryEditorDialogBase {
+  private NewLibraryEditor myLibraryEditor;
+  private ComboBox myLibraryLevelCombobox;
+
+  public static CreateNewLibraryDialog createDialog(JComponent parent, @Nullable Project project, @NotNull Disposable parentDisposable,
+                                                    @NotNull List<LibraryTable> libraryTables,
+                                                    int selectedTable) {
+    NewLibraryEditor libraryEditor = new NewLibraryEditor();
+    Disposer.register(parentDisposable, libraryEditor);
+    return new CreateNewLibraryDialog(parent, project, libraryEditor, libraryTables, selectedTable);
+  }
+
+  private CreateNewLibraryDialog(@NotNull JComponent parent, @Nullable Project project, @NotNull NewLibraryEditor libraryEditor,
+                                 @NotNull List<LibraryTable> libraryTables, int selectedTable) {
+    super(parent, LibraryTableEditor.editLibrary(project, libraryEditor));
+    myLibraryEditor = libraryEditor;
+    final DefaultComboBoxModel model = new DefaultComboBoxModel();
+    for (LibraryTable table : libraryTables) {
+      model.addElement(table);
+    }
+    myLibraryLevelCombobox = new ComboBox(model);
+    myLibraryLevelCombobox.setSelectedIndex(selectedTable);
+    myLibraryLevelCombobox.setRenderer(new DefaultListCellRenderer() {
+      @Override
+      public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+        final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+        if (value instanceof LibraryTable) {
+          setText(((LibraryTable)value).getPresentation().getDisplayName(false));
+        }
+        return component;
+      }
+    });
+    init();
+  }
+
+  public LibraryTable getSelectedTable() {
+    return (LibraryTable)myLibraryLevelCombobox.getSelectedItem();
+  }
+
+  public Library createLibrary(final @NotNull LibraryTable.ModifiableModel modifiableModel) {
+    final Library library = modifiableModel.createLibrary(myLibraryEditor.getName());
+    final Library.ModifiableModel model = library.getModifiableModel();
+    myLibraryEditor.apply(model);
+    new WriteAction() {
+      protected void run(final Result result) {
+        model.commit();
+      }
+    }.execute();
+    return library;
+  }
+
+  @Override
+  protected void addNorthComponents(FormBuilder formBuilder) {
+    formBuilder.addLabeledComponent("Level:", myLibraryLevelCombobox);
+  }
+}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/EditExistingLibraryDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/EditExistingLibraryDialog.java
new file mode 100644 (file)
index 0000000..269e5ec
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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.openapi.roots.ui.configuration.libraryEditor;
+
+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.LibraryTableModifiableModelProvider;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
+import com.intellij.openapi.util.Disposer;
+import org.jetbrains.annotations.Nullable;
+
+import java.awt.*;
+
+/**
+ * @author nik
+ */
+public class EditExistingLibraryDialog extends LibraryEditorDialogBase {
+  private ExistingLibraryEditor myLibraryEditor;
+  private boolean myCommitChanges;
+  private LibraryTable.ModifiableModel myTableModifiableModel;
+
+  public static EditExistingLibraryDialog createDialog(Component parent,
+                                                       LibraryTableModifiableModelProvider modelProvider,
+                                                       Library library,
+                                                       @Nullable Project project) {
+    LibraryTable.ModifiableModel modifiableModel = modelProvider.getModifiableModel();
+    boolean commitChanges = false;
+    ExistingLibraryEditor libraryEditor;
+    if (modifiableModel instanceof LibrariesModifiableModel) {
+      libraryEditor = ((LibrariesModifiableModel)modifiableModel).getLibraryEditor(library);
+    }
+    else {
+      libraryEditor = new ExistingLibraryEditor(library, null);
+      commitChanges = true;
+    }
+    return new EditExistingLibraryDialog(parent, modifiableModel, project, libraryEditor, commitChanges);
+  }
+
+  private EditExistingLibraryDialog(Component parent,
+                                   LibraryTable.ModifiableModel tableModifiableModel,
+                                   @Nullable Project project, ExistingLibraryEditor libraryEditor, boolean commitChanges) {
+    super(parent, LibraryTableEditor.editLibrary(project, libraryEditor));
+    myTableModifiableModel = tableModifiableModel;
+    myLibraryEditor = libraryEditor;
+    myCommitChanges = commitChanges;
+    if (commitChanges) {
+      Disposer.register(getDisposable(), libraryEditor);
+    }
+    init();
+  }
+
+  @Override
+  protected boolean validateAndApply() {
+    if (!super.validateAndApply()) {
+      return false;
+    }
+
+    if (myCommitChanges) {
+      myLibraryEditor.commit();
+    }
+    return true;
+  }
+
+  @Override
+  protected LibraryTable.ModifiableModel getTableModifiableModel() {
+    return myTableModifiableModel;
+  }
+}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ExistingLibraryEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ExistingLibraryEditor.java
new file mode 100644 (file)
index 0000000..1ba3c49
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2000-2009 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.openapi.roots.ui.configuration.libraryEditor;
+
+import com.intellij.openapi.roots.OrderRootType;
+import com.intellij.openapi.roots.libraries.Library;
+import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.Nullable;
+
+public class ExistingLibraryEditor implements LibraryEditor {
+  private final Library myLibrary;
+  private final LibraryEditorListener myListener;
+  private String myLibraryName = null;
+  private Library.ModifiableModel myModel = null;
+
+  public ExistingLibraryEditor(Library library, @Nullable LibraryEditorListener listener) {
+    myLibrary = library;
+    myListener = listener;
+  }
+
+  public Library getLibrary() {
+    return myLibrary;
+  }
+
+  @Override
+  public String getName() {
+    if (myLibraryName != null) {
+      return myLibraryName;
+    }
+    return myLibrary.getName();
+  }
+
+  public void dispose() {
+    if (myModel != null) {
+      // dispose if wasn't committed
+      Disposer.dispose(myModel);
+    }
+  }
+
+  @Override
+  public String[] getUrls(OrderRootType rootType) {
+    if (myModel != null) {
+      return myModel.getUrls(rootType);
+    }
+    return myLibrary.getUrls(rootType);
+  }
+
+  @Override
+  public VirtualFile[] getFiles(OrderRootType rootType) {
+    if (myModel != null) {
+      return myModel.getFiles(rootType);
+    }
+    return myLibrary.getFiles(rootType);
+  }
+
+  @Override
+  public void setName(String name) {
+    String oldName = getModel().getName();
+    myLibraryName = name;
+    getModel().setName(name);
+    if (myListener != null) {
+      myListener.libraryRenamed(myLibrary, oldName, name);
+    }
+  }
+
+  @Override
+  public void addRoot(VirtualFile file, OrderRootType rootType) {
+    getModel().addRoot(file, rootType);
+  }
+
+  @Override
+  public void addJarDirectory(VirtualFile file, boolean recursive) {
+    getModel().addJarDirectory(file, recursive);
+  }
+
+  @Override
+  public void removeRoot(String url, OrderRootType rootType) {
+    while (getModel().removeRoot(url, rootType)) ;
+  }
+
+  public void commit() {
+    if (myModel != null) {
+      myModel.commit();
+      myModel = null;
+      myLibraryName = null;
+    }
+  }
+
+  public Library.ModifiableModel getModel() {
+    if (myModel == null) {
+      myModel = myLibrary.getModifiableModel();
+    }
+    return myModel;
+  }
+
+  @Override
+  public boolean hasChanges() {
+    return myModel != null && myModel.isChanged();
+  }
+  
+  @Override
+  public boolean isJarDirectory(String url) {
+    if (myModel != null) {
+      return myModel.isJarDirectory(url);
+    }
+    return myLibrary.isJarDirectory(url); 
+  }
+
+  @Override
+  public boolean isValid(final String url, final OrderRootType orderRootType) {
+    if (myModel != null) {
+      return myModel.isValid(url, orderRootType);
+    }
+    return myLibrary.isValid(url, orderRootType); 
+  }
+}
index 42e6bcc7a6cc7336a722a4648df8722cab8cbd84..1647521143996faaae2d391779bfd5c8cf2fe6ea 100644 (file)
@@ -17,20 +17,18 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
 
 import com.intellij.ide.util.treeView.NodeDescriptor;
 import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.libraries.Library;
 
 
 class ItemElement extends LibraryTableTreeContentElement {
   private final LibraryTableTreeContentElement myParent;
-  private final Library myLibrary;
   private final String myUrl;
   private final OrderRootType myRootType;
   private final boolean myIsJarDirectory;
   private final boolean myValid;
 
-  public ItemElement(LibraryTableTreeContentElement parent, Library library, String url, OrderRootType rootType, final boolean isJarDirectory, boolean isValid) {
+  public ItemElement(LibraryTableTreeContentElement parent, String url, OrderRootType rootType, final boolean isJarDirectory,
+                     boolean isValid) {
     myParent = parent;
-    myLibrary = library;
     myUrl = url;
     myRootType = rootType;
     myIsJarDirectory = isJarDirectory;
@@ -65,17 +63,12 @@ class ItemElement extends LibraryTableTreeContentElement {
     return myRootType;
   }
 
-  public Library getLibrary() {
-    return myLibrary;
-  }
-
   public boolean equals(Object o) {
     if (this == o) return true;
     if (!(o instanceof ItemElement)) return false;
 
     final ItemElement itemElement = (ItemElement)o;
 
-    if (!myLibrary.equals(itemElement.myLibrary)) return false;
     if (!myParent.equals(itemElement.myParent)) return false;
     if (!myRootType.equals(itemElement.myRootType)) return false;
     if (!myUrl.equals(itemElement.myUrl)) return false;
@@ -86,7 +79,6 @@ class ItemElement extends LibraryTableTreeContentElement {
   public int hashCode() {
     int result;
     result = myParent.hashCode();
-    result = 29 * result + myLibrary.hashCode();
     result = 29 * result + myUrl.hashCode();
     result = 29 * result + myRootType.hashCode();
     return result;
index a14a4e827b993d508640ecb6e021110eb1db0c87..499215d0caac9f1475f547cf95869e28399b9d74 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -17,115 +17,29 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
 
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.impl.libraries.LibraryEx;
-import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.vfs.VirtualFile;
-import org.jetbrains.annotations.NotNull;
 
-public class LibraryEditor implements Disposable {
-  private final Library myLibrary;
-  private final LibraryEditorListener myListener;
-  private String myLibraryName = null;
-  private Library.ModifiableModel myModel = null;
-
-  public LibraryEditor(Library library, @NotNull LibraryEditorListener listener) {
-    myLibrary = library;
-    myListener = listener;
-  }
-
-  public String getName() {
-    if (myLibraryName != null) {
-      return myLibraryName;
-    }
-    return myLibrary.getName();
-  }
-
-  public void dispose() {
-    if (myModel != null) {
-      // dispose if wasn't committed
-      Disposer.dispose(myModel);
-    }
-  }
-
-  public String[] getUrls(OrderRootType rootType) {
-    if (myModel != null) {
-      return myModel.getUrls(rootType);
-    }
-    return myLibrary.getUrls(rootType);
-  }
-
-  public VirtualFile[] getFiles(OrderRootType rootType) {
-    if (myModel != null) {
-      return myModel.getFiles(rootType);
-    }
-    return myLibrary.getFiles(rootType);
-  }
-
-  public void setName(String name) {
-    String oldName = getModel().getName();
-    myLibraryName = name;
-    getModel().setName(name);
-    myListener.libraryRenamed(myLibrary, oldName, name);
-  }
+/**
+ * @author nik
+ */
+public interface LibraryEditor extends Disposable {
+  String getName();
 
-  public void addRoot(String url, OrderRootType rootType) {
-    getModel().addRoot(url, rootType);
-  }
+  String[] getUrls(OrderRootType rootType);
 
-  public void addRoot(VirtualFile file, OrderRootType rootType) {
-    getModel().addRoot(file, rootType);
-  }
+  VirtualFile[] getFiles(OrderRootType rootType);
 
-  public void addJarDirectory(String url, boolean recursive) {
-    getModel().addJarDirectory(url, recursive);
-  }
+  void setName(String name);
 
-  public void addJarDirectory(VirtualFile file, boolean recursive) {
-    getModel().addJarDirectory(file, recursive);
-  }
+  void addRoot(VirtualFile file, OrderRootType rootType);
 
-  public void removeRoot(String url, OrderRootType rootType) {
-    while (getModel().removeRoot(url, rootType)) ;
-  }
+  void addJarDirectory(VirtualFile file, boolean recursive);
 
-  public void commit() {
-    if (myModel != null) {
-      myModel.commit();
-      myModel = null;
-      myLibraryName = null;
-    }
-  }
+  void removeRoot(String url, OrderRootType rootType);
 
-  public Library.ModifiableModel getModel() {
-    if (myModel == null) {
-      myModel = myLibrary.getModifiableModel();
-    }
-    return myModel;
-  }
+  boolean hasChanges();
 
-  public boolean hasChanges() {
-    return myModel != null && myModel.isChanged();
-  }
-  
-  public boolean isJarDirectory(String url) {
-    if (myModel != null) {
-      return myModel.isJarDirectory(url);
-    }
-    return myLibrary.isJarDirectory(url); 
-  }
-  
-  public boolean allPathsValid(OrderRootType orderRootType) {
-    if (myModel != null) {
-      return ((LibraryEx.ModifiableModelEx)myModel).allPathsValid(orderRootType);
-    }
-    return ((LibraryEx)myLibrary).allPathsValid(orderRootType); 
-  }
+  boolean isJarDirectory(String url);
 
-  public boolean isValid(final String url, final OrderRootType orderRootType) {
-    if (myModel != null) {
-      return myModel.isValid(url, orderRootType);
-    }
-    return myLibrary.isValid(url, orderRootType); 
-  }
+  boolean isValid(String url, OrderRootType orderRootType);
 }
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorDialogBase.java
new file mode 100644 (file)
index 0000000..4359382
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * 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.openapi.roots.ui.configuration.libraryEditor;
+
+import com.intellij.openapi.actionSystem.DataKey;
+import com.intellij.openapi.project.ProjectBundle;
+import com.intellij.openapi.roots.impl.ModuleLibraryTable;
+import com.intellij.openapi.roots.libraries.LibraryTable;
+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;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+* @author nik
+*/
+public abstract class LibraryEditorDialogBase extends DialogWrapper {
+  private JTextField myNameField;
+  private LibraryTableEditor myLibraryTableEditor;
+
+  public LibraryEditorDialogBase(final Component parent, final LibraryTableEditor libraryTableEditor) {
+    super(parent, true);
+    myLibraryTableEditor = libraryTableEditor;
+    setTitle(ProjectBundle.message("library.configure.title"));
+    Disposer.register(getDisposable(), myLibraryTableEditor);
+  }
+
+  public <T> void addFileChooserContext(DataKey<T> key, T value) {
+    myLibraryTableEditor.addFileChooserContext(key, value);
+  }
+
+  protected String getDimensionServiceKey() {
+    return "#com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorDialog";
+  }
+
+  public JComponent getPreferredFocusedComponent() {
+    return myNameField;
+  }
+
+  protected final void doOKAction() {
+    if (!validateAndApply()) {
+      return;
+    }
+    super.doOKAction();
+  }
+
+  protected boolean validateAndApply() {
+    final String currentName = myLibraryTableEditor.getLibraryEditor().getName();
+    String newName = myNameField.getText().trim();
+    if (newName.length() == 0) {
+      newName = null;
+    }
+    if (!Comparing.equal(newName, currentName)) {
+      final LibraryTable.ModifiableModel tableModifiableModel = getTableModifiableModel();
+      if (tableModifiableModel != null && !(tableModifiableModel instanceof ModuleLibraryTable)) {
+        if (newName == null) {
+          Messages.showErrorDialog(ProjectBundle.message("library.name.not.specified.error", newName), ProjectBundle.message("library.name.not.specified.title"));
+          return false;
+        }
+        if (LibraryTableEditor.libraryAlreadyExists(tableModifiableModel, newName)) {
+          Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", newName), ProjectBundle.message("library.name.already.exists.title"));
+          return false;
+        }
+      }
+      myLibraryTableEditor.renameLibrary(newName);
+    }
+    return true;
+  }
+
+  @Nullable
+  protected LibraryTable.ModifiableModel getTableModifiableModel() {
+    return null;
+  }
+
+  protected JComponent createNorthPanel() {
+    FormBuilder formBuilder = new FormBuilder();
+    String currentName = myLibraryTableEditor.getLibraryEditor().getName();
+    myNameField = new JTextField(currentName);
+    formBuilder.addLabeledComponent("&Name:", myNameField);
+    addNorthComponents(formBuilder);
+    myNameField.selectAll();
+
+    final JPanel panel = formBuilder.getPanel();
+    panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
+    return panel;
+  }
+
+  protected void addNorthComponents(FormBuilder formBuilder) {
+  }
+
+  protected JComponent createCenterPanel() {
+    return myLibraryTableEditor.getComponent();
+  }
+}
index 07ec1515d38c469622cd8ac319aa97d07f5170cf..93922c349189add638f27429c83b49c91b6f8bf9 100644 (file)
@@ -17,25 +17,18 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
 
 import com.intellij.ide.util.treeView.NodeDescriptor;
 import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.libraries.Library;
 
 public class LibraryElement extends LibraryTableTreeContentElement {
-  private final Library myLibrary;
   private final LibraryTableEditor myParentEditor;
   private final boolean myHasInvalidPaths;
 
-  public LibraryElement(Library library, LibraryTableEditor parentEditor, final boolean hasInvalidPaths) {
-    myLibrary = library;
+  public LibraryElement(LibraryTableEditor parentEditor, final boolean hasInvalidPaths) {
     myParentEditor = parentEditor;
     myHasInvalidPaths = hasInvalidPaths;
   }
 
-  public Library getLibrary() {
-    return myLibrary;
-  }
-
   public boolean isAnonymous() {
-    final String name = myParentEditor.getLibraryEditor(myLibrary).getName();
+    final String name = myParentEditor.getLibraryEditor().getName();
     return name == null;
   }
 
@@ -45,22 +38,11 @@ public class LibraryElement extends LibraryTableTreeContentElement {
 
   public boolean equals(Object o) {
     if (this == o) return true;
-    if (!(o instanceof LibraryElement)) {
-      return false;
-    }
-
-    final LibraryElement libraryElement = (LibraryElement)o;
-
-
-    if (!myLibrary.equals(libraryElement.myLibrary)) {
-      return false;
-    }
-
-    return true;
+    return o instanceof LibraryElement;
   }
 
   public int hashCode() {
-    return myLibrary.hashCode();
+    return 0;
   }
 
   public LibraryTableTreeContentElement getParent() {
index 68871923126c1d3d5512a4673e9b218adb2dff59..6662d033d41ad515018103e43bd889b7abe3403c 100644 (file)
@@ -18,7 +18,6 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
 import com.intellij.ide.util.treeView.NodeDescriptor;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.Icons;
 
@@ -37,10 +36,9 @@ class LibraryElementDescriptor extends NodeDescriptor<LibraryElement> {
   }
 
   public boolean update() {
-    final Library library = myElement.getLibrary();
     final String name;
     final Icon icon;
-    final LibraryEditor libraryEditor = myParentEditor.getLibraryEditor(library);
+    final LibraryEditor libraryEditor = myParentEditor.getLibraryEditor();
     if (myElement.isAnonymous()) {
       final VirtualFile[] files = libraryEditor.getFiles(OrderRootType.CLASSES);
       if (files.length > 0) {
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryFileChooser.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryFileChooser.java
deleted file mode 100644 (file)
index 85373c8..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright 2000-2009 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.openapi.roots.ui.configuration.libraryEditor;
-
-import com.intellij.openapi.fileChooser.FileChooserDescriptor;
-import com.intellij.openapi.fileChooser.ex.FileChooserDialogImpl;
-import com.intellij.openapi.project.ProjectBundle;
-import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.ui.FieldPanel;
-import com.intellij.util.ui.UIUtil;
-import org.jetbrains.annotations.Nullable;
-
-import javax.swing.*;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
-import java.awt.*;
-
-public class LibraryFileChooser extends FileChooserDialogImpl {
-  private JTextField myNameField;
-  private final boolean myInputName;
-  private final LibraryTableEditor myParentEditor;
-  private boolean myNameChangedByUser = false;
-
-  public LibraryFileChooser(FileChooserDescriptor chooserDescriptor,
-                            Component parent,
-                            boolean inputName,
-                            LibraryTableEditor parentEditor) {
-    super(chooserDescriptor, parent);
-    myInputName = inputName;
-    myParentEditor = parentEditor;
-  }
-
-  public String getName() {
-    if (myNameField != null) {
-      final String name = myNameField.getText().trim();
-      return name.length() > 0 ? name : null;
-    }
-    return null;
-  }
-
-  private void setName(String name) {
-    if (myNameField != null) {
-      final boolean savedValue = myNameChangedByUser;
-      try {
-        myNameField.setText(name);
-      }
-      finally {
-        myNameChangedByUser = savedValue;
-      }
-    }
-  }
-
-  public JComponent getPreferredFocusedComponent() {
-    return myInputName ? myNameField : super.getPreferredFocusedComponent();
-  }
-
-  protected JComponent createCenterPanel() {
-    final JComponent centerPanel = super.createCenterPanel();
-    if (!myInputName) {
-      return centerPanel;
-    }
-
-    final JPanel panel = new JPanel(new BorderLayout());
-    panel.add(centerPanel, BorderLayout.CENTER);
-
-    final FieldPanel fieldPanel = FieldPanel.create(ProjectBundle.message("library.name.prompt"), null);
-    fieldPanel.getFieldLabel().setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
-    myNameField = fieldPanel.getTextField();
-    myNameField.getDocument().addDocumentListener(new DocumentListener() {
-      public void changedUpdate(DocumentEvent e) {
-        myNameChangedByUser = true;
-      }
-
-      public void insertUpdate(DocumentEvent e) {
-        myNameChangedByUser = true;
-      }
-
-      public void removeUpdate(DocumentEvent e) {
-        myNameChangedByUser = true;
-      }
-    });
-    panel.add(fieldPanel, BorderLayout.NORTH);
-
-    myFileSystemTree.getTree().addTreeSelectionListener(new TreeSelectionListener() {
-      public void valueChanged(TreeSelectionEvent e) {
-        if (myNameField == null || myNameChangedByUser) {
-          return;
-        }
-        final VirtualFile[] selectedFiles = getSelectedFiles();
-        setName(selectedFiles.length == 1 ? selectedFiles[0].getNameWithoutExtension() : "");
-      }
-    });
-    return panel;
-  }
-
-  protected void doOKAction() {
-    if (!validateData()) {
-      return;
-    }
-
-    super.doOKAction();
-  }
-
-  private boolean validateData() {
-    JComponent componentToFocus = null;
-    try {
-      final VirtualFile[] chosenFiles = getSelectedFiles();
-      if (chosenFiles != null && chosenFiles.length > 0) {
-        if (myInputName) {
-          final String name = getName();
-          if (name == null) {
-            Messages.showErrorDialog(myNameField, ProjectBundle.message("library.name.not.specified.error"),
-                                     ProjectBundle.message("library.name.not.specified.title"));
-            componentToFocus = myNameField;
-            return false;
-          }
-          if (myParentEditor.libraryAlreadyExists(name)) {
-            Messages.showErrorDialog(myNameField, ProjectBundle.message("library.name.already.exists.error", name),
-                                     ProjectBundle.message("library.name.already.exists.title"));
-            componentToFocus = myNameField;
-            return false;
-          }
-        }
-      }
-      else {
-        Messages.showErrorDialog(ProjectBundle.message("library.files.not.selected.error"),
-                                 ProjectBundle.message("library.files.not.selected.title"));
-        componentToFocus = myFileSystemTree.getTree();
-        return false;
-      }
-      return true;
-    }
-    finally {
-      if (componentToFocus != null) {
-        final JComponent _componentToFocus = componentToFocus;
-        SwingUtilities.invokeLater(new Runnable() {
-          public void run() {
-            _componentToFocus.requestFocus();
-          }
-        });
-      }
-    }
-  }
-
-  public Pair<String, VirtualFile[]> chooseNameAndFiles(@Nullable VirtualFile toSelect) {
-    VirtualFile[] chosenFiles = choose(toSelect, null);
-    return new Pair<String, VirtualFile[]>(getName(), chosenFiles);
-  }
-
-  public Pair<String, VirtualFile[]> chooseNameAndFiles() {
-    return chooseNameAndFiles(null);
-  }
-}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsData.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsData.java
new file mode 100644 (file)
index 0000000..6b7bebf
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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.openapi.roots.ui.configuration.libraryEditor;
+
+/**
+ * @author nik
+ */
+public class LibraryRootsData {
+
+
+}
index a8124ef78e0ae5df633b9995c0841978ae794b15..6b6e7066d62744279cdd9dab562bd95d1e5b6162 100644 (file)
@@ -21,7 +21,6 @@ import com.intellij.ide.util.treeView.NodeDescriptor;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.DataKey;
 import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.fileChooser.FileChooser;
 import com.intellij.openapi.fileChooser.FileChooserDescriptor;
 import com.intellij.openapi.module.Module;
@@ -32,27 +31,22 @@ import com.intellij.openapi.roots.AnnotationOrderRootType;
 import com.intellij.openapi.roots.JavadocOrderRootType;
 import com.intellij.openapi.roots.OrderRootType;
 import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
-import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil;
 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.libraries.LibraryUtil;
-import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
 import com.intellij.openapi.roots.ui.configuration.ModuleEditor;
 import com.intellij.openapi.roots.ui.configuration.PathUIUtils;
-import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
-import com.intellij.openapi.roots.ui.configuration.projectRoot.BaseLibrariesConfigurable;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.ui.InputValidator;
-import com.intellij.openapi.ui.MasterDetailsComponent;
-import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
 import com.intellij.openapi.ui.popup.ListPopup;
 import com.intellij.openapi.ui.popup.PopupStep;
 import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
-import com.intellij.openapi.util.*;
+import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.IconLoader;
+import com.intellij.openapi.util.NullableComputable;
+import com.intellij.openapi.util.Ref;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.*;
 import com.intellij.openapi.vfs.ex.http.HttpFileSystem;
 import com.intellij.ui.ScrollPaneFactory;
@@ -61,7 +55,6 @@ import com.intellij.ui.treeStructure.Tree;
 import com.intellij.util.ArrayUtil;
 import com.intellij.util.Icons;
 import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -70,7 +63,6 @@ import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeModel;
-import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
 import java.awt.*;
 import java.awt.event.ActionEvent;
@@ -85,13 +77,11 @@ import java.util.List;
  * @author Eugene Zhuravlev
  *         Date: Jan 11, 2004
  */
-public class LibraryTableEditor implements Disposable, LibraryEditorListener {
+public class LibraryTableEditor implements Disposable {
   static final UrlComparator ourUrlComparator = new UrlComparator();
 
   private JPanel myPanel;
-  private JButton myAddLibraryButton;
   private JButton myRemoveButton;
-  private JButton myRenameLibraryButton;
   private JButton myAttachClassesButton;
   private JButton myAttachJarDirectoriesButton;
   private JButton myAttachSourcesButton;
@@ -101,57 +91,46 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
   private JButton myAttachAnnotationsButton;
   private JButton myAttachMoreButton;
   private Tree myTree;
-  private final Map<Library, LibraryEditor> myLibraryToEditorMap = new HashMap<Library, LibraryEditor>();
-
-  private final LibraryTableModifiableModelProvider myLibraryTableProvider;
-  private final boolean myEditingModuleLibraries;
   private LibraryTableTreeBuilder myTreeBuilder;
-  private LibraryTable.ModifiableModel myTableModifiableModel;
   private static final Icon INVALID_ITEM_ICON = IconLoader.getIcon("/nodes/ppInvalid.png");
   private static final Icon JAR_DIRECTORY_ICON = IconLoader.getIcon("/nodes/jarDirectory.png");
 
   private final Collection<Runnable> myListeners = new ArrayList<Runnable>();
-  private final List<LibraryEditorListener> myLibraryEditorListeners = new ArrayList<LibraryEditorListener>();
   @Nullable private final Project myProject;
 
   private final Map<DataKey, Object> myFileChooserUserData = new HashMap<DataKey, Object>();
+  private final LibraryEditor myLibraryEditor;
 
-  private LibraryTableEditor(LibraryTableModifiableModelProvider provider, Project project){
+  private LibraryTableEditor(Project project,
+                             LibraryEditor libraryEditor){
     myProject = project;
-    myLibraryTableProvider = provider;
-    myTableModifiableModel = myLibraryTableProvider.getModifiableModel();
-    final String tableLevel = provider.getTableLevel();
-    myEditingModuleLibraries = LibraryTableImplUtil.MODULE_LEVEL.equals(tableLevel);
-    if (!provider.isLibraryTableEditable()) {
-      myAddLibraryButton.setVisible(false);
-      myRenameLibraryButton.setVisible(false);
-    }
-  }
-
-  public static LibraryTableEditor editLibraryTable(LibraryTableModifiableModelProvider provider, Project project) {
-    LibraryTableEditor result = new LibraryTableEditor(provider,project);
-    result.init(new LibraryTableTreeStructure(result));
-    return result;
+    myLibraryEditor = libraryEditor;
   }
 
-  public static LibraryTableEditor editLibrary(final LibraryTableModifiableModelProvider provider,
-                                               final Library library,
-                                               final Project project) {
-    LibraryTableEditor tableEditor = new LibraryTableEditor(provider,project);
-    tableEditor.init(new LibraryTreeStructure(tableEditor, library));
-    Disposer.register(project, tableEditor);
+  public static LibraryTableEditor editLibrary(final @Nullable Project project, @NotNull LibraryEditor libraryEditor) {
+    LibraryTableEditor tableEditor = new LibraryTableEditor(project, libraryEditor);
+    tableEditor.init(new LibraryTreeStructure(tableEditor));
+    if (project != null) {
+      Disposer.register(project, tableEditor);
+    }
     return tableEditor;
   }
 
-  public static LibraryTableEditor editLibrary(LibraryTableModifiableModelProvider provider, Library library) {
-    LibraryTableEditor result = new LibraryTableEditor(provider,null);
-    result.init(new LibraryTreeStructure(result, library));
-    return result;
+  public static LibraryTableEditor editLibrary(@NotNull LibraryEditor libraryEditor) {
+    return editLibrary(null, libraryEditor);
   }
 
-  private static boolean libraryAlreadyExists(LibraryTable.ModifiableModel table, String libraryName) {
+  public static boolean libraryAlreadyExists(LibraryTable.ModifiableModel table, String libraryName) {
     for (Iterator<Library> it = table.getLibraryIterator(); it.hasNext(); ) {
-      if (libraryName.equals(it.next().getName())) {
+      final Library library = it.next();
+      final String libName;
+      if (table instanceof LibrariesModifiableModel){
+        libName = ((LibrariesModifiableModel)table).getLibraryEditor(library).getName();
+      }
+      else {
+        libName = library.getName();
+      }
+      if (libraryName.equals(libName)) {
         return true;
       }
     }
@@ -177,16 +156,7 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
     myTreePanel.setLayout(new BorderLayout());
     myTreePanel.add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER);
 
-    myAddLibraryButton.setText(myEditingModuleLibraries? ProjectBundle.message("library.add.jar.directory.action") :
-                               ProjectBundle.message("library.create.library.action"));
-    myAddLibraryButton.addActionListener(new AddLibraryAction());
     myRemoveButton.addActionListener(new RemoveAction());
-    if (myEditingModuleLibraries) {
-      myRenameLibraryButton.setVisible(false);
-    }
-    else if (myRenameLibraryButton.isVisible()){
-      myRenameLibraryButton.addActionListener(new RenameLibraryAction());
-    }
     myAttachClassesButton.addActionListener(new AttachClassesAction());
     myAttachJarDirectoriesButton.addActionListener(new AttachJarDirectoriesAction());
     myAttachSourcesButton.addActionListener(new AttachSourcesAction());
@@ -195,107 +165,39 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
     myAttachAnnotationsButton.addActionListener(new AttachAnnotationsAction());
 
     final LibraryTableAttachHandler[] handlers = LibraryTableAttachHandler.EP_NAME.getExtensions();
-    if (handlers.length == 0 || myProject == null) myAttachMoreButton.setVisible(false);
-    else if (handlers.length == 1) {
-      myAttachMoreButton.setText(handlers[0].getLongName());
+    final LibraryEditor libraryEditor = getLibraryEditor();
+    if (handlers.length == 0 || myProject == null || !(libraryEditor instanceof ExistingLibraryEditor)) {
+      myAttachMoreButton.setVisible(false);
+    }
+    else {
+      myAttachMoreButton.addActionListener(new AttachMoreAction(handlers, (ExistingLibraryEditor)libraryEditor));
+      if (handlers.length == 1) {
+        myAttachMoreButton.setText(handlers[0].getLongName());
+      }
     }
-    myAttachMoreButton.addActionListener(new AttachMoreAction(handlers));
 
     treeSelectionListener.updateButtons();
-
     Disposer.register(this, myTreeBuilder);
   }
 
-  public JComponent getComponent() {
-    return myPanel;
+  public Tree getTree() {
+    return myTree;
   }
 
-  public void selectLibrary(Library library, boolean expand) {
-    LibraryTableTreeContentElement element = new LibraryElement(library, this, false);
-    myTreeBuilder.updateAndSelect(element);
+  public JComponent getComponent() {
+    return myPanel;
   }
 
   public <T> void addFileChooserContext(DataKey<T> key, T value) {
     myFileChooserUserData.put(key, value);
   }
 
-  public LibraryEditor getLibraryEditor(Library library) {
-    if (myTableModifiableModel instanceof LibrariesModifiableModel){
-      return ((LibrariesModifiableModel)myTableModifiableModel).getLibraryEditor(library);
-    }
-    LibraryEditor libraryEditor = myLibraryToEditorMap.get(library);
-    if (libraryEditor == null) {
-      libraryEditor = new LibraryEditor(library, this);
-      myLibraryToEditorMap.put(library, libraryEditor);
-    }
-    return libraryEditor;
-  }
-
-  private void removeLibrary(Library library) {
-    final LibraryEditor libraryEditor = myLibraryToEditorMap.remove(library);
-    if (libraryEditor != null) Disposer.dispose(libraryEditor);
-    myTableModifiableModel.removeLibrary(library);
-    if (myProject != null){
-      ModuleStructureConfigurable.getInstance(myProject).fireItemsChangeListener(library);
-    }
-  }
-
-  /**
-   * Should call this method in order to commit all the changes that were done by the editor
-   */
-  public void commitChanges() {
-    ApplicationManager.getApplication().runWriteAction(new Runnable() {
-      public void run() {
-        for (LibraryEditor libraryEditor : myLibraryToEditorMap.values()) {
-          libraryEditor.commit();
-          Disposer.dispose(libraryEditor);
-        }
-        myTableModifiableModel.commit();
-      }
-    });
-    myTableModifiableModel = myLibraryTableProvider.getModifiableModel();
-    myLibraryToEditorMap.clear();
-  }
-
-  public void cancelChanges() {
-    for (LibraryEditor libraryEditor : new ArrayList<LibraryEditor>(myLibraryToEditorMap.values())) {
-      Disposer.dispose(libraryEditor);
-    }
-
-    myLibraryToEditorMap.clear();
+  public LibraryEditor getLibraryEditor() {
+    return myLibraryEditor;
   }
 
   public boolean hasChanges() {
-    if (myTableModifiableModel.isChanged()) {
-      return true;
-    }
-    for (final Library library : myLibraryToEditorMap.keySet()) {
-      final LibraryEditor libraryEditor = myLibraryToEditorMap.get(library);
-      if (libraryEditor.hasChanges()) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  public void addLibraryEditorListener(@NotNull LibraryEditorListener listener) {
-    myLibraryEditorListeners.add(listener);
-  }
-
-  public void libraryRenamed(@NotNull Library library, String oldName, String newName) {
-    for (LibraryEditorListener listener : myLibraryEditorListeners) {
-      listener.libraryRenamed(library, oldName, newName);
-    }
-  }
-
-  public Library[] getLibraries() {
-    return myTableModifiableModel.getLibraries();
-  }
-
-  @Nullable
-  private Object getSelectedElement() {
-    final TreePath selectionPath = myTreeBuilder.getTree().getSelectionPath();
-    return getPathElement(selectionPath);
+    return getLibraryEditor().hasChanges();
   }
 
   private Object[] getSelectedElements() {
@@ -334,157 +236,16 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
     return element;
   }
 
-  @Nullable
-  private Library getSelectedLibrary() {
-    if (myTreeBuilder != null && myTreeBuilder.getTreeStructure() instanceof LibraryTreeStructure) {
-      return ((LibraryTreeStructure)myTreeBuilder.getTreeStructure()).getLibrary();
-    } else {
-      return convertElementToLibrary(getSelectedElement());
-    }
-  }
-
-  private Library[] getSelectedLibraries() {
-    final List<Library> libs = new ArrayList<Library>();
-    final Object[] selectedElements = getSelectedElements();
-    for (Object selectedElement : selectedElements) {
-      final Library library = convertElementToLibrary(selectedElement);
-      if (library != null) {
-        libs.add(library);
-      }
-    }
-    return libs.toArray(new Library[libs.size()]);
-  }
-
-  @Nullable
-  private static Library convertElementToLibrary(Object selectedElement) {
-    LibraryElement libraryElement = null;
-    if (selectedElement instanceof LibraryElement) {
-      libraryElement = (LibraryElement)selectedElement;
-    }
-    else if (selectedElement instanceof ItemElement) {
-      selectedElement = ((ItemElement)selectedElement).getParent();
-    }
-    if (selectedElement instanceof ClassesElement) {
-      libraryElement = ((ClassesElement)selectedElement).getParent();
-    }
-    else if (selectedElement instanceof SourcesElement) {
-      libraryElement = ((SourcesElement)selectedElement).getParent();
-    }
-    else if (selectedElement instanceof JavadocElement) {
-      libraryElement = ((JavadocElement)selectedElement).getParent();
-    }
-    return libraryElement != null? libraryElement.getLibrary() : null;
-  }
-
-  public void renameLibrary(Library library, String newName) {
-    if (library == null) {
-      return;
-    }
-    final LibraryEditor libraryEditor = getLibraryEditor(library);
+  public void renameLibrary(String newName) {
+    final LibraryEditor libraryEditor = getLibraryEditor();
     libraryEditor.setName(newName);
     librariesChanged(false);
   }
 
-  /**
-   * @return true if Ok button was pressed on dialog close, false otherwise
-   */
-  @Nullable
-  public Library[] openDialog(final Component parent, final Collection<Library> selection, final boolean expandSelectedItems) {
-    final MyDialogWrapper dialogWrapper = new MyDialogWrapper(parent);
-    if (selection != null) {
-      ApplicationManager.getApplication().invokeLater(new Runnable() {
-        public void run() {
-          for (final Library library : selection) {
-            selectLibrary(library, expandSelectedItems);
-          }
-        }
-      }, ModalityState.stateForComponent(dialogWrapper.getContentPane()));
-    }
-    dialogWrapper.show();
-    return dialogWrapper.isOK() ? dialogWrapper.getSelectedLibraries() : null;
-  }
-
-  public ActionListener createAddLibraryAction(boolean select){
-    return new AddLibraryAction(select);
-  }
-
   public void dispose() {
     myTreeBuilder = null;
   }
 
-  private class AddLibraryAction implements ActionListener {
-    private boolean myNeedSelection;
-
-    public AddLibraryAction() {
-      this(false);
-    }
-
-    public AddLibraryAction(boolean select) {
-      myNeedSelection = select;
-    }
-
-    public void actionPerformed(ActionEvent e) {
-      final String initial = suggestNewLibraryName(myTableModifiableModel);
-      final String prompt = ProjectBundle.message("library.name.prompt");
-      final String title = myAddLibraryButton.getText().replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
-      final Icon icon = Messages.getQuestionIcon();
-      final String libraryName = Messages.showInputDialog(myProject, prompt, title, icon, initial, new InputValidator() {
-        public boolean checkInput(final String inputString) {
-          return true;
-        }
-        public boolean canClose(final String inputString) {
-          if (inputString.length() == 0)  {
-            Messages.showErrorDialog(ProjectBundle.message("library.name.not.specified.error"), ProjectBundle.message("library.name.not.specified.title"));
-            return false;
-          }
-          if (libraryAlreadyExists(myTableModifiableModel, inputString)) {
-            Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", inputString), ProjectBundle.message("library.name.already.exists.title"));
-            return false;
-          }
-          return true;
-        }
-      });
-      if (libraryName == null) return;
-      final Library library = myTableModifiableModel.createLibrary(libraryName);
-      selectLibrary(library, true);
-      if (myProject != null){
-        final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library);
-        final LibraryEditor libraryEditor = getLibraryEditor(library);
-        if (libraryEditor.hasChanges()) {
-          ApplicationManager.getApplication().runWriteAction(new Runnable(){
-            public void run() {
-              libraryEditor.commit();  //update lib node
-            }
-          });
-        }
-        final DefaultMutableTreeNode libraryNode = MasterDetailsComponent.findNodeByObject((TreeNode)rootConfigurable.getTree().getModel().getRoot(), library);
-        if (myNeedSelection){
-          rootConfigurable.selectNodeInTree(libraryNode);
-          if (!myEditingModuleLibraries) {
-            appendLibraryToModules(ModuleStructureConfigurable.getInstance(myProject), library);
-          }
-        }
-      }
-      librariesChanged(true);
-    }
-
-    private void appendLibraryToModules(final ModuleStructureConfigurable rootConfigurable, final Library libraryToSelect) {
-      final List<Module> modules = new ArrayList<Module>();
-      ContainerUtil.addAll(modules, rootConfigurable.getModules());
-      final ChooseModulesDialog dlg = new ChooseModulesDialog(myProject,
-                                                              modules, ProjectBundle.message("choose.modules.dialog.title"),
-                                                              ProjectBundle
-                                                                .message("choose.modules.dialog.description", libraryToSelect.getName()));
-      dlg.show();
-      if (dlg.isOK()) {
-        final List<Module> choosenModules = dlg.getChosenElements();
-        for (Module module : choosenModules) {
-          rootConfigurable.addLibraryOrderEntry(module, libraryToSelect);
-        }
-      }
-    }
-  }
-
   private abstract class AttachItemAction implements ActionListener {
     private final FileChooserDescriptor myDescriptor;
     private VirtualFile myLastChosen = null;
@@ -510,31 +271,28 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
     }
     
     public final void actionPerformed(ActionEvent e) {
-      final Library library = getSelectedLibrary();
-      if (library != null) {
-        myDescriptor.setTitle(getTitle());
-        myDescriptor.setDescription(getDescription());
-        for (Map.Entry<DataKey, Object> entry : myFileChooserUserData.entrySet()) {
-          myDescriptor.putUserData(entry.getKey(), entry.getValue());
-        }
-        VirtualFile toSelect = getFileToSelect(library);
-        final VirtualFile[] attachedFiles =
-          attachFiles(library, scanForActualRoots(FileChooser.chooseFiles(myPanel, myDescriptor, toSelect)), getRootType(),
-                      addAsJarDirectories());
-        if (attachedFiles.length > 0) {
-          myLastChosen = attachedFiles[0];
-        }
+      myDescriptor.setTitle(getTitle());
+      myDescriptor.setDescription(getDescription());
+      for (Map.Entry<DataKey, Object> entry : myFileChooserUserData.entrySet()) {
+        myDescriptor.putUserData(entry.getKey(), entry.getValue());
+      }
+      VirtualFile toSelect = getFileToSelect();
+      final VirtualFile[] attachedFiles =
+        attachFiles(scanForActualRoots(FileChooser.chooseFiles(myPanel, myDescriptor, toSelect)), getRootType(),
+                    addAsJarDirectories());
+      if (attachedFiles.length > 0) {
+        myLastChosen = attachedFiles[0];
       }
       fireLibrariesChanged();
       myTree.requestFocus();
     }
 
     @Nullable
-    private VirtualFile getFileToSelect(Library library) {
+    private VirtualFile getFileToSelect() {
       VirtualFile toSelect = myLastChosen;
       if (toSelect == null) {
         for (OrderRootType orderRootType : OrderRootType.getAllPersistentTypes()) {
-          final VirtualFile[] existingRoots = library.getFiles(orderRootType);
+          final VirtualFile[] existingRoots = getLibraryEditor().getFiles(orderRootType);
           if (existingRoots.length > 0) {
             VirtualFile existingRoot = existingRoots [0];
             if (existingRoot.getFileSystem() instanceof JarFileSystem) {
@@ -552,9 +310,10 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
           }
         }
       }
-      if (toSelect == null && Comparing.strEqual(myLibraryTableProvider.getTableLevel(), LibraryTablesRegistrar.PROJECT_LEVEL)) {
+      if (toSelect == null) {
         final Project project = myProject;
         if (project != null) {
+          //todo[nik] perhaps we shouldn't select project base dir if global library is edited
           toSelect = project.getBaseDir();
         }
       }
@@ -562,12 +321,12 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
     }
   }
 
-  private VirtualFile[] attachFiles(final Library library, final VirtualFile[] files, final OrderRootType rootType, final boolean isJarDirectories) {
-    final VirtualFile[] filesToAttach = filterAlreadyAdded(library, files, rootType);
+  private VirtualFile[] attachFiles(final VirtualFile[] files, final OrderRootType rootType, final boolean isJarDirectories) {
+    final VirtualFile[] filesToAttach = filterAlreadyAdded(files, rootType);
     if (filesToAttach.length > 0) {
       ApplicationManager.getApplication().runWriteAction(new Runnable() {
         public void run() {
-          final LibraryEditor libraryEditor = getLibraryEditor(library);
+          final LibraryEditor libraryEditor = getLibraryEditor();
           for (VirtualFile file : filesToAttach) {
             if (isJarDirectories) {
               libraryEditor.addJarDirectory(file, false);
@@ -576,9 +335,6 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
               libraryEditor.addRoot(file, rootType);
             }
           }
-          if (myEditingModuleLibraries) {
-            commitChanges();
-          }
         }
       });
       myTreeBuilder.updateFromRoot();
@@ -586,23 +342,14 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
     return filesToAttach;
   }
 
-  private VirtualFile[] filterAlreadyAdded(Library lib, VirtualFile[] files, final OrderRootType rootType) {
+  private VirtualFile[] filterAlreadyAdded(VirtualFile[] files, final OrderRootType rootType) {
     if (files == null || files.length == 0) {
       return VirtualFile.EMPTY_ARRAY;
     }
     final Set<VirtualFile> chosenFilesSet = new HashSet<VirtualFile>(Arrays.asList(files));
     final Set<VirtualFile> alreadyAdded = new HashSet<VirtualFile>();
-    if (lib == null) {
-      final Library[] libraries = myTableModifiableModel.getLibraries();
-      for (Library library : libraries) {
-        final VirtualFile[] libraryFiles = getLibraryEditor(library).getFiles(rootType);
-        ContainerUtil.addAll(alreadyAdded, libraryFiles);
-      }
-    }
-    else {
-      final VirtualFile[] libraryFiles = getLibraryEditor(lib).getFiles(rootType);
-      ContainerUtil.addAll(alreadyAdded, libraryFiles);
-    }
+    final VirtualFile[] libraryFiles = getLibraryEditor().getFiles(rootType);
+    ContainerUtil.addAll(alreadyAdded, libraryFiles);
     chosenFilesSet.removeAll(alreadyAdded);
     return VfsUtil.toVirtualFileArray(chosenFilesSet);
   }
@@ -614,12 +361,12 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
     }
 
     protected String getTitle() {
-      final Library selectedLibrary = getSelectedLibrary();
-      if (selectedLibrary != null) {
-        return ProjectBundle.message("library.attach.classes.to.library.action", getLibraryEditor(selectedLibrary).getName());
+      final String name = getLibraryEditor().getName();
+      if (StringUtil.isEmpty(name)) {
+        return ProjectBundle.message("library.attach.classes.action");
       }
       else {
-        return ProjectBundle.message("library.attach.classes.action");
+        return ProjectBundle.message("library.attach.classes.to.library.action", name);
       }
     }
 
@@ -643,12 +390,12 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
     }
 
     protected String getTitle() {
-      final Library selectedLibrary = getSelectedLibrary();
-      if (selectedLibrary != null) {
-        return ProjectBundle.message("library.attach.jar.directory.to.library.action", getLibraryEditor(selectedLibrary).getName());
+      final String name = getLibraryEditor().getName();
+      if (StringUtil.isEmpty(name)) {
+        return ProjectBundle.message("library.attach.jar.directory.action");
       }
       else {
-        return ProjectBundle.message("library.attach.jar.directory.action");
+        return ProjectBundle.message("library.attach.jar.directory.to.library.action", name);
       }
     }
 
@@ -714,12 +461,9 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
 
   private class AttachUrlJavadocAction implements ActionListener {
     public void actionPerformed(ActionEvent e) {
-      final Library library = getSelectedLibrary();
-      if (library != null) {
-        final VirtualFile vFile = Util.showSpecifyJavadocUrlDialog(myPanel);
-        if (vFile != null) {
-          attachFiles(library, new VirtualFile[] {vFile}, JavadocOrderRootType.getInstance(), false);
-        }
+      final VirtualFile vFile = Util.showSpecifyJavadocUrlDialog(myPanel);
+      if (vFile != null) {
+        attachFiles(new VirtualFile[] {vFile}, JavadocOrderRootType.getInstance(), false);
       }
       myTree.requestFocus();
     }
@@ -734,18 +478,11 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
       ApplicationManager.getApplication().runWriteAction(new Runnable() {
         public void run() {
           for (Object selectedElement : selectedElements) {
-            if (selectedElement instanceof LibraryElement) {
-              removeLibrary(((LibraryElement)selectedElement).getLibrary());
-            }
-            else if (selectedElement instanceof ItemElement) {
+            if (selectedElement instanceof ItemElement) {
               final ItemElement itemElement = (ItemElement)selectedElement;
-              final Library library = itemElement.getLibrary();
-              getLibraryEditor(library).removeRoot(itemElement.getUrl(), itemElement.getRootType());
+              getLibraryEditor().removeRoot(itemElement.getUrl(), itemElement.getRootType());
             }
           }
-          if (myEditingModuleLibraries) {
-            commitChanges();
-          }
         }
       });
       librariesChanged(true);
@@ -776,136 +513,6 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
     myListeners.remove(listener);
   }
 
-  private class RenameLibraryAction implements ActionListener {
-    public void actionPerformed(ActionEvent e) {
-      final Library selectedLibrary = getSelectedLibrary();
-      if (selectedLibrary == null) {
-        return;
-      }
-      final String currentName = selectedLibrary.getName();
-      final String newName = Messages.showInputDialog(myTree, ProjectBundle.message("library.rename.prompt"),
-                                                      ProjectBundle.message("library.rename.title", getLibraryEditor(selectedLibrary).getName()), Messages.getQuestionIcon(), getLibraryEditor(selectedLibrary).getName(), new InputValidator() {
-        public boolean checkInput(String inputString) {
-          return true;
-        }
-        public boolean canClose(String libraryName) {
-          if (!currentName.equals(libraryName)) {
-            if (libraryAlreadyExists(libraryName)) {
-              Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", libraryName),
-                                       ProjectBundle.message("library.name.already.exists.title"));
-              return false;
-            }
-          }
-          return true;
-        }
-      });
-      renameLibrary(selectedLibrary, newName);
-    }
-  }
-
-  boolean libraryAlreadyExists(String libraryName) {
-    for (Iterator it = myTableModifiableModel.getLibraryIterator(); it.hasNext(); ) {
-      final Library lib = (Library)it.next();
-      final LibraryEditor editor = getLibraryEditor(lib);
-      final String libName = editor != null ? editor.getName() : lib.getName();
-      if (libraryName.equals(libName)) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  private class MyDialogWrapper extends DialogWrapper {
-    private JTextField myNameField;
-    private Library[] mySelectedLibraries;
-
-    public MyDialogWrapper(final Component parent) {
-      super(parent, true);
-      setTitle(myLibraryTableProvider.getLibraryTablePresentation().getLibraryTableEditorTitle());
-      init();
-      
-      Disposer.register(getDisposable(), LibraryTableEditor.this);
-    }
-
-    @SuppressWarnings({"RefusedBequest"})
-    protected String getDimensionServiceKey() {
-      return "#com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor.MyDialogWrapper";
-    }
-
-    @SuppressWarnings({"RefusedBequest"})
-    public JComponent getPreferredFocusedComponent() {
-      if (myNameField != null) {
-        return myNameField;
-      }
-      return myTree;
-    }
-
-    protected void doOKAction() {
-      mySelectedLibraries = LibraryTableEditor.this.getSelectedLibraries();
-
-      if (myNameField != null) {
-        final Library library = getSelectedLibrary();
-        final String currentName = getLibraryEditor(library).getName();
-        String newName = myNameField.getText().trim();
-        if (newName.length() == 0) {
-          newName = null;
-        }
-        if (!Comparing.equal(newName, currentName)) {
-          if (!myEditingModuleLibraries) {
-            if (newName == null) {
-              Messages.showErrorDialog(ProjectBundle.message("library.name.not.specified.error", newName), ProjectBundle.message("library.name.not.specified.title"));
-              return;
-            }
-            if (libraryAlreadyExists(newName)) {
-              Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", newName), ProjectBundle.message("library.name.already.exists.title"));
-              return;
-            }
-          }
-          renameLibrary(library, newName);
-        }
-      }
-      commitChanges();
-      super.doOKAction();
-    }
-
-    protected JComponent createNorthPanel() {
-      if (myTreeBuilder.getTreeStructure() instanceof LibraryTreeStructure) {
-        final Library library = getSelectedLibrary();
-        final JPanel panel = new JPanel(new BorderLayout());
-        panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
-        final LibraryEditor libraryEditor = getLibraryEditor(library);
-        String currentName = libraryEditor.getName();
-        /*
-        if (currentName == null || currentName.length() == 0) {
-          final String[] urls = libraryEditor.getUrls(OrderRootType.CLASSES);
-          if (urls.length > 0) {
-            String url = urls[0];
-            final int idx = url.lastIndexOf('/');
-            if (idx)
-          }
-        }
-        */
-        myNameField = new JTextField(currentName);
-        panel.add(myNameField, BorderLayout.CENTER);
-        final JLabel label = new JLabel("Name: ");
-        panel.add(label, BorderLayout.WEST);
-        label.setLabelFor(myNameField);
-        label.setDisplayedMnemonic('N');
-        myNameField.selectAll();
-        return panel;
-      }
-      return super.createNorthPanel();
-    }
-
-    protected JComponent createCenterPanel() {
-      return LibraryTableEditor.this.getComponent();
-    }
-
-    public Library[] getSelectedLibraries() {
-      return mySelectedLibraries;
-    }
-  }
-
   private class MyTreeSelectionListener implements TreeSelectionListener {
     public void valueChanged(TreeSelectionEvent e) {
       updateButtons();
@@ -913,35 +520,18 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
 
     public void updateButtons() {
       final Object[] selectedElements = getSelectedElements();
-      final Class<? extends Object> elementsClass = getElementsClass(selectedElements);
-      myRemoveButton.setEnabled(
-        elementsClass != null &&
-        !(elementsClass.isAssignableFrom(ClassesElement.class) || elementsClass.equals(SourcesElement.class) || elementsClass.isAssignableFrom(JavadocElement.class) || elementsClass.isAssignableFrom(AnnotationElement.class))
-        && (myLibraryTableProvider.isLibraryTableEditable() || !elementsClass.isAssignableFrom(LibraryElement.class))
+      final Class<?> elementsClass = getElementsClass(selectedElements);
+      myRemoveButton.setEnabled(elementsClass != null &&
+                !(elementsClass.isAssignableFrom(ClassesElement.class) || elementsClass.equals(SourcesElement.class) || elementsClass.isAssignableFrom(JavadocElement.class) || elementsClass.isAssignableFrom(AnnotationElement.class))
       );
-      myRenameLibraryButton.setEnabled(selectedElements.length == 1 && elementsClass != null && elementsClass.equals(LibraryElement.class));
-      if (elementsClass != null && elementsClass.isAssignableFrom(ItemElement.class)) {
-        myRemoveButton.setText(ProjectBundle.message("library.detach.action"));
-      }
-      else {
-        myRemoveButton.setText(ProjectBundle.message("library.detach.action"));
-      }
-      boolean attachActionsEnabled = selectedElements.length == 1 || getSelectedLibrary() != null;
-      myAttachClassesButton.setEnabled(attachActionsEnabled);
-      myAttachJavadocsButton.setEnabled(attachActionsEnabled);
-      myAttachUrlJavadocsButton.setEnabled(attachActionsEnabled);
-      myAttachSourcesButton.setEnabled(attachActionsEnabled);
-      myAttachAnnotationsButton.setEnabled(attachActionsEnabled);
-      myAttachJarDirectoriesButton.setEnabled(attachActionsEnabled);
-      myAttachMoreButton.setEnabled(attachActionsEnabled);
     }
 
     @Nullable
-    private Class<? extends Object> getElementsClass(Object[] elements) {
+    private Class<?> getElementsClass(Object[] elements) {
       if (elements.length == 0) {
         return null;
       }
-      Class<? extends Object> cls = null;
+      Class<?> cls = null;
       for (Object element : elements) {
         if (cls == null) {
           cls = element.getClass();
@@ -1052,19 +642,20 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
 
   private class AttachMoreAction implements ActionListener {
     private final LibraryTableAttachHandler[] myHandlers;
+    private final ExistingLibraryEditor myLibraryEditor;
 
-    public AttachMoreAction(LibraryTableAttachHandler[] handlers) {
+    public AttachMoreAction(LibraryTableAttachHandler[] handlers, final ExistingLibraryEditor libraryEditor) {
       myHandlers = handlers;
+      myLibraryEditor = libraryEditor;
     }
 
     public void actionPerformed(ActionEvent e) {
-      final Library library = getSelectedLibrary();
-      assert library != null;
       final Ref<Library.ModifiableModel> modelRef = Ref.create(null);
       final NullableComputable<Library.ModifiableModel> computable = new NullableComputable<Library.ModifiableModel>() {
         public Library.ModifiableModel compute() {
           if (myTreeBuilder == null) {
             // The following lines were born in severe pain & suffering, please respect
+            final Library library = myLibraryEditor.getLibrary();
             final InvocationHandler invocationHandler = Proxy.isProxyClass(library.getClass())? Proxy.getInvocationHandler(library) : null;
             final Library realLibrary = invocationHandler instanceof ModuleEditor.ProxyDelegateAccessor? (Library)((ModuleEditor.ProxyDelegateAccessor)invocationHandler)
               .getDelegate() : library;
@@ -1076,7 +667,7 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
             return model;
           }
           else {
-            return getLibraryEditor(library).getModel();
+            return myLibraryEditor.getModel();
           }
         }
       };
@@ -1089,7 +680,7 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
             public void run() {
               if (myTreeBuilder != null) myTreeBuilder.queueUpdate();
               if (myProject != null) {
-                ModuleStructureConfigurable.getInstance(myProject).fireItemsChangeListener(library);
+                ModuleStructureConfigurable.getInstance(myProject).fireItemsChangeListener(myLibraryEditor.getLibrary());
               }
             }
           });
@@ -1119,7 +710,6 @@ public class LibraryTableEditor implements Disposable, LibraryEditorListener {
           public PopupStep onChosen(final LibraryTableAttachHandler handler, final boolean finalChoice) {
             ApplicationManager.getApplication().invokeLater(new Runnable() {
               public void run() {
-                getSelectedLibrary();
                 handler.performAttach(myProject, computable).doWhenProcessed(successRunnable).doWhenRejected(rejectRunnable);
               }
             });
index da2b2cacb9d053c7c28cbd60bbda38bed69ad003..0bed99458b4cc8770735da3ea777b8d172f54a6a 100644 (file)
@@ -20,7 +20,6 @@ import com.intellij.openapi.roots.OrderRootType;
 import org.jetbrains.annotations.Nullable;
 
 public abstract class LibraryTableTreeContentElement {
-  // empty, just to serve as a base for all tree structure elements
 
   public abstract LibraryTableTreeContentElement getParent();
 
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableTreeStructure.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableTreeStructure.java
deleted file mode 100644 (file)
index a3dd827..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2000-2009 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.openapi.roots.ui.configuration.libraryEditor;
-
-import com.intellij.ide.util.treeView.NodeDescriptor;
-import com.intellij.openapi.project.ProjectBundle;
-import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.openapi.roots.ui.configuration.LibrariesAlphaComparator;
-import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
-import com.intellij.util.ArrayUtil;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-class LibraryTableTreeStructure extends AbstractLibraryTreeStructure {
-  private final Object myRootElement = new Object();
-
-  public LibraryTableTreeStructure(LibraryTableEditor parentEditor) {
-    super(parentEditor);
-    myRootElementDescriptor = new NodeDescriptor(null, null) {
-      public boolean update() {
-        myName = ProjectBundle.message("library.root.node");
-        return false;
-      }
-      public Object getElement() {
-        return myRootElement;
-      }
-    };
-  }
-
-  public Object getRootElement() {
-    return myRootElement;
-  }
-
-  public Object[] getChildElements(Object element) {
-    if (element == myRootElement) {
-      final Library[] libraries = myParentEditor.getLibraries();
-      Arrays.sort(libraries, LibrariesAlphaComparator.INSTANCE);
-      LibraryElement[] elements = new LibraryElement[libraries.length];
-      for (int idx = 0; idx < libraries.length; idx++) {
-        final Library library = libraries[idx];
-        boolean allPathsValid = true;
-        for (OrderRootType type : OrderRootType.getAllTypes()) {
-          allPathsValid &= allPathsValid(library, type);
-        }
-        elements[idx] = new LibraryElement(library, myParentEditor, !allPathsValid);
-      }
-      return elements;
-    }
-
-    if (element instanceof LibraryElement) {
-      final LibraryElement libraryItemElement = (LibraryElement)element;
-      ArrayList<LibraryTableTreeContentElement> elements = new ArrayList<LibraryTableTreeContentElement>(3);
-      final Library library = libraryItemElement.getLibrary();
-
-      final LibraryEditor parentEditor = myParentEditor.getLibraryEditor(library);
-      for (OrderRootType type : OrderRootType.getAllTypes()) {
-        final String[] urls = parentEditor.getUrls(type);
-        if (urls.length > 0) {
-          elements.add(OrderRootTypeUIFactory.FACTORY.getByKey(type).createElement(libraryItemElement));
-        }
-      }
-      return elements.toArray();
-    }
-
-    if (element instanceof LibraryTableTreeContentElement) {
-      final LibraryTableTreeContentElement contentElement = (LibraryTableTreeContentElement)element;
-      final LibraryTableTreeContentElement parentElement = contentElement.getParent();
-      if (parentElement instanceof LibraryElement) {
-        return buildItems(contentElement, ((LibraryElement)parentElement).getLibrary(), contentElement.getOrderRootType());
-      }
-    }
-    return ArrayUtil.EMPTY_OBJECT_ARRAY;
-  }
-
-  private boolean allPathsValid(Library library, OrderRootType orderRootType) {
-    return myParentEditor.getLibraryEditor(library).allPathsValid(orderRootType);
-  }
-
-}
index 4362bebd5c63735cf9fc091cc870219fd2166728..756ed767248de51e4c917fb860c56086029190fe 100644 (file)
  */
 package com.intellij.openapi.roots.ui.configuration.libraryEditor;
 
+import com.intellij.ide.util.treeView.AbstractTreeStructure;
 import com.intellij.ide.util.treeView.NodeDescriptor;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.roots.ui.configuration.OrderRootTypeUIFactory;
 import com.intellij.util.ArrayUtil;
+import org.jetbrains.annotations.NotNull;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 
-public class LibraryTreeStructure extends AbstractLibraryTreeStructure {
+public class LibraryTreeStructure extends AbstractTreeStructure {
   private final LibraryElement myRootElement;
+  protected NodeDescriptor myRootElementDescriptor;
+  protected final LibraryTableEditor myParentEditor;
 
-  public LibraryTreeStructure(LibraryTableEditor parentElement, Library library) {
-    super(parentElement);
-    myRootElement = new LibraryElement(library, myParentEditor, false);
+  public LibraryTreeStructure(LibraryTableEditor parentElement) {
+    myParentEditor = parentElement;
+    myRootElement = new LibraryElement(myParentEditor, false);
     myRootElementDescriptor = new NodeDescriptor(null, null) {
       public boolean update() {
         myName = ProjectBundle.message("library.root.node");
@@ -48,8 +52,7 @@ public class LibraryTreeStructure extends AbstractLibraryTreeStructure {
   public Object[] getChildElements(Object element) {
     if (element == myRootElement) {
       ArrayList<LibraryTableTreeContentElement> elements = new ArrayList<LibraryTableTreeContentElement>(3);
-      final Library library = myRootElement.getLibrary();
-      final LibraryEditor parentEditor = myParentEditor.getLibraryEditor(library);
+      final LibraryEditor parentEditor = myParentEditor.getLibraryEditor();
       for (OrderRootType type : OrderRootType.getAllTypes()) {
         final String[] urls = parentEditor.getUrls(type);
         if (urls.length > 0) {
@@ -63,13 +66,49 @@ public class LibraryTreeStructure extends AbstractLibraryTreeStructure {
       final LibraryTableTreeContentElement contentElement = (LibraryTableTreeContentElement)element;
       final LibraryTableTreeContentElement parentElement = contentElement.getParent();
       if (parentElement instanceof LibraryElement) {
-        return buildItems(contentElement, ((LibraryElement)parentElement).getLibrary(), contentElement.getOrderRootType());
+        return buildItems(contentElement, contentElement.getOrderRootType());
       }
     }
     return ArrayUtil.EMPTY_OBJECT_ARRAY;
   }
 
-  public Library getLibrary() {
-    return myRootElement.getLibrary();
+  public void commit() {
+  }
+
+  public boolean hasSomethingToCommit() {
+    return false;
+  }
+
+  protected Object[] buildItems(LibraryTableTreeContentElement parent, OrderRootType orderRootType) {
+    ArrayList<ItemElement> items = new ArrayList<ItemElement>();
+    final LibraryEditor libraryEditor = myParentEditor.getLibraryEditor();
+    final String[] urls = libraryEditor.getUrls(orderRootType).clone();
+    Arrays.sort(urls, LibraryTableEditor.ourUrlComparator);
+    for (String url : urls) {
+      items.add(new ItemElement(parent, url, orderRootType, libraryEditor.isJarDirectory(url), libraryEditor.isValid(url, orderRootType)));
+    }
+    return items.toArray();
+  }
+
+  public Object getParentElement(Object element) {
+    Object rootElement = getRootElement();
+    if (element == rootElement) {
+      return null;
+    }
+    if (element instanceof LibraryTableTreeContentElement) {
+      return ((LibraryTableTreeContentElement)element).getParent();
+    }
+    return rootElement;
+  }
+
+  @NotNull
+  public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
+    if (element == getRootElement()) {
+      return myRootElementDescriptor;
+    }
+    if (element instanceof LibraryTableTreeContentElement) {
+      return ((LibraryTableTreeContentElement)element).createDescriptor(parentDescriptor, myParentEditor);
+    }
+    return null;
   }
 }
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java
new file mode 100644 (file)
index 0000000..2ed87b4
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * 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.openapi.roots.ui.configuration.libraryEditor;
+
+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.vfs.VirtualFile;
+import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
+import com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer;
+import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author nik
+ */
+public class NewLibraryEditor implements LibraryEditor {
+  private String myLibraryName;
+  private final Map<OrderRootType, VirtualFilePointerContainer> myRoots;
+  private final Map<String, Boolean> myJarDirectories = new HashMap<String, Boolean>();
+
+  public NewLibraryEditor() {
+    myRoots = new HashMap<OrderRootType, VirtualFilePointerContainer>();
+    for (OrderRootType rootType : OrderRootType.getAllTypes()) {
+      myRoots.put(rootType, VirtualFilePointerManager.getInstance().createContainer(this));
+    }
+  }
+
+  @Override
+  public String getName() {
+    return myLibraryName;
+  }
+
+  @Override
+  public String[] getUrls(OrderRootType rootType) {
+    return myRoots.get(rootType).getUrls();
+  }
+
+  @Override
+  public VirtualFile[] getFiles(OrderRootType rootType) {
+    return LibraryImpl.getRootFiles(myRoots.get(rootType), myJarDirectories);
+  }
+
+  @Override
+  public void setName(String name) {
+    myLibraryName = name;
+  }
+
+  @Override
+  public void addRoot(VirtualFile file, OrderRootType rootType) {
+    myRoots.get(rootType).add(file);
+  }
+
+  @Override
+  public void addJarDirectory(VirtualFile file, boolean recursive) {
+    myRoots.get(OrderRootType.CLASSES).add(file);
+    myJarDirectories.put(file.getUrl(), recursive);
+  }
+
+  @Override
+  public void removeRoot(String url, OrderRootType rootType) {
+    final VirtualFilePointerContainer container = myRoots.get(rootType);
+    final VirtualFilePointer pointer = container.findByUrl(url);
+    if (pointer != null) {
+      myJarDirectories.remove(pointer.getUrl());
+      container.remove(pointer);
+    }
+  }
+
+  @Override
+  public boolean hasChanges() {
+    return true;
+  }
+
+  @Override
+  public boolean isJarDirectory(String url) {
+    return myJarDirectories.containsKey(url);
+  }
+
+  @Override
+  public boolean isValid(String url, OrderRootType orderRootType) {
+    final VirtualFilePointer pointer = myRoots.get(orderRootType).findByUrl(url);
+    return pointer != null && pointer.isValid();
+  }
+
+  @Override
+  public void dispose() {
+  }
+
+  public void apply(@NotNull Library.ModifiableModel model) {
+    model.setName(myLibraryName);
+    for (Map.Entry<OrderRootType, VirtualFilePointerContainer> entry : myRoots.entrySet()) {
+      for (String url : entry.getValue().getUrls()) {
+        model.addRoot(url, entry.getKey());
+      }
+    }
+    for (Map.Entry<String, Boolean> entry : myJarDirectories.entrySet()) {
+      model.addJarDirectory(entry.getKey(), entry.getValue());
+    }
+  }
+}
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java
deleted file mode 100644 (file)
index d73f74b..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2000-2009 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.openapi.roots.ui.configuration.packaging;
-
-import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.ide.util.ChooseElementsDialog;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.project.Project;
-import com.intellij.util.Icons;
-
-import javax.swing.*;
-import java.util.List;
-
-/**
- * @author nik
- */
-public class ChooseLibrariesDialog extends ChooseElementsDialog<Library> {
-
-  public ChooseLibrariesDialog(Project project, List<? extends Library> items, String title, String description) {
-    super(project, items, title, description, true);
-  }
-
-  protected String getItemText(final Library item) {
-    return item != null ? PackagingEditorUtil.getLibraryItemText(item, true) : "";
-  }
-
-  protected Icon getItemIcon(final Library item) {
-    if (item.getName() != null) {
-      return Icons.LIBRARY_ICON;
-    }
-    VirtualFile[] files = item.getFiles(OrderRootType.CLASSES);
-    if (files.length == 1) {
-      return files[0].getFileType().getIcon();
-    }
-    return Icons.LIBRARY_ICON;
-  }
-}
index 2d3079a3e5c0b6f5ff8b740a163d3082261e5ad2..472db8b275a484bf6a18c5f3fbeed846afec4a32 100644 (file)
@@ -27,15 +27,13 @@ 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.LibraryTableModifiableModelProvider;
-import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
+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.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.ui.NamedConfigurable;
 import com.intellij.openapi.ui.TextFieldWithBrowseButton;
-import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VfsUtil;
@@ -98,7 +96,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
   }
 
   protected void loadTree() {
-    createLibrariesNode(myContext.createModifiableModelProvider(myLevel, false));
+    createLibrariesNode(myContext.createModifiableModelProvider(myLevel));
   }
 
   @NotNull
@@ -118,7 +116,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
     return result;
   }
 
-  private void createLibrariesNode(final LibraryTableModifiableModelProvider modelProvider) {
+  private void createLibrariesNode(final StructureLibraryTableModifiableModelProvider modelProvider) {
     final Library[] libraries = modelProvider.getModifiableModel().getLibraries();
     for (Library library : libraries) {
       myRoot.add(new MyNode(new LibraryConfigurable(modelProvider, library, myProject, TREE_UPDATER)));
@@ -149,7 +147,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
     if (table != null) {
       final String level = table.getTableLevel();
       final LibraryConfigurable configurable =
-        new LibraryConfigurable(myContext.createModifiableModelProvider(level, false), library, myProject, TREE_UPDATER);
+        new LibraryConfigurable(myContext.createModifiableModelProvider(level), library, myProject, TREE_UPDATER);
       final MyNode node = new MyNode(configurable);
       addNode(node, myRoot);
       myContext.getDaemonAnalyzer().queueUpdate(new LibraryProjectStructureElement(myContext, library));
@@ -175,29 +173,23 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
         setPopup(false);
       }
 
+      @NotNull
       public AnAction[] getChildren(@Nullable final AnActionEvent e) {
-        return new AnAction[]{new AnAction(getAddText()) {
-          public void actionPerformed(AnActionEvent e) {
-            final LibraryTableEditor editor = LibraryTableEditor.editLibraryTable(getModelProvider(false), myProject);
-            editor.addLibraryEditorListener(myContext);
-            editor.createAddLibraryAction(true).actionPerformed(null);
-            Disposer.dispose(editor);
-          }
-        }};
+        return new AnAction[]{new CreateNewLibraryAction(getAddText(), getModelProvider(), myProject)};
       }
     };
   }
 
   protected abstract String getAddText();
 
-  public abstract LibraryTableModifiableModelProvider getModelProvider(final boolean editable);
+  public abstract StructureLibraryTableModifiableModelProvider getModelProvider();
 
   public abstract BaseLibrariesConfigurable getOppositeGroup();
 
   protected void removeLibrary(final Library library) {
     final LibraryTable table = library.getTable();
     if (table != null) {
-      getModelProvider(true).getModifiableModel().removeLibrary(library);
+      getModelProvider().getModifiableModel().removeLibrary(library);
       myContext.getDaemonAnalyzer().removeElement(new LibraryProjectStructureElement(myContext, library));
       // TODO: myContext.invalidateModules(myContext.myLibraryDependencyCache.get(library.getName()));
     }
@@ -266,7 +258,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
 
         LOG.assertTrue(library != null);
 
-        final LibraryTable.ModifiableModel libsModel = configurable.getModelProvider(true).getModifiableModel();
+        final LibraryTable.ModifiableModel libsModel = configurable.getModelProvider().getModifiableModel();
         final Library lib = libsModel.createLibrary(myNameTf.getText());
         final Library.ModifiableModel model = ((LibrariesModifiableModel)libsModel).getLibraryEditor(lib).getModel();
         for (OrderRootType type : OrderRootType.getAllTypes()) {
index 7730b1eb78fca45ffd07d609a6aeb3e207fa0ec4..de9e38f82b2ed7a38bcc0c9f58976d4055581672 100644 (file)
@@ -21,7 +21,6 @@ import com.intellij.openapi.components.Storage;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
-import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
 import org.jetbrains.annotations.Nls;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.Nullable;
@@ -63,8 +62,8 @@ public class GlobalLibrariesConfigurable extends BaseLibrariesConfigurable {
     return ServiceManager.getService(project, GlobalLibrariesConfigurable.class);
   }
 
-  public LibraryTableModifiableModelProvider getModelProvider(final boolean editable) {
-    return myContext.getGlobalLibrariesProvider(editable);
+  public StructureLibraryTableModifiableModelProvider getModelProvider() {
+    return myContext.getGlobalLibrariesProvider();
   }
 
   public BaseLibrariesConfigurable getOppositeGroup() {
index 820eba5e0bbac7ea746c13656ea9a01f7d455386..a5d4723d38afea8c78c0672bd5dfd85caadb2791 100644 (file)
@@ -248,10 +248,10 @@ public class LibrariesContainerFactory {
     @Nullable
     private LibraryTableModifiableModelProvider getProvider(LibraryLevel libraryLevel) {
       if (libraryLevel == LibraryLevel.PROJECT) {
-        return myContext.getProjectLibrariesProvider(false);
+        return myContext.getProjectLibrariesProvider();
       }
       else if (libraryLevel == LibraryLevel.GLOBAL) {
-        return myContext.getGlobalLibrariesProvider(false);
+        return myContext.getGlobalLibrariesProvider();
       }
       else {
         return null;
@@ -264,12 +264,12 @@ public class LibrariesContainerFactory {
 
     @NotNull
     public VirtualFile[] getLibraryFiles(@NotNull final Library library, @NotNull final OrderRootType rootType) {
-      LibrariesModifiableModel projectLibrariesModel = (LibrariesModifiableModel)myContext.getProjectLibrariesProvider(false).getModifiableModel();
+      LibrariesModifiableModel projectLibrariesModel = myContext.getProjectLibrariesProvider().getModifiableModel();
       if (projectLibrariesModel.hasLibraryEditor(library)) {
         LibraryEditor libraryEditor = projectLibrariesModel.getLibraryEditor(library);
         return libraryEditor.getFiles(rootType);
       }
-      LibrariesModifiableModel globalLibraries = (LibrariesModifiableModel)myContext.getGlobalLibrariesProvider(false).getModifiableModel();
+      LibrariesModifiableModel globalLibraries = myContext.getGlobalLibrariesProvider().getModifiableModel();
       if (globalLibraries.hasLibraryEditor(library)) {
         LibraryEditor libraryEditor = globalLibraries.getLibraryEditor(library);
         return libraryEditor.getFiles(rootType);
index 17d813c7b4afa7bbb285cf375c7dbc571ffd32e1..be95b31d7d2bb7fa9c20d2b3bffde9476b1176f7 100644 (file)
@@ -21,6 +21,7 @@ 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.ProjectStructureConfigurable;
+import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
 import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
 import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorListener;
 import com.intellij.openapi.util.Disposer;
@@ -34,7 +35,7 @@ import java.util.*;
  */
 
 public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
-  private final Map<Library, LibraryEditor> myLibrary2EditorMap = new HashMap<Library, LibraryEditor>();
+  private final Map<Library, ExistingLibraryEditor> myLibrary2EditorMap = new HashMap<Library, ExistingLibraryEditor>();
   private final Set<Library> myRemovedLibraries = new HashSet<Library>();
 
   private LibraryTable.ModifiableModel myLibrariesModifiableModel;
@@ -96,15 +97,16 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
   }
 
   public void deferredCommit(){
-    for (LibraryEditor libraryEditor : new ArrayList<LibraryEditor>(myLibrary2EditorMap.values())) {
+    final List<ExistingLibraryEditor> libraryEditors = new ArrayList<ExistingLibraryEditor>(myLibrary2EditorMap.values());
+    myLibrary2EditorMap.clear();
+    for (ExistingLibraryEditor libraryEditor : libraryEditors) {
       libraryEditor.commit(); // TODO: is seems like commit will recreate the editor, but it should not
       Disposer.dispose(libraryEditor);
     }
-    if (!(myLibrary2EditorMap.isEmpty() && myRemovedLibraries.isEmpty())) {
+    if (!libraryEditors.isEmpty() || !myRemovedLibraries.isEmpty()) {
       getLibrariesModifiableModel().commit();
       myLibrariesModifiableModel = null;
     }
-    myLibrary2EditorMap.clear();
     myRemovedLibraries.clear();
   }
 
@@ -116,20 +118,20 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
     return myLibrary2EditorMap.containsKey(library);
   }
 
-  public LibraryEditor getLibraryEditor(Library library){
+  public ExistingLibraryEditor getLibraryEditor(Library library){
     final Library source = ((LibraryImpl)library).getSource();
     if (source != null) {
       return getLibraryEditor(source);
     }
-    LibraryEditor libraryEditor = myLibrary2EditorMap.get(library);
+    ExistingLibraryEditor libraryEditor = myLibrary2EditorMap.get(library);
     if (libraryEditor == null){
       libraryEditor = createLibraryEditor(library);
     }
     return libraryEditor;
   }
 
-  private LibraryEditor createLibraryEditor(final Library library) {
-    final LibraryEditor libraryEditor = new LibraryEditor(library, myLibraryEditorListener);
+  private ExistingLibraryEditor createLibraryEditor(final Library library) {
+    final ExistingLibraryEditor libraryEditor = new ExistingLibraryEditor(library, myLibraryEditorListener);
     myLibrary2EditorMap.put(library, libraryEditor);
     return libraryEditor;
   }
index d4f78dfd237fd598a3df6f245f85c1ff9a287362..b4f83bfda5d0b8d1b065b94baf6aabf0058cefbf 100644 (file)
@@ -21,12 +21,10 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectBundle;
 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.libraryEditor.LibraryEditor;
 import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
 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 com.intellij.openapi.util.IconLoader;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.Nullable;
@@ -42,17 +40,17 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
 
   private LibraryTableEditor myLibraryEditor;
   private final Library myLibrary;
-  private final LibraryTableModifiableModelProvider myModel;
+  private final StructureLibraryTableModifiableModelProvider myModel;
   private final Project myProject;
   private final LibraryProjectStructureElement myProjectStructureElement;
   private boolean myUpdatingName;
 
-  protected LibraryConfigurable(final LibraryTableModifiableModelProvider libraryTable,
+  protected LibraryConfigurable(final StructureLibraryTableModifiableModelProvider modelProvider,
                                 final Library library,
                                 final Project project,
                                 final Runnable updateTree) {
     super(true, updateTree);
-    myModel = libraryTable;
+    myModel = modelProvider;
     myProject = project;
     myLibrary = library;
     final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext();
@@ -60,9 +58,8 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
   }
 
   public JComponent createOptionsPanel() {
-    myLibraryEditor = LibraryTableEditor.editLibrary(myModel, myLibrary, myProject);
+    myLibraryEditor = LibraryTableEditor.editLibrary(myProject, myModel.getModifiableModel().getLibraryEditor(myLibrary));
     final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext();
-    myLibraryEditor.addLibraryEditorListener(context);
     myLibraryEditor.addListener(new Runnable() {
       public void run() {
         context.getDaemonAnalyzer().queueUpdate(myProjectStructureElement);
@@ -89,11 +86,7 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
   }
 
   public void disposeUIResources() {
-    if (myLibraryEditor != null) {
-      myLibraryEditor.cancelChanges();
-      Disposer.dispose(myLibraryEditor);
-      myLibraryEditor = null;
-    }
+    myLibraryEditor = null;
   }
 
   public void setDisplayName(final String name) {
@@ -103,7 +96,7 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
   }
 
   private LibraryEditor getLibraryEditor() {
-    return ((LibrariesModifiableModel)myModel.getModifiableModel()).getLibraryEditor(myLibrary);
+    return myModel.getModifiableModel().getLibraryEditor(myLibrary);
   }
 
   @Override
@@ -131,7 +124,11 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
   }
 
   public String getDisplayName() {
-    return getLibraryEditor().getName();
+    if (myModel.getModifiableModel().hasLibraryEditor(myLibrary)) {
+      return getLibraryEditor().getName();
+    }
+
+    return myLibrary.getName();
   }
 
   public Icon getIcon() {
index 74ae6a3d778fd6876da446a270c8b38f8258def7..484a625f5b3988766af7363668516eb3217e6cea 100644 (file)
@@ -59,8 +59,8 @@ public class ProjectLibrariesConfigurable extends BaseLibrariesConfigurable {
   }
 
 
-  public LibraryTableModifiableModelProvider getModelProvider(final boolean editable) {
-    return myContext.getProjectLibrariesProvider(editable);
+  public StructureLibraryTableModifiableModelProvider getModelProvider() {
+    return myContext.getProjectLibrariesProvider();
   }
 
   public BaseLibrariesConfigurable getOppositeGroup() {
index 7fda371b5992bc1e1463b8ec0b685c6752a89872..6cfd45485a442016394eead4af49d4df0a09d384 100644 (file)
@@ -19,9 +19,9 @@ import com.intellij.openapi.Disposable;
 import com.intellij.openapi.module.ModifiableModuleModel;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil;
 import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.roots.libraries.LibraryTable;
-import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
 import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
 import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
 import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator;
@@ -103,45 +103,35 @@ public class StructureConfigurableContext implements Disposable, LibraryEditorLi
     }
   }
 
-  public LibraryTableModifiableModelProvider getGlobalLibrariesProvider(final boolean tableEditable) {
-    return createModifiableModelProvider(LibraryTablesRegistrar.APPLICATION_LEVEL, tableEditable);
+  public StructureLibraryTableModifiableModelProvider getGlobalLibrariesProvider() {
+    return createModifiableModelProvider(LibraryTablesRegistrar.APPLICATION_LEVEL);
   }
 
-  public LibraryTableModifiableModelProvider createModifiableModelProvider(final String level, final boolean isTableEditable) {
-    final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, myProject);
-    return new LibraryTableModifiableModelProvider() {
-        public LibraryTable.ModifiableModel getModifiableModel() {
-          return myLevel2Providers.get(level);
-        }
-
-        public String getTableLevel() {
-          return table.getTableLevel();
-        }
-
-        public LibraryTablePresentation getLibraryTablePresentation() {
-          return table.getPresentation();
-        }
-
-        public boolean isLibraryTableEditable() {
-          return isTableEditable && table.isEditable();
-        }
-      };
+  public StructureLibraryTableModifiableModelProvider createModifiableModelProvider(final String level) {
+    return new StructureLibraryTableModifiableModelProvider(level, this);
   }
 
-  public LibraryTableModifiableModelProvider getProjectLibrariesProvider(final boolean tableEditable) {
-    return createModifiableModelProvider(LibraryTablesRegistrar.PROJECT_LEVEL, tableEditable);
+  public StructureLibraryTableModifiableModelProvider getProjectLibrariesProvider() {
+    return createModifiableModelProvider(LibraryTablesRegistrar.PROJECT_LEVEL);
   }
 
 
-  public List<LibraryTableModifiableModelProvider> getCustomLibrariesProviders(final boolean tableEditable) {
+  public List<LibraryTableModifiableModelProvider> getCustomLibrariesProviders() {
     return ContainerUtil.map2List(LibraryTablesRegistrar.getInstance().getCustomLibraryTables(), new NotNullFunction<LibraryTable, LibraryTableModifiableModelProvider>() {
       @NotNull
       public LibraryTableModifiableModelProvider fun(final LibraryTable libraryTable) {
-        return createModifiableModelProvider(libraryTable.getTableLevel(), tableEditable);
+        return createModifiableModelProvider(libraryTable.getTableLevel());
       }
     });
   }
 
+  public LibraryTable.ModifiableModel getModifiableLibraryTable(@NotNull LibraryTable table) {
+    final String tableLevel = table.getTableLevel();
+    if (tableLevel.equals(LibraryTableImplUtil.MODULE_LEVEL)) {
+      return table.getModifiableModel();
+    }
+    return myLevel2Providers.get(tableLevel);
+  }
 
   @Nullable
   public Library getLibrary(final String libraryName, final String libraryLevel) {
@@ -187,4 +177,5 @@ public class StructureConfigurableContext implements Disposable, LibraryEditorLi
   public void clear() {
     myLevel2Providers.clear();
   }
+
 }
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureLibraryTableModifiableModelProvider.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureLibraryTableModifiableModelProvider.java
new file mode 100644 (file)
index 0000000..23ab664
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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.openapi.roots.ui.configuration.projectRoot;
+
+import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
+
+/**
+* @author nik
+*/
+public class StructureLibraryTableModifiableModelProvider implements LibraryTableModifiableModelProvider {
+  private final String myLevel;
+  private final StructureConfigurableContext myContext;
+
+  public StructureLibraryTableModifiableModelProvider(String level,
+                                                      final StructureConfigurableContext context) {
+    myLevel = level;
+    myContext = context;
+  }
+
+  public LibrariesModifiableModel getModifiableModel() {
+    return myContext.myLevel2Providers.get(myLevel);
+  }
+
+}
index 9d64108d6bab060700c7de77d8fc416428811e92..547e60f218a0e9b203c51e1b1f8a2d55308f88e7 100644 (file)
@@ -34,8 +34,9 @@ public class LibraryProjectStructureElement extends ProjectStructureElement {
 
   @Override
   public void check(ProjectStructureProblemsHolder problemsHolder) {
+    if (((LibraryEx)myLibrary).isDisposed()) return;
     final LibraryEx library = (LibraryEx)myContext.getLibraryModel(myLibrary);
-    if (library == null) return;
+    if (library == null || library.isDisposed()) return;
 
     final String libraryName = library.getName();
     if (!library.allPathsValid(OrderRootType.CLASSES)) {
index 32808d2f7520738c0628064ef31b2758bd2f995f..bb24cd53f60c6ec73d6b92084fccb37211306a60 100644 (file)
@@ -170,11 +170,6 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
             final List<ExpectedTypeInfo> infos = Arrays.asList(getExpectedTypes(parameters));
             for (final LookupElement item : completeReference(element, reference, filter, true, parameters)) {
               if (item.getObject() instanceof PsiClass) {
-                if (AFTER_THROW_NEW.accepts(element)) {
-                  //((LookupItem)item).setAttribute(LookupItem.DONT_CHECK_FOR_INNERS, "");
-                  JavaCompletionUtil.setShowFQN((LookupItem)item);
-                } else {
-                }
                 result.addElement(decorate(LookupElementDecorator.withInsertHandler((LookupItem)item, ConstructorInsertHandler.INSTANCE), infos));
               }
             }
index e9aff65950baaf29bf8fa76e6d46d8abcf482832..585eee3ab9c27cc9db51cf5991e3b6e010103124 100644 (file)
@@ -36,6 +36,7 @@ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
 import com.intellij.psi.impl.source.tree.java.ClassElement;
 import com.intellij.psi.jsp.JspElementType;
 import com.intellij.psi.tree.IElementType;
+import com.intellij.psi.tree.TokenSet;
 import com.intellij.util.text.CharArrayUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -63,9 +64,8 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
    * @see CodeStyleSettings#ALIGN_GROUP_FIELD_DECLARATIONS
    */
   private static final AlignmentInColumnsConfig ALIGNMENT_IN_COLUMNS_CONFIG = new AlignmentInColumnsConfig(
-    JavaTokenType.IDENTIFIER, ElementType.WHITE_SPACE_BIT_SET, ElementType.JAVA_COMMENT_BIT_SET, JavaTokenType.EQ,
-    JavaElementType.FIELD
-  );
+    TokenSet.create(JavaTokenType.IDENTIFIER), ElementType.WHITE_SPACE_BIT_SET, ElementType.JAVA_COMMENT_BIT_SET,
+    TokenSet.create(JavaTokenType.EQ), TokenSet.create(JavaElementType.FIELD));
 
   /**
    * Enumerates types of variable declaration sub-elements that should be aligned in columns.
@@ -1266,7 +1266,8 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
    */
   protected boolean shouldUseVarDeclarationAlignment(ASTNode node) {
     return mySettings.ALIGN_GROUP_FIELD_DECLARATIONS && ALIGN_IN_COLUMNS_ELEMENT_TYPES.contains(node.getElementType())
-           && !myAlignmentInColumnsHelper.useDifferentVarDeclarationAlignment(node, ALIGNMENT_IN_COLUMNS_CONFIG);
+           && !myAlignmentInColumnsHelper.useDifferentVarDeclarationAlignment(node, ALIGNMENT_IN_COLUMNS_CONFIG,
+                                                                              mySettings.KEEP_BLANK_LINES_IN_DECLARATIONS);
   }
 
   private SyntheticCodeBlock createCodeBlockBlock(final ArrayList<Block> localResult, final Indent indent, final int childrenIndent) {
index 4af29e1b1990ecdc4147ac23628ce7f66e621597..ab2b60d30939b09083647af33e6d8f3b019c7872 100644 (file)
@@ -683,8 +683,18 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
     }
     else if (myRole1 == ChildRole.LBRACE) {
       if (!keepInOneLine) {
+        int blankLines = 1;
+        if (myParent != null) {
+          ASTNode parentNode = myParent.getNode();
+          if (parentNode != null) {
+            ASTNode grandPa = parentNode.getTreeParent();
+            if (grandPa != null && grandPa.getElementType() == JavaElementType.METHOD) {
+              blankLines += mySettings.BLANK_LINES_BEFORE_METHOD_BODY;
+            }
+          }
+        }
         myResult = Spacing.createSpacing(
-          0, 0, mySettings.BLANK_LINES_BEFORE_METHOD_BODY + 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE
+          0, 0, blankLines, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE
         );
       }
       else {
index 3f31c68e55bead30e652ee3edb2e7db852bafa70..064af0cebb7025db0c60e3c9e7fe13c5dec9de17 100644 (file)
@@ -131,7 +131,7 @@ public class ChangeSignatureProcessor extends ChangeSignatureProcessorBase {
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
     for (ChangeSignatureUsageProcessor processor : ChangeSignatureUsageProcessor.EP_NAME.getExtensions()) {
-      processor.setupDefaultValues(myChangeInfo, refUsages, myProject);
+      if (!processor.setupDefaultValues(myChangeInfo, refUsages, myProject)) return false;
     }
     MultiMap<PsiElement, String> conflictDescriptions = new MultiMap<PsiElement, String>();
     for (ChangeSignatureUsageProcessor usageProcessor : ChangeSignatureUsageProcessor.EP_NAME.getExtensions()) {
index f23cabd6143b1ce44dfd1626cbe6ad549cbc7b26..665d3d574c487d4a344a04a92fbd77a495aa7f31 100644 (file)
@@ -72,19 +72,21 @@ public class ChangeSignatureUtil {
           }
         }
       } else {
-        PsiElement anchor = null;
-        if (index == 0) {
-          anchor = list.getFirstChild();
-        } else {
-          anchor = elements.get(index - 1);
-        }
-        final PsiElement psi = Factory
-          .createSingleLeafElement(JavaTokenType.COMMA, ",", 0, 1, SharedImplUtil.findCharTableByTree(list.getNode()), list.getManager())
-          .getPsi();
-        if (anchor != null) {
-          list.addAfter(psi, anchor);
-        } else {
-          list.add(psi);
+        if (newElements.size() > 1) {
+          PsiElement anchor;
+          if (index == 0) {
+            anchor = list.getFirstChild();
+          } else {
+            anchor = elements.get(index - 1);
+          }
+          final PsiElement psi = Factory
+            .createSingleLeafElement(JavaTokenType.COMMA, ",", 0, 1, SharedImplUtil.findCharTableByTree(list.getNode()), list.getManager())
+            .getPsi();
+          if (anchor != null) {
+            list.addAfter(psi, anchor);
+          } else {
+            list.add(psi);
+          }
         }
       }
       index++;
index 7ccbc8f6cb37de5ae1f16c537dd210609b22d628..49a492b5b68d3a082bc83ef58244572464455358 100644 (file)
@@ -26,6 +26,7 @@ import com.intellij.openapi.util.TextRange;
 import com.intellij.psi.*;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.refactoring.util.CanonicalTypes;
+import com.intellij.usageView.UsageInfo;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.VisibilityUtil;
 import org.jetbrains.annotations.NotNull;
@@ -45,6 +46,7 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
                                                  final @Nullable ChangeInfo changeInfo) {
     PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false);
     if (method != null && isInsideMethodSignature(element, method)) {
+      if (PsiTreeUtil.hasErrorElements(method.getParameterList())) return changeInfo;
       final String newVisibility = VisibilityUtil.getVisibilityModifier(method.getModifierList());
       final PsiType returnType = method.getReturnType();
       final CanonicalTypes.Type newReturnType;
@@ -154,6 +156,7 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
 
   private static class MyJavaChangeInfo extends JavaChangeInfoImpl  {
     private PsiMethod mySuperMethod;
+    private String[] myModifiers;
     private MyJavaChangeInfo(String newVisibility,
                              PsiMethod method,
                              CanonicalTypes.Type newType,
@@ -163,6 +166,16 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
       super(newVisibility, method, method.getName(), newType, newParms, newExceptions, false,
             new HashSet<PsiMethod>(),
             new HashSet<PsiMethod>(), oldName);
+      final PsiParameter[] parameters = method.getParameterList().getParameters();
+      myModifiers = new String[parameters.length];
+      for (int i = 0; i < parameters.length; i++) {
+        PsiParameter parameter = parameters[i];
+        final PsiModifierList modifierList = parameter.getModifierList();
+        if (modifierList != null) {
+          final String text = modifierList.getText();
+          myModifiers[i] = text;
+        }
+      }
     }
 
     @Override
@@ -180,6 +193,10 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
     public void setSuperMethod(PsiMethod superMethod) {
       mySuperMethod = superMethod;
     }
+
+    public String[] getModifiers() {
+      return myModifiers;
+    }
   }
 
   @Override
@@ -253,7 +270,25 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
         oldParameterNames = info.getOldParameterNames();
         oldParameterTypes = info.getOldParameterTypes();
       }
-    });
+    }) {
+      @Override
+      protected void performRefactoring(UsageInfo[] usages) {
+        super.performRefactoring(usages);
+        final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(method.getProject());
+        final PsiParameter[] parameters = method.getParameterList().getParameters();
+        for (int i = 0; i < info.getModifiers().length; i++) {
+          final String modifier = info.getModifiers()[i];
+          final PsiModifierList modifierList = parameters[i].getModifierList();
+          if (modifierList != null && !Comparing.strEqual(modifier, modifierList.getText())) {
+            final PsiModifierList newModifierList =
+              elementFactory.createParameterFromText(modifier + " type name", method).getModifierList();
+            if (newModifierList != null) {
+              modifierList.replace(newModifierList);
+            }
+          }
+        }
+      }
+    };
   }
 
   @Override
index 60e76508a167024c067eb0f526bd4a7fec9fb3b2..db4a5af670b3ecb92ac1d0386c349fb2821e2ac9 100644 (file)
@@ -28,10 +28,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
 import com.intellij.psi.codeStyle.VariableKind;
 import com.intellij.psi.scope.processor.VariablesProcessor;
 import com.intellij.psi.scope.util.PsiScopesUtil;
-import com.intellij.psi.util.MethodSignatureUtil;
-import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.psi.util.PsiUtil;
-import com.intellij.psi.util.TypeConversionUtil;
+import com.intellij.psi.util.*;
 import com.intellij.refactoring.RefactoringBundle;
 import com.intellij.refactoring.rename.RenameUtil;
 import com.intellij.refactoring.util.*;
@@ -536,13 +533,15 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
   }
 
   @Override
-  public void setupDefaultValues(ChangeInfo changeInfo, Ref<UsageInfo[]> refUsages, Project project) {
-    if (!(changeInfo instanceof JavaChangeInfo)) return;
+  public boolean setupDefaultValues(ChangeInfo changeInfo, Ref<UsageInfo[]> refUsages, Project project) {
+    if (!(changeInfo instanceof JavaChangeInfo)) return true;
     for (UsageInfo usageInfo : refUsages.get()) {
       if (usageInfo instanceof  MethodCallUsageInfo) {
         MethodCallUsageInfo methodCallUsageInfo = (MethodCallUsageInfo)usageInfo;
         if (methodCallUsageInfo.isToChangeArguments()){
-          final boolean needDefaultValue = needDefaultValue(changeInfo, RefactoringUtil.getEnclosingMethod(methodCallUsageInfo.getElement()));
+          final PsiElement element = methodCallUsageInfo.getElement();
+          if (element == null) continue;
+          final boolean needDefaultValue = needDefaultValue(changeInfo, RefactoringUtil.getEnclosingMethod(element));
           if (needDefaultValue) {
             final ParameterInfo[] parameters = changeInfo.getNewParameters();
             for (ParameterInfo parameter : parameters) {
@@ -550,7 +549,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
               if (defaultValue == null && parameter.getOldIndex() == -1) {
                 ((ParameterInfoImpl)parameter).setDefaultValue("");
                 if (!ApplicationManager.getApplication().isUnitTestMode()) {
-                  final DefaultValueChooser chooser = new DefaultValueChooser(project, parameter.getName());
+                  final PsiType type = ((ParameterInfoImpl)parameter).getTypeWrapper().getType(element, element.getManager());
+                  final DefaultValueChooser chooser = new DefaultValueChooser(project, parameter.getName(), PsiTypesUtil.getDefaultValueOfType(type));
                   chooser.show();
                   if (chooser.isOK()) {
                     if (chooser.feelLucky()) {
@@ -558,6 +558,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
                     } else {
                       ((ParameterInfoImpl)parameter).setDefaultValue(chooser.getDefaultValue());
                     }
+                  } else {
+                    return false;
                   }
                 }
               }
@@ -566,6 +568,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
         }
       }
     }
+    return true;
   }
 
   private static boolean needDefaultValue(ChangeInfo changeInfo, PsiMethod method) {
diff --git a/java/java-tests/testData/codeInsight/softwrap/SoftWrapAdditionOnTyping.txt b/java/java-tests/testData/codeInsight/softwrap/SoftWrapAdditionOnTyping.txt
new file mode 100644 (file)
index 0000000..22294ce
--- /dev/null
@@ -0,0 +1 @@
+this is a test string that is expected to end just before right margin<caret>
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/changeSignatureGesture/AddParameterFinal.java b/java/java-tests/testData/refactoring/changeSignatureGesture/AddParameterFinal.java
new file mode 100644 (file)
index 0000000..37d9f03
--- /dev/null
@@ -0,0 +1,8 @@
+public class Test {
+  public void foo(<caret>) {
+  }
+
+  void bar() {
+    foo();
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/changeSignatureGesture/AddParameterFinal_after.java b/java/java-tests/testData/refactoring/changeSignatureGesture/AddParameterFinal_after.java
new file mode 100644 (file)
index 0000000..a8d0b7a
--- /dev/null
@@ -0,0 +1,8 @@
+public class Test {
+  public void foo(final int param) {
+  }
+
+  void bar() {
+    foo();
+  }
+}
\ No newline at end of file
index 3c795695d7fccca0094b388df9f60df2947dafa5..74f53a7d73a81f3b70746852858a0f31285ba199 100644 (file)
@@ -350,4 +350,31 @@ public class JavaFormatterBlankLinesTest extends AbstractJavaFormatterTest {
       "}"
     );
   }
+
+  public void testBeforeMethodBodyWithCodeBlockInside() {
+    // Inspired by IDEA-54747
+    getSettings().BLANK_LINES_BEFORE_METHOD_BODY = 3;
+    doTextTest(
+      "public class FormattingTest {\n" +
+      "    public void foo() {\n" +
+      "        System.out.println(\"\");\n" +
+      "        try {\n" +
+      "        } catch (Exception e) {\n" +
+      "        }\n" +
+      "    }\n" +
+      "}",
+
+      "public class FormattingTest {\n" +
+      "    public void foo() {\n" +
+      "\n" +
+      "\n" +
+      "\n" +
+      "        System.out.println(\"\");\n" +
+      "        try {\n" +
+      "        } catch (Exception e) {\n" +
+      "        }\n" +
+      "    }\n" +
+      "}"
+    );
+  }
 }
index 812953a282ec006e9b823d1ac1b446631eaf09fc..f60b7feb1e94d323017d1d30824d093c20d27f98 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.psi.formatter.java;
 
+import com.intellij.openapi.util.TextRange;
 import com.intellij.psi.codeStyle.CodeStyleSettings;
 
 /**
@@ -149,4 +150,78 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest {
     // Expecting the code to be left as-is
     doClassTest(text, text);
   }
+
+  public void testWrapLongLine() {
+    // Inspired by IDEA-55782
+    getSettings().RIGHT_MARGIN = 50;
+    getSettings().WRAP_LONG_LINES = true;
+
+    doTextTest(
+      "class TestClass {\n" +
+      "    // Single line comment that exceeds right margin\n" +
+      "    /* Multi line comment that exceeds right margin*/\n" +
+      "    /**\n" +
+      "      Javadoc comment that exceeds right margin" +
+      "     */\n" +
+      "     public String s = \"this is a long string to be wrapped\"\n" +
+      "}",
+      "class TestClass {\n" +
+      "    // Single line comment that exceeds right\n" +
+      "    // margin\n" +
+      "    /* Multi line comment that exceeds right\n" +
+      "    margin*/\n" +
+      "    /**\n" +
+      "     * Javadoc comment that exceeds right\n" +
+      "     * margin\n" +
+      "     */\n" +
+      "    public String s = \"this is a long string to\" +\n" +
+      "            \" be wrapped\"\n" +
+      "}"
+    );
+  }
+
+  public void testWrapLongLineWithTabs() {
+    // Inspired by IDEA-55782
+    getSettings().RIGHT_MARGIN = 20;
+    getSettings().WRAP_LONG_LINES = true;
+    getIndentOptions().USE_TAB_CHARACTER = true;
+    getIndentOptions().TAB_SIZE = 4;
+
+    doTextTest(
+      "class TestClass {\n" +
+      "\t \t   //This is a comment\n" +
+      "}",
+      "class TestClass {\n" +
+      "\t//This is a\n" +
+      "\t// comment\n" +
+      "}"
+    );
+  }
+
+  public void testWrapLongLineWithSelection() {
+    // Inspired by IDEA-55782
+    getSettings().RIGHT_MARGIN = 20;
+    getSettings().WRAP_LONG_LINES = true;
+
+    String initial =
+      "class TestClass {\n" +
+      "    //This is a comment\n" +
+      "    //This is another comment\n" +
+      "}";
+
+    int start = initial.indexOf("//");
+    int end = initial.indexOf("comment");
+    myTextRange = new TextRange(start, end);
+    doTextTest(initial, initial);
+
+    myLineRange = new TextRange(1, 1);
+    doTextTest(
+      initial,
+      "class TestClass {\n" +
+      "    //This is a\n" +
+      "    // comment\n" +
+      "    //This is another comment\n" +
+      "}"
+    );
+  }
 }
index 68ac7c7ad7197fa340137a4cda21fa00345679ee..a7dfaced63a5a9f8973230a883e51052752bd357 100644 (file)
@@ -91,6 +91,10 @@ public class ChangeSignatureGestureTest extends LightCodeInsightFixtureTestCase
     doTypingNoBorderTest("private");
   }
 
+  public void testAddParameterFinal() {
+    doTypingTest("final int param");
+  }
+
   private void doTypingNoBorderTest(final String param) {
     doTest(new Runnable() {
       @Override
index 9d172e85dff6ef4205ca702dc6e5c1f4c261553b..ee342b92fa66300c5f343c79b8a95766864df469 100644 (file)
@@ -27,6 +27,8 @@ import org.jetbrains.annotations.NotNull;
  *  @author dsl
  */
 public interface Library extends JDOMExternalizable, Disposable {
+  Library[] EMPTY_ARRAY = new Library[0];
+
   String getName();
 
   @NotNull String[] getUrls(@NotNull OrderRootType rootType);
index 0e18b178c7aba2caa328e763bdc541b91eeee617..a565eeecfa22bd070cc8efcbdccaf6bb6ffd0655 100644 (file)
@@ -70,6 +70,7 @@ public interface CodeStyleSettingsCustomizable {
     CodeStyleSettings.WRAP_AS_NEEDED |
     CodeStyleSettings.WRAP_ON_EVERY_ITEM,
     CodeStyleSettings.WRAP_ALWAYS};
+
   int[] WRAP_VALUES_FOR_SINGLETON = new int[]{CodeStyleSettings.DO_NOT_WRAP,
     CodeStyleSettings.WRAP_AS_NEEDED,
     CodeStyleSettings.WRAP_ALWAYS};
index a0387d87d0daf415949494bb16aedd975b03be89..eba4b435ffdc95105c531cee5f6511062585cb4d 100644 (file)
@@ -684,6 +684,8 @@ public class CommonCodeStyleSettings {
   public int WHILE_BRACE_FORCE = DO_NOT_FORCE;
   public int FOR_BRACE_FORCE = DO_NOT_FORCE;
 
+  public boolean WRAP_LONG_LINES = false;
+
   //-------------- Annotation formatting settings-------------------------------------------
 
   public int METHOD_ANNOTATION_WRAP = WRAP_ALWAYS;
index a798a1e96d2501c1124111549e02e20f114da762..99fd6956efe81c6c5dc6f7b9c2eaa4662f417c5f 100644 (file)
@@ -39,5 +39,5 @@ public interface ChangeSignatureUsageProcessor {
 
   boolean shouldPreviewUsages(ChangeInfo changeInfo, UsageInfo[] usages);
 
-  void setupDefaultValues(ChangeInfo changeInfo, Ref<UsageInfo[]> refUsages, Project project);
+  boolean setupDefaultValues(ChangeInfo changeInfo, Ref<UsageInfo[]> refUsages, Project project);
 }
index 104e300045fb4a3f44e0a2d6d1ad0c9761590fe0..b65164d1071e5ff02180e91a4c3c8634928c3541 100644 (file)
@@ -94,9 +94,9 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel {
     initBooleanField("SPACE_BEFORE_FINALLY_KEYWORD", ApplicationBundle.message("checkbox.spaces.finally.keyword"), SPACES_BEFORE_KEYWORD);
     initCustomOptions(SPACES_BEFORE_KEYWORD);
 
-    initBooleanField("SPACE_WITHIN_BRACKETS", ApplicationBundle.message("checkbox.spaces.within.brackets"), SPACES_WITHIN);
     initBooleanField("SPACE_WITHIN_BRACES", ApplicationBundle.message("checkbox.spaces.within.braces"),
                      SPACES_WITHIN);
+    initBooleanField("SPACE_WITHIN_BRACKETS", ApplicationBundle.message("checkbox.spaces.within.brackets"), SPACES_WITHIN);</