use of com.intellij.packaging.elements.CompositePackagingElement in project intellij-community by JetBrains.
the class LayoutTreeComponent method putIntoDefaultLocations.
public void putIntoDefaultLocations(@NotNull final List<? extends PackagingSourceItem> items) {
final List<PackagingElement<?>> toSelect = new ArrayList<>();
editLayout(() -> {
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);
}
use of com.intellij.packaging.elements.CompositePackagingElement in project intellij-community by JetBrains.
the class LayoutTreeComponent method removeNodes.
public void removeNodes(final List<PackagingElementNode<?>> nodes) {
Set<PackagingElement<?>> parents = new HashSet<>();
for (PackagingElementNode<?> node : nodes) {
final List<? extends PackagingElement<?>> toDelete = node.getPackagingElements();
for (PackagingElement<?> element : toDelete) {
final Collection<PackagingNodeSource> nodeSources = node.getNodeSource(element);
if (nodeSources.isEmpty()) {
final CompositePackagingElement<?> parent = node.getParentElement(element);
if (parent != null) {
parents.add(parent);
parent.removeChild(element);
}
} else {
Collection<PackagingNodeSource> rootSources = getRootNodeSources(nodeSources);
for (PackagingNodeSource source : rootSources) {
parents.add(source.getSourceParentElement());
source.getSourceParentElement().removeChild(source.getSourceElement());
}
}
}
}
final List<PackagingElementNode<?>> parentNodes = myTree.findNodes(parents);
for (PackagingElementNode<?> parentNode : parentNodes) {
myTree.addSubtreeToUpdate(parentNode);
}
}
use of com.intellij.packaging.elements.CompositePackagingElement in project intellij-community by JetBrains.
the class LayoutTreeComponent method findParentCompositeElementNode.
@Nullable
private DefaultMutableTreeNode findParentCompositeElementNode(Point point) {
TreePath path = myTree.getPathForLocation(point.x, point.y);
while (path != null) {
final PackagingElement<?> element = myTree.getElementByPath(path);
if (element instanceof CompositePackagingElement) {
return (DefaultMutableTreeNode) path.getLastPathComponent();
}
path = path.getParentPath();
}
return null;
}
use of com.intellij.packaging.elements.CompositePackagingElement 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();
}
use of com.intellij.packaging.elements.CompositePackagingElement in project intellij-community by JetBrains.
the class MovePackagingElementAction method isEnabled.
private boolean isEnabled() {
if (myLayoutTreeComponent.isSortElements()) {
return false;
}
final PackagingElementNode<?> node = myLayoutTreeComponent.getSelection().getNodeIfSingle();
if (node == null) {
return false;
}
final CompositePackagingElementNode parent = node.getParentNode();
if (parent == null)
return false;
final PackagingElement<?> element = node.getElementIfSingle();
final CompositePackagingElement<?> parentElement = parent.getElementIfSingle();
if (parentElement == null || element == null)
return false;
final List<PackagingElement<?>> children = parentElement.getChildren();
final int index = children.indexOf(element);
return index != -1 && 0 <= index + myDirection && index + myDirection < children.size();
}
Aggregations