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

jvergara
22.30.2007 b54e25e8af0e73b7ddaca4eaec088803ea6a7e4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
 
package org.opends.quicksetup;
 
import java.io.File;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
 
import javax.swing.SwingUtilities;
 
import org.opends.quicksetup.event.ButtonActionListener;
import org.opends.quicksetup.event.ButtonEvent;
import org.opends.quicksetup.event.InstallProgressUpdateEvent;
import org.opends.quicksetup.event.InstallProgressUpdateListener;
import org.opends.quicksetup.event.UninstallProgressUpdateEvent;
import org.opends.quicksetup.event.UninstallProgressUpdateListener;
import org.opends.quicksetup.i18n.ResourceProvider;
import org.opends.quicksetup.installer.DataOptions;
import org.opends.quicksetup.installer.FieldName;
import org.opends.quicksetup.installer.InstallProgressDescriptor;
import org.opends.quicksetup.installer.InstallProgressStep;
import org.opends.quicksetup.installer.Installer;
import org.opends.quicksetup.installer.UserInstallData;
import org.opends.quicksetup.installer.UserInstallDataException;
import org.opends.quicksetup.installer.offline.OfflineInstaller;
import org.opends.quicksetup.installer.webstart.WebStartDownloader;
import org.opends.quicksetup.installer.webstart.WebStartInstaller;
import org.opends.quicksetup.ui.QuickSetupDialog;
import org.opends.quicksetup.ui.UIFactory;
import org.opends.quicksetup.uninstaller.UninstallProgressDescriptor;
import org.opends.quicksetup.uninstaller.UninstallProgressStep;
import org.opends.quicksetup.uninstaller.Uninstaller;
import org.opends.quicksetup.uninstaller.UserUninstallData;
import org.opends.quicksetup.uninstaller.UserUninstallDataException;
import org.opends.quicksetup.util.BackgroundTask;
import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
 
/**
 * This class is responsible for doing the following:
 *
 * Check whether we are installing or uninstalling and which type of
 * installation we are running.
 *
 * Performs all the checks and validation of the data provided by the user
 * during the setup.
 *
 * It will launch also the installation once the user clicks on 'Finish' if we
 * are installing the product.
 *
 * If we are running a web start installation it will start the background
 * downloading of the jar files that are required to perform the installation
 * (OpenDS.jar, je.jar, etc.).  The global idea is to force the user to
 * download just one jar file (quicksetup.jar) to launch the Web Start
 * installer.  Then QuickSetup will call WebStartDownloader to download the jar
 * files.  Until this class is not finished the WebStart Installer will be on
 * the InstallProgressStep.DOWNLOADING step.
 *
 */
