Java Code Examples for com.intellij.openapi.fileChooser.FileChooserDescriptor#setTitle()

The following examples show how to use com.intellij.openapi.fileChooser.FileChooserDescriptor#setTitle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonProgramParametersPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void initComponents() {
  myProgramParametersComponent = LabeledComponent.create(new RawCommandLineEditor(), ExecutionBundle.message("run.configuration.program.parameters"));

  FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  //noinspection DialogTitleCapitalization
  fileChooserDescriptor.setTitle(ExecutionBundle.message("select.working.directory.message"));
  myWorkingDirectoryComboBox = new MacroComboBoxWithBrowseButton(fileChooserDescriptor, getProject());

  myWorkingDirectoryComponent = LabeledComponent.create(myWorkingDirectoryComboBox, ExecutionBundle.message("run.configuration.working.directory.label"));
  myEnvVariablesComponent = new EnvironmentVariablesComponent();

  myEnvVariablesComponent.setLabelLocation(BorderLayout.WEST);
  myProgramParametersComponent.setLabelLocation(BorderLayout.WEST);
  myWorkingDirectoryComponent.setLabelLocation(BorderLayout.WEST);

  addComponents();

  setPreferredSize(new Dimension(10, 10));

  copyDialogCaption(myProgramParametersComponent);
}
 
Example 2
Source File: MuleUIUtils.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Nullable public static MuleSdk selectSdk(@NotNull JComponent parentComponent)
{
    final VirtualFile initial = findFile(System.getenv("MULE_HOME"));

    final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false)
    {
        @Override
        public boolean isFileSelectable(VirtualFile file)
        {
            return super.isFileSelectable(file) && MuleSdk.isValidMuleHome(file.getCanonicalPath());
        }
    };
    descriptor.setTitle("Mule SDK");
    descriptor.setDescription("Choose a directory containing Mule distribution");
    final VirtualFile dir = FileChooser.chooseFile(descriptor, parentComponent, null, initial);
    if (dir == null || !MuleSdk.isValidMuleHome(dir.getCanonicalPath()))
    {
        return null;
    }
    return new MuleSdk(dir.getCanonicalPath());
}
 
Example 3
Source File: SdkConfigurationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static FileChooserDescriptor createCompositeDescriptor(final SdkType... sdkTypes) {
  FileChooserDescriptor descriptor0 = sdkTypes[0].getHomeChooserDescriptor();
  FileChooserDescriptor descriptor =
    new FileChooserDescriptor(descriptor0.isChooseFiles(), descriptor0.isChooseFolders(), descriptor0.isChooseJars(),
                              descriptor0.isChooseJarsAsFiles(), descriptor0.isChooseJarContents(), descriptor0.isChooseMultiple()) {

      @Override
      public void validateSelectedFiles(final VirtualFile[] files) throws Exception {
        if (files.length > 0) {
          for (SdkType type : sdkTypes) {
            if (type.isValidSdkHome(files[0].getPath())) {
              return;
            }
          }
        }
        String message = files.length > 0 && files[0].isDirectory()
                         ? ProjectBundle.message("sdk.configure.home.invalid.error", sdkTypes[0].getPresentableName())
                         : ProjectBundle.message("sdk.configure.home.file.invalid.error", sdkTypes[0].getPresentableName());
        throw new Exception(message);
      }
    };
  descriptor.setTitle(descriptor0.getTitle());
  return descriptor;
}
 
Example 4
Source File: ModuleImportProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static FileChooserDescriptor createAllImportDescriptor(boolean isModuleImport) {
  FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, true, false, false) {
    @Override
    public Image getIcon(VirtualFile file) {
      for (ModuleImportProvider importProvider : ModuleImportProviders.getExtensions(isModuleImport)) {
        if (importProvider.canImport(VfsUtilCore.virtualToIoFile(file))) {
          return importProvider.getIcon();
        }
      }
      return super.getIcon(file);
    }
  };
  descriptor.setHideIgnored(false);
  descriptor.setTitle("Select File or Directory to Import");
  String description = getFileChooserDescription(isModuleImport);
  descriptor.setDescription(description);
  return descriptor;
}
 
