actions to create archive artifact from exploded

This commit is contained in:
nik
2009-10-16 09:52:02 +04:00
parent 2ca8636fce
commit 4904a66411
6 changed files with 83 additions and 11 deletions
@@ -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);
@@ -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);
}
@@ -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<? extends ArtifactTemplate> getNewArtifactTemplates(@NotNull PackagingElementResolvingContext context) {
return Collections.emptyList();
}
public void checkRootElement(@NotNull CompositePackagingElement<?> rootElement, @NotNull Artifact artifact, @NotNull ArtifactValidationManager manager) {
}
@@ -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
@@ -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<? extends ArtifactTemplate> 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);
}
}
}
@@ -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: