1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.setup.Controller;
25 
26 import java.util.Vector;
27 import org.openoffice.setup.InstallData;
28 import org.openoffice.setup.PanelController;
29 import org.openoffice.setup.Panel.ChooseComponents;
30 import org.openoffice.setup.ResourceManager;
31 import org.openoffice.setup.SetupData.PackageDescription;
32 import org.openoffice.setup.SetupData.SetupDataProvider;
33 import org.openoffice.setup.Util.Calculator;
34 import org.openoffice.setup.Util.Dumper;
35 import org.openoffice.setup.Util.Informer;
36 import org.openoffice.setup.Util.ModuleCtrl;
37 import org.openoffice.setup.Util.PackageCollector;
38 
39 public class ChooseComponentsCtrl extends PanelController {
40 
41     private String helpFile;
42 
ChooseComponentsCtrl()43     public ChooseComponentsCtrl() {
44         super("ChooseComponents", new ChooseComponents());
45         helpFile = "String_Helpfile_ChooseComponents";
46     }
47 
getNext()48     public String getNext() {
49         return new String("InstallationImminent");
50     }
51 
getPrevious()52     public String getPrevious() {
53 
54         InstallData data = InstallData.getInstance();
55 
56         if ( data.isRootInstallation() ) {
57             if ( data.sameVersionExists() ) {
58                 if ( data.hideEula() ) {
59                     return new String("Prologue");
60                 } else {
61                     return new String("AcceptLicense");
62                 }
63             } else {
64                 return new String("ChooseInstallationType");
65             }
66         } else {
67             if ( data.sameVersionExists() ) {
68                 return new String("ChooseDirectory");
69             } else {
70                 return new String("ChooseInstallationType");
71             }
72         }
73     }
74 
getHelpFileName()75     public final String getHelpFileName () {
76         return this.helpFile;
77     }
78 
beforeShow()79     public void beforeShow() {
80 
81         InstallData data = InstallData.getInstance();
82 
83         // Setting the package size for node modules, that have hidden children
84         // -> Java module has three hidden children and 0 byte size
85 
86         if ( ! data.moduleSizeSet() ) {
87             PackageDescription packageData = SetupDataProvider.getPackageDescription();
88             ModuleCtrl.setModuleSize(packageData);
89             data.setModuleSizeSet(true);
90         }
91 
92         if ( data.sameVersionExists() ) {
93             ChooseComponents panel = (ChooseComponents)getPanel();
94             String dialogTitle = ResourceManager.getString("String_ChooseComponents1_Maintain");
95             panel.setTitleText(dialogTitle);
96         }
97 
98     }
99 
afterShow(boolean nextButtonPressed)100     public boolean afterShow(boolean nextButtonPressed) {
101         boolean repeatDialog = false;
102 
103         InstallData data = InstallData.getInstance();
104         PackageDescription packageData = SetupDataProvider.getPackageDescription();
105 
106         if ( nextButtonPressed ) {
107 
108             // Check, if at least one visible module was selected for installation
109             data.setVisibleModulesChecked(false);
110             ModuleCtrl.checkVisibleModulesInstall(packageData, data);
111 
112             if ( data.visibleModulesChecked() ) {
113 
114                 // Check, if at least one application module was selected for installation
115                 // (not necessary, if an older product is updated or additional modules are
116                 // added in maintenance mode).
117 
118                 boolean applicationSelected = false;
119                 if ( data.olderVersionExists() || data.sameVersionExists() ) {
120                     applicationSelected = true;
121                 } else {
122                     data.setApplicationModulesChecked(false);
123                     ModuleCtrl.checkApplicationSelection(packageData, data);
124                     applicationSelected = data.applicationModulesChecked();
125                 }
126 
127                 if ( applicationSelected ) {
128 
129                     // Check, if at least one language module was selected for installation
130                     // (not necessary, if an older product is updated or additional modules are
131                     // added in maintenance mode).
132 
133                     boolean languageSelected = false;
134                     if ( data.olderVersionExists() || data.sameVersionExists() || ( ! data.isMultiLingual())) {
135                         languageSelected = true;
136                     } else {
137                         data.setLanguageModulesChecked(false);
138                         ModuleCtrl.checkLanguageSelection(packageData, data);
139                         languageSelected = data.languageModulesChecked();
140                     }
141 
142                     if ( languageSelected ) {
143 
144                         // Set module settings for hidden modules.
145                         // Then it is possible to calculate the size of the installed product,
146                         // to show a warning and to set the repeatDialog value to true
147 
148                         if ( data.logModuleStates() ) {
149                             Dumper.logModuleStates(packageData, "ChooseComponentsCtrl: Before setHiddenModuleSettingsInstall");
150                         }
151 
152                         ModuleCtrl.setHiddenModuleSettingsInstall(packageData);
153                         // Dumper.dumpInstallPackages(packageData);
154 
155                         if ( data.logModuleStates() ) {
156                             Dumper.logModuleStates(packageData, "ChooseComponentsCtrl: After setHiddenModuleSettingsInstall");
157                         }
158 
159                         // Collecting packages to install
160                         Vector installPackages = new Vector();
161                         PackageCollector.collectInstallPackages(packageData, installPackages);
162                         data.setInstallPackages(installPackages);
163 
164                         // Check disc space
165                         if ( Calculator.notEnoughDiscSpace(data) ) {
166                             repeatDialog = true;
167                             System.err.println("Not enough disc space");
168                         }
169                     } else {   // no language modules selected for installation
170                         String message = ResourceManager.getString("String_No_Language_Selected_1") + "\n" +
171                                          ResourceManager.getString("String_No_Language_Selected_2");
172                         String title = ResourceManager.getString("String_Change_Selection");
173                         Informer.showInfoMessage(message, title);
174                         repeatDialog = true;
175                     }
176                 } else {
177                     String message = ResourceManager.getString("String_No_Application_Selected_1") + "\n" +
178                                      ResourceManager.getString("String_No_Application_Selected_2");
179                     String title = ResourceManager.getString("String_Change_Selection");
180                     Informer.showInfoMessage(message, title);
181                     repeatDialog = true;
182                 }
183             } else {  // no modules selected for installation
184                 String message = ResourceManager.getString("String_No_Components_Selected_1") + "\n" +
185                                  ResourceManager.getString("String_No_Components_Selected_2");
186                 String title = ResourceManager.getString("String_Nothing_To_Install");
187                 Informer.showInfoMessage(message, title);
188                 repeatDialog = true;
189             }
190         } else {  // the back button was pressed
191             // Saving typical selection state values (always if back button is pressed!).
192             // System.err.println("Saving custom selection states");
193             ModuleCtrl.saveCustomSelectionStates(packageData);
194             data.setCustomSelectionStateSaved(true);
195         }
196 
197         return repeatDialog;
198     }
199 
200 }
201