Search in sources :

Example 1 with LayoutTreeComponent

use of com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent 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 LayoutTreeComponent

use of com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent in project intellij-community by JetBrains.

the class SurroundElementWithAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final LayoutTreeComponent treeComponent = myArtifactEditor.getLayoutTreeComponent();
    final LayoutTreeSelection selection = treeComponent.getSelection();
    final CompositePackagingElement<?> parent = selection.getCommonParentElement();
    if (parent == null)
        return;
    final PackagingElementNode<?> parentNode = selection.getNodes().get(0).getParentNode();
    if (parentNode == null)
        return;
    if (!treeComponent.checkCanModifyChildren(parent, parentNode, selection.getNodes())) {
        return;
    }
    final CompositePackagingElementType<?>[] types = PackagingElementFactory.getInstance().getCompositeElementTypes();
    final List<PackagingElement<?>> selected = selection.getElements();
    if (types.length == 1) {
        surroundWith(types[0], parent, selected, treeComponent);
    } else {
        JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CompositePackagingElementType>("Surround With...", types) {

            @Override
            public Icon getIconFor(CompositePackagingElementType aValue) {
                return aValue.getCreateElementIcon();
            }

            @NotNull
            @Override
            public String getTextFor(CompositePackagingElementType value) {
                return value.getPresentableName();
            }

            @Override
            public PopupStep onChosen(final CompositePackagingElementType selectedValue, boolean finalChoice) {
                return doFinalStep(() -> surroundWith(selectedValue, parent, selected, treeComponent));
            }
        }).showInBestPositionFor(e.getDataContext());
    }
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) CompositePackagingElementType(com.intellij.packaging.elements.CompositePackagingElementType) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)

Example 3 with LayoutTreeComponent

use of com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent in project intellij-community by JetBrains.

the class ExtractArtifactAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final LayoutTreeComponent treeComponent = myArtifactEditor.getLayoutTreeComponent();
    final LayoutTreeSelection selection = treeComponent.getSelection();
    final CompositePackagingElement<?> parent = selection.getCommonParentElement();
    if (parent == null)
        return;
    final PackagingElementNode<?> parentNode = selection.getNodes().get(0).getParentNode();
    if (parentNode == null)
        return;
    if (!treeComponent.checkCanModifyChildren(parent, parentNode, selection.getNodes())) {
        return;
    }
    final Collection<? extends PackagingElement> selectedElements = selection.getElements();
    String initialName = "artifact";
    if (selectedElements.size() == 1) {
        initialName = PathUtil.suggestFileName(ContainerUtil.getFirstItem(selectedElements, null).createPresentation(myArtifactEditor.getContext()).getPresentableName());
    }
    IExtractArtifactDialog dialog = showDialog(treeComponent, initialName);
    if (dialog == null)
        return;
    final Project project = myArtifactEditor.getContext().getProject();
    final ModifiableArtifactModel model = myArtifactEditor.getContext().getOrCreateModifiableArtifactModel();
    final ModifiableArtifact artifact = model.addArtifact(dialog.getArtifactName(), dialog.getArtifactType());
    treeComponent.editLayout(() -> {
        for (PackagingElement<?> element : selectedElements) {
            artifact.getRootElement().addOrFindChild(ArtifactUtil.copyWithChildren(element, project));
        }
        for (PackagingElement element : selectedElements) {
            parent.removeChild(element);
        }
        parent.addOrFindChild(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(artifact, myArtifactEditor.getContext().getArtifactModel())));
    });
    treeComponent.rebuildTree();
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) ModifiableArtifact(com.intellij.packaging.artifacts.ModifiableArtifact) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent) Project(com.intellij.openapi.project.Project) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel)

Aggregations

LayoutTreeComponent (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)3 LayoutTreeSelection (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection)3 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)2 PackagingElement (com.intellij.packaging.elements.PackagingElement)2 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)2 Project (com.intellij.openapi.project.Project)1 CompositePackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 Artifact (com.intellij.packaging.artifacts.Artifact)1 ModifiableArtifact (com.intellij.packaging.artifacts.ModifiableArtifact)1 ModifiableArtifactModel (com.intellij.packaging.artifacts.ModifiableArtifactModel)1 ArtifactRootElement (com.intellij.packaging.elements.ArtifactRootElement)1 CompositePackagingElementType (com.intellij.packaging.elements.CompositePackagingElementType)1 ArtifactEditorContext (com.intellij.packaging.ui.ArtifactEditorContext)1