class QuickSetup implements ButtonActionListener, InstallProgressUpdateListener,
UninstallProgressUpdateListener
{
  // Contains the data provided by the user in the install
  private UserInstallData userInstallData;
 
  // Contains the data provided by the user in the uninstall
  private UserUninstallData userUninstallData;
 
  private Installer installer;
 
  private Uninstaller uninstaller;
 
  private WebStartDownloader jnlpDownloader;
 
  private CurrentInstallStatus installStatus;
 
  private Step currentStep = Step.WELCOME;
 
  private QuickSetupDialog dialog;
 
  private StringBuffer progressDetails = new StringBuffer();
 
  private InstallProgressDescriptor lastInstallDescriptor;
 
  private InstallProgressDescriptor lastDisplayedInstallDescriptor;
 
  private InstallProgressDescriptor installDescriptorToDisplay;
 
  private UninstallProgressDescriptor lastUninstallDescriptor;
 
  private UninstallProgressDescriptor lastDisplayedUninstallDescriptor;
 
  private UninstallProgressDescriptor uninstallDescriptorToDisplay;
 
  // Constants used to do checks
  private static final int MIN_DIRECTORY_MANAGER_PWD = 1;
 
  private static final int MIN_PORT_VALUE = 1;
 
  private static final int MAX_PORT_VALUE = 65535;
 
  private static final int MIN_NUMBER_ENTRIES = 1;
 
  private static final int MAX_NUMBER_ENTRIES = 10000000;
 
  // Update period of the dialogs.
  private static final int UPDATE_PERIOD = 500;
 
  /**
   * This method creates the install/uninstall dialogs and to check the current
   * install status. This method must be called outside the event thread because
   * it can perform long operations which can make the user think that the UI is
   * blocked.
   *
   * @param args for the moment this parameter is not used but we keep it in
   * order to (in case of need) pass parameters through the command line.
   */
  public void initialize(String[] args)
  {
    if (isWebStart())
    {
      jnlpDownloader = new WebStartDownloader();
      jnlpDownloader.start(false);
    }
    installStatus = new CurrentInstallStatus();
    initLookAndFeel();
    /* In the calls to setCurrentStep the dialog will be created */
    if (Utils.isUninstall())
    {
      setCurrentStep(Step.CONFIRM_UNINSTALL);
    } else
    {
      setCurrentStep(Step.WELCOME);
    }
  }
 
  /**
   * This method displays the setup dialog. This method must be called from the
   * event thread.
   */
  public void display()
  {
    getDialog().packAndShow();
  }
 
  /**
   * ButtonActionListener implementation. It assumes that we are called in the
   * event thread.
   *
   * @param ev the ButtonEvent we receive.
   */
  public void buttonActionPerformed(ButtonEvent ev)
  {
    switch (ev.getButtonName())
    {
    case NEXT:
      nextClicked();
      break;
 
    case CLOSE:
      closeClicked();
      break;
 
    case FINISH:
      finishClicked();
      break;
 
    case QUIT:
      quitClicked();
      break;
 
    case CONTINUE_INSTALL:
      continueInstallClicked();
      break;
 
    case PREVIOUS:
      previousClicked();
      break;
 
    case CANCEL:
      cancelClicked();
      break;
 
    case LAUNCH_STATUS_PANEL:
      launchStatusPanelClicked();
      break;
 
    default:
      throw new IllegalArgumentException("Unknown button name: "
          + ev.getButtonName());
    }
  }
 
  /**
   * InstallProgressUpdateListener implementation. Here we take the
   * InstallProgressUpdateEvent and create an InstallProgressDescriptor that
   * will be used to update the progress dialog.
   *
   * @param ev the InstallProgressUpdateEvent we receive.
   *
   * @see #runDisplayUpdater()
   */
  public void progressUpdate(InstallProgressUpdateEvent ev)
  {
    synchronized (this)
    {
      InstallProgressDescriptor desc = createInstallProgressDescriptor(ev);
      boolean isLastDescriptor =
          desc.getProgressStep() == InstallProgressStep.FINISHED_SUCCESSFULLY
              || desc.getProgressStep() ==
                InstallProgressStep.FINISHED_WITH_ERROR;
      if (isLastDescriptor)
      {
        lastInstallDescriptor = desc;
      }
 
      installDescriptorToDisplay = desc;
    }
  }
 
  /**
   * UninstallProgressUpdateListener implementation. Here we take the
   * UninstallProgressUpdateEvent and create an UninstallProgressDescriptor that
   * will be used to update the progress dialog.
   *
   * @param ev the UninstallProgressUpdateEvent we receive.
   *
   * @see #runDisplayUpdater()
   */
  public void progressUpdate(UninstallProgressUpdateEvent ev)
  {
    synchronized (this)
    {
      UninstallProgressDescriptor desc = createUninstallProgressDescriptor(ev);
      boolean isLastDescriptor =
          desc.getProgressStep() == UninstallProgressStep.FINISHED_SUCCESSFULLY
              || desc.getProgressStep() ==
                UninstallProgressStep.FINISHED_WITH_ERROR;
      if (isLastDescriptor)
      {
        lastUninstallDescriptor = desc;
      }
 
      uninstallDescriptorToDisplay = desc;
    }
  }
 
  /**
   * This method is used to update the progress dialog.
   *
   * We are receiving notifications from the installer and uninstaller (this
   * class is a ProgressListener). However if we lots of notifications updating
   * the progress panel every time we get a progress update can result of a lot
   * of flickering. So the idea here is to have a minimal time between 2 updates
   * of the progress dialog (specified by UPDATE_PERIOD).
   *
   * @see #progressUpdate(InstallProgressUpdateEvent ev)
   * @see #progressUpdate(UninstallProgressUpdateEvent ev)
   *
   */
  private void runDisplayUpdater()
  {
    boolean doPool = true;
    while (doPool)
    {
      try
      {
        Thread.sleep(UPDATE_PERIOD);
      } catch (Exception ex)
      {
      }
      synchronized (this)
      {
        if (Utils.isUninstall())
        {
          final UninstallProgressDescriptor desc = uninstallDescriptorToDisplay;
          if (desc != null)
          {
            if (desc != lastDisplayedUninstallDescriptor)
            {
              lastDisplayedUninstallDescriptor = desc;
 
              SwingUtilities.invokeLater(new Runnable()
              {
                public void run()
                {
                  getDialog().displayProgress(desc);
                }
              });
            }
            doPool = desc != lastUninstallDescriptor;
          }
        }
        else
        {
          final InstallProgressDescriptor desc = installDescriptorToDisplay;
          if (desc != null)
          {
            if (desc != lastDisplayedInstallDescriptor)
            {
              lastDisplayedInstallDescriptor = desc;
 
              SwingUtilities.invokeLater(new Runnable()
              {
                public void run()
                {
                  getDialog().displayProgress(desc);
                }
              });
            }
            doPool = desc != lastInstallDescriptor;
          }
        }
      }
    }
  }
 
  /**
   * Method called when user clicks 'Next' button of the wizard.
   *
   */
  private void nextClicked()
  {
    final Step cStep = getCurrentStep();
    switch (cStep)
    {
    case PROGRESS:
      throw new IllegalStateException(
          "Cannot click on next from progress step");
 
    case REVIEW:
      throw new IllegalStateException("Cannot click on next from review step");
 
    default:
      BackgroundTask worker = new BackgroundTask()
      {
        public Object processBackgroundTask() throws UserInstallDataException
        {
          try
          {
            updateUserInstallData(cStep);
          }
          catch (UserInstallDataException uide)
          {
            throw uide;
          }
          catch (Throwable t)
          {
            throw new UserInstallDataException(cStep,
                getThrowableMsg("bug-msg", t));
          }
          return null;
        }
 
        public void backgroundTaskCompleted(Object returnValue,
            Throwable throwable)
        {
          getDialog().workerFinished();
 
          if (throwable != null)
          {
            UserInstallDataException ude = (UserInstallDataException)throwable;
            displayError(ude.getLocalizedMessage(), getMsg("error-title"));
          }
          else
          {
            setCurrentStep(nextStep(cStep));
          }
        }
      };
      getDialog().workerStarted();
      worker.startBackgroundTask();
    }
  }
 
  /**
   * Method called when user clicks 'Finish' button of the wizard.
   *
   */
  private void finishClicked()
  {
    final Step cStep = getCurrentStep();
    switch (cStep)
    {
    case REVIEW:
      updateUserDataForReviewPanel();
      launchInstallation();
      setCurrentStep(Step.PROGRESS);
      break;
 
    case CONFIRM_UNINSTALL:
      BackgroundTask worker = new BackgroundTask()
      {
        public Object processBackgroundTask() throws UserUninstallDataException
        {
          try
          {
            updateUserDataForConfirmUninstallPanel();
          }
          catch (UserUninstallDataException uude)
          {
            throw uude;
          } catch (Throwable t)
          {
            throw new UserUninstallDataException(cStep,
                getThrowableMsg("bug-msg", t));
          }
          return new Boolean(installStatus.isServerRunning());
        }
 
        public void backgroundTaskCompleted(Object returnValue,
            Throwable throwable)
        {
          getDialog().workerFinished();
          if (throwable != null)
          {
            UserUninstallDataException ude =
              (UserUninstallDataException)throwable;
            displayError(ude.getLocalizedMessage(), getMsg("error-title"));
          } else
          {
            boolean serverRunning = ((Boolean)returnValue).booleanValue();
            if (!serverRunning)
            {
              getUserUninstallData().setStopServer(false);
              if (displayConfirmation(
                  getMsg("confirm-uninstall-server-not-running-msg"),
                  getMsg("confirm-uninstall-server-not-running-title")))
              {
                launchUninstallation();
                setCurrentStep(nextStep(cStep));
              }
            }
            else
            {
              if (displayConfirmation(
                      getMsg("confirm-uninstall-server-running-msg"),
                      getMsg("confirm-uninstall-server-running-title")))
              {
                  getUserUninstallData().setStopServer(true);
                  launchUninstallation();
                  setCurrentStep(nextStep(cStep));
              } else
              {
                  getUserUninstallData().setStopServer(false);
              }
            }
          }
        }
      };
      getDialog().workerStarted();
      worker.startBackgroundTask();
      break;
 
    default:
      throw new IllegalStateException(
          "Cannot click on finish when we are not in the Review window");
    }
  }
 
  /**
   * Method called when user clicks 'Previous' button of the wizard.
   *
   */
  private void previousClicked()
  {
    Step cStep = getCurrentStep();
    switch (cStep)
    {
    case WELCOME:
      throw new IllegalStateException(
          "Cannot click on previous from progress step");
 
    case PROGRESS:
      throw new IllegalStateException(
          "Cannot click on previous from progress step");
 
    default:
      setCurrentStep(previousStep(cStep));
    }
  }
 
  /**
   * Method called when user clicks 'Quit' button of the wizard.
   *
   */
  private void quitClicked()
  {
    Step cStep = getCurrentStep();
    switch (cStep)
    {
    case PROGRESS:
      throw new IllegalStateException(
          "Cannot click on quit from progress step");
 
    default:
      if (Utils.isUninstall())
      {
        quit();
      }
      else if (installStatus.isInstalled())
      {
        quit();
 
      } else if (displayConfirmation(getMsg("confirm-quit-install-msg"),
          getMsg("confirm-quit-install-title")))
      {
        quit();
      }
    }
  }
 
  /**
   * Method called when user clicks 'Continue' button in the case where there
   * is something installed.
   */
  private void continueInstallClicked()
  {
    Step cStep = getCurrentStep();
    switch (cStep)
    {
    case WELCOME:
      getDialog().forceToDisplaySetup();
      setCurrentStep(Step.WELCOME);
      break;
    default:
      throw new IllegalStateException(
          "Continue only can be clicked on WELCOME step");
    }
  }
 
  /**
   * Method called when user clicks 'Close' button of the wizard.
   *
   */
  private void closeClicked()
  {
    Step cStep = getCurrentStep();
    switch (cStep)
    {
    case PROGRESS:
      if (Utils.isUninstall())
      {
        boolean finished = uninstaller.isFinished();
        if (finished
            || displayConfirmation(getMsg("confirm-close-uninstall-msg"),
                getMsg("confirm-close-uninstall-title")))
        {
          quit();
        }
      } else
      {
        boolean finished = installer.isFinished();
        if (finished
            || displayConfirmation(getMsg("confirm-close-install-msg"),
                getMsg("confirm-close-install-title")))
        {
          quit();
        }
      }
      break;
 
    default:
      throw new IllegalStateException(
          "Close only can be clicked on PROGRESS step");
    }
  }
 
  /**
   * Method called when user clicks 'Cancel' button of the wizard.
   *
   */
  private void cancelClicked()
  {
    Step cStep = getCurrentStep();
    switch (cStep)
    {
    case CONFIRM_UNINSTALL:
      quit();
      break;
 
    default:
      throw new IllegalStateException(
          "Cancel only can be clicked on CONFIRM_UNINSTALL step");
    }
  }
 
  private void launchStatusPanelClicked()
  {
    BackgroundTask worker = new BackgroundTask()
    {
      public Object processBackgroundTask() throws UserInstallDataException
      {
        try
        {
          String cmd = Utils.isWindows()?"statuspanel.bat":"statuspanel";
          String serverPath;
          if (Utils.isWebStart())
          {
            serverPath = getUserInstallData().getServerLocation();
          }
          else
          {
            serverPath = Utils.getInstallPathFromClasspath();
          }
          cmd = Utils.getPath(serverPath, "bin"+File.separator+cmd);
          ProcessBuilder pb = new ProcessBuilder(new String[]{cmd});
          Map<String, String> env = pb.environment();
          env.put("JAVA_HOME", System.getProperty("java.home"));
          /* Remove JAVA_BIN to be sure that we use the JVM running the
           * uninstaller JVM to stop the server.
           */
          env.remove("JAVA_BIN");
          Process process = pb.start();
          int returnValue = process.waitFor();
 
          if (returnValue != 0)
          {
            throw new Error(getMsg("could-not-launch-status-panel-msg"));
          }
        }
        catch (Throwable t)
        {
          // This looks like a bug
          t.printStackTrace();
          throw new Error(getMsg("could-not-launch-status-panel-msg"));
        }
        return null;
      }
 
      public void backgroundTaskCompleted(Object returnValue,
          Throwable throwable)
      {
        getDialog().workerFinished();
 
        if (throwable != null)
        {
          displayError(throwable.getMessage(), getMsg("error-title"));
        }
      }
    };
    getDialog().workerStarted();
    worker.startBackgroundTask();
  }
 
  /**
   * Method called when we want to quit the setup (for instance when the user
   * clicks on 'Close' or 'Quit' buttons and has confirmed that (s)he wants to
   * quit the program.
   *
   */
  private void quit()
  {
    System.exit(0);
  }
 
  /**
   * These methods validate the data provided by the user in the panels and
   * update the UserInstallData object according to that content.
   *
   * @param cStep
   *          the current step of the wizard
   *
   * @throws an
   *           UserInstallDataException if the data provided by the user is not
   *           valid.
   *
   */
  private void updateUserInstallData(Step cStep) throws UserInstallDataException
  {
    switch (cStep)
    {
    case SERVER_SETTINGS:
      updateUserInstallDataForServerSettingsPanel();
      break;
 
    case DATA_OPTIONS:
      updateUserDataForDataOptionsPanel();
      break;
 
    case REVIEW:
      updateUserDataForReviewPanel();
      break;
    }
  }
 
  /**
   * Validate the data provided by the user in the server settings panel and
   * update the UserInstallData object according to that content.
   *
   * @throws an
   *           UserInstallDataException if the data provided by the user is not
   *           valid.
   *
   */
  private void updateUserInstallDataForServerSettingsPanel()
      throws UserInstallDataException
  {
    ArrayList<String> errorMsgs = new ArrayList<String>();
 
    if (isWebStart())
    {
      // Check the server location
      String serverLocation = getFieldStringValue(FieldName.SERVER_LOCATION);
 
      if ((serverLocation == null) || ("".equals(serverLocation.trim())))
      {
        errorMsgs.add(getMsg("empty-server-location"));
        displayFieldInvalid(FieldName.SERVER_LOCATION, true);
      } else if (!Utils.parentDirectoryExists(serverLocation))
      {
        String[] arg =
          { serverLocation };
        errorMsgs.add(getMsg("parent-directory-does-not-exist", arg));
        displayFieldInvalid(FieldName.SERVER_LOCATION, true);
      } else if (Utils.fileExists(serverLocation))
      {
        String[] arg =
          { serverLocation };
        errorMsgs.add(getMsg("file-exists", arg));
        displayFieldInvalid(FieldName.SERVER_LOCATION, true);
      } else if (Utils.directoryExistsAndIsNotEmpty(serverLocation))
      {
        String[] arg =
          { serverLocation };
        errorMsgs.add(getMsg("directory-exists-not-empty", arg));
        displayFieldInvalid(FieldName.SERVER_LOCATION, true);
      } else if (!Utils.canWrite(serverLocation))
      {
        String[] arg =
          { serverLocation };
        errorMsgs.add(getMsg("directory-not-writable", arg));
        displayFieldInvalid(FieldName.SERVER_LOCATION, true);
 
      } else if (!Utils.hasEnoughSpace(serverLocation,
          getRequiredInstallSpace()))
      {
        long requiredInMb = getRequiredInstallSpace() / (1024 * 1024);
        String[] args =
          { serverLocation, String.valueOf(requiredInMb) };
        errorMsgs.add(getMsg("not-enough-disk-space", args));
        displayFieldInvalid(FieldName.SERVER_LOCATION, true);
 
      } else
      {
        getUserInstallData().setServerLocation(serverLocation);
        displayFieldInvalid(FieldName.SERVER_LOCATION, false);
      }
    }
 
    // Check the port
    String sPort = getFieldStringValue(FieldName.SERVER_PORT);
    try
    {
      int port = Integer.parseInt(sPort);
      if ((port < MIN_PORT_VALUE) || (port > MAX_PORT_VALUE))
      {
        String[] args =
          { String.valueOf(MIN_PORT_VALUE), String.valueOf(MAX_PORT_VALUE) };
        errorMsgs.add(getMsg("invalid-port-value-range", args));
        displayFieldInvalid(FieldName.SERVER_PORT, true);
      } else if (!Utils.canUseAsPort(port))
      {
        if (Utils.isPriviledgedPort(port))
        {
          errorMsgs.add(getMsg("cannot-bind-priviledged-port", new String[]
            { String.valueOf(port) }));
        } else
        {
          errorMsgs.add(getMsg("cannot-bind-port", new String[]
            { String.valueOf(port) }));
        }
        displayFieldInvalid(FieldName.SERVER_PORT, true);
 
      } else
      {
        getUserInstallData().setServerPort(port);
        displayFieldInvalid(FieldName.SERVER_PORT, false);
      }
 
    } catch (NumberFormatException nfe)
    {
      String[] args =
        { String.valueOf(MIN_PORT_VALUE), String.valueOf(MAX_PORT_VALUE) };
      errorMsgs.add(getMsg("invalid-port-value-range", args));
      displayFieldInvalid(FieldName.SERVER_PORT, true);
    }
 
    // Check the Directory Manager DN
    String dmDn = getFieldStringValue(FieldName.DIRECTORY_MANAGER_DN);
 
    if ((dmDn == null) || (dmDn.trim().length() == 0))
    {
      errorMsgs.add(getMsg("empty-directory-manager-dn"));
      displayFieldInvalid(FieldName.DIRECTORY_MANAGER_DN, true);
    } else if (!Utils.isDn(dmDn))
    {
      errorMsgs.add(getMsg("not-a-directory-manager-dn"));
      displayFieldInvalid(FieldName.DIRECTORY_MANAGER_DN, true);
    } else if (Utils.isConfigurationDn(dmDn))
    {
      errorMsgs.add(getMsg("directory-manager-dn-is-config-dn"));
      displayFieldInvalid(FieldName.DIRECTORY_MANAGER_DN, true);
    } else
    {
      getUserInstallData().setDirectoryManagerDn(dmDn);
      displayFieldInvalid(FieldName.DIRECTORY_MANAGER_DN, false);
    }
 
    // Check the provided passwords
    String pwd1 = getFieldStringValue(FieldName.DIRECTORY_MANAGER_PWD);
    String pwd2 = getFieldStringValue(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM);
    if (pwd1 == null)
    {
      pwd1 = "";
    }
 
    boolean pwdValid = true;
    if (!pwd1.equals(pwd2))
    {
      errorMsgs.add(getMsg("not-equal-pwd"));
      displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM, true);
      pwdValid = false;
 
    }
    if (pwd1.length() < MIN_DIRECTORY_MANAGER_PWD)
    {
      errorMsgs.add(getMsg(("pwd-too-short"), new String[]
        { String.valueOf(MIN_DIRECTORY_MANAGER_PWD) }));
      displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD, true);
      if ((pwd2 == null) || (pwd2.length() < MIN_DIRECTORY_MANAGER_PWD))
      {
        displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM, true);
      }
      pwdValid = false;
    }
 
    if (pwdValid)
    {
      getUserInstallData().setDirectoryManagerPwd(pwd1);
      displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD, false);
      displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM, false);
    }
 
    if (errorMsgs.size() > 0)
    {
      throw new UserInstallDataException(Step.SERVER_SETTINGS,
          Utils.getStringFromCollection(errorMsgs, "\n"));
    }
  }
 
  /**
   * Validate the data provided by the user in the data options panel and update
   * the UserInstallData object according to that content.
   *
   * @throws an
   *           UserInstallDataException if the data provided by the user is not
   *           valid.
   *
   */
  private void updateUserDataForDataOptionsPanel()
      throws UserInstallDataException
  {
    ArrayList<String> errorMsgs = new ArrayList<String>();
 
    DataOptions dataOptions = null;
 
    // Check the base dn
    boolean validBaseDn = false;
    String baseDn = getFieldStringValue(FieldName.DIRECTORY_BASE_DN);
    if ((baseDn == null) || (baseDn.trim().length() == 0))
    {
      errorMsgs.add(getMsg("empty-base-dn"));
      displayFieldInvalid(FieldName.DIRECTORY_BASE_DN, true);
    } else if (!Utils.isDn(baseDn))
    {
      errorMsgs.add(getMsg("not-a-base-dn"));
      displayFieldInvalid(FieldName.DIRECTORY_BASE_DN, true);
    } else if (Utils.isConfigurationDn(baseDn))
    {
      errorMsgs.add(getMsg("base-dn-is-configuration-dn"));
      displayFieldInvalid(FieldName.DIRECTORY_BASE_DN, true);
    } else
    {
      displayFieldInvalid(FieldName.DIRECTORY_BASE_DN, false);
      validBaseDn = true;
    }
 
    // Check the data options
    DataOptions.Type type =
        (DataOptions.Type) getFieldValue(FieldName.DATA_OPTIONS);
 
    switch (type)
    {
    case IMPORT_FROM_LDIF_FILE:
      String ldifPath = getFieldStringValue(FieldName.LDIF_PATH);
      if ((ldifPath == null) || (ldifPath.trim().equals("")))
      {
        errorMsgs.add(getMsg("no-ldif-path"));
        displayFieldInvalid(FieldName.LDIF_PATH, true);
      } else if (!Utils.fileExists(ldifPath))
      {
        errorMsgs.add(getMsg("ldif-file-does-not-exist"));
        displayFieldInvalid(FieldName.LDIF_PATH, true);
      } else if (validBaseDn)
      {
        dataOptions = new DataOptions(type, baseDn, ldifPath);
        displayFieldInvalid(FieldName.LDIF_PATH, false);
      }
      break;
 
    case IMPORT_AUTOMATICALLY_GENERATED_DATA:
      // variable used to know if everything went ok during these
      // checks
      int startErrors = errorMsgs.size();
 
      // Check the number of entries
      String nEntries = getFieldStringValue(FieldName.NUMBER_ENTRIES);
      if ((nEntries == null) || (nEntries.trim().equals("")))
      {
        errorMsgs.add(getMsg("no-number-entries"));
        displayFieldInvalid(FieldName.NUMBER_ENTRIES, true);
      } else
      {
        boolean nEntriesValid = false;
        try
        {
          int n = Integer.parseInt(nEntries);
 
          nEntriesValid = n >= MIN_NUMBER_ENTRIES && n <= MAX_NUMBER_ENTRIES;
        } catch (NumberFormatException nfe)
        {
        }
 
        if (!nEntriesValid)
        {
          String[] args =
                { String.valueOf(MIN_NUMBER_ENTRIES),
                    String.valueOf(MAX_NUMBER_ENTRIES) };
          errorMsgs.add(getMsg("invalid-number-entries-range", args));
          displayFieldInvalid(FieldName.NUMBER_ENTRIES, true);
        } else
        {
          displayFieldInvalid(FieldName.NUMBER_ENTRIES, false);
        }
      }
      if (startErrors == errorMsgs.size() && validBaseDn)
      {
        // No validation errors
        dataOptions = new DataOptions(type, baseDn, new Integer(nEntries));
      }
      break;
 
    default:
      displayFieldInvalid(FieldName.LDIF_PATH, false);
      displayFieldInvalid(FieldName.NUMBER_ENTRIES, false);
      if (validBaseDn)
      {
        dataOptions = new DataOptions(type, baseDn);
      }
    }
 
    if (dataOptions != null)
    {
      getUserInstallData().setDataOptions(dataOptions);
    }
 
    if (errorMsgs.size() > 0)
    {
      throw new UserInstallDataException(Step.DATA_OPTIONS,
          Utils.getStringFromCollection(errorMsgs, "\n"));
    }
  }
 
  /**
   * Update the UserInstallData object according to the content of the review
   * panel.
   *
   */
  private void updateUserDataForReviewPanel()
  {
    Boolean b = (Boolean) getFieldValue(FieldName.SERVER_START);
    getUserInstallData().setStartServer(b.booleanValue());
  }
 
  /**
   * Update the UserUninstallData object according to the content of the review
   * panel.
   *
   */
  private void updateUserDataForConfirmUninstallPanel()
  throws UserUninstallDataException
  {
    getUserUninstallData().setRemoveLibrariesAndTools(
        (Boolean)getFieldValue(FieldName.REMOVE_LIBRARIES_AND_TOOLS));
    getUserUninstallData().setRemoveDatabases(
        (Boolean)getFieldValue(FieldName.REMOVE_DATABASES));
    getUserUninstallData().setRemoveConfigurationAndSchema(
        (Boolean)getFieldValue(FieldName.REMOVE_CONFIGURATION_AND_SCHEMA));
    getUserUninstallData().setRemoveBackups(
        (Boolean)getFieldValue(FieldName.REMOVE_BACKUPS));
    getUserUninstallData().setRemoveLDIFs(
        (Boolean)getFieldValue(FieldName.REMOVE_LDIFS));
    getUserUninstallData().setRemoveLogs(
        (Boolean)getFieldValue(FieldName.REMOVE_LOGS));
 
    Set<String> dbs = new HashSet<String>();
    Set s = (Set)getFieldValue(FieldName.EXTERNAL_DB_DIRECTORIES);
    for (Object v: s)
    {
      dbs.add((String)v);
    }
 
    Set<String> logs = new HashSet<String>();
    s = (Set)getFieldValue(FieldName.EXTERNAL_LOG_FILES);
    for (Object v: s)
    {
      logs.add((String)v);
    }
 
    getUserUninstallData().setExternalDbsToRemove(dbs);
    getUserUninstallData().setExternalLogsToRemove(logs);
 
    if ((dbs.size() == 0) &&
        (logs.size() == 0) &&
        !getUserUninstallData().getRemoveLibrariesAndTools() &&
        !getUserUninstallData().getRemoveDatabases() &&
        !getUserUninstallData().getRemoveConfigurationAndSchema() &&
        !getUserUninstallData().getRemoveBackups() &&
        !getUserUninstallData().getRemoveLDIFs() &&
        !getUserUninstallData().getRemoveLogs())
    {
      throw new UserUninstallDataException(Step.CONFIRM_UNINSTALL,
          getMsg("nothing-selected-to-uninstall"));
    }
  }
 
  /**
   * Launch the installation of Open DS. Depending on whether we are running a
   * web start or not it will use on Installer object or other.
   *
   */
  private void launchInstallation()
  {
    ProgressMessageFormatter formatter = getDialog().getFormatter();
    if (isWebStart())
    {
      installer = new WebStartInstaller(getUserInstallData(), jnlpDownloader,
          formatter);
    } else
    {
      installer = new OfflineInstaller(getUserInstallData(), formatter);
    }
    installer.addProgressUpdateListener(this);
    installer.start();
    Thread t = new Thread(new Runnable()
    {
      public void run()
      {
        runDisplayUpdater();
      }
    });
    t.start();
  }
 
  /**
   * Launch the uninstallation of Open DS.
   *
   */
  private void launchUninstallation()
  {
    uninstaller = new Uninstaller(getUserUninstallData(),
        getDialog().getFormatter());
    uninstaller.addProgressUpdateListener(this);
    uninstaller.start();
    Thread t = new Thread(new Runnable()
    {
      public void run()
      {
        runDisplayUpdater();
      }
    });
    t.start();
  }
 
  /**
   * Provides the object representing the data provided by the user in the
   * install.
   *
   * @return the UserInstallData representing the data provided by the user in
   *         the Install wizard.
   */
  private UserInstallData getUserInstallData()
  {
    if (userInstallData == null)
    {
      userInstallData = new UserInstallData();
    }
    return userInstallData;
  }
 
  /**
   * Provides the object representing the data provided by the user in the
   * uninstall.
   *
   * @return the UserUninstallData representing the data provided by the user in
   *         the Uninstall wizard.
   */
  private UserUninstallData getUserUninstallData()
  {
    if (userUninstallData == null)
    {
      userUninstallData = new UserUninstallData();
    }
    return userUninstallData;
  }
 
  /**
   * Provides an object representing the default data/install parameters that
   * will be proposed to the user in the Installation wizard. This data includes
   * elements such as the default dn of the directory manager or the default
   * install location.
   *
   * @return the UserInstallData representing the default data/parameters that
   *         will be proposed to the user.
   */
  private UserInstallData getDefaultUserData()
  {
    UserInstallData defaultUserData = new UserInstallData();
 
    DataOptions defaultDataOptions = new DefaultDataOptions();
 
    defaultUserData.setServerLocation(Utils.getDefaultServerLocation());
    // See what we can propose as port
    int defaultPort = getDefaultPort();
    if (defaultPort != -1)
    {
      defaultUserData.setServerPort(defaultPort);
    }
    defaultUserData.setDirectoryManagerDn("cn=Directory Manager");
 
    defaultUserData.setDataOptions(defaultDataOptions);
    defaultUserData.setStartServer(true);
 
    return defaultUserData;
  }
 
  /**
   * The following three methods are just commodity methods to get localized
   * messages.
   */
  private String getMsg(String key)
  {
    return getI18n().getMsg(key);
  }
 
  private String getMsg(String key, String[] args)
  {
    return getI18n().getMsg(key, args);
  }
 
  private String getThrowableMsg(String key, Throwable t)
  {
    return Utils.getThrowableMsg(getI18n(), key, null, t);
  }
 
  private ResourceProvider getI18n()
  {
    return ResourceProvider.getInstance();
  }
 
  /**
   * Get the current step.
   *
   * @return the currently displayed Step of the wizard.
   */
  private Step getCurrentStep()
  {
    return currentStep;
  }
 
  /**
   * Set the current step. This will basically make the required calls in the
   * dialog to display the panel that corresponds to the step passed as
   * argument.
   *
   * @param step.
   *          The step to be displayed.
   */
  private void setCurrentStep(Step step)
  {
    if (step == null)
    {
      throw new NullPointerException("step is null");
    }
    currentStep = step;
    getDialog().setDisplayedStep(step, getUserInstallData());
  }
 
  /**
   * Gets the next step corresponding to the step passed as parameter.
   *
   * @param step,
   *          the step of which we want to get the new step.
   * @return the next step for the current step.
   * @throws IllegalArgumentException
   *           if the current step has not a next step.
   */
  private Step nextStep(Step step)
  {
    Step nextStep;
    if (step == Step.CONFIRM_UNINSTALL)
    {
      nextStep = Step.PROGRESS;
    }
    else
    {
      Iterator<Step> it = EnumSet.range(step, Step.PROGRESS).iterator();
      it.next();
      if (!it.hasNext())
      {
        throw new IllegalArgumentException("No next for step: " + step);
      }
      nextStep = it.next();
    }
    return nextStep;
  }
 
  /**
   * Gets the previous step corresponding to the step passed as parameter.
   *
   * @param step,
   *          the step of which we want to get the previous step.
   * @return the next step for the current step.
   * @throws IllegalArgumentException
   *           if the current step has not a previous step.
   */
  private Step previousStep(Step step)
  {
    Step previous = null;
    for (Step s : Step.values())
    {
      if (s == step)
      {
        return previous;
      }
      previous = s;
    }
    throw new IllegalArgumentException("No previous for step: " + step);
  }
 
  /**
   * Get the dialog that is displayed.
   *
   * @return the dialog.
   */
  private QuickSetupDialog getDialog()
  {
    if (dialog == null)
    {
      dialog = new QuickSetupDialog(getDefaultUserData(), installStatus);
      dialog.addButtonActionListener(this);
    }
    return dialog;
  }
 
  /**
   * Displays an error message dialog.
   *
   * @param msg
   *          the error message.
   * @param title
   *          the title for the dialog.
   */
  private void displayError(String msg, String title)
  {
    getDialog().displayError(msg, title);
  }
 
  /**
   * Displays a confirmation message dialog.
   *
   * @param msg
   *          the confirmation message.
   * @param title
   *          the title of the dialog.
   * @return <CODE>true</CODE> if the user confirms the message, or
   * <CODE>false</CODE> if not.
   */
  private boolean displayConfirmation(String msg, String title)
  {
    return getDialog().displayConfirmation(msg, title);
  }
 
  /**
   * Gets the string value for a given field name.
   *
   * @param fieldName
   *          the field name object.
   * @return the string value for the field name.
   */
  private String getFieldStringValue(FieldName fieldName)
  {
    String sValue = null;
 
    Object value = getFieldValue(fieldName);
    if (value != null)
    {
      if (value instanceof String)
      {
        sValue = (String) value;
      } else
      {
        sValue = String.valueOf(value);
      }
    }
    return sValue;
  }
 
  /**
   * Gets the value for a given field name.
   *
   * @param fieldName
   *          the field name object.
   * @return the value for the field name.
   */
  private Object getFieldValue(FieldName fieldName)
  {
    return getDialog().getFieldValue(fieldName);
  }
 
  /**
   * Marks the fieldName as valid or invalid depending on the value of the
   * invalid parameter. With the current implementation this implies basically
   * using a red color in the label associated with the fieldName object. The
   * color/style used to mark the label invalid is specified in UIFactory.
   *
   * @param fieldName
   *          the field name object.
   * @param invalid
   *          whether to mark the field valid or invalid.
   */
  private void displayFieldInvalid(FieldName fieldName, boolean invalid)
  {
    getDialog().displayFieldInvalid(fieldName, invalid);
  }
 
  /**
   * A method to initialize the look and feel.
   *
   */
  private void initLookAndFeel()
  {
    UIFactory.initialize();
  }
 
  /**
   * A methods that creates an InstallProgressDescriptor based on the value of a
   * InstallProgressUpdateEvent.
   *
   * @param ev
   *          the InstallProgressUpdateEvent used to generate the
   *          InstallProgressDescriptor.
   * @return the InstallProgressDescriptor.
   */
  private InstallProgressDescriptor createInstallProgressDescriptor(
      InstallProgressUpdateEvent ev)
  {
    InstallProgressStep status = ev.getProgressStep();
    String newProgressLabel = ev.getCurrentPhaseSummary();
    String additionalDetails = ev.getNewLogs();
    Integer ratio = ev.getProgressRatio();
 
    if (additionalDetails != null)
    {
      progressDetails.append(additionalDetails);
    }
 
    return new InstallProgressDescriptor(status, ratio, newProgressLabel,
        progressDetails.toString());
  }
 
  /**
   * A methods that creates an UninstallProgressDescriptor based on the value of
   * a UninstallProgressUpdateEvent.
   *
   * @param ev
   *          the UninstallProgressUpdateEvent used to generate the
   *          UninstallProgressDescriptor.
   * @return the InstallProgressDescriptor.
   */
  private UninstallProgressDescriptor createUninstallProgressDescriptor(
      UninstallProgressUpdateEvent ev)
  {
    UninstallProgressStep status = ev.getProgressStep();
    String newProgressLabel = ev.getCurrentPhaseSummary();
    String additionalDetails = ev.getNewLogs();
    Integer ratio = ev.getProgressRatio();
 
    if (additionalDetails != null)
    {
      progressDetails.append(additionalDetails);
    }
 
    return new UninstallProgressDescriptor(status, ratio, newProgressLabel,
        progressDetails.toString());
  }
 
  /**
   * Indicates whether we are in a web start installation or not.
   *
   * @return <CODE>true</CODE> if we are in a web start installation and
   *         <CODE>false</CODE> if not.
   */
  private boolean isWebStart()
  {
    return Utils.isWebStart();
  }
 
  /**
   * Provides the port that will be proposed to the user in the second page of
   * the installation wizard. It will check whether we can use 389 and if not it
   * will return -1.
   *
   * @return the port 389 if it is available and we can use and -1 if not.
   */
  private int getDefaultPort()
  {
    int defaultPort = -1;
 
    for (int i=0;i<10000 && (defaultPort == -1);i+=1000)
    {
      int port = i + 389;
      if (Utils.canUseAsPort(port))
      {
        defaultPort = port;
      }
    }
    return defaultPort;
  }
 
  /**
   * Returns the number of free disk space in bytes required to install Open DS
   *
   * For the moment we just return 15 Megabytes. TODO we might want to have
   * something dynamic to calculate the required free disk space for the
   * installation.
   *
   * @return the number of free disk space required to install Open DS.
   */
  private long getRequiredInstallSpace()
  {
    return 15 * 1024 * 1024;
  }
}
 
/**
 * This class is just used to specify which are the default values that will be
 * proposed to the user in the Data Options panel of the Installation wizard.
 *
 */
class DefaultDataOptions extends DataOptions
{
  /**
   * Default constructor.
   *
   */
  public DefaultDataOptions()
  {
    super(Type.CREATE_BASE_ENTRY, "dc=example,dc=com");
  }
 
  /**
   * Get the number of entries that will be automatically generated.
   *
   * @return the number of entries that will be automatically generated.
   */
  public int getNumberEntries()
  {
    return 2000;
  }
}