コード例 #1
0
  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);
  }
コード例 #2
0
 @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();
   }
 }
コード例 #3
0
  public boolean checkCanRemove(final List<? extends PackagingElementNode<?>> nodes) {
    Set<PackagingNodeSource> rootSources = new HashSet<PackagingNodeSource>();
    for (PackagingElementNode<?> node : nodes) {
      rootSources.addAll(getRootNodeSources(node.getNodeSources()));
    }

    if (!rootSources.isEmpty()) {
      final String message;
      if (rootSources.size() == 1) {
        final String name = rootSources.iterator().next().getPresentableName();
        message =
            "The selected node belongs to '"
                + name
                + "' element. Do you want to remove the whole '"
                + name
                + "' element from the artifact?";
      } else {
        message =
            "The selected node belongs to "
                + nodes.size()
                + " elements. Do you want to remove all these elements from the artifact?";
      }
      final int answer =
          Messages.showYesNoDialog(
              myArtifactsEditor.getMainComponent(), message, "Remove Elements", null);
      if (answer != Messages.YES) return false;
    }
    return true;
  }
コード例 #4
0
 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();
 }
コード例 #5
0
  public boolean checkCanModify(final Collection<PackagingNodeSource> nodeSources) {
    if (nodeSources.isEmpty()) {
      return true;
    }

    if (nodeSources.size() > 1) {
      Messages.showErrorDialog(
          myArtifactsEditor.getMainComponent(),
          "The selected node consist of several elements so it cannot be edited.\nSwitch off 'Show content of elements' checkbox to edit the output layout.");
    } else {
      final PackagingNodeSource source = ContainerUtil.getFirstItem(nodeSources, null);
      if (source != null) {
        Messages.showErrorDialog(
            myArtifactsEditor.getMainComponent(),
            "The selected node belongs to '"
                + source.getPresentableName()
                + "' element so it cannot be edited.\nSwitch off 'Show content of elements' checkbox to edit the output layout.");
      }
    }
    return false;
  }
コード例 #6
0
  public void removeSelectedElements() {
    final LayoutTreeSelection selection = myTree.getSelection();
    if (!checkCanRemove(selection.getNodes())) return;

    editLayout(
        new Runnable() {
          @Override
          public void run() {
            removeNodes(selection.getNodes());
          }
        });

    myArtifactsEditor.rebuildTries();
  }
コード例 #7
0
 public void updateAndSelect(
     PackagingElementNode<?> node, final List<? extends PackagingElement<?>> toSelect) {
   myArtifactsEditor.queueValidation();
   myTreeStructure.clearCaches();
   myBuilder
       .queueUpdateFrom(node, true)
       .doWhenDone(
           new Runnable() {
             @Override
             public void run() {
               List<PackagingElementNode<?>> nodes = myTree.findNodes(toSelect);
               myBuilder.select(ArrayUtil.toObjectArray(nodes), null);
             }
           });
 }
コード例 #8
0
 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);
 }
コード例 #9
0
  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);
  }
コード例 #10
0
 public void rebuildTree() {
   myBuilder.updateFromRoot(true);
   updatePropertiesPanel(true);
   myArtifactsEditor.queueValidation();
 }
コード例 #11
0
 public Artifact getArtifact() {
   return myArtifactsEditor.getArtifact();
 }
コード例 #12
0
 public void setSortElements(boolean sortElements) {
   mySortElements = sortElements;
   myBuilder.setNodeDescriptorComparator(getComparator());
   myArtifactsEditor.getContext().getParent().getDefaultSettings().setSortElements(sortElements);
 }