Example 5
Source File: LibraryTypeServiceImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public NewLibraryConfiguration createLibraryFromFiles(@Nonnull LibraryRootsComponentDescriptor descriptor,
                                                      @Nonnull JComponent parentComponent,
                                                      @Nullable VirtualFile contextDirectory,
                                                      LibraryType<?> type,
                                                      final Project project) {
  final FileChooserDescriptor chooserDescriptor = descriptor.createAttachFilesChooserDescriptor(null);
  chooserDescriptor.setTitle("Select Library Files");
  final VirtualFile[] rootCandidates = FileChooser.chooseFiles(chooserDescriptor, parentComponent, project, contextDirectory);
  if (rootCandidates.length == 0) {
    return null;
  }

  final List<OrderRoot> roots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, project, descriptor);
  if (roots.isEmpty()) return null;
  String name = suggestLibraryName(roots);
  return doCreate(type, name, roots);
}
 
Example 6
Source File: PsiUtil.java    From CodeGen with MIT License 6 votes vote down vote up
public static PsiDirectory createDirectory(Project project, String title, String description) {
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    descriptor.setTitle(title);
    descriptor.setShowFileSystemRoots(false);
    descriptor.setDescription(description);
    descriptor.setHideIgnored(true);
    descriptor.setRoots(project.getBaseDir());
    descriptor.setForcedToUseIdeaFileChooser(true);
    VirtualFile file = FileChooser.chooseFile(descriptor, project, project.getBaseDir());
    if(Objects.isNull(file)){
        Messages.showInfoMessage("Cancel " + title, "Error");
        return null;
    }

    PsiDirectory psiDirectory = PsiDirectoryFactory.getInstance(project).createDirectory(file);
    if(PsiDirectoryFactory.getInstance(project).isPackage(psiDirectory)){
        return psiDirectory;
    }else {
        Messages.showInfoMessage("请选择正确的 package 路径。", "Error");
        return createDirectory(project, title, description);
    }
}
 
Example 7
Source File: SdkType.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public FileChooserDescriptor getHomeChooserDescriptor() {
  final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
    @Override
    public void validateSelectedFiles(VirtualFile[] files) throws Exception {
      if (files.length != 0) {
        final String selectedPath = files[0].getPath();
        boolean valid = isValidSdkHome(selectedPath);
        if (!valid) {
          valid = isValidSdkHome(adjustSelectedSdkHome(selectedPath));
          if (!valid) {
            String message = files[0].isDirectory()
                             ? ProjectBundle.message("sdk.configure.home.invalid.error", getPresentableName())
                             : ProjectBundle.message("sdk.configure.home.file.invalid.error", getPresentableName());
            throw new Exception(message);
          }
        }
      }
    }
  };
  descriptor.setTitle(ProjectBundle.message("sdk.configure.home.title", getPresentableName()));
  return descriptor;
}
 
Example 8
Source File: ChooseComponentsToExportDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredUIAccess
public static AsyncResult<String> chooseSettingsFile(String oldPath, Component parent, final String title, final String description) {
  FileChooserDescriptor chooserDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
  chooserDescriptor.setDescription(description);
  chooserDescriptor.setHideIgnored(false);
  chooserDescriptor.setTitle(title);

  VirtualFile initialDir;
  if (oldPath != null) {
    final File oldFile = new File(oldPath);
    initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile);
    if (initialDir == null && oldFile.getParentFile() != null) {
      initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile.getParentFile());
    }
  }
  else {
    initialDir = null;
  }
  final AsyncResult<String> result = AsyncResult.undefined();
  AsyncResult<VirtualFile[]> fileAsyncResult = FileChooser.chooseFiles(chooserDescriptor, null, parent, initialDir);
  fileAsyncResult.doWhenDone(files -> {
    VirtualFile file = files[0];
    if (file.isDirectory()) {
      result.setDone(file.getPath() + '/' + new File(DEFAULT_PATH).getName());
    }
    else {
      result.setDone(file.getPath());
    }
  });
  fileAsyncResult.doWhenRejected((Runnable)result::setRejected);
  return result;
}
 
