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