Search in sources :

Example 96 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class VcsProjectSetProcessor method getDirectory.

private static boolean getDirectory(@NotNull Context context) {
    if (context.directory != null)
        return true;
    FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false);
    descriptor.setTitle("Select Destination Folder");
    descriptor.setDescription("");
    VirtualFile[] files = FileChooser.chooseFiles(descriptor, null, null);
    context.directory = files.length == 0 ? null : files[0];
    return context.directory != null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 97 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class SelectLocationStep method init.

protected void init() {
    final DefaultActionGroup fileSystemActionGroup = createFileSystemActionGroup();
    myFileSystemToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, fileSystemActionGroup, true);
    final JTree tree = myFileSystemTree.getTree();
    tree.getSelectionModel().addTreeSelectionListener(myTreeSelectionListener);
    tree.setCellRenderer(new NodeRenderer());
    tree.addMouseListener(new PopupHandler() {

        public void invokePopup(Component comp, int x, int y) {
            final ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UPDATE_POPUP, fileSystemActionGroup);
            popupMenu.getComponent().show(comp, x, y);
        }
    });
    tree.addSelectionPath(tree.getPathForRow(0));
    new FileDrop(tree, new FileDrop.Target() {

        public FileChooserDescriptor getDescriptor() {
            return myChooserDescriptor;
        }

        public boolean isHiddenShown() {
            return myFileSystemTree.areHiddensShown();
        }

        public void dropFiles(final List<VirtualFile> files) {
            if (files.size() > 0) {
                selectInTree(files.toArray(new VirtualFile[files.size()]));
            }
        }
    });
    super.init();
}
Also used : NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) FileDrop(com.intellij.openapi.fileChooser.ex.FileDrop) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PopupHandler(com.intellij.ui.PopupHandler) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 98 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class InjectionsSettingsUI method doImportAction.

