diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form index d6a4003268a2..1a5cb135c8b6 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LibraryRootsComponentForm.form @@ -1,6 +1,6 @@
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModificationOfImportedModelWarningComponent.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModificationOfImportedModelWarningComponent.java new file mode 100644 index 000000000000..564731c2a112 --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModificationOfImportedModelWarningComponent.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2017 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; + +import com.intellij.icons.AllIcons; +import com.intellij.openapi.roots.ProjectModelExternalSource; +import com.intellij.util.ui.JBUI; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author nik + */ +public class ModificationOfImportedModelWarningComponent { + private final JLabel myLabel; + + public ModificationOfImportedModelWarningComponent() { + myLabel = new JLabel(); + hideWarning(); + } + + public JLabel getLabel() { + return myLabel; + } + + public void showWarning(@NotNull String elementDescription, @NotNull ProjectModelExternalSource externalSource) { + myLabel.setVisible(true); + myLabel.setBorder(JBUI.Borders.empty(5, 5)); + myLabel.setIcon(AllIcons.General.Warning); + myLabel.setText(UIUtil.toHtml(elementDescription + " is imported from " + externalSource.getDisplayName() + ". Any changes made in its configuration may be lost after reimporting.")); + } + + public void hideWarning() { + myLabel.setVisible(false); + } +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java index addc09c7cabc..a2cee1fd3cd1 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModuleEditor.java @@ -16,7 +16,6 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.facet.impl.ProjectFacetsConfigurator; -import com.intellij.icons.AllIcons; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.LangDataKeys; @@ -41,8 +40,6 @@ import com.intellij.ui.navigation.History; import com.intellij.ui.navigation.Place; import com.intellij.util.EventDispatcher; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.ui.JBUI; -import com.intellij.util.ui.UIUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -70,7 +67,7 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable { private final Project myProject; private JPanel myGenericSettingsPanel; - private JLabel myModificationOfImportedModelWarningLabel; + private ModificationOfImportedModelWarningComponent myModificationOfImportedModelWarningComponent; private ModifiableRootModel myModifiableRootModel; // important: in order to correctly update OrderEntries UI use corresponding proxy for the model private final ModulesProvider myModulesProvider; @@ -269,8 +266,8 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable { final JComponent component = createCenterPanel(); myGenericSettingsPanel.add(component, BorderLayout.CENTER); - myModificationOfImportedModelWarningLabel = new JLabel(); - myGenericSettingsPanel.add(myModificationOfImportedModelWarningLabel, BorderLayout.SOUTH); + myModificationOfImportedModelWarningComponent = new ModificationOfImportedModelWarningComponent(); + myGenericSettingsPanel.add(myModificationOfImportedModelWarningComponent.getLabel(), BorderLayout.SOUTH); updateImportedModelWarning(); myEditorsInitialized = true; return myGenericSettingsPanel; @@ -306,13 +303,10 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable { ProjectModelExternalSource externalSource = ModuleRootManager.getInstance(myModule).getExternalSource(); if (externalSource != null && isModified()) { - myModificationOfImportedModelWarningLabel.setVisible(true); - myModificationOfImportedModelWarningLabel.setBorder(JBUI.Borders.empty(5, 5)); - myModificationOfImportedModelWarningLabel.setIcon(AllIcons.General.Warning); - myModificationOfImportedModelWarningLabel.setText(UIUtil.toHtml("Module '" + myModule.getName() + "' is imported from " + externalSource.getDisplayName() + ". Any changes made in its configuration may be lost after reimporting.")); + myModificationOfImportedModelWarningComponent.showWarning("Module '" + myModule.getName() + "'", externalSource); } else { - myModificationOfImportedModelWarningLabel.setVisible(false); + myModificationOfImportedModelWarningComponent.hideWarning(); } } 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 index d33dbb50f2d1..2cde87096266 100644 --- 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 @@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor; import com.intellij.openapi.Disposable; import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.ProjectModelExternalSource; import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.libraries.*; import com.intellij.openapi.util.Disposer; @@ -64,6 +65,12 @@ public class ExistingLibraryEditor extends LibraryEditorBase implements Disposab return detectType(); } + @Nullable + @Override + public ProjectModelExternalSource getExternalSource() { + return myLibrary.getExternalSource(); + } + @Override public void setType(@NotNull LibraryType> type) { getModel().setKind(type.getKind()); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorBase.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorBase.java index c960b4e62fdc..5e8683264a05 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorBase.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryEditorBase.java @@ -16,10 +16,12 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor; import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.ProjectModelExternalSource; import com.intellij.openapi.roots.libraries.LibraryProperties; import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.roots.libraries.ui.OrderRoot; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -57,4 +59,10 @@ public abstract class LibraryEditorBase implements LibraryEditor { } } } + + @Nullable + @Override + public ProjectModelExternalSource getExternalSource() { + return null; + } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java index 6f916de00de1..b1d9695b6888 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryRootsComponent.java @@ -31,11 +31,13 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.PersistentOrderRootType; +import com.intellij.openapi.roots.ProjectModelExternalSource; import com.intellij.openapi.roots.libraries.LibraryKind; import com.intellij.openapi.roots.libraries.LibraryProperties; import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.roots.libraries.ui.*; import com.intellij.openapi.roots.libraries.ui.impl.RootDetectionUtil; +import com.intellij.openapi.roots.ui.configuration.ModificationOfImportedModelWarningComponent; import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager; import com.intellij.openapi.ui.ex.MultiLineLabel; import com.intellij.openapi.ui.popup.JBPopupFactory; @@ -79,9 +81,11 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent private JPanel myTreePanel; private MultiLineLabel myPropertiesLabel; private JPanel myPropertiesPanel; + private JPanel myBottomPanel; private LibraryPropertiesEditor myPropertiesEditor; private Tree myTree; private LibraryTableTreeBuilder myTreeBuilder; + private final ModificationOfImportedModelWarningComponent myModificationOfImportedModelWarningComponent; private VirtualFile myLastChosen; private final Collection