IDEA-133779 Inspection settings: changing Share + Rename is processed not consistently

This commit is contained in:
Dmitry Batkovich
2014-12-03 11:36:12 +03:00
parent f8a0130231
commit fa96506cf9
4 changed files with 52 additions and 49 deletions
@@ -44,9 +44,7 @@ public class IDEInspectionToolsConfigurable extends InspectionToolsConfigurable
}
@Override
public void apply() throws ConfigurationException {
final String rootProfile = getSelectedObject().getName();
myProfileManager.setRootProfile(rootProfile);
super.apply();
protected void applyRootProfile(String name, boolean isShared) {
myProfileManager.setRootProfile(name);
}
}
@@ -43,18 +43,13 @@ public class ProjectInspectionToolsConfigurable extends InspectionToolsConfigura
}
@Override
public void apply() throws ConfigurationException {
final InspectionProfileImpl selectedObject = getSelectedObject();
final String profileName = selectedObject.getName();
final SingleInspectionProfilePanel selectedPanel = getSelectedPanel();
LOG.assertTrue(selectedPanel != null, "selected profile: " + profileName + " panels: " + Arrays.toString(getKnownNames().toArray()));
if (selectedPanel.isProfileShared()) {
myProjectProfileManager.setProjectProfile(profileName);
protected void applyRootProfile(String name, boolean isShared) {
if (isShared) {
myProjectProfileManager.setProjectProfile(name);
} else {
myProfileManager.setRootProfile(profileName);
myProfileManager.setRootProfile(name);
myProjectProfileManager.setProjectProfile(null);
}
InspectionProfileManagerImpl.onProfilesChanged();
super.apply();
}
}
@@ -125,7 +125,7 @@ public class SingleInspectionProfilePanel extends JPanel {
private InspectionsConfigTreeTable myTreeTable;
private TreeExpander myTreeExpander;
@NotNull
private String myInitialProfile;
private String myCurrentProfileName;
private boolean myIsInRestore = false;
private boolean myShareProfile;
private Splitter myRightSplitter;
@@ -143,7 +143,7 @@ public class SingleInspectionProfilePanel extends JPanel {
super(new BorderLayout());
myProjectProfileManager = projectProfileManager;
mySelectedProfile = (InspectionProfileImpl)profile;
myInitialProfile = inspectionProfileName;
myCurrentProfileName = inspectionProfileName;
myShareProfile = profile.getProfileManager() == projectProfileManager;
}
@@ -1045,7 +1045,7 @@ public class SingleInspectionProfilePanel extends JPanel {
if (mySelectedProfile == modifiableModel) return;
mySelectedProfile = (InspectionProfileImpl)modifiableModel;
if (mySelectedProfile != null) {
myInitialProfile = mySelectedProfile.getName();
myCurrentProfileName = mySelectedProfile.getName();
}
initToolStates();
filterTree();
@@ -1121,7 +1121,7 @@ public class SingleInspectionProfilePanel extends JPanel {
if (myModified) return true;
if (mySelectedProfile.isChanged()) return true;
if (myShareProfile != (mySelectedProfile.getProfileManager() == myProjectProfileManager)) return true;
if (!Comparing.strEqual(myInitialProfile, mySelectedProfile.getName())) return true;
if (!Comparing.strEqual(myCurrentProfileName, mySelectedProfile.getName())) return true;
if (!Comparing.equal(myInitialScopesOrder, mySelectedProfile.getScopesOrder())) return true;
if (descriptorsAreChanged()) {
return true;
@@ -1144,6 +1144,12 @@ public class SingleInspectionProfilePanel extends JPanel {
return;
}
final ModifiableModel selectedProfile = getSelectedProfile();
if (!Comparing.equal(myCurrentProfileName, selectedProfile.getName())) {
selectedProfile.getProfileManager().deleteProfile(selectedProfile.getName());
selectedProfile.setName(myCurrentProfileName);
selectedProfile.getProfileManager().updateProfile(selectedProfile);
}
ProfileManager profileManager = myShareProfile ? myProjectProfileManager : InspectionProfileManager.getInstance();
selectedProfile.setProjectLevel(myShareProfile);
if (selectedProfile.getProfileManager() != profileManager) {
@@ -1210,6 +1216,15 @@ public class SingleInspectionProfilePanel extends JPanel {
myShareProfile = profileShared;
}
@NotNull
public String getCurrentProfileName() {
return myCurrentProfileName;
}
public void setCurrentProfileName(@NotNull String currentProfileName) {
myCurrentProfileName = currentProfileName;
}
@Override
public void setVisible(boolean aFlag) {
if (aFlag && myInspectionProfilePanel == null) {
@@ -113,11 +113,10 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
myProfiles = new ProfilesConfigurableComboBox(new ListCellRendererWrapper<Profile>() {
@Override
public void customize(final JList list, final Profile value, final int index, final boolean selected, final boolean hasFocus) {
final String profileName = value.getName();
final SingleInspectionProfilePanel singleInspectionProfilePanel = myPanels.get(value);
final boolean isShared = singleInspectionProfilePanel != null && singleInspectionProfilePanel.isProfileShared();
final boolean isShared = singleInspectionProfilePanel.isProfileShared();
setIcon(isShared ? AllIcons.General.ProjectSettings : AllIcons.General.Settings);
setText(profileName);
setText(singleInspectionProfilePanel.getCurrentProfileName());
}
}) {
@Override
@@ -139,12 +138,13 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
@Override
public void setShareToTeamMembers(boolean shared) {
final InspectionProfileImpl inspectionProfile = getSelectedObject();
final String name = inspectionProfile.getName();
for (Map.Entry<Profile, SingleInspectionProfilePanel> e : myPanels.entrySet()) {
final InspectionProfileImpl currentProfile = (InspectionProfileImpl)e.getKey();
if (currentProfile.getName().equals(name) && !currentProfile.equals(inspectionProfile)) {
final boolean curShared = e.getValue().isProfileShared();
final SingleInspectionProfilePanel selectedPanel = getSelectedPanel();
LOG.assertTrue(selectedPanel != null, "No settings selectedPanel for: " + getSelectedObject());
final String name = getSelectedPanel().getCurrentProfileName();
for (SingleInspectionProfilePanel p : myPanels.values()) {
if (p != selectedPanel && Comparing.equal(p.getCurrentProfileName(), name)) {
final boolean curShared = p.isProfileShared();
if (curShared == shared) {
Messages.showErrorDialog((shared ? "Shared" : "Application level") + " profile with same name exists.", "Inspections Settings");
return;
@@ -152,9 +152,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
}
}
final SingleInspectionProfilePanel panel = getSelectedPanel();
LOG.assertTrue(panel != null, "No settings panel for: " + getSelectedObject());
panel.setProfileShared(shared);
selectedPanel.setProfileShared(shared);
myProfiles.repaint();
}
@@ -182,23 +180,23 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
}
private void rename(@NotNull final InspectionProfileImpl inspectionProfile) {
final String initialName = inspectionProfile.getName();
myProfiles.showEditCard(inspectionProfile.getName(), new SaveInputComponentValidator() {
final String initialName = getSelectedPanel().getCurrentProfileName();
myProfiles.showEditCard(initialName, new SaveInputComponentValidator() {
@Override
public void doSave(@NotNull String text) {
if (!text.equals(initialName)) {
deleteProfile(inspectionProfile);
myProfiles.getModel().removeElement(inspectionProfile);
inspectionProfile.setName(text);
inspectionProfile.setModified(true);
addProfile(inspectionProfile);
getProfilePanel(inspectionProfile).setCurrentProfileName(text);
}
myProfiles.showComboBoxCard();
}
@Override
public boolean checkValid(@NotNull String text) {
final boolean isValid = text.equals(initialName) || !hasName(text, myPanels.get(inspectionProfile).isProfileShared());
final SingleInspectionProfilePanel singleInspectionProfilePanel = myPanels.get(inspectionProfile);
if (singleInspectionProfilePanel == null) {
return false;
}
final boolean isValid = text.equals(initialName) || !hasName(text, singleInspectionProfilePanel.isProfileShared());
if (isValid) {
myAuxiliaryRightPanel.showDescription(getSelectedObject().getDescription());
}
@@ -460,7 +458,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
public boolean isModified() {
final InspectionProfileImpl selectedProfile = getSelectedObject();
final InspectionProfileImpl currentProfile = getCurrentProfile();
if (!Comparing.equal(selectedProfile.getName(), currentProfile.getName()) || selectedProfile.isProjectLevel() != currentProfile.isProjectLevel()) {
if (!Comparing.equal(selectedProfile, currentProfile)) {
return true;
}
for (SingleInspectionProfilePanel panel : myPanels.values()) {
@@ -472,6 +470,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
@Override
public void apply() throws ConfigurationException {
final SingleInspectionProfilePanel selectedPanel = getSelectedPanel();
for (final Profile inspectionProfile : myPanels.keySet()) {
if (myDeletedProfiles.remove(inspectionProfile)) {
deleteProfile(getProfilePanel(inspectionProfile).getSelectedProfile());
@@ -479,11 +478,16 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
else {
final SingleInspectionProfilePanel panel = getProfilePanel(inspectionProfile);
panel.apply();
if (panel == selectedPanel) {
applyRootProfile(panel.getCurrentProfileName(), panel.isProfileShared());
}
}
}
doReset();
}
protected abstract void applyRootProfile(final String name, final boolean isShared);
private SingleInspectionProfilePanel getProfilePanel(Profile inspectionProfile) {
return myPanels.get(inspectionProfile);
}
@@ -630,18 +634,9 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
return "configured profiles: " + StringUtil.join(myPanels.keySet(), ", ");
}
protected Collection<String> getKnownNames() {
return ContainerUtil.map(myPanels.keySet(), new Function<Profile, String>() {
@Override
public String fun(Profile profile) {
return profile.getName();
}
});
}
private boolean hasName(final @NotNull String name, boolean shared) {
for (Map.Entry<Profile, SingleInspectionProfilePanel> e : myPanels.entrySet()) {
if (name.equals(e.getKey().getName()) && shared == e.getValue().isProfileShared()) {
for (SingleInspectionProfilePanel p : myPanels.values()) {
if (name.equals(p.getCurrentProfileName()) && shared == p.isProfileShared()) {
return true;
}
}