private void doImportAction(final DataContext dataContext) {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
        }

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            return file.getFileType() == StdFileTypes.XML;
        }
    };
    descriptor.setDescription("Please select the configuration file (usually named IntelliLang.xml) to import.");
    descriptor.setTitle("Import Configuration");
    descriptor.putUserData(LangDataKeys.MODULE_CONTEXT, LangDataKeys.MODULE.getData(dataContext));
    final SplitterProportionsData splitterData = new SplitterProportionsDataImpl();
    splitterData.externalizeFromDimensionService("IntelliLang.ImportSettingsKey.SplitterProportions");
    final VirtualFile file = FileChooser.chooseFile(descriptor, myProject, null);
    if (file == null)
        return;
    try {
        final Configuration cfg = Configuration.load(file.getInputStream());
        if (cfg == null) {
            Messages.showWarningDialog(myProject, "The selected file does not contain any importable configuration.", "Nothing to Import");
            return;
        }
        final CfgInfo info = getDefaultCfgInfo();
        final Map<String, Set<InjInfo>> currentMap = ContainerUtil.classify(info.injectionInfos.iterator(), new Convertor<InjInfo, String>() {

            public String convert(final InjInfo o) {
                return o.injection.getSupportId();
            }
        });
        final List<BaseInjection> originalInjections = new ArrayList<>();
        final List<BaseInjection> newInjections = new ArrayList<>();
        for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
            ArrayList<InjInfo> list = new ArrayList<>(ObjectUtils.notNull(currentMap.get(supportId), Collections.<InjInfo>emptyList()));
            final List<BaseInjection> currentInjections = getInjectionList(list);
            final List<BaseInjection> importingInjections = cfg.getInjections(supportId);
            if (currentInjections == null) {
                newInjections.addAll(importingInjections);
            } else {
                Configuration.importInjections(currentInjections, importingInjections, originalInjections, newInjections);
            }
        }
        info.replace(originalInjections, newInjections);
        myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
        final int n = newInjections.size();
        if (n > 1) {
            Messages.showInfoMessage(myProject, n + " entries have been successfully imported", "Import Successful");
        } else if (n == 1) {
            Messages.showInfoMessage(myProject, "One entry has been successfully imported", "Import Successful");
        } else {
            Messages.showInfoMessage(myProject, "No new entries have been imported", "Import");
        }
    } catch (Exception ex) {
        Configuration.LOG.error(ex);
        final String msg = ex.getLocalizedMessage();
        Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Import Failed");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) THashSet(gnu.trove.THashSet) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) IOException(java.io.IOException) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 99 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class LibraryRootsComponentDescriptor method createAttachFilesChooserDescriptor.

/**
   * @return descriptor for the file chooser which will be shown when 'Attach Files' button is pressed
   * @param libraryName
   */
@NotNull
public FileChooserDescriptor createAttachFilesChooserDescriptor(@Nullable String libraryName) {
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createMultipleJavaPathDescriptor();
    descriptor.setTitle(StringUtil.isEmpty(libraryName) ? ProjectBundle.message("library.attach.files.action") : ProjectBundle.message("library.attach.files.to.library.action", libraryName));
    descriptor.setDescription(ProjectBundle.message("library.attach.files.description"));
    return descriptor;
}
Also used : FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 100 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.

the class SdkConfigurationUtil method createSdk.

public static void createSdk(@Nullable final Project project, final Sdk[] existingSdks, final NullableConsumer<Sdk> onSdkCreatedCallBack, final boolean createIfExists, final boolean followSymLinks, final SdkType... sdkTypes) {
    if (sdkTypes.length == 0) {
        onSdkCreatedCallBack.consume(null);
        return;
    }
    FileChooserDescriptor descriptor = createCompositeDescriptor(sdkTypes);
    // XXX: Workaround for PY-21787 since the native macOS dialog always follows symlinks
    if (!followSymLinks) {
        descriptor.setForcedToUseIdeaFileChooser(true);
    }
    VirtualFile suggestedDir = getSuggestedSdkRoot(sdkTypes[0]);
    FileChooser.chooseFiles(descriptor, project, suggestedDir, new FileChooser.FileChooserConsumer() {

        @Override
        public void consume(List<VirtualFile> selectedFiles) {
            for (SdkType sdkType : sdkTypes) {
                final String path = selectedFiles.get(0).getPath();
                if (sdkType.isValidSdkHome(path)) {
                    Sdk newSdk = null;
                    if (!createIfExists) {
                        for (Sdk sdk : existingSdks) {
                            if (path.equals(sdk.getHomePath())) {
                                newSdk = sdk;
                                break;
                            }
                        }
                    }
                    if (newSdk == null) {
                        newSdk = setupSdk(existingSdks, selectedFiles.get(0), sdkType, false, null, null);
                    }
                    onSdkCreatedCallBack.consume(newSdk);
                    return;
                }
            }
            onSdkCreatedCallBack.consume(null);
        }

        @Override
        public void cancelled() {
            onSdkCreatedCallBack.consume(null);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SdkType(com.intellij.openapi.projectRoots.SdkType) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileChooser(com.intellij.openapi.fileChooser.FileChooser) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)142 VirtualFile (com.intellij.openapi.vfs.VirtualFile)96 NotNull (org.jetbrains.annotations.NotNull)35 Project (com.intellij.openapi.project.Project)21 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)19 Nullable (org.jetbrains.annotations.Nullable)18 ActionEvent (java.awt.event.ActionEvent)17 File (java.io.File)17 ActionListener (java.awt.event.ActionListener)16 DocumentEvent (javax.swing.event.DocumentEvent)13 DocumentAdapter (com.intellij.ui.DocumentAdapter)10 ArrayList (java.util.ArrayList)10 FileChooser (com.intellij.openapi.fileChooser.FileChooser)9 List (java.util.List)9 IOException (java.io.IOException)8 JBLabel (com.intellij.ui.components.JBLabel)7 javax.swing (javax.swing)7 Module (com.intellij.openapi.module.Module)5 StringUtil (com.intellij.openapi.util.text.StringUtil)5 JBTable (com.intellij.ui.table.JBTable)5