Search in sources :

Example 1 with CompositePackagingElementType

use of com.intellij.packaging.elements.CompositePackagingElementType 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)

Aggregations

LayoutTreeComponent (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)1 LayoutTreeSelection (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)1 CompositePackagingElementType (com.intellij.packaging.elements.CompositePackagingElementType)1 PackagingElement (com.intellij.packaging.elements.PackagingElement)1