コード例 #1
0
  @Nullable
  @Override
  protected JComponent createCenterPanel() {
    final JPanel content = new JPanel(new BorderLayout());

    final JPanel topLine = new JPanel(new BorderLayout());
    content.setBorder(
        IdeBorderFactory.createTitledBorder(
            "Thrift compiler " + myGenerator.getType().name(), false));
    myOutputFolderChooser.addBrowseFolderListener(
        new TextBrowseFolderListener(
            FileChooserDescriptorFactory.createSingleFolderDescriptor(), myProject) {
          @Nullable
          @Override
          protected VirtualFile getInitialFile() {
            if (myGenerator.getOutputDir() != null) {
              return LocalFileFinder.findFile(myGenerator.getOutputDir());
            } else {
              return null;
            }
          }

          @Override
          protected void onFileChosen(@NotNull VirtualFile chosenFile) {
            final String absolutePath = VfsUtil.virtualToIoFile(chosenFile).getAbsolutePath();
            myOutputFolderChooser.setText(absolutePath);
          }
        });

    topLine.add(new JBLabel("Output folder:"), BorderLayout.WEST);
    topLine.add(myOutputFolderChooser, BorderLayout.CENTER);

    content.add(topLine, BorderLayout.NORTH);

    final JPanel options = new JPanel(new BorderLayout());
    content.add(options, BorderLayout.CENTER);

    myPane = AOptionPane.get(myGenerator.getType());
    if (myPane != null) {
      options.setBorder(IdeBorderFactory.createTitledBorder("Additional options"));
      options.add(myPane.getPanel());
      myPane.setValues(myGenerator);
    } else {
      options.setBorder(null);
    }

    final String url = myGenerator.getOutputDir();
    final VirtualFile file =
        url == null ? null : VirtualFileManager.getInstance().findFileByUrl(url);
    myOutputFolderChooser.setText(file == null ? VfsUtil.urlToPath(url) : file.getPath());

    return content;
  }
コード例 #2
0
  public Generator getModifiedObject() {
    if (isOK()) {
      if (myPane != null) {
        myPane.readValuesTo(myGenerator);
      }
      final String dir = StringUtils.trimToNull(myOutputFolderChooser.getText());
      assert dir != null;

      final String url = VfsUtil.pathToUrl(dir);
      final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);

      myGenerator.setOutputDir(file == null ? url : file.getUrl());
      return myGenerator;
    } else {
      return null;
    }
  }