Example 9
Source File: DependencyViewer.java    From gradle-view with Apache License 2.0 5 votes vote down vote up
private void promptForGradleBaseDir() {
    FileChooserDescriptor fcd = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    fcd.setShowFileSystemRoots(true);
    fcd.setTitle("Choose a Project Folder");
    fcd.setDescription("Pick the top level directory to use when viewing dependencies (in case you have a multi-module project).");
    fcd.setHideIgnored(false);

    FileChooser.chooseFiles(fcd, project, project.getBaseDir(), new Consumer<List<VirtualFile>>() {
        @Override
        public void consume(List<VirtualFile> files) {
            gradleBaseDir = files.get(0).getPath();
        }
    });
}
 
Example 10
Source File: ChooserBasedAttachRootButtonDescriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public VirtualFile[] selectFiles(final @Nonnull JComponent parent, @Nullable VirtualFile initialSelection,
                                 final @Nullable Module contextModule, @Nonnull LibraryEditor libraryEditor) {
  final FileChooserDescriptor chooserDescriptor = createChooserDescriptor();
  chooserDescriptor.setTitle(getChooserTitle(libraryEditor.getName()));
  chooserDescriptor.setDescription(getChooserDescription());
  if (contextModule != null) {
    chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, contextModule);
  }
  return FileChooser.chooseFiles(chooserDescriptor, parent, contextModule != null ? contextModule.getProject() : null, initialSelection);
}
 
Example 11
Source File: LibraryRootsComponentDescriptor.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return descriptor for the file chooser which will be shown when 'Attach Files' button is pressed
 * @param libraryName
 */
@Nonnull
public FileChooserDescriptor createAttachFilesChooserDescriptor(@Nullable String libraryName) {
  final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, false, true, true);
  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;
}
 
Example 12
Source File: ApplyPatchDifferentiatedDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void run() {
  final FileChooserDescriptor descriptor = myDirectorySelector
                                           ? FileChooserDescriptorFactory.createSingleFolderDescriptor()
                                           : FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor();
  descriptor.setTitle(String.format("Select %s Base", myDirectorySelector ? "Directory" : "File"));
  VirtualFile selectedFile = FileChooser.chooseFile(descriptor, myProject, null);
  if (selectedFile == null) {
    return;
  }

  final List<AbstractFilePatchInProgress.PatchChange> selectedChanges = myChangesTreeList.getSelectedChanges();
  if (selectedChanges.size() >= 1) {
    for (AbstractFilePatchInProgress.PatchChange patchChange : selectedChanges) {
      final AbstractFilePatchInProgress patch = patchChange.getPatchInProgress();
      if (myDirectorySelector) {
        patch.setNewBase(selectedFile);
      }
      else {
        final FilePatch filePatch = patch.getPatch();
        //if file was renamed in the patch but applied on another or already renamed local one then we shouldn't apply this rename/move
        filePatch.setAfterName(selectedFile.getName());
        filePatch.setBeforeName(selectedFile.getName());
        patch.setNewBase(selectedFile.getParent());
      }
    }
    updateTree(false);
  }
}
 
Example 13
Source File: ImportTestsFromFileAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public VirtualFile getFile(@Nonnull Project project) {
  final FileChooserDescriptor xmlDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withFileFilter(virtualFile -> "xml".equals(virtualFile.getExtension()));
  xmlDescriptor.setTitle("Choose a File with Tests Result");
  return FileChooser.chooseFile(xmlDescriptor, project, null);
}
 
Example 14
Source File: ProjectSettingsForm.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
private boolean browseForFile(@NotNull final JTextField target, FileChooserDescriptor descriptor, String title) {
	descriptor.setHideIgnored(false);

	descriptor.setTitle(title);
	String text = target.getText();
	final VirtualFile toSelect = text == null || text.isEmpty() ? getProject().getBaseDir() : LocalFileSystem.getInstance().findFileByPath(text);

	// 10.5 does not have #chooseFile
	VirtualFile[] virtualFile = FileChooser.chooseFiles(descriptor, getProject(), toSelect);
	if (virtualFile != null && virtualFile.length > 0) {
		target.setText(virtualFile[0].getPath());
		return true;
	}
	return false;
}
 
