mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
04.02.2015 f8b11288a317201ce86b9ebd8f79cb5e371b206f
OPENDJ-1991 Code cleanup

* org.opends.guitools.controlpanel.ui.AbstractBrowseEntriesPanel.java
** Autorefactor'ed file
** Reformat
** Inline some local variables
*** Refactor method getFieldStringValue(FieldName) (Thanks JNR!)
1 files modified
356 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/QuickSetup.java 356 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/QuickSetup.java
@@ -54,24 +54,16 @@
import java.util.Map;
/**
 * This class is responsible for doing the following:
 *
 * Check whether we are installing or uninstalling and which type of
 * installation we are running.
 *
 * This class is responsible for doing the following: Check whether we are
 * installing or uninstalling and which type of installation we are running.
 * Performs all the checks and validation of the data provided by the user
 * during the setup.
 *
 * It will launch also the installation once the user clicks on 'Finish' if we
 * are installing the product.
 *
 * If we are running a web start installation it will start the background
 * downloading of the jar files that are required to perform the installation
 * (OpenDS.jar, je.jar, etc.).  The global idea is to force the user to
 * download just one jar file (quicksetup.jar) to launch the Web Start
 * installer.  Until this class is not finished the WebStart Installer will be
 * on the ProgressStep.DOWNLOADING step.
 *
 * during the setup. It will launch also the installation once the user clicks
 * on 'Finish' if we are installing the product. If we are running a web start
 * installation it will start the background downloading of the jar files that
 * are required to perform the installation (OpenDS.jar, je.jar, etc.). The
 * global idea is to force the user to download just one jar file
 * (quicksetup.jar) to launch the Web Start installer. Until this class is not
 * finished the WebStart Installer will be on the ProgressStep.DOWNLOADING step.
 */
public class QuickSetup implements ButtonActionListener, ProgressUpdateListener
{
@@ -106,8 +98,9 @@
   * it can perform long operations which can make the user think that the UI is
   * blocked.
   *
   * @param args for the moment this parameter is not used but we keep it in
   * order to (in case of need) pass parameters through the command line.
   * @param args
   *          for the moment this parameter is not used but we keep it in order
   *          to (in case of need) pass parameters through the command line.
   */
  public void initialize(String[] args)
  {
@@ -124,7 +117,7 @@
    }
    else
    {
      application.setUserArguments(new String[]{});
      application.setUserArguments(new String[] {});
    }
    try
    {
@@ -137,12 +130,12 @@
    }
    /* In the calls to setCurrentStep the dialog will be created */
      setCurrentStep(application.getFirstWizardStep());
    setCurrentStep(application.getFirstWizardStep());
  }
  /**
   * This method displays the setup dialog. This method must be called from the
   * event thread.
   * This method displays the setup dialog.
   * This method must be called from the event thread.
   */
  public void display()
  {
@@ -153,7 +146,8 @@
   * ButtonActionListener implementation. It assumes that we are called in the
   * event thread.
   *
   * @param ev the ButtonEvent we receive.
   * @param ev
   *          the ButtonEvent we receive.
   */
  public void buttonActionPerformed(ButtonEvent ev)
  {
@@ -162,48 +156,39 @@
    case NEXT:
      nextClicked();
      break;
    case CLOSE:
      closeClicked();
      break;
    case FINISH:
      finishClicked();
      break;
    case QUIT:
      quitClicked();
      break;
    case CONTINUE_INSTALL:
      continueInstallClicked();
      break;
    case PREVIOUS:
      previousClicked();
      break;
    case LAUNCH_STATUS_PANEL:
      launchStatusPanelClicked();
      break;
    case INPUT_PANEL_BUTTON:
      inputPanelButtonClicked();
      break;
    default:
      throw new IllegalArgumentException("Unknown button name: "
          + ev.getButtonName());
      throw new IllegalArgumentException("Unknown button name: " + ev.getButtonName());
    }
  }
  /**
   * ProgressUpdateListener implementation. Here we take the
   * ProgressUpdateEvent and create a ProgressDescriptor that
   * will be used to update the progress dialog.
   * ProgressUpdateListener implementation. Here we take the ProgressUpdateEvent
   * and create a ProgressDescriptor that will be used to update the progress
   * dialog.
   *
   * @param ev the ProgressUpdateEvent we receive.
   *
   * @param ev
   *          the ProgressUpdateEvent we receive.
   * @see #runDisplayUpdater()
   */
  public void progressUpdate(ProgressUpdateEvent ev)
