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