mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
artifacts editor: "Pack into archive and put it to default location" action
This commit is contained in:
@@ -17,10 +17,8 @@ package com.intellij.packaging.impl.artifacts;
|
||||
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementResolvingContext;
|
||||
import com.intellij.packaging.elements.PackagingElementOutputKind;
|
||||
import com.intellij.packaging.impl.elements.ArchivePackagingElement;
|
||||
import com.intellij.packaging.ui.PackagingSourceItem;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -40,12 +38,7 @@ public class JarArtifactType extends ArtifactType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultPathFor(@NotNull PackagingSourceItem sourceItem) {
|
||||
return "/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultPathFor(@NotNull PackagingElement<?> element, @NotNull PackagingElementResolvingContext context) {
|
||||
public String getDefaultPathFor(@NotNull PackagingElementOutputKind kind) {
|
||||
return "/";
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,9 @@ package com.intellij.packaging.impl.artifacts;
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementResolvingContext;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementOutputKind;
|
||||
import com.intellij.packaging.impl.elements.ArtifactRootElementImpl;
|
||||
import com.intellij.packaging.ui.PackagingSourceItem;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -50,12 +48,8 @@ public class PlainArtifactType extends ArtifactType {
|
||||
return ARTIFACT_ICON;
|
||||
}
|
||||
|
||||
public String getDefaultPathFor(@NotNull PackagingSourceItem sourceItem) {
|
||||
return "/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultPathFor(@NotNull PackagingElement<?> element, @NotNull PackagingElementResolvingContext context) {
|
||||
public String getDefaultPathFor(@NotNull PackagingElementOutputKind kind) {
|
||||
return "/";
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementOutputKind;
|
||||
import com.intellij.packaging.elements.PackagingElementResolvingContext;
|
||||
import com.intellij.packaging.ui.ArtifactValidationManager;
|
||||
import com.intellij.packaging.ui.PackagingSourceItem;
|
||||
@@ -55,10 +56,17 @@ public abstract class ArtifactType {
|
||||
public abstract Icon getIcon();
|
||||
|
||||
@Nullable
|
||||
public abstract String getDefaultPathFor(@NotNull PackagingSourceItem sourceItem);
|
||||
public String getDefaultPathFor(@NotNull PackagingSourceItem sourceItem) {
|
||||
return getDefaultPathFor(sourceItem.getKindOfProducedElements());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract String getDefaultPathFor(@NotNull PackagingElement<?> element, @NotNull PackagingElementResolvingContext context);
|
||||
public String getDefaultPathFor(@NotNull PackagingElement<?> element, @NotNull PackagingElementResolvingContext context) {
|
||||
return getDefaultPathFor(element.getFilesKind(context));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract String getDefaultPathFor(@NotNull PackagingElementOutputKind kind);
|
||||
|
||||
public boolean isSuitableItem(@NotNull PackagingSourceItem sourceItem) {
|
||||
return true;
|
||||
|
||||
+18
@@ -433,6 +433,24 @@ public class LayoutTreeComponent implements DnDTarget, Disposable {
|
||||
updateAndSelect(myTree.getRootPackagingNode(), toSelect);
|
||||
}
|
||||
|
||||
public void packInto(@NotNull final List<? extends PackagingSourceItem> items, final String pathToJar) {
|
||||
final List<PackagingElement<?>> toSelect = new ArrayList<PackagingElement<?>>();
|
||||
final CompositePackagingElement<?> rootElement = getArtifact().getRootElement();
|
||||
editLayout(new Runnable() {
|
||||
public void run() {
|
||||
final CompositePackagingElement<?> archive = PackagingElementFactory.getInstance().getOrCreateArchive(rootElement, pathToJar);
|
||||
for (PackagingSourceItem item : items) {
|
||||
final List<? extends PackagingElement<?>> elements = item.createElements(myContext);
|
||||
archive.addOrFindChildren(elements);
|
||||
}
|
||||
toSelect.add(archive);
|
||||
}
|
||||
});
|
||||
|
||||
myArtifactsEditor.getSourceItemsTree().rebuildTree();
|
||||
updateAndSelect(myTree.getRootPackagingNode(), toSelect);
|
||||
}
|
||||
|
||||
public boolean isPropertiesModified() {
|
||||
final PackagingElementPropertiesPanel panel = mySelectedElementInfo.myCurrentPanel;
|
||||
return panel != null && panel.isModified();
|
||||
|
||||
+2
-4
@@ -28,10 +28,7 @@ import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorImpl;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.SimpleDnDAwareTree;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.SourceItemsDraggingObject;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.actions.PutSourceItemIntoDefaultLocationAction;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.actions.PutSourceItemIntoParentAndLinkViaManifestAction;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.actions.SourceItemFindUsagesAction;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.actions.SourceItemNavigateAction;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.actions.*;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
@@ -70,6 +67,7 @@ public class SourceItemsTree implements DnDSource, Disposable{
|
||||
private ActionGroup createPopupGroup() {
|
||||
final DefaultActionGroup group = new DefaultActionGroup();
|
||||
group.add(new PutSourceItemIntoDefaultLocationAction(this, myArtifactsEditor));
|
||||
group.add(new PackAndPutIntoDefaultLocationAction(this, myArtifactsEditor));
|
||||
group.add(new PutSourceItemIntoParentAndLinkViaManifestAction(this, myArtifactsEditor));
|
||||
|
||||
group.add(Separator.getInstance());
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.sourceItems.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.deployment.DeploymentUtil;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.SourceItemsTree;
|
||||
import com.intellij.packaging.elements.PackagingElementOutputKind;
|
||||
import com.intellij.packaging.ui.PackagingSourceItem;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class PackAndPutIntoDefaultLocationAction extends PutIntoDefaultLocationActionBase {
|
||||
public PackAndPutIntoDefaultLocationAction(SourceItemsTree sourceItemsTree, ArtifactEditorEx artifactEditor) {
|
||||
super(sourceItemsTree, artifactEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
final String jarName = suggestJarName();
|
||||
final String pathForJars = myArtifactEditor.getArtifact().getArtifactType().getDefaultPathFor(PackagingElementOutputKind.JAR_FILES);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
if (jarName != null && pathForJars != null) {
|
||||
presentation.setText("Pack Into " + DeploymentUtil.appendToPath(pathForJars, jarName + ".jar"));
|
||||
presentation.setVisible(true);
|
||||
}
|
||||
else {
|
||||
presentation.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String suggestJarName() {
|
||||
final List<PackagingSourceItem> items = mySourceItemsTree.getSelectedItems();
|
||||
for (PackagingSourceItem item : items) {
|
||||
if (item.isProvideElements() && item.getKindOfProducedElements().containsDirectoriesWithClasses()) {
|
||||
return item.createPresentation(myArtifactEditor.getContext()).getPresentableName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final String pathForJars = myArtifactEditor.getArtifact().getArtifactType().getDefaultPathFor(PackagingElementOutputKind.JAR_FILES);
|
||||
final String jarName = suggestJarName();
|
||||
if (pathForJars != null) {
|
||||
myArtifactEditor.getLayoutTreeComponent().packInto(mySourceItemsTree.getSelectedItems(),
|
||||
DeploymentUtil.appendToPath(pathForJars, jarName + ".jar"));
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.sourceItems.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.SourceItemsTree;
|
||||
import com.intellij.packaging.ui.PackagingSourceItem;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class PutIntoDefaultLocationActionBase extends AnAction {
|
||||
protected final SourceItemsTree mySourceItemsTree;
|
||||
protected final ArtifactEditorEx myArtifactEditor;
|
||||
|
||||
public PutIntoDefaultLocationActionBase(SourceItemsTree sourceItemsTree, ArtifactEditorEx artifactEditor) {
|
||||
mySourceItemsTree = sourceItemsTree;
|
||||
myArtifactEditor = artifactEditor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getDefaultPath(PackagingSourceItem item) {
|
||||
return myArtifactEditor.getArtifact().getArtifactType().getDefaultPathFor(item);
|
||||
}
|
||||
}
|
||||
+4
-11
@@ -15,34 +15,27 @@
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.SourceItemsTree;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import com.intellij.packaging.ui.PackagingSourceItem;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class PutSourceItemIntoDefaultLocationAction extends AnAction {
|
||||
private final SourceItemsTree mySourceItemsTree;
|
||||
private final ArtifactEditorEx myArtifactEditor;
|
||||
|
||||
public class PutSourceItemIntoDefaultLocationAction extends PutIntoDefaultLocationActionBase {
|
||||
public PutSourceItemIntoDefaultLocationAction(SourceItemsTree sourceItemsTree, ArtifactEditorEx artifactEditor) {
|
||||
mySourceItemsTree = sourceItemsTree;
|
||||
myArtifactEditor = artifactEditor;
|
||||
super(sourceItemsTree, artifactEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
final ArtifactType type = myArtifactEditor.getArtifact().getArtifactType();
|
||||
final List<PackagingSourceItem> items = mySourceItemsTree.getSelectedItems();
|
||||
boolean enabled = false;
|
||||
final Presentation presentation = e.getPresentation();
|
||||
@@ -50,7 +43,7 @@ public class PutSourceItemIntoDefaultLocationAction extends AnAction {
|
||||
enabled = true;
|
||||
Set<String> paths = new HashSet<String>();
|
||||
for (PackagingSourceItem item : items) {
|
||||
final String path = type.getDefaultPathFor(item);
|
||||
final String path = getDefaultPath(item);
|
||||
if (path == null) {
|
||||
enabled = false;
|
||||
break;
|
||||
|
||||
+2
-7
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx;
|
||||
@@ -41,13 +40,9 @@ import java.util.List;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class PutSourceItemIntoParentAndLinkViaManifestAction extends AnAction {
|
||||
private final SourceItemsTree mySourceItemsTree;
|
||||
private final ArtifactEditorEx myArtifactEditor;
|
||||
|
||||
public class PutSourceItemIntoParentAndLinkViaManifestAction extends PutIntoDefaultLocationActionBase {
|
||||
public PutSourceItemIntoParentAndLinkViaManifestAction(SourceItemsTree sourceItemsTree, ArtifactEditorEx artifactEditor) {
|
||||
mySourceItemsTree = sourceItemsTree;
|
||||
myArtifactEditor = artifactEditor;
|
||||
super(sourceItemsTree, artifactEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user