Example 15
Source File: BashConfigForm.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
protected void initOwnComponents() {
    Project project = getProject();

    FileChooserDescriptor chooseInterpreterDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
    chooseInterpreterDescriptor.setTitle("Choose Interpreter...");

    interpreterPathField = new TextFieldWithBrowseButton();
    interpreterPathField.addBrowseFolderListener(new MacroAwareTextBrowseFolderListener(chooseInterpreterDescriptor, project));

    interpreterPathComponent = LabeledComponent.create(createComponentWithMacroBrowse(interpreterPathField), "Interpreter path:");
    interpreterPathComponent.setLabelLocation(BorderLayout.WEST);

    projectInterpreterCheckbox = new JBCheckBox();
    projectInterpreterCheckbox.setToolTipText("If enabled then the interpreter path configured in the project settings will be used instead of a custom location.");
    projectInterpreterCheckbox.addChangeListener(e -> {
        boolean selected = projectInterpreterCheckbox.isSelected();
        UIUtil.setEnabled(interpreterPathComponent, !selected, true);
    });
    projectInterpreterLabeled = LabeledComponent.create(projectInterpreterCheckbox, "Use project interpreter");
    projectInterpreterLabeled.setLabelLocation(BorderLayout.WEST);

    interpreterParametersComponent = LabeledComponent.create(new RawCommandLineEditor(), "Interpreter options");
    interpreterParametersComponent.setLabelLocation(BorderLayout.WEST);

    scriptNameField = new TextFieldWithBrowseButton();
    scriptNameField.addBrowseFolderListener(new MacroAwareTextBrowseFolderListener(FileChooserDescriptorFactory.createSingleLocalFileDescriptor(), project));

    scriptNameComponent = LabeledComponent.create(createComponentWithMacroBrowse(scriptNameField), "Script:");
    scriptNameComponent.setLabelLocation(BorderLayout.WEST);
}
 
Example 16
Source File: BashProjectSettingsPane.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
    descriptor.setTitle("Chooser Bash Interpreter...");

    this.interpreterPath = new TextFieldWithBrowseButton(null, this);
    this.interpreterPath.addBrowseFolderListener("Choose Bash Interpreter...", null, project, descriptor);
}
 
Example 17
Source File: PsiUtil.java    From CodeGen with MIT License 5 votes vote down vote up
public static VirtualFile chooseFile(@Nullable Project project, String title, String description, boolean showFileSystemRoots, boolean hideIgnored, @Nullable VirtualFile toSelect){
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor();
    descriptor.setTitle(title);
    descriptor.setDescription(description);
    descriptor.setShowFileSystemRoots(showFileSystemRoots);
    descriptor.setHideIgnored(hideIgnored);
    return FileChooser.chooseFile(descriptor, project, toSelect);
}
 
Example 18
Source File: PsiUtil.java    From CodeGen with MIT License 5 votes vote down vote up
public static VirtualFile chooseFolder(@Nullable Project project, String title, String description, boolean showFileSystemRoots, boolean hideIgnored, @Nullable VirtualFile toSelect){
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    descriptor.setTitle(title);
    descriptor.setDescription(description);
    descriptor.setShowFileSystemRoots(showFileSystemRoots);
    descriptor.setHideIgnored(hideIgnored);
    return FileChooser.chooseFile(descriptor, project, toSelect);
}
 
