Search in sources :

Example 6 with LayoutTreeSelection

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

Example 7 with LayoutTreeSelection

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

the class HideContentAction method update.

@Override
public void update(AnActionEvent e) {
    final LayoutTreeSelection selection = myArtifactEditor.getLayoutTreeComponent().getSelection();
    final PackagingElementNode<?> node = selection.getNodeIfSingle();
    if (node != null) {
        final Collection<PackagingNodeSource> sources = node.getNodeSources();
        if (!sources.isEmpty()) {
            String description;
            if (sources.size() == 1) {
                description = "Hide Content of '" + sources.iterator().next().getPresentableName() + "'";
            } else {
                description = "Hide Content";
            }
            e.getPresentation().setVisible(true);
            e.getPresentation().setText(description);
            return;
        }
    }
    e.getPresentation().setVisible(false);
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) PackagingNodeSource(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingNodeSource)

Example 8 with LayoutTreeSelection

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

the class InlineArtifactAction method update.

@Override
public void update(AnActionEvent e) {
    final LayoutTreeSelection selection = myEditor.getLayoutTreeComponent().getSelection();
    final PackagingElementNode<?> node = selection.getNodeIfSingle();
    PackagingElement<?> element = selection.getElementIfSingle();
    e.getPresentation().setEnabled(element instanceof ArtifactPackagingElement && node != null && node.getParentElement(element) != null);
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement)

Aggregations

LayoutTreeSelection (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection)8 LayoutTreeComponent (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)3 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)3 PackagingNodeSource (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingNodeSource)2 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)2 PackagingElement (com.intellij.packaging.elements.PackagingElement)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 RenameablePackagingElement (com.intellij.packaging.elements.RenameablePackagingElement)1 ArtifactEditorContext (com.intellij.packaging.ui.ArtifactEditorContext)1 TreePath (javax.swing.tree.TreePath)1