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 org.openoffice.setup.InstallData;
27 import org.openoffice.setup.PanelController;
28 import org.openoffice.setup.Panel.ChooseUninstallationType;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import org.openoffice.setup.SetupData.PackageDescription;
32 import org.openoffice.setup.SetupData.SetupDataProvider;
33 import org.openoffice.setup.Util.ModuleCtrl;
34 
35 public class ChooseUninstallationTypeCtrl extends PanelController implements ActionListener {
36 
37     private String helpFile;
38 
ChooseUninstallationTypeCtrl()39     public ChooseUninstallationTypeCtrl() {
40         super("ChooseUninstallationType", new ChooseUninstallationType());
41         helpFile = "String_Helpfile_ChooseUninstallationType";
42     }
43 
getNext()44     public String getNext() {
45 
46         InstallData data = InstallData.getInstance();
47 
48         if ( data.getInstallationType().equals(data.getCustomActionCommand()) ) {
49             return new String("ChooseUninstallationComponents");
50         } else if ( data.getInstallationType().equals(data.getTypicalActionCommand()) ) {
51             return new String("UninstallationImminent");
52         } else {
53             System.err.println("Error: Unknown uninstallation type!" );
54             return new String("Error");
55         }
56     }
57 
getPrevious()58     public String getPrevious() {
59         return new String("UninstallationPrologue");
60     }
61 
beforeShow()62     public void beforeShow() {
63 
64         InstallData data = InstallData.getInstance();
65 
66         ChooseUninstallationType panel = (ChooseUninstallationType)getPanel();
67         panel.setActionListener((ChooseUninstallationTypeCtrl)this);
68         panel.setCompleteActionCommand(data.getTypicalActionCommand());
69         panel.setCustomActionCommand(data.getCustomActionCommand());
70     }
71 
afterShow(boolean nextButtonPressed)72     public boolean afterShow(boolean nextButtonPressed) {
73         boolean repeatDialog = false;
74 
75         ChooseUninstallationType panel = (ChooseUninstallationType)getPanel();
76         panel.removeActionListener((ChooseUninstallationTypeCtrl)this);
77 
78         if ( nextButtonPressed ) {
79 
80             InstallData data = InstallData.getInstance();
81             PackageDescription packageData = SetupDataProvider.getPackageDescription();
82 
83             // Typical uninstallation type
84             if ( data.getInstallationType().equals(data.getTypicalActionCommand()) ) {
85                 // If typical selection state values have been saved before,
86                 // it is now time to restore them
87 
88                 if ( data.typicalSelectionStateSaved()) {
89                     ModuleCtrl.restoreTypicalSelectionStates(packageData);
90                 }
91             }
92 
93             // Custom uninstallation type
94             if ( data.getInstallationType().equals(data.getCustomActionCommand())) {
95                 // Saving typical selection state values, if they are not already saved.
96                 if ( ! data.typicalSelectionStateSaved()) {
97                     ModuleCtrl.saveTypicalSelectionStates(packageData);
98                     data.setTypicalSelectionStateSaved(true);
99                 }
100 
101                 // Setting custom selection state values, if they have been saved before.
102                 if ( data.customSelectionStateSaved() ) {
103                     ModuleCtrl.restoreCustomSelectionStates(packageData);
104                 }
105             }
106         }
107 
108         return repeatDialog;
109     }
110 
actionPerformed(ActionEvent evt)111     public void actionPerformed(ActionEvent evt) {
112 
113         InstallData data = InstallData.getInstance();
114 
115         if (evt.getActionCommand().equals(data.getTypicalActionCommand())) {
116             data.setInstallationType(data.getTypicalActionCommand());
117             // System.err.println("Setting uninstallation type: " +  data.getTypicalActionCommand());
118         } else if (evt.getActionCommand().equals(data.getCustomActionCommand())) {
119             data.setInstallationType(data.getCustomActionCommand());
120             // System.err.println("Setting uninstallation type: " +  data.getCustomActionCommand());
121         }
122 
123     }
124 
getHelpFileName()125     public final String getHelpFileName () {
126         return this.helpFile;
127     }
128 
129 }
130