use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class IdeaJdkConfigurable method createComponent.
public JComponent createComponent() {
mySandboxHome.setHistorySize(5);
JPanel wholePanel = new JPanel(new GridBagLayout());
wholePanel.add(mySandboxHomeLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
wholePanel.add(GuiUtils.constructFieldWithBrowseButton(mySandboxHome, new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
descriptor.setTitle(DevKitBundle.message("sandbox.home"));
descriptor.setDescription(DevKitBundle.message("sandbox.purpose"));
VirtualFile file = FileChooser.chooseFile(descriptor, mySandboxHome, null, null);
if (file != null) {
mySandboxHome.setText(FileUtil.toSystemDependentName(file.getPath()));
}
myModified = true;
}
}), new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
wholePanel.add(myInternalJreLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
wholePanel.add(myInternalJres, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
myInternalJres.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof Sdk) {
setText(((Sdk) value).getName());
}
}
});
myInternalJres.addItemListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
if (myFreeze)
return;
final Sdk javaJdk = (Sdk) e.getItem();
for (OrderRootType type : OrderRootType.getAllTypes()) {
if (!((SdkType) javaJdk.getSdkType()).isRootTypeApplicable(type)) {
continue;
}
final VirtualFile[] internalRoots = javaJdk.getSdkModificator().getRoots(type);
final VirtualFile[] configuredRoots = mySdkModificator.getRoots(type);
for (VirtualFile file : internalRoots) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
mySdkModificator.removeRoot(file, type);
} else {
if (ArrayUtil.find(configuredRoots, file) == -1) {
mySdkModificator.addRoot(file, type);
}
}
}
}
}
});
mySandboxHome.addDocumentListener(new DocumentAdapter() {
protected void textChanged(DocumentEvent e) {
myModified = true;
}
});
mySandboxHome.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
myModified = true;
}
});
mySandboxHome.setText("");
myModified = true;
return wholePanel;
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class LibraryDataService method registerPaths.
static void registerPaths(boolean unresolved, @NotNull Map<OrderRootType, Collection<File>> libraryFiles, @NotNull Library.ModifiableModel model, @NotNull String libraryName) {
for (Map.Entry<OrderRootType, Collection<File>> entry : libraryFiles.entrySet()) {
for (File file : entry.getValue()) {
VirtualFile virtualFile = unresolved ? null : ExternalSystemUtil.refreshAndFindFileByIoFile(file);
if (virtualFile == null) {
if (!unresolved && ExternalSystemConstants.VERBOSE_PROCESSING && entry.getKey() == OrderRootType.CLASSES) {
LOG.warn(String.format("Can't find %s of the library '%s' at path '%s'", entry.getKey(), libraryName, file.getAbsolutePath()));
}
String url = VfsUtil.getUrlForLibraryRoot(file);
String[] urls = model.getUrls(entry.getKey());
if (!ArrayUtil.contains(url, urls)) {
model.addRoot(url, entry.getKey());
}
continue;
}
if (virtualFile.isDirectory()) {
VirtualFile[] files = model.getFiles(entry.getKey());
if (!ArrayUtil.contains(virtualFile, files)) {
model.addRoot(virtualFile, entry.getKey());
}
} else {
VirtualFile root = virtualFile;
if (virtualFile.getFileType() instanceof ArchiveFileType) {
root = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
if (root == null) {
LOG.warn(String.format("Can't parse contents of the JAR file at path '%s' for the library '%s''", file.getAbsolutePath(), libraryName));
continue;
}
}
VirtualFile[] files = model.getFiles(entry.getKey());
if (!ArrayUtil.contains(root, files)) {
model.addRoot(root, entry.getKey());
}
}
}
}
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class ChangeLibraryLevelActionBase method doCopy.
@Nullable
protected Library doCopy(LibraryEx library) {
final VirtualFile baseDir = getBaseDir();
final String libPath = baseDir != null ? baseDir.getPath() + "/lib" : "";
final VirtualFile[] classesRoots = library.getFiles(OrderRootType.CLASSES);
boolean allowEmptyName = isConvertingToModuleLibrary() && classesRoots.length == 1;
final String libraryName = allowEmptyName ? "" : StringUtil.notNullize(library.getName(), LibraryTypeServiceImpl.suggestLibraryName(classesRoots));
final LibraryTableModifiableModelProvider provider = getModifiableTableModelProvider();
final ChangeLibraryLevelDialog dialog = new ChangeLibraryLevelDialog(getParentComponent(), myProject, myCopy, libraryName, libPath, allowEmptyName, provider);
if (!dialog.showAndGet()) {
return null;
}
final Set<File> fileToCopy = new LinkedHashSet<>();
final Map<String, String> copiedFiles = new HashMap<>();
final String targetDirectoryPath = dialog.getDirectoryForFilesPath();
if (targetDirectoryPath != null) {
for (OrderRootType type : OrderRootType.getAllTypes()) {
for (VirtualFile root : library.getFiles(type)) {
if (root.isInLocalFileSystem() || root.getFileSystem() instanceof ArchiveFileSystem) {
fileToCopy.add(VfsUtil.virtualToIoFile(PathUtil.getLocalFile(root)));
}
}
}
if (!copyOrMoveFiles(fileToCopy, targetDirectoryPath, copiedFiles)) {
return null;
}
}
final Library copied = provider.getModifiableModel().createLibrary(StringUtil.nullize(dialog.getLibraryName()), library.getKind());
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) copied.getModifiableModel();
LibraryEditingUtil.copyLibrary(library, copiedFiles, model);
WriteAction.run(() -> model.commit());
return copied;
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class LibraryRootsComponent method init.
private void init(AbstractTreeStructure treeStructure) {
myTree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode()));
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
new LibraryRootsTreeSpeedSearch(myTree);
myTree.setCellRenderer(new LibraryTreeRenderer());
myTreeBuilder = new LibraryTableTreeBuilder(myTree, (DefaultTreeModel) myTree.getModel(), treeStructure);
myTreePanel.setLayout(new BorderLayout());
ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(myTree).disableUpDownActions().setRemoveActionName(ProjectBundle.message("library.remove.action")).disableRemoveAction();
toolbarDecorator.setPanelBorder(new CustomLineBorder(1, 0, 0, 0));
final List<AttachRootButtonDescriptor> popupItems = new ArrayList<>();
for (AttachRootButtonDescriptor descriptor : myDescriptor.createAttachButtons()) {
Icon icon = descriptor.getToolbarIcon();
if (icon != null) {
AttachItemAction action = new AttachItemAction(descriptor, descriptor.getButtonText(), icon);
toolbarDecorator.addExtraAction(AnActionButton.fromAction(action));
} else {
popupItems.add(descriptor);
}
}
myAddExcludedRootActionButton = new AddExcludedRootActionButton();
toolbarDecorator.addExtraAction(myAddExcludedRootActionButton);
toolbarDecorator.addExtraAction(new AnActionButton("Remove", IconUtil.getRemoveIcon()) {
@Override
public void actionPerformed(AnActionEvent e) {
final Object[] selectedElements = getSelectedElements();
if (selectedElements.length == 0) {
return;
}
ApplicationManager.getApplication().runWriteAction(() -> {
for (Object selectedElement : selectedElements) {
if (selectedElement instanceof ItemElement) {
final ItemElement itemElement = (ItemElement) selectedElement;
getLibraryEditor().removeRoot(itemElement.getUrl(), itemElement.getRootType());
} else if (selectedElement instanceof OrderRootTypeElement) {
final OrderRootType rootType = ((OrderRootTypeElement) selectedElement).getOrderRootType();
final String[] urls = getLibraryEditor().getUrls(rootType);
for (String url : urls) {
getLibraryEditor().removeRoot(url, rootType);
}
} else if (selectedElement instanceof ExcludedRootElement) {
getLibraryEditor().removeExcludedRoot(((ExcludedRootElement) selectedElement).getUrl());
}
}
});
libraryChanged(true);
}
@Override
public void updateButton(AnActionEvent e) {
super.updateButton(e);
Object[] elements = getSelectedElements();
Presentation presentation = e.getPresentation();
if (ContainerUtil.and(elements, new FilteringIterator.InstanceOf<>(ExcludedRootElement.class))) {
presentation.setText("Cancel Exclusion");
} else {
presentation.setText(getTemplatePresentation().getText());
}
}
@Override
public ShortcutSet getShortcut() {
return CommonShortcuts.getDelete();
}
});
toolbarDecorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
if (popupItems.isEmpty()) {
new AttachFilesAction(myDescriptor.getAttachFilesActionName()).actionPerformed(null);
return;
}
List<AnAction> actions = new ArrayList<>();
actions.add(new AttachFilesAction(myDescriptor.getAttachFilesActionName()));
for (AttachRootButtonDescriptor descriptor : popupItems) {
actions.add(new AttachItemAction(descriptor, descriptor.getButtonText(), null));
}
final DefaultActionGroup group = new DefaultActionGroup(actions);
JBPopupFactory.getInstance().createActionGroupPopup(null, group, DataManager.getInstance().getDataContext(button.getContextComponent()), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true).show(button.getPreferredPopupPoint());
}
});
myTreePanel.add(toolbarDecorator.createPanel(), BorderLayout.CENTER);
Disposer.register(this, myTreeBuilder);
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class LibraryDownloadSettings method download.
@Nullable
public NewLibraryEditor download(JComponent parent, @Nullable String rootPath) {
final List<DownloadableFileDescription> toDownload = new ArrayList<>(mySelectedDownloads);
Map<DownloadableFileDescription, OrderRootType> rootTypes = new HashMap<>();
for (DownloadableLibraryFileDescription description : mySelectedDownloads) {
final DownloadableFileDescription sources = description.getSourcesDescription();
if (myDownloadSources && sources != null) {
toDownload.add(sources);
rootTypes.put(sources, OrderRootType.SOURCES);
}
final DownloadableFileDescription docs = description.getDocumentationDescription();
if (myDownloadJavaDocs && docs != null) {
toDownload.add(docs);
rootTypes.put(docs, JavadocOrderRootType.getInstance());
}
}
String path = rootPath != null && !FileUtil.isAbsolute(myLibrariesPath) ? new File(rootPath, myLibrariesPath).getPath() : myLibrariesPath;
List<Pair<VirtualFile, DownloadableFileDescription>> downloaded = DownloadableFileService.getInstance().createDownloader(toDownload, myLibraryName + " Library").downloadWithProgress(path, null, parent);
if (downloaded == null) {
return null;
}
final NewLibraryEditor libraryEditor;
if (myLibraryType != null) {
libraryEditor = new NewLibraryEditor(myLibraryType, new LibraryVersionProperties(myVersion.getVersionString()));
} else {
libraryEditor = new NewLibraryEditor();
}
libraryEditor.setName(myLibraryName);
for (Pair<VirtualFile, DownloadableFileDescription> pair : downloaded) {
final OrderRootType rootType = rootTypes.containsKey(pair.getSecond()) ? rootTypes.get(pair.getSecond()) : OrderRootType.CLASSES;
libraryEditor.addRoot(pair.getFirst(), rootType);
}
return libraryEditor;
}
Aggregations