@@ -222,13 +207,12 @@
  }
  /**
   * This method is used to update the progress dialog.
   *
   * We are receiving notifications from the installer and uninstaller (this
   * class is a ProgressListener). However if we lots of notifications updating
   * the progress panel every time we get a progress update can result of a lot
   * of flickering. So the idea here is to have a minimal time between 2 updates
   * of the progress dialog (specified by UPDATE_PERIOD).
   * This method is used to update the progress dialog. We are receiving
   * notifications from the installer and uninstaller (this class is a
   * ProgressListener). However if we lots of notifications updating the
   * progress panel every time we get a progress update can result of a lot of
   * flickering. So the idea here is to have a minimal time between 2 updates of
   * the progress dialog (specified by UPDATE_PERIOD).
   *
   * @see #progressUpdate(org.opends.quicksetup.event.ProgressUpdateEvent)
   */
@@ -240,19 +224,23 @@
      try
      {
        Thread.sleep(UPDATE_PERIOD);
      } catch (Exception ex)
      {
      }
      synchronized (this) {
      catch (Exception ex) {}
      synchronized (this)
      {
        final ProgressDescriptor desc = descriptorToDisplay;
        if (desc != null) {
          if (desc != lastDisplayedDescriptor) {
        if (desc != null)
        {
          if (desc != lastDisplayedDescriptor)
          {
            lastDisplayedDescriptor = desc;
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                if (application.isFinished() &&
                    !getCurrentStep().isFinishedStep())
            SwingUtilities.invokeLater(new Runnable()
            {
              public void run()
              {
                if (application.isFinished() && !getCurrentStep().isFinishedStep())
                {
                  setCurrentStep(application.getFinishedStep());
                }
@@ -266,10 +254,7 @@
    }
  }
  /**
   * Method called when user clicks 'Next' button of the wizard.
   *
   */
  /** Method called when user clicks 'Next' button of the wizard. */
  private void nextClicked()
  {
    final WizardStep cStep = getCurrentStep();
@@ -279,36 +264,41 @@
    worker.startBackgroundTask();
  }
  private void updateUserData(final WizardStep cStep) {
    BackgroundTask<?> worker = new BackgroundTask<Object>() {
      public Object processBackgroundTask() throws UserDataException {
        try {
  private void updateUserData(final WizardStep cStep)
  {
    BackgroundTask<?> worker = new BackgroundTask<Object>()
    {
      public Object processBackgroundTask() throws UserDataException
      {
        try
        {
          application.updateUserData(cStep, QuickSetup.this);
        }
        catch (UserDataException uide) {
        catch (UserDataException uide)
        {
          throw uide;
        }
        catch (Throwable t) {
          throw new UserDataException(cStep,
                  getThrowableMsg(INFO_BUG_MSG.get(), t));
        catch (Throwable t)
        {
          throw new UserDataException(cStep, getThrowableMsg(INFO_BUG_MSG.get(), t));
        }
        return null;
      }
      public void backgroundTaskCompleted(Object returnValue,
                                          Throwable throwable) {
      public void backgroundTaskCompleted(Object returnValue, Throwable throwable)
      {
        getDialog().workerFinished();
        if (throwable != null) {
        if (throwable != null)
        {
          UserDataException ude = (UserDataException) throwable;
          if (ude instanceof UserDataConfirmationException)
          {
            if (displayConfirmation(ude.getMessageObject(),
                INFO_CONFIRMATION_TITLE.get()))
            if (displayConfirmation(ude.getMessageObject(), INFO_CONFIRMATION_TITLE.get()))
            {
              try
              {
              setCurrentStep(application.getNextWizardStep(cStep));
                setCurrentStep(application.getNextWizardStep(cStep));
              }
              catch (Throwable t)
              {
@@ -320,10 +310,13 @@
          {
            displayError(ude.getMessageObject(), INFO_ERROR_TITLE.get());
          }
        } else {
        }
        else
        {
          setCurrentStep(application.getNextWizardStep(cStep));
        }
        if (currentStep.isProgressStep()) {
        if (currentStep.isProgressStep())
        {
          launch();
        }
      }
@@ -332,22 +325,17 @@
    worker.startBackgroundTask();
  }
  /**
   * Method called when user clicks 'Finish' button of the wizard.
   *
   */
  /** Method called when user clicks 'Finish' button of the wizard. */
  private void finishClicked()
  {
    final WizardStep cStep = getCurrentStep();
    if (application.finishClicked(cStep, this)) {
    if (application.finishClicked(cStep, this))
    {
      updateUserData(cStep);
    }
  }
  /**
   * Method called when user clicks 'Previous' button of the wizard.
   *
   */
  /** Method called when user clicks 'Previous' button of the wizard. */
  private void previousClicked()
  {
    WizardStep cStep = getCurrentStep();
@@ -355,19 +343,15 @@
    setCurrentStep(application.getPreviousWizardStep(cStep));
  }
  /**
   * Method called when user clicks 'Quit' button of the wizard.
   *
   */
  /** Method called when user clicks 'Quit' button of the wizard. */
  private void quitClicked()
  {
    WizardStep cStep = getCurrentStep();
    application.quitClicked(cStep, this);
    application.quitClicked(getCurrentStep(), this);
  }
  /**
   * Method called when user clicks 'Continue' button in the case where there
   * is something installed.
   * Method called when user clicks 'Continue' button in the case where there is
   * something installed.
   */
  private void continueInstallClicked()
  {
@@ -380,101 +364,93 @@
  /** Method called when user clicks 'Close' button of the wizard. */
  private void closeClicked()
  {
    WizardStep cStep = getCurrentStep();
    application.closeClicked(cStep, this);
    application.closeClicked(getCurrentStep(), this);
  }
  private void launchStatusPanelClicked()
  {
    BackgroundTask<Object> worker = new BackgroundTask<Object>()
    {
      public Object processBackgroundTask() throws UserDataException {
      public Object processBackgroundTask() throws UserDataException
      {
        try
        {
          Installation installation;
          if (isWebStart()) {
          final Installation installation;
          if (isWebStart())
          {
            String installDir = application.getUserData().getServerLocation();
            installation =
              new Installation(installDir, installDir);
          } else {
            installation = new Installation(installDir, installDir);
          }
          else
          {
            installation = Installation.getLocal();
          }
          ProcessBuilder pb;
          if (isMacOS()) {
            List<String> cmd = new ArrayList<String>();
          final ProcessBuilder pb;
          if (isMacOS())
          {
            List<String> cmd = new ArrayList<>();
            cmd.add(MAC_APPLICATIONS_OPENER);
            cmd.add(getScriptPath(
                getPath(installation.getControlPanelCommandFile())));
            pb = new ProcessBuilder(cmd);
          } else {
            String cmd = getScriptPath(
                getPath(installation.getControlPanelCommandFile()));
            cmd.add(getScriptPath(getPath(installation.getControlPanelCommandFile())));
            pb = new ProcessBuilder(cmd);
          }
          else
          {
            pb = new ProcessBuilder(getScriptPath(getPath(installation.getControlPanelCommandFile())));
          }
          Map<String, String> env = pb.environment();
          env.put(SetupUtils.OPENDJ_JAVA_HOME, System.getProperty("java.home"));
          Process process = pb.start();
          /*
           * Wait for 3 seconds.  Assume that if the process has not exited
           * everything went fine.
           */
          final Process process = pb.start();
          // Wait for 3 seconds. Assume that if the process has not exited everything went fine.
          int returnValue = 0;
          try
          {
            Thread.sleep(3000);
          }
          catch (Throwable t)
          {
          }
          catch (Throwable t) {}
          try
          {
            returnValue = process.exitValue();
          }
          catch (IllegalThreadStateException e)
          {
            // The process has not exited: assume that the status panel could
            // be launched successfully.
            // The process has not exited: assume that the status panel could be launched successfully.
          }
          if (returnValue != 0)
          {
            throw new Error(
                    INFO_COULD_NOT_LAUNCH_CONTROL_PANEL_MSG.get().toString());
            throw new Error(INFO_COULD_NOT_LAUNCH_CONTROL_PANEL_MSG.get().toString());
          }
        }
        catch (Throwable t)
        {
          // This looks like a bug
          t.printStackTrace();
          throw new Error(
              INFO_COULD_NOT_LAUNCH_CONTROL_PANEL_MSG.get().toString());
          throw new Error(INFO_COULD_NOT_LAUNCH_CONTROL_PANEL_MSG.get().toString());
        }
        return null;
      }
      public void backgroundTaskCompleted(Object returnValue,
          Throwable throwable)
      public void backgroundTaskCompleted(Object returnValue, Throwable throwable)
      {
        getDialog().getFrame().setCursor(
            Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        getDialog().getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        if (throwable != null)
        {
          displayError(LocalizableMessage.raw(throwable.getMessage()),
                  INFO_ERROR_TITLE.get());
          displayError(LocalizableMessage.raw(throwable.getMessage()), INFO_ERROR_TITLE.get());
        }
      }
    };
    getDialog().getFrame().setCursor(
        Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    getDialog().getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    worker.startBackgroundTask();
  }
  /**
   * This method tries to update the visibility of the steps panel.  The
   * contents are updated because the user clicked in one of the buttons
   * that could make the steps panel to change.
   *
   * This method tries to update the visibility of the steps panel. The contents
   * are updated because the user clicked in one of the buttons that could make
   * the steps panel to change.
   */
  private void inputPanelButtonClicked()
  {
@@ -485,7 +461,6 @@
   * Method called when we want to quit the setup (for instance when the user
   * clicks on 'Close' or 'Quit' buttons and has confirmed that (s)he wants to
   * quit the program.
   *
   */
  public void quit()
  {
@@ -494,19 +469,20 @@
    System.exit(0);
  }
  private void flushLogs() {
  private void flushLogs()
  {
    java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(logger.getName());
    Handler[] handlers = julLogger.getHandlers();
    if (handlers != null) {
      for (Handler h : handlers) {
    if (handlers != null)
    {
      for (Handler h : handlers)
      {
        h.flush();
      }
    }
  }
  /**
   * Launch the QuickSetup application Open DS.
   */
  /** Launch the QuickSetup application Open DS. */
  public void launch()
  {
    application.addProgressUpdateListener(this);
@@ -538,7 +514,8 @@
   * dialog to display the panel that corresponds to the step passed as
   * argument.
   *
   * @param step The step to be displayed.
   * @param step
   *          The step to be displayed.
   */
  public void setCurrentStep(WizardStep step)
  {
@@ -547,8 +524,7 @@
      throw new NullPointerException("step is null");
    }
    currentStep = step;
    application.setDisplayedWizardStep(step, application.getUserData(),
        getDialog());
    application.setDisplayedWizardStep(step, application.getUserData(), getDialog());
  }
  /**
@@ -560,8 +536,7 @@
  {
    if (dialog == null)
    {
      dialog = new QuickSetupDialog(application,
              installStatus, this);
      dialog = new QuickSetupDialog(application, installStatus, this);
      dialog.addButtonActionListener(this);
      application.setQuickSetupDialog(dialog);
    }
@@ -578,9 +553,12 @@
   */
  public void displayError(LocalizableMessage msg, LocalizableMessage title)
  {
    if (isCli()) {
    if (isCli())
    {
      System.err.println(msg);
    } else {
    }
    else
    {
      getDialog().displayError(msg, title);
    }
  }
@@ -593,7 +571,7 @@
   * @param title
   *          the title of the dialog.
   * @return <CODE>true</CODE> if the user confirms the message, or
   * <CODE>false</CODE> if not.
   *         <CODE>false</CODE> if not.
   */
  public boolean displayConfirmation(LocalizableMessage msg, LocalizableMessage title)
  {
@@ -609,20 +587,13 @@
   */
  public String getFieldStringValue(FieldName fieldName)
  {
    String sValue = null;
    Object value = getFieldValue(fieldName);
    final Object value = getFieldValue(fieldName);
    if (value != null)
    {
      if (value instanceof String)
      {
        sValue = (String) value;
      } else
      {
        sValue = String.valueOf(value);
      }
      return String.valueOf(value);
    }
    return sValue;
    return null;
  }
  /**
@@ -655,7 +626,6 @@
  /**
   * A method to initialize the look and feel.
   *
   */
  private void initLookAndFeel() throws Throwable
  {
@@ -667,8 +637,7 @@
   * ProgressUpdateEvent.
   *
   * @param ev
   *          the ProgressUpdateEvent used to generate the
   *          ProgressDescriptor.
   *          the ProgressUpdateEvent used to generate the ProgressDescriptor.
   * @return the ProgressDescriptor.
   */
  private ProgressDescriptor createProgressDescriptor(ProgressUpdateEvent ev)
@@ -683,13 +652,12 @@
      progressDetails.append(additionalDetails);
    }
    /*
    Note: progressDetails might have a certain number of characters that
    break LocalizableMessage Formatter (for instance percentages).  When fix for
    issue 2142 was committed it broke this code.  So here
    we use LocalizableMessage.raw instead of calling directly progressDetails.toMessage
    */
    return new ProgressDescriptor(status, ratio, newProgressLabel,
        LocalizableMessage.raw(progressDetails.toString()));
     * Note: progressDetails might have a certain number of characters that
     * break LocalizableMessage Formatter (for instance percentages).
     * When fix for issue 2142 was committed it broke this code.
     * So here we use LocalizableMessage.raw instead of calling directly progressDetails.toMessage
     */
    return new ProgressDescriptor(status, ratio, newProgressLabel, LocalizableMessage.raw(progressDetails.toString()));
  }
  /**
@@ -699,27 +667,31 @@
  private class NextClickedBackgroundTask extends BackgroundTask<Object>
  {
    private WizardStep cStep;
    public NextClickedBackgroundTask(WizardStep cStep)
    {
      this.cStep = cStep;
    }
    public Object processBackgroundTask() throws UserDataException {
      try {
    public Object processBackgroundTask() throws UserDataException
    {
      try
      {
        application.updateUserData(cStep, QuickSetup.this);
      }
      catch (UserDataException uide) {
      catch (UserDataException uide)
      {
        throw uide;
      }
      catch (Throwable t) {
        throw new UserDataException(cStep,
                getThrowableMsg(INFO_BUG_MSG.get(), t));
      catch (Throwable t)
      {
        throw new UserDataException(cStep, getThrowableMsg(INFO_BUG_MSG.get(), t));
      }
      return null;
    }
    public void backgroundTaskCompleted(Object returnValue,
                                        Throwable throwable) {
    public void backgroundTaskCompleted(Object returnValue, Throwable throwable)
    {
      getDialog().workerFinished();
      if (throwable != null)
@@ -733,31 +705,25 @@
          UserDataException ude = (UserDataException) throwable;
          if (ude instanceof UserDataConfirmationException)
          {
            if (displayConfirmation(ude.getMessageObject(),
                INFO_CONFIRMATION_TITLE.get()))
            if (displayConfirmation(ude.getMessageObject(), INFO_CONFIRMATION_TITLE.get()))
            {
              setCurrentStep(application.getNextWizardStep(cStep));
            }
          }
          else if (ude instanceof UserDataCertificateException)
          {
            final UserDataCertificateException ce =
              (UserDataCertificateException)ude;
            CertificateDialog dlg =
              new CertificateDialog(getDialog().getFrame(), ce);
            final UserDataCertificateException ce = (UserDataCertificateException) ude;
            CertificateDialog dlg = new CertificateDialog(getDialog().getFrame(), ce);
            dlg.pack();
            dlg.setVisible(true);
            CertificateDialog.ReturnType answer = dlg.getUserAnswer();
            if (answer != CertificateDialog.ReturnType.NOT_ACCEPTED)
            {
              /*
               * Retry the click but now with the certificate accepted.
               */
              application.acceptCertificateForException(ce,
                  answer == CertificateDialog.ReturnType.ACCEPTED_PERMANENTLY);
              // Retry the click but now with the certificate accepted.
              final boolean acceptPermanently = answer == CertificateDialog.ReturnType.ACCEPTED_PERMANENTLY;
              application.acceptCertificateForException(ce, acceptPermanently);
              application.nextClicked(cStep, QuickSetup.this);
              BackgroundTask<Object> worker =
                new NextClickedBackgroundTask(cStep);
              BackgroundTask<Object> worker = new NextClickedBackgroundTask(cStep);
              getDialog().workerStarted();
              worker.startBackgroundTask();
            }
@@ -767,7 +733,9 @@
            displayError(ude.getMessageObject(), INFO_ERROR_TITLE.get());
          }
        }
      } else {
      }
      else
      {
        setCurrentStep(application.getNextWizardStep(cStep));
      }
    }