mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
project structure dialog: show warning if user tries to manually edit configuration of a library imported from an external model (IDEA-171948)
This commit is contained in:
+9
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryRootsComponent">
|
||||
<grid id="e9129" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="2">
|
||||
<grid id="e9129" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="2">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="97" y="50" width="403" height="352"/>
|
||||
@@ -33,6 +33,14 @@
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="69aae" binding="myBottomPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+51
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -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());
|
||||
|
||||
+8
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -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<Runnable> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
@@ -112,6 +116,8 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
|
||||
if (myDescriptor == null) {
|
||||
myDescriptor = new DefaultLibraryRootsComponentDescriptor();
|
||||
}
|
||||
myModificationOfImportedModelWarningComponent = new ModificationOfImportedModelWarningComponent();
|
||||
myBottomPanel.add(BorderLayout.CENTER, myModificationOfImportedModelWarningComponent.getLabel());
|
||||
init(new LibraryTreeStructure(this, myDescriptor));
|
||||
updatePropertiesLabel();
|
||||
onRootsChanged();
|
||||
@@ -490,6 +496,14 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
|
||||
for (Runnable listener : myListeners) {
|
||||
listener.run();
|
||||
}
|
||||
ProjectModelExternalSource externalSource = getLibraryEditor().getExternalSource();
|
||||
if (externalSource != null && hasChanges()) {
|
||||
String name = getLibraryEditor().getName();
|
||||
myModificationOfImportedModelWarningComponent.showWarning(name != null ? "Library '" + name + "'" : "Library", externalSource);
|
||||
}
|
||||
else {
|
||||
myModificationOfImportedModelWarningComponent.hideWarning();
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(Runnable listener) {
|
||||
|
||||
+4
@@ -16,6 +16,7 @@
|
||||
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;
|
||||
@@ -67,4 +68,7 @@ public interface LibraryEditor {
|
||||
LibraryType<?> getType();
|
||||
|
||||
void addRoots(Collection<? extends OrderRoot> roots);
|
||||
|
||||
@Nullable
|
||||
ProjectModelExternalSource getExternalSource();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user