Пример #1
0
  /** Call this to browse for a custom gradle executor. */
  private void browseForCustomGradleExecutor() {
    File startingDirectory = new File(SystemProperties.getInstance().getUserHome());
    File currentFile = gradlePluginLord.getCustomGradleExecutor();
    if (currentFile != null) {
      startingDirectory = currentFile.getAbsoluteFile();
    } else {
      if (gradlePluginLord.getCurrentDirectory() != null) {
        startingDirectory = gradlePluginLord.getCurrentDirectory();
      }
    }

    JFileChooser chooser = new JFileChooser(startingDirectory);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);

    File file = null;
    if (chooser.showOpenDialog(mainPanel) == JFileChooser.APPROVE_OPTION) {
      file = chooser.getSelectedFile();
    }

    if (file != null) {
      setCustomGradleExecutor(file);
    } else { // if they canceled, and they have no custom gradle executor specified, then we must
             // clear things
      // This will reset the UI back to 'not using a custom executor'. We can't have them check the
      // field and not have a value here.
      if (gradlePluginLord.getCustomGradleExecutor() == null) {
        setCustomGradleExecutor(null);
      }
    }
  }
Пример #2
0
  /**
   * Call this to set a custom gradle executor. We'll enable all fields appropriately and setup the
   * foundation settings. We'll also fire off a refresh.
   *
   * @param file the file to use as a custom executor. Null not to use one.
   */
  private void setCustomGradleExecutor(File file) {
    String storagePath;
    boolean isUsingCustom = false;
    if (file == null) {
      isUsingCustom = false;
      storagePath = null;
    } else {
      isUsingCustom = true;
      storagePath = file.getAbsolutePath();
    }

    // set the executor in the foundation
    if (gradlePluginLord.setCustomGradleExecutor(file)) {
      // refresh the tasks only if we actually changed the executor
      gradlePluginLord.addRefreshRequestToQueue();
    }

    // set the UI values
    useCustomGradleExecutorCheckBox.setSelected(isUsingCustom);
    customGradleExecutorField.setText(storagePath);

    // enable the UI appropriately.
    browseForCustomGradleExecutorButton.setEnabled(isUsingCustom);
    customGradleExecutorField.setEnabled(isUsingCustom);

    // store the settings
    settingsNode.setValueOfChild(CUSTOM_GRADLE_EXECUTOR, storagePath);
  }
Пример #3
0
  private Component createCurrentDirectoryPanel() {
    currentDirectoryTextField = new JTextField();
    currentDirectoryTextField.setEditable(false);

    String currentDirectory = settingsNode.getValueOfChild(CURRENT_DIRECTORY, null);
    if (currentDirectory == null || "".equals(currentDirectory.trim())) {
      currentDirectory = gradlePluginLord.getCurrentDirectory().getAbsolutePath();
    }

    currentDirectoryTextField.setText(currentDirectory);
    gradlePluginLord.setCurrentDirectory(new File(currentDirectory));

    JButton browseButton =
        new JButton(
            new AbstractAction("Browse...") {
              public void actionPerformed(ActionEvent e) {
                File file = browseForDirectory(gradlePluginLord.getCurrentDirectory());
                if (file != null) {
                  setCurrentDirectory(file);
                }
              }
            });

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    panel.add(Utility.addLeftJustifiedComponent(new JLabel("Current Directory")));
    panel.add(createSideBySideComponent(currentDirectoryTextField, browseButton));

    return panel;
  }
Пример #4
0
  /**
   * Called upon start up and whenever GradlePluginLord settings are changed. We'll update our
   * values. Note: this actually gets called several times in a row for each settings during
   * initialization. Its not optimal, but functional and I didn't want to deal with numerous,
   * specific-field notifications.
   */
  private void updatePluginLordSettings() {
    setCustomGradleExecutor(gradlePluginLord.getCustomGradleExecutor());

    setCurrentDirectory(gradlePluginLord.getCurrentDirectory());

    setSelectedStackTraceLevel(gradlePluginLord.getStackTraceLevel());

    setLogLevelComboBoxSetting(gradlePluginLord.getLogLevel());
  }
Пример #5
0
  private void setCurrentDirectory(File file) {

    if (file == null) {
      currentDirectoryTextField.setText("");
      settingsNode.setValueOfChild(CURRENT_DIRECTORY, "");
    } else {
      currentDirectoryTextField.setText(file.getAbsolutePath());
      settingsNode.setValueOfChild(CURRENT_DIRECTORY, file.getAbsolutePath());
    }

    if (gradlePluginLord.setCurrentDirectory(file)) {
      // refresh the tasks only if we actually changed the current directory
      gradlePluginLord.addRefreshRequestToQueue();
    }
  }
Пример #6
0
  /** This stores the current stack trace setting (based on the UI controls) in the plugin. */
  private void updateStackTraceSetting(boolean saveSetting) {
    ShowStacktrace stackTraceLevel = getSelectedStackTraceLevel();
    gradlePluginLord.setStackTraceLevel(stackTraceLevel);

    if (saveSetting) {
      settingsNode.setValueOfChild(STACK_TRACE_LEVEL, stackTraceLevel.name());
    }
  }
Пример #7
0
  /** Creates a panel that has a combo box to select a log level */
  private Component createLogLevelPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    logLevelComboBox = new JComboBox(getLogLevelWrappers());

    panel.add(Utility.addLeftJustifiedComponent(new JLabel("Log Level")));
    panel.add(Utility.addLeftJustifiedComponent(logLevelComboBox));

    // initialize our value
    String logLevelName = settingsNode.getValueOfChild(LOG_LEVEL, null);
    LogLevel logLevel = gradlePluginLord.getLogLevel();
    if (logLevelName != null) {
      try {
        logLevel = LogLevel.valueOf(logLevelName);
      } catch (
          IllegalArgumentException
              e) // this may happen if the enum changes. We don't want this to stop the whole UI
      {
        logger.error("Converting log level text to log level enum '" + logLevelName + "'", e);
      }
    }

    gradlePluginLord.setLogLevel(logLevel);
    setLogLevelComboBoxSetting(logLevel);

    logLevelComboBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            LogLevelWrapper wrapper = (LogLevelWrapper) logLevelComboBox.getSelectedItem();
            if (wrapper != null) {
              gradlePluginLord.setLogLevel(wrapper.logLevel);
              settingsNode.setValueOfChild(LOG_LEVEL, wrapper.logLevel.name());
            }
          }
        });

    return panel;
  }
Пример #8
0
 /**
  * Notification that this component is about to be shown. Do whatever initialization you choose.
  */
 public void aboutToShow() {
   updatePluginLordSettings();
   gradlePluginLord.addSettingsObserver(this, true);
 }
 public void executeAgain(GradlePluginLord gradlePluginLord) {
   gradlePluginLord.addRefreshRequestToQueue();
 }