use of com.intellij.packaging.elements.PackagingElement in project intellij-community by JetBrains.
the class ArtifactBySourceFileFinderImpl method computeFileToArtifactsMap.
private MultiValuesMap<VirtualFile, Artifact> computeFileToArtifactsMap() {
final MultiValuesMap<VirtualFile, Artifact> result = new MultiValuesMap<>();
final ArtifactManager artifactManager = ArtifactManager.getInstance(myProject);
for (final Artifact artifact : artifactManager.getArtifacts()) {
final PackagingElementResolvingContext context = artifactManager.getResolvingContext();
ArtifactUtil.processPackagingElements(artifact, null, new PackagingElementProcessor<PackagingElement<?>>() {
@Override
public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
if (element instanceof FileOrDirectoryCopyPackagingElement<?>) {
final VirtualFile root = ((FileOrDirectoryCopyPackagingElement) element).findFile();
if (root != null) {
result.put(root, artifact);
}
} else if (element instanceof ModuleOutputPackagingElement) {
for (VirtualFile sourceRoot : ((ModuleOutputPackagingElement) element).getSourceRoots(context)) {
result.put(sourceRoot, artifact);
}
}
return true;
}
}, context, true);
}
return result;
}
use of com.intellij.packaging.elements.PackagingElement in project intellij-community by JetBrains.
the class ExtractedDirectoryElementType method chooseAndCreate.
@NotNull
public List<? extends PackagingElement<?>> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement<?> parent) {
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, true, false, true, true) {
@Override
public boolean isFileSelectable(VirtualFile file) {
if (file.isInLocalFileSystem() && file.isDirectory())
return false;
return super.isFileSelectable(file);
}
};
final VirtualFile[] files = FileChooser.chooseFiles(descriptor, context.getProject(), null);
final List<PackagingElement<?>> list = new ArrayList<>();
final PackagingElementFactory factory = PackagingElementFactory.getInstance();
for (VirtualFile file : files) {
list.add(factory.createExtractedDirectory(file));
}
return list;
}
use of com.intellij.packaging.elements.PackagingElement in project intellij-community by JetBrains.
the class LibraryPackagingElement method getSubstitution.
public List<? extends PackagingElement<?>> getSubstitution(@NotNull PackagingElementResolvingContext context, @NotNull ArtifactType artifactType) {
final Library library = findLibrary(context);
if (library != null) {
final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
final List<PackagingElement<?>> elements = new ArrayList<>();
for (VirtualFile file : files) {
String localPath = PathUtil.getLocalPath(file);
if (localPath != null) {
final String path = FileUtil.toSystemIndependentName(localPath);
elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path));
}
}
return elements;
}
return null;
}
use of com.intellij.packaging.elements.PackagingElement in project intellij-community by JetBrains.
the class ModuleOutputElementTypeBase method chooseAndCreate.
@NotNull
public List<? extends PackagingElement<?>> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement<?> parent) {
List<Module> suitableModules = getSuitableModules(context);
List<Module> selected = context.chooseModules(suitableModules, ProjectBundle.message("dialog.title.packaging.choose.module"));
final List<PackagingElement<?>> elements = new ArrayList<>();
final ModulePointerManager pointerManager = ModulePointerManager.getInstance(context.getProject());
for (Module module : selected) {
elements.add(createElement(context.getProject(), pointerManager.create(module)));
}
return elements;
}
use of com.intellij.packaging.elements.PackagingElement in project intellij-community by JetBrains.
the class SurroundElementWithAction 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 CompositePackagingElementType<?>[] types = PackagingElementFactory.getInstance().getCompositeElementTypes();
final List<PackagingElement<?>> selected = selection.getElements();
if (types.length == 1) {
surroundWith(types[0], parent, selected, treeComponent);
} else {
JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CompositePackagingElementType>("Surround With...", types) {
@Override
public Icon getIconFor(CompositePackagingElementType aValue) {
return aValue.getCreateElementIcon();
}
@NotNull
@Override
public String getTextFor(CompositePackagingElementType value) {
return value.getPresentableName();
}
@Override
public PopupStep onChosen(final CompositePackagingElementType selectedValue, boolean finalChoice) {
return doFinalStep(() -> surroundWith(selectedValue, parent, selected, treeComponent));
}
}).showInBestPositionFor(e.getDataContext());
}
}
Aggregations