Java Code Examples for com.intellij.openapi.fileChooser.FileChooserDescriptorFactory#createSingleFolderDescriptor()

The following examples show how to use com.intellij.openapi.fileChooser.FileChooserDescriptorFactory#createSingleFolderDescriptor() . 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: 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 2
Source File: Settings.java    From backgroundImagePlus with MIT License 6 votes vote down vote up
@Nullable
@Override
public JComponent createComponent() {
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    imageFolder.addBrowseFolderListener(new TextBrowseFolderListener(descriptor) {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser();
            String current = imageFolder.getText();
            if (!current.isEmpty()) {
                fc.setCurrentDirectory(new File(current));
            }
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.showOpenDialog(rootPanel);

            File file = fc.getSelectedFile();
            String path = file == null
                    ? ""
                    : file.getAbsolutePath();
            imageFolder.setText(path);
        }
    });
    autoChangeCheckBox.addActionListener(e -> intervalSpinner.setEnabled(autoChangeCheckBox.isSelected()));
    return rootPanel;
}
 
Example 3
Source File: GUI.java    From svgtoandroid with MIT License 6 votes vote down vote up
private void showSVGChooser() {
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    if (!batch.isSelected()) {
        descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor("svg");
    }
    VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null);
    if (virtualFile != null) {
        if (!virtualFile.isDirectory() && virtualFile.getName().toLowerCase().endsWith("svg")) {
            svg = (XmlFile) PsiManager.getInstance(project).findFile(virtualFile);
            //got *.svg file as xml
            svgPath.setText(virtualFile.getPath());
            xmlName.setEditable(true);
            xmlName.setEnabled(true);
            xmlName.setText(CommonUtil.getValidName(svg.getName().split("\\.")[0]) + ".xml");
        } else if (virtualFile.isDirectory()) {
            svgDir = PsiManager.getInstance(project).findDirectory(virtualFile);
            svgPath.setText(virtualFile.getPath());
            xmlName.setEditable(false);
            xmlName.setEnabled(false);
            xmlName.setText("keep origin name");
        }
    }
    frame.setAlwaysOnTop(true);
}
 
Example 4
Source File: BuildElementsEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private CommitableFieldPanel createOutputPathPanel(final String title, final CommitPathRunnable commitPathRunnable) {
  final JTextField textField = new JTextField();
  final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  outputPathsChooserDescriptor.setHideIgnored(false);
  InsertPathAction.addTo(textField, outputPathsChooserDescriptor);
  FileChooserFactory.getInstance().installFileCompletion(textField, outputPathsChooserDescriptor, true, null);

  CommitableFieldPanel commitableFieldPanel =
          new CommitableFieldPanel(textField, null, null, new BrowseFilesListener(textField, title, "", outputPathsChooserDescriptor), null);
  commitableFieldPanel.myCommitRunnable = new Runnable() {
    @Override
    public void run() {
      if (!getModel().isWritable()) {
        return;
      }
      String url = commitableFieldPanel.getUrl();
      commitPathRunnable.saveUrl(url);
    }
  };
  return commitableFieldPanel;
}
 
Example 5
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 6
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 7
Source File: AemdcConfigurationDialog.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public  BaseTextBrowseFolderListener(Project project, VirtualFile projectFolder) {
    super(FileChooserDescriptorFactory.createSingleFolderDescriptor(), project);
    // In order to let the user select folders outside of the project we cannot
    // set any roots
    // That said we use the getInitialFile() to make sure that the File Chooser
    // is set to the current folder if found otherwise the project root folder
    this.projectFolder = projectFolder;
}
 
Example 8
Source File: ConfigANTLRPerGrammar.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void initAntlrFields(Project project, String qualFileName) {
	FileChooserDescriptor dirChooser =
			FileChooserDescriptorFactory.createSingleFolderDescriptor();
	outputDirField.addBrowseFolderListener("Select output dir", null, project, dirChooser);
	outputDirField.setTextFieldPreferredWidth(50);

	dirChooser =
			FileChooserDescriptorFactory.createSingleFolderDescriptor();
	libDirField.addBrowseFolderListener("Select lib dir", null, project, dirChooser);
	libDirField.setTextFieldPreferredWidth(50);

	loadValues(project, qualFileName);
}
 
