diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java index b7937546b8ee..442af50d39b0 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java @@ -64,11 +64,13 @@ public class ArtifactModelImpl extends ArtifactModelBase implements ModifiableAr @NotNull public ModifiableArtifact addArtifact(@NotNull final String name, @NotNull ArtifactType artifactType) { - final String outputPath = ArtifactUtil.getDefaultArtifactOutputPath(name, myArtifactManager.getProject()); + return addArtifact(name, artifactType, artifactType.createRootElement(name)); + } - final String artifactName = generateUniqueName(name); - final CompositePackagingElement rootElement = artifactType.createRootElement(artifactName); - final ArtifactImpl artifact = new ArtifactImpl(artifactName, artifactType, false, rootElement, outputPath); + @NotNull + public ModifiableArtifact addArtifact(@NotNull String name, @NotNull ArtifactType artifactType, CompositePackagingElement rootElement) { + final String outputPath = ArtifactUtil.getDefaultArtifactOutputPath(name, myArtifactManager.getProject()); + final ArtifactImpl artifact = new ArtifactImpl(generateUniqueName(name), artifactType, false, rootElement, outputPath); myOriginalArtifacts.add(artifact); myArtifact2ModifiableCopy.put(artifact, artifact); myModifiable2Original.put(artifact, artifact); diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactTemplate.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactTemplate.java new file mode 100644 index 000000000000..1b35071bb41d --- /dev/null +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactTemplate.java @@ -0,0 +1,28 @@ +/* + * 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.artifacts; + +import com.intellij.packaging.elements.CompositePackagingElement; +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public abstract class ArtifactTemplate { + public abstract String getPresentableName(); + + public abstract CompositePackagingElement createRootElement(@NotNull String artifactName); +} diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactType.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactType.java index 13492d2d2dfd..1e2f1235b34f 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactType.java +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactType.java @@ -27,6 +27,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.util.Collections; import java.util.List; /** @@ -80,6 +81,11 @@ public abstract class ArtifactType { @NotNull public abstract CompositePackagingElement createRootElement(@NotNull String artifactName); + @NotNull + public List getNewArtifactTemplates(@NotNull PackagingElementResolvingContext context) { + return Collections.emptyList(); + } + public void checkRootElement(@NotNull CompositePackagingElement rootElement, @NotNull Artifact artifact, @NotNull ArtifactValidationManager manager) { } diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ModifiableArtifactModel.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ModifiableArtifactModel.java index fd0826325999..da5a5ca5f0e5 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ModifiableArtifactModel.java +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ModifiableArtifactModel.java @@ -15,6 +15,7 @@ */ package com.intellij.packaging.artifacts; +import com.intellij.packaging.elements.CompositePackagingElement; import org.jetbrains.annotations.NotNull; /** @@ -25,6 +26,9 @@ public interface ModifiableArtifactModel extends ArtifactModel { @NotNull ModifiableArtifact addArtifact(final @NotNull String name, @NotNull ArtifactType artifactType); + @NotNull + ModifiableArtifact addArtifact(final @NotNull String name, @NotNull ArtifactType artifactType, CompositePackagingElement rootElement); + void removeArtifact(@NotNull Artifact artifact); @NotNull diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java index d8f17d68a401..ae92071004e4 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurable.java @@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.configuration.artifacts; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.components.State; @@ -29,6 +30,7 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.BaseStructureConf import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement; import com.intellij.packaging.artifacts.*; +import com.intellij.packaging.elements.CompositePackagingElement; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -127,21 +129,49 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { final ArtifactType[] types = ArtifactType.getAllTypes(); final AnAction[] actions = new AnAction[types.length]; for (int i = 0; i < types.length; i++) { - actions[i] = new AddArtifactAction(types[i]); + actions[i] = createAddArtifactAction(types[i]); } return actions; } }; } - private void addArtifact(@NotNull ArtifactType type) { + private AnAction createAddArtifactAction(@NotNull final ArtifactType type) { + final List templates = type.getNewArtifactTemplates(myPackagingEditorContext); + final ArtifactTemplate emptyTemplate = new ArtifactTemplate() { + @Override + public String getPresentableName() { + return "Empty"; + } + + @Override + public CompositePackagingElement createRootElement(@NotNull String artifactName) { + return type.createRootElement(artifactName); + } + + }; + + if (templates.isEmpty()) { + return new AddArtifactAction(type, emptyTemplate, type.getPresentableName(), type.getIcon()); + } + final DefaultActionGroup group = new DefaultActionGroup(type.getPresentableName(), true); + group.getTemplatePresentation().setIcon(type.getIcon()); + group.add(new AddArtifactAction(type, emptyTemplate, emptyTemplate.getPresentableName(), null)); + group.addSeparator(); + for (ArtifactTemplate template : templates) { + group.add(new AddArtifactAction(type, template, template.getPresentableName(), null)); + } + return group; + } + + private void addArtifact(@NotNull ArtifactType type, @NotNull ArtifactTemplate artifactTemplate) { String name = DEFAULT_ARTIFACT_NAME; int i = 2; while (myPackagingEditorContext.getArtifactModel().findArtifact(name) != null) { name = DEFAULT_ARTIFACT_NAME + i; i++; } - final ModifiableArtifact artifact = myPackagingEditorContext.getModifiableArtifactModel().addArtifact(name, type); + final ModifiableArtifact artifact = myPackagingEditorContext.getModifiableArtifactModel().addArtifact(name, type, artifactTemplate.createRootElement(name)); selectNodeInTree(findNodeByObject(myRoot, artifact)); } @@ -203,15 +233,18 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable { private class AddArtifactAction extends DumbAwareAction { private final ArtifactType myType; + private final ArtifactTemplate myArtifactTemplate; - public AddArtifactAction(ArtifactType type) { - super(ProjectBundle.message("action.text.add.artifact", type.getPresentableName()), null, type.getIcon()); + public AddArtifactAction(@NotNull ArtifactType type, @NotNull ArtifactTemplate artifactTemplate, final @NotNull String actionText, + final Icon icon) { + super(actionText, null, icon); myType = type; + myArtifactTemplate = artifactTemplate; } @Override public void actionPerformed(AnActionEvent e) { - addArtifact(myType); + addArtifact(myType, myArtifactTemplate); } } } diff --git a/platform/platform-resources-en/src/messages/ProjectBundle.properties b/platform/platform-resources-en/src/messages/ProjectBundle.properties index e254eb57d087..f773584a8b4b 100644 --- a/platform/platform-resources-en/src/messages/ProjectBundle.properties +++ b/platform/platform-resources-en/src/messages/ProjectBundle.properties @@ -421,7 +421,6 @@ text.and=and #artifacts display.name.artifacts=Artifacts -action.text.add.artifact={0} banner.slogan.artifact.0=Artifact ''{0}'' artifacts.add.copy.action=Add Copy of label.text.output.directory=Output directory: