public void putIntoDefaultLocations(@NotNull final List<? extends PackagingSourceItem> items) {
    final List<PackagingElement<?>> toSelect = new ArrayList<PackagingElement<?>>();
    editLayout(
        new Runnable() {
          @Override
          public void run() {
            final CompositePackagingElement<?> rootElement = getArtifact().getRootElement();
            final ArtifactType artifactType = getArtifact().getArtifactType();
            for (PackagingSourceItem item : items) {
              final String path = artifactType.getDefaultPathFor(item);
              if (path != null) {
                final CompositePackagingElement<?> parent;
                if (path.endsWith(URLUtil.JAR_SEPARATOR)) {
                  parent =
                      PackagingElementFactory.getInstance()
                          .getOrCreateArchive(
                              rootElement, StringUtil.trimEnd(path, URLUtil.JAR_SEPARATOR));
                } else {
                  parent =
                      PackagingElementFactory.getInstance().getOrCreateDirectory(rootElement, path);
                }
                final List<? extends PackagingElement<?>> elements = item.createElements(myContext);
                toSelect.addAll(parent.addOrFindChildren(elements));
              }
            }
          }
        });

    myArtifactsEditor.getSourceItemsTree().rebuildTree();
    updateAndSelect(myTree.getRootPackagingNode(), toSelect);
  }
  public void addNewPackagingElement(@NotNull PackagingElementType<?> type) {
    PackagingElementNode<?> parentNode = getParentNode(myTree.getSelection());
    final PackagingElement<?> element = parentNode.getFirstElement();
    final CompositePackagingElement<?> parent;
    if (element instanceof CompositePackagingElement<?>) {
      parent = (CompositePackagingElement<?>) element;
    } else {
      parent = getArtifact().getRootElement();
      parentNode = myTree.getRootPackagingNode();
    }
    if (!checkCanAdd(parent, parentNode)) return;

    final List<? extends PackagingElement<?>> children =
        type.chooseAndCreate(myContext, getArtifact(), parent);
    final PackagingElementNode<?> finalParentNode = parentNode;
    editLayout(
        new Runnable() {
          @Override
          public void run() {
            CompositePackagingElement<?> actualParent =
                getOrCreateModifiableParent(parent, finalParentNode);
            for (PackagingElement<?> child : children) {
              actualParent.addOrFindChild(child);
            }
          }
        });
    updateAndSelect(parentNode, children);
  }
 private PackagingElementNode<?> getParentNode(final LayoutTreeSelection selection) {
   final PackagingElementNode<?> node = selection.getNodeIfSingle();
   if (node != null) {
     if (node.getFirstElement() instanceof CompositePackagingElement) {
       return node;
     }
     final PackagingElementNode<?> parent = node.getParentNode();
     if (parent != null) {
       return parent;
     }
   }
   return myTree.getRootPackagingNode();
 }
 public void putElements(
     @NotNull final String path, @NotNull final List<? extends PackagingElement<?>> elements) {
   final List<PackagingElement<?>> toSelect = new ArrayList<PackagingElement<?>>();
   editLayout(
       new Runnable() {
         @Override
         public void run() {
           final CompositePackagingElement<?> directory =
               PackagingElementFactory.getInstance()
                   .getOrCreateDirectory(getArtifact().getRootElement(), path);
           toSelect.addAll(directory.addOrFindChildren(elements));
         }
       });
   myArtifactsEditor.getSourceItemsTree().rebuildTree();
   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() {
          @Override
          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);
  }