Example 9
Source File: LocalPathCellEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FileChooserDescriptor getFileChooserDescriptor() {
  if (myFileChooserDescriptor == null) {
    myFileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    if (myTitle != null) {
      myFileChooserDescriptor.setTitle(myTitle);
    }
    myFileChooserDescriptor.setShowFileSystemRoots(true);
  }
  return myFileChooserDescriptor;
}
 
Example 10
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 11
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 12
Source File: AddDirectoryToProjectAction.java    From intellij with Apache License 2.0 4 votes vote down vote up
OpenBlazeWorkspaceFileActionDialog(
    Project project, ProjectViewSet projectView, WorkspacePathResolver workspacePathResolver) {
  super(project, /* canBeParent= */ false, IdeModalityType.PROJECT);
  this.project = project;
  this.projectView = projectView;
  this.workspacePathResolver = workspacePathResolver;

  FileChooserDescriptor descriptor =
      FileChooserDescriptorFactory.createSingleFolderDescriptor();
  fileTextField =
      WorkspaceFileTextField.create(
          workspacePathResolver, descriptor, PATH_FIELD_WIDTH, myDisposable);
  JBLabel directoryLabel = new JBLabel("Directory:", Nodes.Package, SwingConstants.LEFT);
  JPanel directoryPanel =
      SwingHelper.newHorizontalPanel(
          Component.TOP_ALIGNMENT, directoryLabel, fileTextField.getField());

  boolean autoDeriveTargets = autoDeriveTargets();
  addTargetsCheckBox = new JBCheckBox("Add build targets to the project", !autoDeriveTargets);
  JBLabel warning =
      new JBLabel(
          "<html>" + ADD_TARGETS_WARNING_TEXT + "</html>",
          AllIcons.General.BalloonWarning,
          SwingConstants.LEFT);
  warning.setPreferredSize(new Dimension(800, 100));

  addTargetsCheckBox.addChangeListener(
      e -> {
        String warningText;
        if (autoDeriveTargets || addTargetsCheckBox.isSelected()) {
          warningText = ADD_TARGETS_WARNING_TEXT;
        } else {
          warningText = NO_TARGETS_WARNING_TEXT;
        }
        warning.setText("<html>" + warningText + "</html>");
      });

  if (autoDeriveTargets) {
    addTargetsCheckBox.setVisible(false);
  }

  component =
      SwingHelper.newLeftAlignedVerticalPanel(
          directoryPanel, addTargetsCheckBox, warning, Box.createVerticalGlue());

  setTitle("Add Directory to Project");

  init();
}
 
Example 13
Source File: FolderSelectionDialog.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
public BaseTextBrowseFolderListener(Project project, VirtualFile baseDir) {
    super(FileChooserDescriptorFactory.createSingleFolderDescriptor(), project);
    this.baseDir = baseDir;
}
 
Example 14
Source File: ProjectConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void init() {
  myPanel = new JPanel(new VerticalFlowLayout(true, false));

  final JPanel namePanel = new JPanel(new BorderLayout());
  final JLabel label = new JLabel("<html><body><b>Project name:</b></body></html>", SwingConstants.LEFT);
  namePanel.add(label, BorderLayout.NORTH);

  myProjectName = new JTextField();
  myProjectName.setColumns(40);

  final JPanel nameFieldPanel = new JPanel();
  nameFieldPanel.setLayout(new BoxLayout(nameFieldPanel, BoxLayout.X_AXIS));
  nameFieldPanel.add(Box.createHorizontalStrut(4));
  nameFieldPanel.add(myProjectName);

  namePanel.add(nameFieldPanel, BorderLayout.CENTER);
  final JPanel wrapper = new JPanel(new FlowLayout(FlowLayout.LEFT));
  wrapper.add(namePanel);
  wrapper.setAlignmentX(0);
  myPanel.add(wrapper);

  myPanel.add(new JLabel(ProjectBundle.message("project.compiler.output")));

  final JTextField textField = new JTextField();
  final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  InsertPathAction.addTo(textField, outputPathsChooserDescriptor);
  outputPathsChooserDescriptor.setHideIgnored(false);
  BrowseFilesListener listener = new BrowseFilesListener(textField, "", ProjectBundle.message("project.compiler.output"), outputPathsChooserDescriptor);
  myProjectCompilerOutput = new FieldPanel(textField, null, null, listener, EmptyRunnable.getInstance());
  FileChooserFactory.getInstance().installFileCompletion(myProjectCompilerOutput.getTextField(), outputPathsChooserDescriptor, true, null);

  myProjectCompilerOutput.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      if (myFreeze) return;
      myModulesConfigurator.processModuleCompilerOutputChanged(getCompilerOutputUrl());
    }
  });

  myPanel.add(myProjectCompilerOutput);
  myPanel.add(ScrollPaneFactory.createScrollPane(myErrorsComponent, true));
}
 
