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);
  }
 @Override
 public void drop(DnDEvent aEvent) {
   final Object object = aEvent.getAttachedObject();
   if (object instanceof PackagingElementDraggingObject) {
     final PackagingElementDraggingObject draggingObject = (PackagingElementDraggingObject) object;
     final PackagingElementNode<?> targetNode = draggingObject.getTargetNode();
     final CompositePackagingElement<?> targetElement = draggingObject.getTargetElement();
     if (targetElement == null || targetNode == null || !draggingObject.checkCanDrop()) return;
     if (!checkCanAdd(targetElement, targetNode)) {
       return;
     }
     final List<PackagingElement<?>> toSelect = new ArrayList<PackagingElement<?>>();
     editLayout(
         new Runnable() {
           @Override
           public void run() {
             draggingObject.beforeDrop();
             final CompositePackagingElement<?> parent =
                 getOrCreateModifiableParent(targetElement, targetNode);
             for (PackagingElement<?> element :
                 draggingObject.createPackagingElements(myContext)) {
               toSelect.add(element);
               parent.addOrFindChild(element);
             }
           }
         });
     updateAndSelect(targetNode, toSelect);
     myArtifactsEditor.getSourceItemsTree().rebuildTree();
   }
 }
 public void setRootElement(CompositePackagingElement<?> rootElement) {
   myContext
       .getOrCreateModifiableArtifactModel()
       .getOrCreateModifiableArtifact(myOriginalArtifact)
       .setRootElement(rootElement);
   myTreeStructure.updateRootElement();
   final DefaultMutableTreeNode node = myTree.getRootNode();
   node.setUserObject(myTreeStructure.getRootElement());
   myBuilder.updateNode(node);
   rebuildTree();
   myArtifactsEditor.getSourceItemsTree().rebuildTree();
 }
 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);
  }