IDEADEV-40679: Artifacts editor: Sort button loses its state on reopening dialog and Apply,

IDEADEV-40781: Artifacts editor: pressing Aplly set "Show content of elements" to Off
This commit is contained in:
nik
2009-10-21 12:56:54 +04:00
parent 01e9f670fb
commit 0e8d562cc2
6 changed files with 124 additions and 13 deletions
@@ -87,12 +87,13 @@ public class ArtifactEditorImpl implements ArtifactEditorEx {
private ArtifactPropertiesEditors myPropertiesEditors;
private ArtifactValidationManagerImpl myValidationManager;
public ArtifactEditorImpl(final ArtifactsStructureConfigurableContext context, Artifact artifact) {
public ArtifactEditorImpl(final @NotNull ArtifactsStructureConfigurableContext context, @NotNull Artifact artifact, @NotNull ArtifactEditorSettings settings) {
myContext = new ArtifactEditorContextImpl(context, this);
myOriginalArtifact = artifact;
myProject = context.getProject();
mySubstitutionParameters.setTypesToShowContent(settings.getTypesToShowContent());
mySourceItemsTree = new SourceItemsTree(myContext, this);
myLayoutTreeComponent = new LayoutTreeComponent(this, mySubstitutionParameters, myContext, myOriginalArtifact);
myLayoutTreeComponent = new LayoutTreeComponent(this, mySubstitutionParameters, myContext, myOriginalArtifact, settings.isSortElements());
myPropertiesEditors = new ArtifactPropertiesEditors(myContext, myOriginalArtifact, myOriginalArtifact);
Disposer.register(this, mySourceItemsTree);
Disposer.register(this, myLayoutTreeComponent);
@@ -247,6 +248,10 @@ public class ArtifactEditorImpl implements ArtifactEditorEx {
myShowContentCheckBox.setState(state);
}
public ArtifactEditorSettings createSettings() {
return new ArtifactEditorSettings(myLayoutTreeComponent.isSortElements(), mySubstitutionParameters.getTypesToSubstitute());
}
private DefaultActionGroup createToolbarActionGroup() {
final DefaultActionGroup toolbarActionGroup = new DefaultActionGroup();
@@ -0,0 +1,87 @@
/*
* 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.artifacts;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.packaging.elements.ComplexPackagingElementType;
import com.intellij.packaging.elements.PackagingElementFactory;
import com.intellij.packaging.elements.PackagingElementType;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Tag;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author nik
*/
public class ArtifactEditorSettings implements PersistentStateComponent<ArtifactEditorSettings.ArtifactEditorSettingsState> {
private boolean mySortElements = true;
private List<ComplexPackagingElementType<?>> myTypesToShowContent = new ArrayList<ComplexPackagingElementType<?>>();
public ArtifactEditorSettings() {
}
public ArtifactEditorSettings(boolean sortElements, Collection<ComplexPackagingElementType<?>> typesToShowContent) {
mySortElements = sortElements;
myTypesToShowContent.addAll(typesToShowContent);
}
public ArtifactEditorSettingsState getState() {
final ArtifactEditorSettingsState state = new ArtifactEditorSettingsState();
state.mySortElements = mySortElements;
for (ComplexPackagingElementType<?> type : myTypesToShowContent) {
state.myTypesToShowContentIds.add(type.getId());
}
return state;
}
public void loadState(ArtifactEditorSettingsState state) {
mySortElements = state.mySortElements;
myTypesToShowContent.clear();
for (String id : state.myTypesToShowContentIds) {
final PackagingElementType<?> type = PackagingElementFactory.getInstance().findElementType(id);
if (type instanceof ComplexPackagingElementType<?>) {
myTypesToShowContent.add((ComplexPackagingElementType<?>)type);
}
}
}
public boolean isSortElements() {
return mySortElements;
}
public List<ComplexPackagingElementType<?>> getTypesToShowContent() {
return myTypesToShowContent;
}
public void setSortElements(boolean sortElements) {
mySortElements = sortElements;
}
public void setTypesToShowContent(Collection<ComplexPackagingElementType<?>> typesToShowContent) {
myTypesToShowContent.clear();
myTypesToShowContent.addAll(typesToShowContent);
}
public static class ArtifactEditorSettingsState {
@Tag("show-sorted")
public boolean mySortElements = true;
@AbstractCollection(elementTag = "show-content", elementValueAttribute = "type-id")
public List<String> myTypesToShowContentIds = new ArrayList<String>();
}
}
@@ -37,9 +37,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.*;
/**
* @author nik
@@ -49,8 +47,8 @@ import java.util.List;
storages = {@Storage(id = "other", file = "$WORKSPACE_FILE$")}
)
public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
private ArtifactsStructureConfigurableContextImpl myPackagingEditorContext;
@NonNls private static final String DEFAULT_ARTIFACT_NAME = "unnamed";
private ArtifactsStructureConfigurableContextImpl myPackagingEditorContext;
public ArtifactsStructureConfigurable(@NotNull Project project) {
super(project);
@@ -177,7 +175,9 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
@Override
public void apply() throws ConfigurationException {
myPackagingEditorContext.saveEditorSettings();
super.apply();
myPackagingEditorContext.getManifestFilesInfo().saveManifestFiles();
final ModifiableArtifactModel modifiableModel = myPackagingEditorContext.getActualModifiableModel();
if (modifiableModel != null) {
@@ -194,6 +194,7 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
@Override
public void disposeUIResources() {
myPackagingEditorContext.saveEditorSettings();
super.disposeUIResources();
myPackagingEditorContext.disposeUIResources();
}
@@ -42,6 +42,8 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon
private Project myProject;
private Map<Artifact, CompositePackagingElement<?>> myModifiableRoots = new HashMap<Artifact, CompositePackagingElement<?>>();
private Map<Artifact, ArtifactEditorImpl> myArtifactEditors = new HashMap<Artifact, ArtifactEditorImpl>();
private Map<ArtifactPointer, ArtifactEditorSettings> myEditorSettings = new HashMap<ArtifactPointer, ArtifactEditorSettings>();
private ArtifactEditorSettings myDefaultSettings = new ArtifactEditorSettings();
public ArtifactsStructureConfigurableContextImpl(StructureConfigurableContext context, Project project, final ArtifactAdapter modifiableModelListener) {
myModifiableModelListener = modifiableModelListener;
@@ -100,7 +102,8 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon
artifact = getOriginalArtifact(artifact);
ArtifactEditorImpl artifactEditor = myArtifactEditors.get(artifact);
if (artifactEditor == null) {
artifactEditor = new ArtifactEditorImpl(this, artifact);
final ArtifactEditorSettings settings = myEditorSettings.get(ArtifactPointerManager.getInstance(myProject).create(artifact));
artifactEditor = new ArtifactEditorImpl(this, artifact, settings != null ? settings : myDefaultSettings);
myArtifactEditors.put(artifact, artifactEditor);
}
return artifactEditor;
@@ -152,4 +155,12 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon
}
myArtifactEditors.clear();
}
public void saveEditorSettings() {
myEditorSettings.clear();
for (ArtifactEditorImpl artifactEditor : myArtifactEditors.values()) {
final ArtifactPointer pointer = ArtifactPointerManager.getInstance(myProject).create(artifactEditor.getArtifact());
myEditorSettings.put(pointer, artifactEditor.createSettings());
}
}
}
@@ -21,10 +21,7 @@ import com.intellij.packaging.elements.ComplexPackagingElementType;
import com.intellij.packaging.elements.PackagingElementFactory;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.*;
/**
* @author nik
@@ -63,6 +60,10 @@ public class ComplexElementSubstitutionParameters {
}
}
public Set<ComplexPackagingElementType<?>> getTypesToSubstitute() {
return Collections.unmodifiableSet(myTypesToSubstitute);
}
public void setShowContent(ComplexPackagingElementNode complexNode) {
mySubstituted.addAll(complexNode.getPackagingElements());
}
@@ -82,4 +83,9 @@ public class ComplexElementSubstitutionParameters {
public boolean isNoneSubstituted() {
return myTypesToSubstitute.isEmpty() && mySubstituted.isEmpty();
}
public void setTypesToShowContent(Collection<ComplexPackagingElementType<?>> types) {
myTypesToSubstitute.clear();
myTypesToSubstitute.addAll(types);
}
}
@@ -65,15 +65,16 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
private JPanel myPropertiesPanelWrapper;
private JPanel myPropertiesPanel;
private LayoutTreeBuilder myBuilder;
private boolean mySortElements = true;
private boolean mySortElements;
private LayoutTreeStructure myTreeStructure;
public LayoutTreeComponent(ArtifactEditorImpl artifactsEditor, ComplexElementSubstitutionParameters substitutionParameters,
ArtifactEditorContext context, Artifact originalArtifact) {
ArtifactEditorContext context, Artifact originalArtifact, boolean sortElements) {
myArtifactsEditor = artifactsEditor;
mySubstitutionParameters = substitutionParameters;
myContext = context;
myOriginalArtifact = originalArtifact;
mySortElements = sortElements;
myTree = new LayoutTree(myArtifactsEditor);
myTreeStructure = new LayoutTreeStructure();
myBuilder = new LayoutTreeBuilder();