Example 15
Source File: MoveFilesOrDirectoriesDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected JComponent createNorthPanel() {
  myNameLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);

  myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
  final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
  if (recentEntries != null) {
    myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
  }
  final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                 RefactoringBundle.message("the.file.will.be.moved.to.this.directory"),
                                                 myProject,
                                                 descriptor,
                                                 TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
  final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor();
  FileChooserFactory.getInstance().installFileCompletion(textField, descriptor, true, getDisposable());
  textField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      validateOKButton();
    }
  });
  myTargetDirectoryField.setTextFieldPreferredWidth(CopyFilesOrDirectoriesDialog.MAX_PATH_LENGTH);
  Disposer.register(getDisposable(), myTargetDirectoryField);

  String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));

  myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references"));
  myCbSearchForReferences.setSelected(RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE);

  myOpenInEditorCb = new NonFocusableCheckBox("Open moved files in editor");
  myOpenInEditorCb.setSelected(isOpenInEditor());

  return FormBuilder.createFormBuilder().addComponent(myNameLabel)
          .addLabeledComponent(RefactoringBundle.message("move.files.to.directory.label"), myTargetDirectoryField, UIUtil.LARGE_VGAP)
          .addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText))
          .addComponentToRightColumn(myCbSearchForReferences, UIUtil.LARGE_VGAP)
          .addComponentToRightColumn(myOpenInEditorCb, UIUtil.LARGE_VGAP)
          .getPanel();
}
 
Example 16
Source File: CopyFilesOrDirectoriesDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected JComponent createNorthPanel() {
  myInformationLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);
  final FormBuilder formBuilder = FormBuilder.createFormBuilder().addComponent(myInformationLabel).addVerticalGap(
    UIUtil.LARGE_VGAP - UIUtil.DEFAULT_VGAP);
  DocumentListener documentListener = new DocumentAdapter() {
    @Override
    public void textChanged(DocumentEvent event) {
      validateOKButton();
    }
  };

  if (myShowNewNameField) {
    myNewNameField = new JTextField();
    myNewNameField.getDocument().addDocumentListener(documentListener);
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNewNameField);
  }

  if (myShowDirectoryField) {
    myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
    myTargetDirectoryField.setTextFieldPreferredWidth(MAX_PATH_LENGTH);
    final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
    if (recentEntries != null) {
      myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
    }
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                   RefactoringBundle.message("the.file.will.be.copied.to.this.directory"),
                                                   myProject, descriptor,
                                                   TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
    myTargetDirectoryField.getChildComponent().addDocumentListener(new DocumentAdapter() {
      @Override
      protected void textChanged(DocumentEvent e) {
        validateOKButton();
      }
    });
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.to.directory.label"), myTargetDirectoryField);

    String shortcutText =
      KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));
    formBuilder.addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText));
  }

  final JPanel wrapper = new JPanel(new BorderLayout());
  wrapper.add(myOpenFilesInEditor, BorderLayout.EAST);
  formBuilder.addComponent(wrapper);
  return formBuilder.getPanel();
}