Search in sources :

Example 1 with ArtifactEditorContext

use of com.intellij.packaging.ui.ArtifactEditorContext in project intellij-community by JetBrains.

the class InlineArtifactAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final LayoutTreeComponent treeComponent = myEditor.getLayoutTreeComponent();
    final LayoutTreeSelection selection = treeComponent.getSelection();
    final PackagingElement<?> element = selection.getElementIfSingle();
    final PackagingElementNode<?> node = selection.getNodeIfSingle();
    if (node == null || !(element instanceof ArtifactPackagingElement))
        return;
    final CompositePackagingElement<?> parent = node.getParentElement(element);
    final CompositePackagingElementNode parentNode = node.getParentNode();
    if (parent == null || parentNode == null) {
        return;
    }
    if (!treeComponent.checkCanModifyChildren(parent, parentNode, Collections.singletonList(node)))
        return;
    treeComponent.editLayout(() -> {
        parent.removeChild(element);
        final ArtifactEditorContext context = myEditor.getContext();
        final Artifact artifact = ((ArtifactPackagingElement) element).findArtifact(context);
        if (artifact != null) {
            final CompositePackagingElement<?> rootElement = artifact.getRootElement();
            if (rootElement instanceof ArtifactRootElement<?>) {
                for (PackagingElement<?> child : rootElement.getChildren()) {
                    parent.addOrFindChild(ArtifactUtil.copyWithChildren(child, context.getProject()));
                }
            } else {
                parent.addOrFindChild(ArtifactUtil.copyWithChildren(rootElement, context.getProject()));
            }
        }
    });
    treeComponent.rebuildTree();
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) ArtifactRootElement(com.intellij.packaging.elements.ArtifactRootElement) CompositePackagingElementNode(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode) ArtifactEditorContext(com.intellij.packaging.ui.ArtifactEditorContext) Artifact(com.intellij.packaging.artifacts.Artifact) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)

Example 2 with ArtifactEditorContext

use of com.intellij.packaging.ui.ArtifactEditorContext in project intellij-community by JetBrains.

the class PutSourceItemIntoParentAndLinkViaManifestAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final List<PackagingSourceItem> items = mySourceItemsTree.getSelectedItems();
    ParentElementsInfo parentsInfo = findParentAndGrandParent(myArtifactEditor.getArtifact());
    if (parentsInfo == null) {
        return;
    }
    final Artifact artifact = parentsInfo.getGrandparentArtifact();
    final ArtifactEditorContext context = myArtifactEditor.getContext();
    //todo[nik] improve
    final Runnable emptyRunnable = EmptyRunnable.getInstance();
    context.editLayout(artifact, emptyRunnable);
    context.editLayout(parentsInfo.getParentArtifact(), emptyRunnable);
    //find elements under modifiable root
    parentsInfo = findParentAndGrandParent(myArtifactEditor.getArtifact());
    if (parentsInfo == null) {
        return;
    }
    final CompositePackagingElement<?> grandParent = parentsInfo.getGrandparentElement();
    final List<String> classpath = new ArrayList<>();
    context.editLayout(artifact, () -> {
        for (PackagingSourceItem item : items) {
            final List<? extends PackagingElement<?>> elements = item.createElements(context);
            grandParent.addOrFindChildren(elements);
            classpath.addAll(ManifestFileUtil.getClasspathForElements(elements, context, artifact.getArtifactType()));
        }
    });
    final ArtifactEditor parentArtifactEditor = context.getOrCreateEditor(parentsInfo.getParentArtifact());
    parentArtifactEditor.addToClasspath(parentsInfo.getParentElement(), classpath);
    ((ArtifactEditorImpl) context.getOrCreateEditor(parentsInfo.getGrandparentArtifact())).rebuildTries();
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) ArtifactEditor(com.intellij.packaging.ui.ArtifactEditor) ArrayList(java.util.ArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) ArtifactEditorImpl(com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorImpl) ArtifactEditorContext(com.intellij.packaging.ui.ArtifactEditorContext)

Example 3 with ArtifactEditorContext

use of com.intellij.packaging.ui.ArtifactEditorContext in project intellij-community by JetBrains.

the class ExtractIntoDefaultLocationAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final String pathForClasses = myArtifactEditor.getArtifact().getArtifactType().getDefaultPathFor(PackagingElementOutputKind.DIRECTORIES_WITH_CLASSES);
    if (pathForClasses != null) {
        final List<PackagingElement<?>> extracted = new ArrayList<>();
        for (PackagingSourceItem item : mySourceItemsTree.getSelectedItems()) {
            final ArtifactEditorContext context = myArtifactEditor.getContext();
            final List<? extends PackagingElement<?>> elements = item.createElements(context);
            ArtifactUtil.processElementsWithSubstitutions(elements, context, context.getArtifactType(), PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {

                @Override
                public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
                    if (element instanceof FileCopyPackagingElement) {
                        final VirtualFile file = ((FileCopyPackagingElement) element).findFile();
                        if (file != null) {
                            final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(file);
                            if (jarRoot != null) {
                                extracted.add(PackagingElementFactory.getInstance().createExtractedDirectory(jarRoot));
                            }
                        }
                    }
                    return true;
                }
            });
        }
        myArtifactEditor.getLayoutTreeComponent().putElements(pathForClasses, extracted);
    }
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) FileCopyPackagingElement(com.intellij.packaging.impl.elements.FileCopyPackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) ArtifactEditorContext(com.intellij.packaging.ui.ArtifactEditorContext) FileCopyPackagingElement(com.intellij.packaging.impl.elements.FileCopyPackagingElement)

Aggregations

ArtifactEditorContext (com.intellij.packaging.ui.ArtifactEditorContext)3 Artifact (com.intellij.packaging.artifacts.Artifact)2 PackagingSourceItem (com.intellij.packaging.ui.PackagingSourceItem)2 ArrayList (java.util.ArrayList)2 ArtifactEditorImpl (com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorImpl)1 LayoutTreeComponent (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)1 LayoutTreeSelection (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection)1 CompositePackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode)1 EmptyRunnable (com.intellij.openapi.util.EmptyRunnable)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArtifactRootElement (com.intellij.packaging.elements.ArtifactRootElement)1 PackagingElement (com.intellij.packaging.elements.PackagingElement)1 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)1 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)1 FileCopyPackagingElement (com.intellij.packaging.impl.elements.FileCopyPackagingElement)1 ArtifactEditor (com.intellij.packaging.ui.ArtifactEditor)1