From bfc4d7044b430081e71b71fafcd8d839ddf60780 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 6 Oct 2009 12:23:46 +0400 Subject: [PATCH] artifacts ui fixes & more detailed options to show content of elements --- .../impl/elements/ArtifactElementType.java | 9 +++- .../impl/elements/LibraryElementType.java | 11 +++-- .../ModuleWithDependenciesElementType.java | 17 +++++--- .../impl/elements/PackagingElementFactoryImpl.java | 12 +++++ .../elements/ComplexPackagingElementType.java | 31 +++++++++++++ .../elements/PackagingElementFactory.java | 2 + .../artifacts/ArtifactEditorImpl.java | 49 ++++++++++++++++++--- .../artifacts/ArtifactsEditorImpl.form | 37 ++++++++++++---- .../ComplexElementSubstitutionParameters.java | 51 ++++++++++++++++++---- .../artifacts/ToggleShowElementContentAction.java | 32 ++++++++++++++ .../artifacts/actions/HideContentAction.java | 2 +- .../artifacts/actions/MoveElementAction.java | 4 +- .../actions/SortElementsToggleAction.java | 2 +- .../nodes/ComplexPackagingElementNode.java | 2 +- 14 files changed, 224 insertions(+), 37 deletions(-) create mode 100644 java/compiler/openapi/src/com/intellij/packaging/elements/ComplexPackagingElementType.java create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ToggleShowElementContentAction.java diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java index b8c882aa76..ac494d8707 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java @@ -5,8 +5,8 @@ import com.intellij.openapi.project.Project; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactManager; import com.intellij.packaging.artifacts.ArtifactPointerManager; +import com.intellij.packaging.elements.ComplexPackagingElementType; import com.intellij.packaging.elements.CompositePackagingElement; -import com.intellij.packaging.elements.PackagingElementType; import com.intellij.packaging.impl.artifacts.ArtifactUtil; import com.intellij.packaging.impl.artifacts.PlainArtifactType; import com.intellij.packaging.ui.ArtifactEditorContext; @@ -19,7 +19,7 @@ import java.util.*; /** * @author nik */ -public class ArtifactElementType extends PackagingElementType { +public class ArtifactElementType extends ComplexPackagingElementType { public static final ArtifactElementType ARTIFACT_ELEMENT_TYPE = new ArtifactElementType(); ArtifactElementType() { @@ -80,4 +80,9 @@ public class ArtifactElementType extends PackagingElementType { +public class LibraryElementType extends ComplexPackagingElementType { public static final LibraryElementType LIBRARY_ELEMENT_TYPE = new LibraryElementType(); LibraryElementType() { @@ -48,7 +48,7 @@ public class LibraryElementType extends PackagingElementType getAllLibraries(ArtifactEditorContext context) { + private static List getAllLibraries(ArtifactEditorContext context) { List libraries = new ArrayList(); libraries.addAll(Arrays.asList(LibraryTablesRegistrar.getInstance().getLibraryTable().getLibraries())); libraries.addAll(Arrays.asList(LibraryTablesRegistrar.getInstance().getLibraryTable(context.getProject()).getLibraries())); @@ -59,4 +59,9 @@ public class LibraryElementType extends PackagingElementType { +public class ModuleWithDependenciesElementType extends ComplexPackagingElementType { public static final ModuleWithDependenciesElementType MODULE_WITH_DEPENDENCIES_TYPE = new ModuleWithDependenciesElementType(); public ModuleWithDependenciesElementType() { @@ -24,6 +24,11 @@ public class ModuleWithDependenciesElementType extends PackagingElementType[] getComplexElementTypes() { + List> types = new ArrayList>(); + for (PackagingElementType type : getAllElementTypes()) { + if (type instanceof ComplexPackagingElementType) { + types.add((ComplexPackagingElementType)type); + } + } + return types.toArray(new ComplexPackagingElementType[types.size()]); + } + @NotNull @Override public CompositePackagingElementType[] getCompositeElementTypes() { diff --git a/java/compiler/openapi/src/com/intellij/packaging/elements/ComplexPackagingElementType.java b/java/compiler/openapi/src/com/intellij/packaging/elements/ComplexPackagingElementType.java new file mode 100644 index 0000000000..4bc66cab5d --- /dev/null +++ b/java/compiler/openapi/src/com/intellij/packaging/elements/ComplexPackagingElementType.java @@ -0,0 +1,31 @@ +/* + * 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.packaging.elements; + +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public abstract class ComplexPackagingElementType> extends PackagingElementType { + protected ComplexPackagingElementType(@NotNull @NonNls String id, @NotNull String presentableName) { + super(id, presentableName); + } + + public abstract String getShowContentActionText(); +} diff --git a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java index f623e0e1f6..689da63e1a 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java +++ b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementFactory.java @@ -82,4 +82,6 @@ public abstract class PackagingElementFactory { @NotNull public abstract PackagingElementType[] getAllElementTypes(); + @NotNull + public abstract ComplexPackagingElementType[] getComplexElementTypes(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java index dc97004da9..ae0b964234 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java @@ -12,6 +12,7 @@ import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.ui.configuration.artifacts.actions.*; import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.LibrarySourceItem; import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.SourceItemsTree; +import com.intellij.openapi.ui.FixedSizeButton; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.Comparing; @@ -20,7 +21,9 @@ import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.io.FileUtil; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ModifiableArtifact; +import com.intellij.packaging.elements.ComplexPackagingElementType; import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.packaging.elements.PackagingElementFactory; import com.intellij.packaging.elements.PackagingElementType; import com.intellij.packaging.impl.artifacts.ArtifactUtil; import com.intellij.packaging.impl.elements.ArchivePackagingElement; @@ -30,6 +33,7 @@ import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.TabbedPaneWrapper; import com.intellij.ui.TreeToolTipHandler; import com.intellij.util.EventDispatcher; +import com.intellij.util.ui.ThreeStateCheckBox; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,9 +53,11 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { private JPanel myMainPanel; private JCheckBox myBuildOnMakeCheckBox; private TextFieldWithBrowseButton myOutputDirectoryField; - private JCheckBox myShowIncludedCheckBox; private JPanel myEditorPanel; private JPanel myErrorPanelPlace; + private ThreeStateCheckBox myShowContentCheckBox; + private FixedSizeButton myShowSpecificContentOptionsButton; + private ActionGroup myShowSpecificContentOptionsGroup; private Splitter mySplitter; private final Project myProject; private final ComplexElementSubstitutionParameters mySubstitutionParameters = new ComplexElementSubstitutionParameters(); @@ -79,9 +85,24 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { CompilerBundle.message("chooser.description.select.output.directory.for.0.artifact", getArtifact().getName()), myProject, FileChooserDescriptorFactory.createSingleFolderDescriptor()); + myShowSpecificContentOptionsGroup = createShowSpecificContentOptionsGroup(); + myShowSpecificContentOptionsButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, myShowSpecificContentOptionsGroup).getComponent().show(myShowSpecificContentOptionsButton, 0, 0); + } + }); setOutputPath(outputPath); myValidationManager = new ArtifactValidationManagerImpl(this); myContext.setValidationManager(myValidationManager); + updateShowContentCheckbox(); + } + + private ActionGroup createShowSpecificContentOptionsGroup() { + final DefaultActionGroup group = new DefaultActionGroup(); + for (ComplexPackagingElementType type : PackagingElementFactory.getInstance().getComplexElementTypes()) { + group.add(new ToggleShowElementContentAction(type, this)); + } + return group; } private void setOutputPath(@Nullable String outputPath) { @@ -162,15 +183,17 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { mySplitter.setSecondComponent(rightPanel); - myShowIncludedCheckBox.addActionListener(new ActionListener() { + myShowContentCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - if (myShowIncludedCheckBox.isSelected()) { + final ThreeStateCheckBox.State state = myShowContentCheckBox.getState(); + if (state == ThreeStateCheckBox.State.SELECTED) { mySubstitutionParameters.setSubstituteAll(); } - else { + else if (state == ThreeStateCheckBox.State.NOT_SELECTED) { mySubstitutionParameters.setSubstituteNone(); } - rebuildTries(); + myShowContentCheckBox.setThirdStateEnabled(false); + myLayoutTreeComponent.rebuildTree(); } }); @@ -190,6 +213,21 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { return getMainComponent(); } + public void updateShowContentCheckbox() { + final ThreeStateCheckBox.State state; + if (mySubstitutionParameters.isAllSubstituted()) { + state = ThreeStateCheckBox.State.SELECTED; + } + else if (mySubstitutionParameters.isNoneSubstituted()) { + state = ThreeStateCheckBox.State.NOT_SELECTED; + } + else { + state = ThreeStateCheckBox.State.DONT_CARE; + } + myShowContentCheckBox.setThirdStateEnabled(state == ThreeStateCheckBox.State.DONT_CARE); + myShowContentCheckBox.setState(state); + } + private DefaultActionGroup createToolbarActionGroup() { final DefaultActionGroup toolbarActionGroup = new DefaultActionGroup(); @@ -201,6 +239,7 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { toolbarActionGroup.add(createAddAction(false)); toolbarActionGroup.add(new RemovePackagingElementAction(this)); + toolbarActionGroup.add(Separator.getInstance()); toolbarActionGroup.add(new SortElementsToggleAction(this.getLayoutTreeComponent())); toolbarActionGroup.add(new MoveElementAction(myLayoutTreeComponent, "Move Up", "", IconLoader.getIcon("/actions/moveUp.png"), -1)); toolbarActionGroup.add(new MoveElementAction(myLayoutTreeComponent, "Move Down", "", IconLoader.getIcon("/actions/moveDown.png"), 1)); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsEditorImpl.form b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsEditorImpl.form index b1c4f58611..cf81d109bd 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsEditorImpl.form +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsEditorImpl.form @@ -55,14 +55,6 @@ - - - - - - - - @@ -81,6 +73,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ComplexElementSubstitutionParameters.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ComplexElementSubstitutionParameters.java index c018cde856..f29bce5818 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ComplexElementSubstitutionParameters.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ComplexElementSubstitutionParameters.java @@ -2,36 +2,69 @@ package com.intellij.openapi.roots.ui.configuration.artifacts; import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.ComplexPackagingElementNode; import com.intellij.packaging.elements.ComplexPackagingElement; +import com.intellij.packaging.elements.ComplexPackagingElementType; +import com.intellij.packaging.elements.PackagingElementFactory; import org.jetbrains.annotations.NotNull; -import java.util.Set; +import java.util.Arrays; import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; /** * @author nik */ public class ComplexElementSubstitutionParameters { - private boolean mySubstituteAll; - private Set mySubstituted = new HashSet(); + private Set> myTypesToSubstitute = new HashSet>(); + private Set> mySubstituted = new HashSet>(); public void setSubstituteAll() { - mySubstituteAll = true; + myTypesToSubstitute.addAll(Arrays.asList(PackagingElementFactory.getInstance().getComplexElementTypes())); + mySubstituted.clear(); } public void setSubstituteNone() { + myTypesToSubstitute.clear(); mySubstituted.clear(); - mySubstituteAll = false; } - public boolean shouldSubstitute(@NotNull ComplexPackagingElement element) { - return mySubstituteAll || mySubstituted.contains(element); + public boolean shouldSubstitute(@NotNull ComplexPackagingElement element) { + final ComplexPackagingElementType type = (ComplexPackagingElementType)element.getType(); + return myTypesToSubstitute.contains(type) || mySubstituted.contains(element); } - public void substitute(ComplexPackagingElementNode complexNode) { + public void setShowContent(ComplexPackagingElementType type, boolean showContent) { + if (showContent) { + myTypesToSubstitute.add(type); + } + else { + myTypesToSubstitute.remove(type); + } + final Iterator> iterator = mySubstituted.iterator(); + while (iterator.hasNext()) { + if (iterator.next().getType().equals(type)) { + iterator.remove(); + } + } + } + + public void setShowContent(ComplexPackagingElementNode complexNode) { mySubstituted.addAll(complexNode.getPackagingElements()); } - public void dontSubstitute(ComplexPackagingElement element) { + public void doNotSubstitute(ComplexPackagingElement element) { mySubstituted.remove(element); } + + public boolean isShowContentForType(@NotNull ComplexPackagingElementType type) { + return myTypesToSubstitute.contains(type); + } + + public boolean isAllSubstituted() { + return myTypesToSubstitute.containsAll(Arrays.asList(PackagingElementFactory.getInstance().getComplexElementTypes())); + } + + public boolean isNoneSubstituted() { + return myTypesToSubstitute.isEmpty() && mySubstituted.isEmpty(); + } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ToggleShowElementContentAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ToggleShowElementContentAction.java new file mode 100644 index 0000000000..ae4a5d5836 --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ToggleShowElementContentAction.java @@ -0,0 +1,32 @@ +package com.intellij.openapi.roots.ui.configuration.artifacts; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.ToggleAction; +import com.intellij.openapi.project.DumbAware; +import com.intellij.packaging.elements.ComplexPackagingElementType; + +/** + * @author nik + */ +public class ToggleShowElementContentAction extends ToggleAction implements DumbAware { + private final ComplexPackagingElementType myType; + private final ArtifactEditorImpl myEditor; + + public ToggleShowElementContentAction(ComplexPackagingElementType type, ArtifactEditorImpl editor) { + super(type.getShowContentActionText()); + myType = type; + myEditor = editor; + } + + @Override + public boolean isSelected(AnActionEvent e) { + return myEditor.getSubstitutionParameters().isShowContentForType(myType); + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + myEditor.getSubstitutionParameters().setShowContent(myType, state); + myEditor.updateShowContentCheckbox(); + myEditor.getLayoutTreeComponent().rebuildTree(); + } +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/HideContentAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/HideContentAction.java index 1681e5d95e..c016e482fe 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/HideContentAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/HideContentAction.java @@ -49,7 +49,7 @@ public class HideContentAction extends DumbAwareAction { final Collection sources = node.getNodeSources(); for (PackagingNodeSource source : sources) { - myArtifactEditor.getSubstitutionParameters().dontSubstitute(source.getSourceElement()); + myArtifactEditor.getSubstitutionParameters().doNotSubstitute(source.getSourceElement()); myArtifactEditor.getLayoutTreeComponent().getLayoutTree().addSubtreeToUpdate(source.getSourceParentNode()); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/MoveElementAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/MoveElementAction.java index d778cd6dd5..47165540d6 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/MoveElementAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/MoveElementAction.java @@ -27,7 +27,9 @@ public class MoveElementAction extends DumbAwareAction { @Override public void update(AnActionEvent e) { - e.getPresentation().setEnabled(isEnabled()); + final boolean b = isEnabled(); + e.getPresentation().setEnabled(b); + e.getPresentation().setText(getTemplatePresentation().getText() + " (disabled if elements are sorted)"); } private boolean isEnabled() { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/SortElementsToggleAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/SortElementsToggleAction.java index e7303ea397..5a7e384c03 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/SortElementsToggleAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/actions/SortElementsToggleAction.java @@ -13,7 +13,7 @@ public class SortElementsToggleAction extends ToggleAction implements DumbAware private LayoutTreeComponent myLayoutTreeComponent; public SortElementsToggleAction(final LayoutTreeComponent layoutTreeComponent) { - super("Sort", "Sort Elements by Names and Types", IconLoader.getIcon("/objectBrowser/sorted.png")); + super("Sort Elements by Names and Types", "Sort Elements by Names and Types", IconLoader.getIcon("/objectBrowser/sorted.png")); myLayoutTreeComponent = layoutTreeComponent; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/nodes/ComplexPackagingElementNode.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/nodes/ComplexPackagingElementNode.java index 3af735ee59..c8cd3b3345 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/nodes/ComplexPackagingElementNode.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/nodes/ComplexPackagingElementNode.java @@ -25,7 +25,7 @@ public class ComplexPackagingElementNode extends PackagingElementNode