001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2010 Sun Microsystems, Inc.
025 *      Portions Copyright 2013-2015 ForgeRock AS.
026 */
027package org.opends.quicksetup.installer.ui;
028
029import org.forgerock.i18n.LocalizableMessage;
030import org.forgerock.i18n.LocalizableMessageBuilder;
031
032import static org.forgerock.util.Utils.*;
033import static org.opends.messages.QuickSetupMessages.*;
034import static org.opends.quicksetup.util.Utils.*;
035
036import static com.forgerock.opendj.util.OperatingSystem.isWindows;
037
038import org.opends.admin.ads.ServerDescriptor;
039import org.opends.quicksetup.Constants;
040import org.opends.quicksetup.Installation;
041import org.opends.quicksetup.JavaArguments;
042import org.opends.quicksetup.UserData;
043import org.opends.quicksetup.installer.AuthenticationData;
044import org.opends.quicksetup.installer.DataReplicationOptions;
045import org.opends.quicksetup.installer.SuffixesToReplicateOptions;
046import org.opends.quicksetup.ui.*;
047import org.opends.quicksetup.util.HtmlProgressMessageFormatter;
048import org.opends.quicksetup.util.ProgressMessageFormatter;
049import org.opends.quicksetup.util.Utils;
050
051import javax.swing.Box;
052import javax.swing.DefaultComboBoxModel;
053import javax.swing.JCheckBox;
054import javax.swing.JComboBox;
055import javax.swing.JComponent;
056import javax.swing.JEditorPane;
057import javax.swing.JLabel;
058import javax.swing.JPanel;
059import javax.swing.JScrollPane;
060import javax.swing.border.EmptyBorder;
061import javax.swing.text.JTextComponent;
062
063import java.awt.CardLayout;
064import java.awt.Component;
065import java.awt.GridBagConstraints;
066import java.awt.GridBagLayout;
067import java.awt.event.ActionEvent;
068import java.awt.event.ActionListener;
069import java.util.ArrayList;
070import java.util.Arrays;
071import java.util.HashMap;
072import java.util.LinkedList;
073import java.util.List;
074import java.util.Map;
075import java.util.TreeSet;
076
077/**
078 * This is the panel that contains the Review Panel.
079 *
080 */
081public class InstallReviewPanel extends ReviewPanel {
082
083  private static final long serialVersionUID = -7356174829193265699L;
084
085  private final HashMap<FieldName, JLabel> hmLabels = new HashMap<>();
086  private final HashMap<FieldName, JTextComponent> hmFields = new HashMap<>();
087  private JPanel bottomComponent;
088  private JCheckBox startCheckBox;
089  private JCheckBox enableWindowsServiceCheckBox;
090  private JLabel warningLabel;
091
092  private JComboBox viewCombo;
093  private final LocalizableMessage DISPLAY_TEXT = INFO_REVIEW_DISPLAY_TEXT.get();
094  private final LocalizableMessage DISPLAY_EQUIVALENT_COMMAND = INFO_REVIEW_DISPLAY_EQUIVALENT_COMMAND.get();
095
096  private JComponent cardLayoutPanel;
097
098  private JEditorPane equivalentCommandPane;
099
100  private UserData lastUserData;
101
102  /**
103   * Constructor of the panel.
104   *
105   * @param application
106   *          Application represented by this panel the fields of the panel.
107   */
108  public InstallReviewPanel(GuiApplication application)
109  {
110    super(application);
111    populateLabelAndFieldsMap();
112  }
113
114  /** {@inheritDoc} */
115  @Override
116  public void beginDisplay(UserData userData)
117  {
118    setFieldValue(FieldName.HOST_NAME, userData.getHostName());
119    setFieldValue(FieldName.SERVER_PORT, Integer.toString(userData.getServerPort()));
120    setFieldValue(FieldName.ADMIN_CONNECTOR_PORT, Integer.toString(userData.getAdminConnectorPort()));
121    setFieldValue(FieldName.SECURITY_OPTIONS, Utils.getSecurityOptionsString(userData.getSecurityOptions(), false));
122    setFieldValue(FieldName.DIRECTORY_MANAGER_DN, userData.getDirectoryManagerDn());
123    setFieldValue(FieldName.DATA_OPTIONS, Utils.getDataDisplayString(userData));
124
125    final boolean mustCreateAdministrator = userData.mustCreateAdministrator();
126    if (mustCreateAdministrator)
127    {
128      setFieldValue(FieldName.GLOBAL_ADMINISTRATOR_UID, userData.getGlobalAdministratorUID());
129    }
130    getField(FieldName.GLOBAL_ADMINISTRATOR_UID).setVisible(mustCreateAdministrator);
131    getLabel(FieldName.GLOBAL_ADMINISTRATOR_UID).setVisible(mustCreateAdministrator);
132
133    final boolean standalone = userData.getReplicationOptions().getType() == DataReplicationOptions.Type.STANDALONE;
134    if (!standalone)
135    {
136      setFieldValue(FieldName.REPLICATION_PORT, getReplicationPortString(userData));
137    }
138    getField(FieldName.REPLICATION_PORT).setVisible(!standalone);
139    getLabel(FieldName.REPLICATION_PORT).setVisible(!standalone);
140
141    setFieldValue(FieldName.SERVER_JAVA_ARGUMENTS, getRuntimeString(userData));
142
143    checkStartWarningLabel();
144    updateEquivalentCommand(userData);
145
146    lastUserData = userData;
147  }
148
149  /**
150   * Creates and returns the instructions panel.
151   *
152   * @return the instructions panel.
153   */
154  @Override
155  protected Component createInstructionsPanel()
156  {
157    final JPanel instructionsPanel = new JPanel(new GridBagLayout());
158    instructionsPanel.setOpaque(false);
159    final LocalizableMessage instructions = getInstructions();
160    final JLabel l = new JLabel(instructions.toString());
161    l.setFont(UIFactory.INSTRUCTIONS_FONT);
162
163    final LocalizableMessage[] values = {
164      DISPLAY_TEXT,
165      DISPLAY_EQUIVALENT_COMMAND
166    };
167
168    final DefaultComboBoxModel model = new DefaultComboBoxModel(values);
169    viewCombo = new JComboBox();
170    viewCombo.setModel(model);
171    viewCombo.setSelectedIndex(0);
172
173    viewCombo.addActionListener(new ActionListener()
174    {
175      @Override
176      public void actionPerformed(ActionEvent ev)
177      {
178        updateInputPanel();
179      }
180    });
181
182    final GridBagConstraints gbc = new GridBagConstraints();
183    gbc.gridx = 0;
184    gbc.gridy = 0;
185    gbc.anchor = GridBagConstraints.WEST;
186    instructionsPanel.add(l, gbc);
187
188    gbc.gridx = 1;
189    gbc.weightx = 1.0;
190    instructionsPanel.add(Box.createHorizontalGlue(), gbc);
191
192    gbc.gridx = 2;
193    gbc.weightx = 0.0;
194    gbc.insets.left = UIFactory.LEFT_INSET_BROWSE;
195    instructionsPanel.add(viewCombo);
196
197    return instructionsPanel;
198  }
199
200  /** {@inheritDoc} */
201  @Override
202  protected boolean requiresScroll()
203  {
204    return false;
205  }
206
207  /** {@inheritDoc} */
208  @Override
209  protected Component createInputPanel()
210  {
211    final JPanel panel = UIFactory.makeJPanel();
212    panel.setLayout(new GridBagLayout());
213
214    final GridBagConstraints gbc = new GridBagConstraints();
215    gbc.insets = UIFactory.getEmptyInsets();
216    gbc.gridwidth = GridBagConstraints.REMAINDER;
217    gbc.weightx = 1.0;
218    gbc.weighty = 1.0;
219    gbc.fill = GridBagConstraints.BOTH;
220    panel.add(createFieldsPanel(), gbc);
221
222    final JComponent chk = getBottomComponent();
223    if (chk != null) {
224      gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD;
225      gbc.weighty = 0.0;
226      gbc.fill = GridBagConstraints.HORIZONTAL;
227      panel.add(chk, gbc);
228    }
229
230    return panel;
231  }
232
233  /** {@inheritDoc} */
234  @Override
235  public Object getFieldValue(FieldName fieldName)
236  {
237    if (fieldName == FieldName.SERVER_START_INSTALLER)
238    {
239      return getStartCheckBox().isSelected();
240    }
241    else if (fieldName == FieldName.ENABLE_WINDOWS_SERVICE)
242    {
243      return getEnableWindowsServiceCheckBox().isSelected();
244    }
245
246    return null;
247  }
248
249  /** {@inheritDoc} */
250  @Override
251  protected LocalizableMessage getInstructions()
252  {
253    return INFO_REVIEW_PANEL_INSTRUCTIONS.get();
254  }
255
256  /** {@inheritDoc} */
257  @Override
258  protected LocalizableMessage getTitle()
259  {
260    return INFO_REVIEW_PANEL_TITLE.get();
261  }
262
263  private void updateInputPanel()
264  {
265    final CardLayout cl = (CardLayout) cardLayoutPanel.getLayout();
266    cl.show(cardLayoutPanel, viewCombo.getSelectedItem().toString());
267  }
268
269  /** Create the components and populate the Maps. */
270  private void populateLabelAndFieldsMap()
271  {
272    final HashMap<FieldName, LabelFieldDescriptor> hm = new HashMap<>();
273
274    hm.put(FieldName.HOST_NAME, new LabelFieldDescriptor(
275            INFO_HOST_NAME_LABEL.get(),
276            INFO_HOST_NAME_TOOLTIP.get(),
277            LabelFieldDescriptor.FieldType.READ_ONLY,
278            LabelFieldDescriptor.LabelType.PRIMARY, 0));
279
280    hm.put(FieldName.SERVER_PORT, new LabelFieldDescriptor(
281            INFO_SERVER_PORT_LABEL.get(),
282            INFO_SERVER_PORT_TOOLTIP.get(),
283            LabelFieldDescriptor.FieldType.READ_ONLY,
284            LabelFieldDescriptor.LabelType.PRIMARY, 0));
285
286    hm.put(FieldName.ADMIN_CONNECTOR_PORT, new LabelFieldDescriptor(
287            INFO_ADMIN_CONNECTOR_PORT_LABEL.get(),
288            INFO_ADMIN_CONNECTOR_PORT_TOOLTIP.get(),
289            LabelFieldDescriptor.FieldType.READ_ONLY,
290            LabelFieldDescriptor.LabelType.PRIMARY, 0));
291
292    hm.put(FieldName.SECURITY_OPTIONS, new LabelFieldDescriptor(
293            INFO_SERVER_SECURITY_LABEL.get(),
294            INFO_SERVER_SECURITY_TOOLTIP.get(),
295            LabelFieldDescriptor.FieldType.READ_ONLY,
296            LabelFieldDescriptor.LabelType.PRIMARY, 0));
297
298    hm.put(FieldName.DIRECTORY_MANAGER_DN, new LabelFieldDescriptor(
299            INFO_SERVER_DIRECTORY_MANAGER_DN_LABEL.get(),
300            INFO_SERVER_DIRECTORY_MANAGER_DN_TOOLTIP.get(),
301            LabelFieldDescriptor.FieldType.READ_ONLY,
302            LabelFieldDescriptor.LabelType.PRIMARY, 0));
303
304    hm.put(FieldName.GLOBAL_ADMINISTRATOR_UID, new LabelFieldDescriptor(
305            INFO_GLOBAL_ADMINISTRATOR_UID_LABEL.get(), null,
306            LabelFieldDescriptor.FieldType.READ_ONLY,
307            LabelFieldDescriptor.LabelType.PRIMARY, 0));
308
309    hm.put(FieldName.DATA_OPTIONS, new LabelFieldDescriptor(
310            INFO_DIRECTORY_DATA_LABEL.get(), null,
311            LabelFieldDescriptor.FieldType.READ_ONLY,
312            LabelFieldDescriptor.LabelType.PRIMARY, 0));
313
314    hm.put(FieldName.REPLICATION_PORT, new LabelFieldDescriptor(
315            INFO_REPLICATION_PORT_LABEL.get(), null,
316            LabelFieldDescriptor.FieldType.READ_ONLY,
317            LabelFieldDescriptor.LabelType.PRIMARY, 0));
318
319    hm.put(FieldName.SERVER_JAVA_ARGUMENTS, new LabelFieldDescriptor(
320            INFO_RUNTIME_OPTIONS_LABEL.get(), null,
321            LabelFieldDescriptor.FieldType.READ_ONLY,
322            LabelFieldDescriptor.LabelType.PRIMARY, 0));
323
324    for (final FieldName fieldName : hm.keySet())
325    {
326      final LabelFieldDescriptor desc = hm.get(fieldName);
327      final JLabel label = UIFactory.makeJLabel(desc);
328      final JTextComponent field = UIFactory.makeJTextComponent(desc, null);
329      field.setOpaque(false);
330      label.setLabelFor(field);
331
332      hmFields.put(fieldName, field);
333      hmLabels.put(fieldName, label);
334    }
335  }
336
337  private JLabel getLabel(FieldName fieldName)
338  {
339    return hmLabels.get(fieldName);
340  }
341
342  private JTextComponent getField(FieldName fieldName)
343  {
344    return hmFields.get(fieldName);
345  }
346
347  private void setFieldValue(FieldName fieldName, String value)
348  {
349    getField(fieldName).setText(value);
350  }
351
352  private String getReplicationPortString(UserData userInstallData)
353  {
354    final LocalizableMessageBuilder buf = new LocalizableMessageBuilder();
355    final DataReplicationOptions repl = userInstallData.getReplicationOptions();
356    final SuffixesToReplicateOptions suf = userInstallData.getSuffixesToReplicateOptions();
357    final Map<ServerDescriptor, AuthenticationData> remotePorts = userInstallData.getRemoteWithNoReplicationPort();
358
359    if (repl.getType() == DataReplicationOptions.Type.IN_EXISTING_TOPOLOGY
360        && suf.getType() == SuffixesToReplicateOptions.Type.REPLICATE_WITH_EXISTING_SUFFIXES
361        && !remotePorts.isEmpty())
362    {
363      final AuthenticationData authData = userInstallData.getReplicationOptions().getAuthenticationData();
364      final String serverToConnectDisplay = authData == null ? "" : authData.getHostName() + ":" + authData.getPort();
365      String s;
366      if (userInstallData.getReplicationOptions().useSecureReplication())
367      {
368        s = INFO_SECURE_REPLICATION_PORT_LABEL.get(
369            userInstallData.getReplicationOptions().getReplicationPort()).toString();
370      }
371      else
372      {
373        s = Integer.toString(userInstallData.getReplicationOptions().getReplicationPort());
374      }
375      buf.append(s);
376
377      final TreeSet<LocalizableMessage> remoteServerLines = new TreeSet<>();
378      for (final ServerDescriptor server : remotePorts.keySet())
379      {
380        String serverDisplay;
381        if (server.getHostPort(false).equalsIgnoreCase(serverToConnectDisplay))
382        {
383          serverDisplay = serverToConnectDisplay;
384        }
385        else
386        {
387          serverDisplay = server.getHostPort(true);
388        }
389
390        final AuthenticationData repPort = remotePorts.get(server);
391        if (repPort.useSecureConnection())
392        {
393          s = INFO_SECURE_REPLICATION_PORT_LABEL.get(repPort.getPort()).toString();
394        }
395        else
396        {
397          s = Integer.toString(repPort.getPort());
398        }
399        remoteServerLines.add(INFO_REMOTE_SERVER_REPLICATION_PORT.get(s, serverDisplay));
400      }
401
402      for (final LocalizableMessage line : remoteServerLines)
403      {
404        buf.append(Constants.LINE_SEPARATOR).append(line);
405      }
406    }
407    else
408    {
409      buf.append(userInstallData.getReplicationOptions().getReplicationPort());
410    }
411
412    return buf.toString();
413  }
414
415 private String getRuntimeString(UserData userData)
416 {
417   final JavaArguments serverArguments = userData.getJavaArguments(UserData.SERVER_SCRIPT_NAME);
418   final JavaArguments importArguments = userData.getJavaArguments(UserData.IMPORT_SCRIPT_NAME);
419   final boolean defaultServer = userData.getDefaultJavaArguments(UserData.SERVER_SCRIPT_NAME).equals(serverArguments);
420   final boolean defaultImport = userData.getDefaultJavaArguments(UserData.IMPORT_SCRIPT_NAME).equals(importArguments);
421
422   if (defaultServer && defaultImport)
423   {
424     return INFO_DEFAULT_JAVA_ARGUMENTS.get().toString();
425   }
426   else if (defaultServer)
427   {
428     return INFO_USE_CUSTOM_IMPORT_RUNTIME.get(importArguments.getStringArguments()).toString();
429   }
430   else if (defaultImport)
431   {
432     return INFO_USE_CUSTOM_SERVER_RUNTIME.get(serverArguments.getStringArguments()).toString();
433   }
434
435   return INFO_USE_CUSTOM_SERVER_RUNTIME.get(serverArguments.getStringArguments()) + Constants.LINE_SEPARATOR
436        + INFO_USE_CUSTOM_IMPORT_RUNTIME.get(importArguments.getStringArguments());
437 }
438
439  /**
440   * Returns and creates the fields panel.
441   *
442   * @return the fields panel.
443   */
444  @Override
445  protected JPanel createFieldsPanel()
446  {
447    final JPanel fieldsPanel = new JPanel(new GridBagLayout());
448    fieldsPanel.setOpaque(false);
449
450    final GridBagConstraints gbc = new GridBagConstraints();
451    cardLayoutPanel = new JPanel(new CardLayout());
452    cardLayoutPanel.setOpaque(false);
453
454    final JComponent p = createReadOnlyPanel();
455    p.setBorder(new EmptyBorder(UIFactory.TOP_INSET_SECONDARY_FIELD,
456        UIFactory.LEFT_INSET_SECONDARY_FIELD,
457        UIFactory.BOTTOM_INSET_SECONDARY_FIELD,
458        UIFactory.LEFT_INSET_SECONDARY_FIELD));
459
460    JScrollPane scroll = new JScrollPane(p);
461    scroll.setOpaque(false);
462    scroll.getViewport().setOpaque(false);
463    scroll.getViewport().setBackground(UIFactory.DEFAULT_BACKGROUND);
464    scroll.setBackground(UIFactory.DEFAULT_BACKGROUND);
465
466    cardLayoutPanel.add(scroll, DISPLAY_TEXT.toString());
467    scroll = new JScrollPane();
468    createEquivalentCommandPanel(scroll);
469    scroll.setOpaque(false);
470    scroll.getViewport().setOpaque(false);
471    scroll.getViewport().setBackground(UIFactory.DEFAULT_BACKGROUND);
472    scroll.setBackground(UIFactory.DEFAULT_BACKGROUND);
473    cardLayoutPanel.add(scroll, DISPLAY_EQUIVALENT_COMMAND.toString());
474
475    gbc.gridx = 0;
476    gbc.gridy = 0;
477    gbc.weightx = 1.0;
478    gbc.weighty = 1.0;
479    gbc.gridwidth = 3;
480    gbc.fill = GridBagConstraints.BOTH;
481    fieldsPanel.add(cardLayoutPanel, gbc);
482
483    return fieldsPanel;
484  }
485
486  private JComponent createReadOnlyPanel()
487  {
488    final JPanel panel = new JPanel(new GridBagLayout());
489    panel.setOpaque(false);
490    final GridBagConstraints gbc = new GridBagConstraints();
491
492    final List<FieldName> fieldNames = new LinkedList<>();
493    fieldNames.addAll(Arrays.asList(
494        new FieldName[] {
495          FieldName.HOST_NAME, FieldName.SERVER_PORT,
496          FieldName.ADMIN_CONNECTOR_PORT, FieldName.SECURITY_OPTIONS,
497          FieldName.DIRECTORY_MANAGER_DN, FieldName.GLOBAL_ADMINISTRATOR_UID,
498          FieldName.DATA_OPTIONS, FieldName.REPLICATION_PORT,
499          FieldName.SERVER_JAVA_ARGUMENTS
500          }
501     ));
502
503    boolean isFirst = true;
504    for (final FieldName fieldName : fieldNames)
505    {
506      gbc.gridwidth = GridBagConstraints.RELATIVE;
507      gbc.weightx = 0.0;
508      gbc.insets.top = isFirst ? 0 : UIFactory.TOP_INSET_PRIMARY_FIELD;
509      gbc.insets.left = 0;
510      gbc.anchor = GridBagConstraints.NORTHWEST;
511      panel.add(getLabel(fieldName), gbc);
512
513      gbc.weightx = 1.0;
514      gbc.fill = GridBagConstraints.HORIZONTAL;
515      gbc.insets.top = isFirst ? 0 : UIFactory.TOP_INSET_PRIMARY_FIELD;
516      gbc.insets.left = UIFactory.LEFT_INSET_PRIMARY_FIELD;
517      gbc.gridwidth = GridBagConstraints.REMAINDER;
518
519      panel.add(getField(fieldName), gbc);
520      isFirst = false;
521    }
522
523    gbc.weighty = 1.0;
524    gbc.insets = UIFactory.getEmptyInsets();
525    gbc.fill = GridBagConstraints.VERTICAL;
526    panel.add(Box.createVerticalGlue(), gbc);
527
528    return panel;
529  }
530
531  private Component createEquivalentCommandPanel(final JScrollPane scroll)
532  {
533    equivalentCommandPane = UIFactory.makeProgressPane(scroll);
534    equivalentCommandPane.setAutoscrolls(true);
535    scroll.setViewportView(equivalentCommandPane);
536    equivalentCommandPane.setOpaque(false);
537
538    return equivalentCommandPane;
539  }
540
541  /** {@inheritDoc} */
542  @Override
543  protected JComponent getBottomComponent()
544  {
545    if (bottomComponent == null)
546    {
547      bottomComponent = new JPanel(new GridBagLayout());
548      bottomComponent.setOpaque(false);
549
550      final GridBagConstraints gbc = new GridBagConstraints();
551      gbc.anchor = GridBagConstraints.WEST;
552
553      final JPanel auxPanel = new JPanel(new GridBagLayout());
554      auxPanel.setOpaque(false);
555
556      gbc.gridwidth = 3;
557      auxPanel.add(getStartCheckBox(), gbc);
558
559      gbc.insets.left = UIFactory.LEFT_INSET_SECONDARY_FIELD;
560      gbc.gridwidth = GridBagConstraints.RELATIVE;
561      auxPanel.add(getWarningLabel(), gbc);
562
563      gbc.gridwidth = GridBagConstraints.REMAINDER;
564      gbc.insets.left = 0;
565      gbc.weightx = 1.0;
566      auxPanel.add(Box.createHorizontalGlue(), gbc);
567      bottomComponent.add(auxPanel, gbc);
568
569      if (isWindows())
570      {
571        gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD;
572        bottomComponent.add(getEnableWindowsServiceCheckBox(), gbc);
573      }
574    }
575
576    return bottomComponent;
577  }
578
579  private JLabel getWarningLabel()
580  {
581    if (warningLabel == null)
582    {
583      warningLabel = UIFactory.makeJLabel(UIFactory.IconType.WARNING,
584                                          INFO_INSTALL_SERVER_MUST_BE_TEMPORARILY_STARTED.get(),
585                                          UIFactory.TextStyle.READ_ONLY);
586    }
587    return warningLabel;
588  }
589
590  private JCheckBox getStartCheckBox()
591  {
592    if (startCheckBox == null)
593    {
594      startCheckBox = UIFactory.makeJCheckBox(INFO_START_SERVER_LABEL.get(),
595                                              INFO_START_SERVER_TOOLTIP.get(),
596                                              UIFactory.TextStyle.CHECKBOX);
597      startCheckBox.setSelected(getApplication().getUserData().getStartServer());
598      startCheckBox.addActionListener(new ActionListener()
599      {
600        @Override
601        public void actionPerformed(ActionEvent ev)
602        {
603          checkStartWarningLabel();
604          lastUserData.setStartServer(startCheckBox.isSelected());
605          updateEquivalentCommand(lastUserData);
606        }
607      });
608    }
609
610    return startCheckBox;
611  }
612
613  private JCheckBox getEnableWindowsServiceCheckBox()
614  {
615    if (enableWindowsServiceCheckBox == null)
616    {
617      enableWindowsServiceCheckBox = UIFactory.makeJCheckBox(INFO_ENABLE_WINDOWS_SERVICE_LABEL.get(),
618                                                             INFO_ENABLE_WINDOWS_SERVICE_TOOLTIP.get(),
619                                                             UIFactory.TextStyle.CHECKBOX);
620      enableWindowsServiceCheckBox.setSelected(getApplication().getUserData().getEnableWindowsService());
621      enableWindowsServiceCheckBox.addActionListener(new ActionListener()
622      {
623        @Override
624        public void actionPerformed(ActionEvent ev)
625        {
626          if (isWindows())
627          {
628            lastUserData.setEnableWindowsService(enableWindowsServiceCheckBox.isSelected());
629            updateEquivalentCommand(lastUserData);
630          }
631        }
632      });
633    }
634
635    return enableWindowsServiceCheckBox;
636  }
637
638  /**
639   * Depending on whether we want to replicate or not, we do have to start the
640   * server temporarily to update its configuration and initialize data.
641   */
642  private void checkStartWarningLabel()
643  {
644    boolean visible = !getStartCheckBox().isSelected();
645    if (visible)
646    {
647      final UserData userData = getApplication().getUserData();
648      visible = userData.getReplicationOptions().getType() != DataReplicationOptions.Type.STANDALONE;
649    }
650    getWarningLabel().setVisible(visible);
651  }
652
653  private void updateEquivalentCommand(UserData userData)
654  {
655    final HtmlProgressMessageFormatter formatter = new HtmlProgressMessageFormatter();
656    final StringBuilder sb = new StringBuilder();
657
658    final String s = getEquivalentJavaPropertiesProcedure(userData, formatter);
659    if (s != null && s.length() > 0)
660    {
661      sb.append(s)
662        .append(formatter.getTaskSeparator());
663    }
664
665    sb.append(formatter.getFormattedProgress(INFO_INSTALL_SETUP_EQUIVALENT_COMMAND_LINE.get()));
666    List<String> setupCmdLine = getSetupEquivalentCommandLine(userData);
667    appendText(sb, formatter, getFormattedEquivalentCommandLine(setupCmdLine, formatter));
668
669    if (userData.getReplicationOptions().getType() == DataReplicationOptions.Type.IN_EXISTING_TOPOLOGY)
670    {
671      sb.append(formatter.getTaskSeparator());
672      final List<List<String>> cmdLines = getDsReplicationEquivalentCommandLines("enable", userData);
673      if (cmdLines.size() == 1)
674      {
675        sb.append(formatter.getFormattedProgress(INFO_INSTALL_ENABLE_REPLICATION_EQUIVALENT_COMMAND_LINE.get()));
676      }
677      else if (cmdLines.size() > 1)
678      {
679        sb.append(formatter.getFormattedProgress(INFO_INSTALL_ENABLE_REPLICATION_EQUIVALENT_COMMAND_LINES.get()));
680      }
681
682      for (final List<String> cmdLine : cmdLines)
683      {
684        appendText(sb, formatter, getFormattedEquivalentCommandLine(cmdLine, formatter));
685      }
686
687      sb.append(formatter.getLineBreak());
688      sb.append(formatter.getLineBreak());
689
690      if (cmdLines.size() == 1)
691      {
692        sb.append(formatter.getFormattedProgress(INFO_INSTALL_INITIALIZE_REPLICATION_EQUIVALENT_COMMAND_LINE.get()));
693      }
694      else if (cmdLines.size() > 1)
695      {
696        sb.append(formatter.getFormattedProgress(INFO_INSTALL_INITIALIZE_REPLICATION_EQUIVALENT_COMMAND_LINES.get()));
697      }
698
699      final List<List<String>> dsReplicationCmdLines = getDsReplicationEquivalentCommandLines("initialize", userData);
700      for (final List<String> cmdLine : dsReplicationCmdLines)
701      {
702        appendText(sb, formatter, getFormattedEquivalentCommandLine(cmdLine, formatter));
703      }
704    }
705    else if (userData.getReplicationOptions().getType() == DataReplicationOptions.Type.FIRST_IN_TOPOLOGY)
706    {
707      sb.append(formatter.getTaskSeparator())
708        .append(formatter.getFormattedProgress(INFO_INSTALL_ENABLE_REPLICATION_EQUIVALENT_COMMAND_LINES.get()));
709      for (final List<String> cmdLine : getDsConfigReplicationEnableEquivalentCommandLines(userData))
710      {
711        appendText(sb, formatter, getFormattedEquivalentCommandLine(cmdLine, formatter));
712      }
713    }
714
715    if (userData.getReplicationOptions().getType() != DataReplicationOptions.Type.STANDALONE
716        && !userData.getStartServer())
717    {
718      sb.append(formatter.getTaskSeparator());
719      sb.append(formatter.getFormattedProgress(INFO_INSTALL_STOP_SERVER_EQUIVALENT_COMMAND_LINE.get()));
720      final String cmd = getPath(Installation.getLocal().getServerStopCommandFile());
721      appendText(sb, formatter, formatter.getFormattedProgress(LocalizableMessage.raw(cmd)));
722    }
723
724    equivalentCommandPane.setText(sb.toString());
725  }
726
727  private void appendText(final StringBuilder sb, final HtmlProgressMessageFormatter formatter, CharSequence text)
728  {
729    sb.append(formatter.getLineBreak())
730      .append(Constants.HTML_BOLD_OPEN)
731      .append(text)
732      .append(Constants.HTML_BOLD_CLOSE);
733  }
734
735  private String getEquivalentJavaPropertiesProcedure(final UserData userData,
736      final ProgressMessageFormatter formatter)
737  {
738    final StringBuilder sb = new StringBuilder();
739    final JavaArguments serverArguments = userData.getJavaArguments(UserData.SERVER_SCRIPT_NAME);
740    final JavaArguments importArguments = userData.getJavaArguments(UserData.IMPORT_SCRIPT_NAME);
741    final List<String> linesToAdd = new ArrayList<>();
742
743    final boolean defaultServer =
744        userData.getDefaultJavaArguments(UserData.SERVER_SCRIPT_NAME).equals(serverArguments);
745    final boolean defaultImport =
746        userData.getDefaultJavaArguments(UserData.IMPORT_SCRIPT_NAME).equals(importArguments);
747
748    if (!defaultServer)
749    {
750      linesToAdd.add(getJavaArgPropertyForScript(UserData.SERVER_SCRIPT_NAME)
751          + ": " + serverArguments.getStringArguments());
752    }
753
754    if (!defaultImport)
755    {
756      linesToAdd.add(getJavaArgPropertyForScript(UserData.IMPORT_SCRIPT_NAME)
757          + ": " + importArguments.getStringArguments());
758    }
759
760    if (linesToAdd.size() == 1)
761    {
762      final String arg0 = getJavaPropertiesFilePath();
763      final String arg1 = linesToAdd.get(0);
764      sb.append(formatter.getFormattedProgress(INFO_EDIT_JAVA_PROPERTIES_LINE.get(arg0, arg1)));
765    }
766    else if (linesToAdd.size() > 1)
767    {
768      final String arg0 = getJavaPropertiesFilePath();
769      final String arg1 = joinAsString(Constants.LINE_SEPARATOR, linesToAdd);
770      sb.append(formatter.getFormattedProgress(INFO_EDIT_JAVA_PROPERTIES_LINES.get(arg0, arg1)));
771    }
772
773    return sb.toString();
774  }
775
776  private static String getJavaArgPropertyForScript(String scriptName)
777  {
778    return scriptName + ".java-args";
779  }
780
781  private String getJavaPropertiesFilePath()
782  {
783    final String path = Utils.getInstancePathFromInstallPath(Utils.getInstallPathFromClasspath());
784    return getPath(getPath(path, Installation.CONFIG_PATH_RELATIVE), Installation.DEFAULT_JAVA_PROPERTIES_FILE);
785  }
786
787}