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