From 7a4e117fe5cd88f0df2b264b3a9e2a2005c8533d Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 17 Mar 2010 14:42:09 +0300 Subject: [PATCH] separate 'build artifact' menu items replaced by 'build artifacts' dialog --- .../actions/BuildAllArtifactsAction.java | 57 ----------- .../compiler/actions/BuildArtifactAction.java | 98 ++++++++++++------- .../actions/BuildArtifactActionGroup.java | 57 ----------- .../compiler/ArtifactsWorkspaceSettings.java | 85 ++++++++++++++++ .../impl/ui}/ChooseArtifactsDialog.java | 2 +- .../artifacts/ArtifactEditorContextImpl.java | 1 + .../ide/util/ChooseElementsDialog.java | 4 + resources/src/META-INF/IdeaPlugin.xml | 3 + resources/src/idea/IdeaActions.xml | 4 +- 9 files changed, 160 insertions(+), 151 deletions(-) delete mode 100644 java/compiler/impl/src/com/intellij/compiler/actions/BuildAllArtifactsAction.java delete mode 100644 java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactActionGroup.java create mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsWorkspaceSettings.java rename java/{idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts => compiler/impl/src/com/intellij/packaging/impl/ui}/ChooseArtifactsDialog.java (95%) diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/BuildAllArtifactsAction.java b/java/compiler/impl/src/com/intellij/compiler/actions/BuildAllArtifactsAction.java deleted file mode 100644 index e21e4183ed7f..000000000000 --- a/java/compiler/impl/src/com/intellij/compiler/actions/BuildAllArtifactsAction.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.compiler.actions; - -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.compiler.CompilerManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.packaging.artifacts.Artifact; -import com.intellij.packaging.artifacts.ArtifactManager; -import com.intellij.packaging.impl.compiler.ArtifactCompileScope; - -import java.util.ArrayList; -import java.util.List; - -/** -* @author nik -*/ -public class BuildAllArtifactsAction extends AnAction { - public BuildAllArtifactsAction() { - super("Build All Artifacts", "Build all configured artifacts", null); - } - - @Override - public void update(AnActionEvent e) { - e.getPresentation().setEnabled(e.getData(PlatformDataKeys.PROJECT) != null); - } - - @Override - public void actionPerformed(AnActionEvent e) { - final Project project = e.getData(PlatformDataKeys.PROJECT); - if (project == null) return; - - List toBuild = new ArrayList(); - for (Artifact artifact : ArtifactManager.getInstance(project).getSortedArtifacts()) { - if (!StringUtil.isEmpty(artifact.getOutputPath())) { - toBuild.add(artifact); - } - } - CompilerManager.getInstance(project).make(ArtifactCompileScope.createArtifactsScope(project, toBuild), null); - } -} diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactAction.java b/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactAction.java index dc9206436c1c..fd634a1fe651 100644 --- a/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactAction.java +++ b/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactAction.java @@ -17,54 +17,86 @@ package com.intellij.compiler.actions; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.fileChooser.FileChooserFactory; -import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; -import com.intellij.openapi.fileChooser.FileChooserDialog; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.application.WriteAction; -import com.intellij.openapi.application.Result; -import com.intellij.openapi.compiler.CompilerManager; -import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactManager; -import com.intellij.packaging.artifacts.ModifiableArtifactModel; import com.intellij.packaging.impl.compiler.ArtifactCompileScope; +import com.intellij.packaging.impl.compiler.ArtifactsWorkspaceSettings; +import com.intellij.packaging.impl.ui.ChooseArtifactsDialog; -import java.util.Collections; +import java.util.ArrayList; +import java.util.List; /** * @author nik */ public class BuildArtifactAction extends AnAction { - private final Project myProject; - private Artifact myArtifact; + public BuildArtifactAction() { + super("Build Artifact"); + } - public BuildArtifactAction(Project project, Artifact artifact) { - super(artifact.getName(), "Build Artifact '" + artifact.getName() + "'", artifact.getArtifactType().getIcon()); - myProject = project; - myArtifact = artifact; + @Override + public void update(AnActionEvent e) { + final Project project = e.getData(PlatformDataKeys.PROJECT); + final Presentation presentation = e.getPresentation(); + presentation.setEnabled(false); + if (project == null) { + return; + } + final List artifacts = getArtifactWithOutputPaths(project); + if (artifacts.isEmpty()) { + return; + } + presentation.setEnabled(true); + if (artifacts.size() == 1) { + presentation.setText("Build '" + StringUtil.first(artifacts.get(0).getName(), 40, true) + "' artifact"); + } + else { + presentation.setText("Build Artifacts..."); + } + } + + private static List getArtifactWithOutputPaths(Project project) { + final List result = new ArrayList(); + for (Artifact artifact : ArtifactManager.getInstance(project).getSortedArtifacts()) { + if (!StringUtil.isEmpty(artifact.getOutputPath())) { + result.add(artifact); + } + } + return result; } public void actionPerformed(AnActionEvent e) { - final String outputPath = myArtifact.getOutputPath(); - if (StringUtil.isEmpty(outputPath)) { - final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); - descriptor.setTitle(CompilerBundle.message("dialog.title.output.directory.for.artifact")); - descriptor.setDescription(CompilerBundle.message("chooser.description.select.output.directory.for.0.artifact", myArtifact.getName())); - final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, myProject); - final VirtualFile[] files = chooser.choose(null, myProject); - if (files.length != 1) return; - final ModifiableArtifactModel model = ArtifactManager.getInstance(myProject).createModifiableModel(); - model.getOrCreateModifiableArtifact(myArtifact).setOutputPath(files[0].getPath()); - new WriteAction() { - protected void run(final Result result) { - model.commit(); - } - }.execute(); + final Project project = e.getData(PlatformDataKeys.PROJECT); + if (project == null) return; + + final List artifacts = getArtifactWithOutputPaths(project); + if (artifacts.isEmpty()) return; + + if (artifacts.size() == 1) { + buildArtifacts(project, artifacts); + return; } - CompilerManager.getInstance(myProject).make(ArtifactCompileScope.createArtifactsScope(myProject, Collections.singletonList(myArtifact)), null); + + final ChooseArtifactsDialog dialog = new ChooseArtifactsDialog(project, artifacts, "Choose Artifacts to Build", "Selected artifacts will be built with all dependencies"); + final List initialSelection = ArtifactsWorkspaceSettings.getInstance(project).getArtifactsToBuild(); + if (!initialSelection.isEmpty()) { + dialog.selectElements(initialSelection); + } + dialog.show(); + + if (dialog.isOK()) { + final List selected = dialog.getChosenElements(); + ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(selected); + buildArtifacts(project, selected); + } + } + + private static void buildArtifacts(Project project, final List artifacts) { + CompilerManager.getInstance(project).make(ArtifactCompileScope.createArtifactsScope(project, artifacts), null); } } diff --git a/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactActionGroup.java b/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactActionGroup.java deleted file mode 100644 index 521e1d2dbbaa..000000000000 --- a/java/compiler/impl/src/com/intellij/compiler/actions/BuildArtifactActionGroup.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.compiler.actions; - -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.packaging.artifacts.Artifact; -import com.intellij.packaging.artifacts.ArtifactManager; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author nik - */ -public class BuildArtifactActionGroup extends ActionGroup { - public BuildArtifactActionGroup() { - super("Build Artifact", true); - } - - @NotNull - public AnAction[] getChildren(@Nullable AnActionEvent e) { - if (e == null) return EMPTY_ARRAY; - final Project project = e.getData(PlatformDataKeys.PROJECT); - if (project == null) return EMPTY_ARRAY; - - final Artifact[] artifacts = ArtifactManager.getInstance(project).getSortedArtifacts(); - List actions = new ArrayList(); - for (Artifact artifact : artifacts) { - if (!StringUtil.isEmpty(artifact.getOutputPath())) { - actions.add(new BuildArtifactAction(project, artifact)); - } - } - if (actions.size() > 1) { - actions.add(0, new BuildAllArtifactsAction()); - actions.add(1, Separator.getInstance()); - } - return actions.toArray(new AnAction[actions.size()]); - } - -} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsWorkspaceSettings.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsWorkspaceSettings.java new file mode 100644 index 000000000000..1f078659493f --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactsWorkspaceSettings.java @@ -0,0 +1,85 @@ +/* + * Copyright 2000-2010 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.impl.compiler; + +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import com.intellij.openapi.project.Project; +import com.intellij.packaging.artifacts.Artifact; +import com.intellij.packaging.artifacts.ArtifactManager; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.xmlb.annotations.AbstractCollection; +import com.intellij.util.xmlb.annotations.Tag; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * @author nik + */ +@State(name = "ArtifactsWorkspaceSettings", + storages = { + @Storage(id = "other", file = "$WORKSPACE_FILE$") + }) +public class ArtifactsWorkspaceSettings implements PersistentStateComponent { + private ArtifactsWorkspaceSettingsState myState = new ArtifactsWorkspaceSettingsState(); + private final Project myProject; + + public ArtifactsWorkspaceSettings(Project project) { + myProject = project; + } + + public static ArtifactsWorkspaceSettings getInstance(@NotNull Project project) { + return ServiceManager.getService(project, ArtifactsWorkspaceSettings.class); + } + + public List getArtifactsToBuild() { + final List result = new ArrayList(); + final ArtifactManager artifactManager = ArtifactManager.getInstance(myProject); + for (String name : myState.myArtifactsToBuild) { + ContainerUtil.addIfNotNull(artifactManager.findArtifact(name), result); + } + return result; + } + + public void setArtifactsToBuild(@NotNull Collection artifacts) { + myState.myArtifactsToBuild.clear(); + for (Artifact artifact : artifacts) { + myState.myArtifactsToBuild.add(artifact.getName()); + } + Collections.sort(myState.myArtifactsToBuild); + } + + public ArtifactsWorkspaceSettingsState getState() { + return myState; + } + + public void loadState(ArtifactsWorkspaceSettingsState state) { + myState = state; + } + + public static class ArtifactsWorkspaceSettingsState { + @Tag("artifacts-to-build") + @AbstractCollection(surroundWithTag = false, elementTag = "artifact", elementValueAttribute = "name") + public List myArtifactsToBuild = new ArrayList(); + + } +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ChooseArtifactsDialog.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ChooseArtifactsDialog.java similarity index 95% rename from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ChooseArtifactsDialog.java rename to java/compiler/impl/src/com/intellij/packaging/impl/ui/ChooseArtifactsDialog.java index da7473d828c1..0dcb2f4e90d5 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ChooseArtifactsDialog.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/ChooseArtifactsDialog.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.openapi.roots.ui.configuration.artifacts; +package com.intellij.packaging.impl.ui; import com.intellij.openapi.project.Project; import com.intellij.ide.util.ChooseElementsDialog; diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java index 2439a6b690c0..c516993ad49b 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java @@ -37,6 +37,7 @@ import com.intellij.packaging.artifacts.ArtifactModel; import com.intellij.packaging.artifacts.ArtifactType; import com.intellij.packaging.artifacts.ModifiableArtifactModel; import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.packaging.impl.ui.ChooseArtifactsDialog; import com.intellij.packaging.ui.ArtifactEditor; import com.intellij.packaging.ui.ArtifactEditorContext; import com.intellij.packaging.ui.ManifestFileConfiguration; diff --git a/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java b/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java index f4558bfa4bf8..19e701b5fffb 100644 --- a/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java +++ b/platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java @@ -94,6 +94,10 @@ public abstract class ChooseElementsDialog extends DialogWrapper { return myChooser.getSelectedElements(); } + public void selectElements(@NotNull List elements) { + myChooser.selectElements(elements); + } + public JComponent getPreferredFocusedComponent() { return myChooser.getComponent(); } diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 7207661d2784..543170e248e7 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -370,6 +370,9 @@ + + diff --git a/resources/src/idea/IdeaActions.xml b/resources/src/idea/IdeaActions.xml index cc1541b0cab0..7f767ef86ee1 100644 --- a/resources/src/idea/IdeaActions.xml +++ b/resources/src/idea/IdeaActions.xml @@ -186,8 +186,6 @@ - - @@ -198,7 +196,7 @@ - +