use of com.intellij.packaging.ui.ArtifactEditorContext in project intellij-community by JetBrains.
the class InlineArtifactAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final LayoutTreeComponent treeComponent = myEditor.getLayoutTreeComponent();
final LayoutTreeSelection selection = treeComponent.getSelection();
final PackagingElement<?> element = selection.getElementIfSingle();
final PackagingElementNode<?> node = selection.getNodeIfSingle();
if (node == null || !(element instanceof ArtifactPackagingElement))
return;
final CompositePackagingElement<?> parent = node.getParentElement(element);
final CompositePackagingElementNode parentNode = node.getParentNode();
if (parent == null || parentNode == null) {
return;
}
if (!treeComponent.checkCanModifyChildren(parent, parentNode, Collections.singletonList(node)))
return;
treeComponent.editLayout(() -> {
parent.removeChild(element);
final ArtifactEditorContext context = myEditor.getContext();
final Artifact artifact = ((ArtifactPackagingElement) element).findArtifact(context);
if (artifact != null) {
final CompositePackagingElement<?> rootElement = artifact.getRootElement();
if (rootElement instanceof ArtifactRootElement<?>) {
for (PackagingElement<?> child : rootElement.getChildren()) {
parent.addOrFindChild(ArtifactUtil.copyWithChildren(child, context.getProject()));
}
} else {
parent.addOrFindChild(ArtifactUtil.copyWithChildren(rootElement, context.getProject()));
}
}
});
treeComponent.rebuildTree();
}
use of com.intellij.packaging.ui.ArtifactEditorContext in project intellij-community by JetBrains.
the class PutSourceItemIntoParentAndLinkViaManifestAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final List<PackagingSourceItem> items = mySourceItemsTree.getSelectedItems();
ParentElementsInfo parentsInfo = findParentAndGrandParent(myArtifactEditor.getArtifact());
if (parentsInfo == null) {
return;
}
final Artifact artifact = parentsInfo.getGrandparentArtifact();
final ArtifactEditorContext context = myArtifactEditor.getContext();
//todo[nik] improve
final Runnable emptyRunnable = EmptyRunnable.getInstance();
context.editLayout(artifact, emptyRunnable);
context.editLayout(parentsInfo.getParentArtifact(), emptyRunnable);
//find elements under modifiable root
parentsInfo = findParentAndGrandParent(myArtifactEditor.getArtifact());
if (parentsInfo == null) {
return;
}
final CompositePackagingElement<?> grandParent = parentsInfo.getGrandparentElement();
final List<String> classpath = new ArrayList<>();
context.editLayout(artifact, () -> {
for (PackagingSourceItem item : items) {
final List<? extends PackagingElement<?>> elements = item.createElements(context);
grandParent.addOrFindChildren(elements);
classpath.addAll(ManifestFileUtil.getClasspathForElements(elements, context, artifact.getArtifactType()));
}
});
final ArtifactEditor parentArtifactEditor = context.getOrCreateEditor(parentsInfo.getParentArtifact());
parentArtifactEditor.addToClasspath(parentsInfo.getParentElement(), classpath);
((ArtifactEditorImpl) context.getOrCreateEditor(parentsInfo.getGrandparentArtifact())).rebuildTries();
}
use of com.intellij.packaging.ui.ArtifactEditorContext in project intellij-community by JetBrains.
the class ExtractIntoDefaultLocationAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final String pathForClasses = myArtifactEditor.getArtifact().getArtifactType().getDefaultPathFor(PackagingElementOutputKind.DIRECTORIES_WITH_CLASSES);
if (pathForClasses != null) {
final List<PackagingElement<?>> extracted = new ArrayList<>();
for (PackagingSourceItem item : mySourceItemsTree.getSelectedItems()) {
final ArtifactEditorContext context = myArtifactEditor.getContext();
final List<? extends PackagingElement<?>> elements = item.createElements(context);
ArtifactUtil.processElementsWithSubstitutions(elements, context, context.getArtifactType(), PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {
@Override
public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
if (element instanceof FileCopyPackagingElement) {
final VirtualFile file = ((FileCopyPackagingElement) element).findFile();
if (file != null) {
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(file);
if (jarRoot != null) {
extracted.add(PackagingElementFactory.getInstance().createExtractedDirectory(jarRoot));
}
}
}
return true;
}
});
}
myArtifactEditor.getLayoutTreeComponent().putElements(pathForClasses, extracted);
}
}
Aggregations