Example 19
Source File: SelectFolder.java    From floobits-intellij with Apache License 2.0 4 votes vote down vote up
public static void build(String owner, String workspace, final RunLater<String> runLater) {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false);
    descriptor.setTitle("Select Folder For Workspace");
    descriptor.setDescription("NOTE: Floobits will NOT make a new, root directory inside the folder you choose. If you have cloned the project already, select that folder.");
    FloorcJson floorcJson;
    try {
        floorcJson =  Settings.get();
    } catch (Exception e) {
        Flog.errorMessage("Your floorc.json has invalid json.", null);
        return;
    }
    File file = null;
    String shareDir = floorcJson.share_dir;
    if (shareDir != null) {
        if (shareDir.substring(0, 2).equals("~/")) {
            shareDir = shareDir.replaceFirst("~/", System.getProperty("user.home") + "/");
        }
        file = createDir(shareDir, owner, workspace);
        if (file == null) {
            Flog.errorMessage(String.format("Your floorc.json share_dir setting %s did not work, using default ~/floobits",
                    floorcJson.share_dir), null);
        }
    }
    if (file == null) {
        file = createDir(Constants.shareDir, owner, workspace);
    }
    if (file == null) {
        Flog.errorMessage(String.format("Could not create a directory for this workspace, tried %s", Constants.shareDir), null);
        return;
    }
    VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
    VirtualFile[] vFiles = FileChooser.chooseFiles(descriptor, null, virtualFile);
    if (vFiles.length == 0) {
        return;
    }
    if (vFiles.length > 1) {
        Flog.errorMessage("You can only select one directory!", null);
        return;
    }
    final String selectedPath = vFiles[0].getPath();
    runLater.run(selectedPath);
}
 
Example 20
Source File: ViewOfflineResultsAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent event) {
  final Project project = event.getData(CommonDataKeys.PROJECT);

  LOG.assertTrue(project != null);

  final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false){
    @Override
    public Image getIcon(VirtualFile file) {
      if (file.isDirectory()) {
        if (file.findChild(InspectionApplication.DESCRIPTIONS + ".xml") != null) {
          return AllIcons.Nodes.InspectionResults;
        }
      }
      return super.getIcon(file);
    }
  };
  descriptor.setTitle("Select Path");
  descriptor.setDescription("Select directory which contains exported inspections results");
  final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null);
  if (virtualFile == null || !virtualFile.isDirectory()) return;

  final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap =
          new HashMap<String, Map<String, Set<OfflineProblemDescriptor>>>();
  final String [] profileName = new String[1];
  final Runnable process = new Runnable() {
    @Override
    public void run() {
      final VirtualFile[] files = virtualFile.getChildren();
      try {
        for (final VirtualFile inspectionFile : files) {
          if (inspectionFile.isDirectory()) continue;
          final String shortName = inspectionFile.getNameWithoutExtension();
          final String extension = inspectionFile.getExtension();
          if (shortName.equals(InspectionApplication.DESCRIPTIONS)) {
            profileName[0] = ApplicationManager.getApplication().runReadAction(
                    new Computable<String>() {
                      @Override
                      @Nullable
                      public String compute() {
                        return OfflineViewParseUtil.parseProfileName(inspectionFile);
                      }
                    }
            );
          }
          else if (XML_EXTENSION.equals(extension)) {
            resMap.put(shortName, ApplicationManager.getApplication().runReadAction(
                    new Computable<Map<String, Set<OfflineProblemDescriptor>>>() {
                      @Override
                      public Map<String, Set<OfflineProblemDescriptor>> compute() {
                        return OfflineViewParseUtil.parse(inspectionFile);
                      }
                    }
            ));
          }
        }
      }
      catch (final Exception e) {  //all parse exceptions
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            Messages.showInfoMessage(e.getMessage(), InspectionsBundle.message("offline.view.parse.exception.title"));
          }
        });
        throw new ProcessCanceledException(); //cancel process
      }
    }
  };
  ProgressManager.getInstance().runProcessWithProgressAsynchronously(project, InspectionsBundle.message("parsing.inspections.dump.progress.title"), process, new Runnable() {
    @Override
    public void run() {
      SwingUtilities.invokeLater(new Runnable(){
        @Override
        public void run() {
          final String name = profileName[0];
          showOfflineView(project, name, resMap,
                          InspectionsBundle.message("offline.view.title") +
                          " (" + (name != null ? name : InspectionsBundle.message("offline.view.editor.settings.title")) +")");
        }
      });
    }
  }, null, new PerformAnalysisInBackgroundOption(project));
}