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.Installer.Installer;
28 import org.openoffice.setup.Installer.InstallerFactory;
29 import org.openoffice.setup.PanelController;
30 import org.openoffice.setup.Panel.UninstallationOngoing;
31 import org.openoffice.setup.SetupData.PackageDescription;
32 import org.openoffice.setup.SetupData.SetupDataProvider;
33 import org.openoffice.setup.Util.InfoDir;
34 import org.openoffice.setup.Util.LogManager;
35 import org.openoffice.setup.Util.PackageCollector;
36 import java.util.Vector;
37 public class UninstallationOngoingCtrl extends PanelController {
38 
39     private String helpFile;
40 
UninstallationOngoingCtrl()41     public UninstallationOngoingCtrl() {
42         super("UninstallationOngoing", new UninstallationOngoing());
43         helpFile = "String_Helpfile_UninstallationOngoing";
44     }
45 
getNext()46     public String getNext() {
47         return new String("UninstallationCompleted");
48     }
49 
getPrevious()50     public String getPrevious() {
51         return new String("UninstallationImminent");
52     }
53 
getHelpFileName()54     public final String getHelpFileName () {
55         return this.helpFile;
56     }
57 
beforeShow()58     public void beforeShow() {
59         getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_PREVIOUS);
60         getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_NEXT);
61         getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_CANCEL);
62         getSetupFrame().setButtonSelected(getSetupFrame().BUTTON_HELP);
63 
64         UninstallationOngoing panel = (UninstallationOngoing)getPanel();
65         panel.setStopButtonActionCommand(getSetupFrame().ACTION_STOP);
66         panel.addStopButtonActionListener(getSetupFrame().getSetupActionListener());
67 
68         // creating list of packages to uninstall
69         InstallData data = InstallData.getInstance();
70         Vector uninstallPackages = new Vector();
71         PackageDescription packageData = SetupDataProvider.getPackageDescription();
72         PackageCollector.collectUninstallPackages(packageData, uninstallPackages);
73 
74         Vector sortedPackages = new Vector();
75         PackageCollector.sortPackages(uninstallPackages, sortedPackages, "uninstall");
76         data.setInstallPackages(sortedPackages);
77 
78         // collectPackages(packageData);
79 
80         Installer installer = InstallerFactory.getInstance();
81         installer.preInstallationOngoing();
82     }
83 
duringShow()84     public void duringShow() {
85 
86         Thread t = new Thread() {
87 
88             UninstallationOngoing panel = (UninstallationOngoing)getPanel();
89             InstallData installData = InstallData.getInstance();
90             Vector uninstallPackages = installData.getInstallPackages();
91 
92             public void run() {
93                 LogManager.setCommandsHeaderLine("Uninstallation");
94                 Installer installer = InstallerFactory.getInstance();
95 
96                 for (int i = 0; i < uninstallPackages.size(); i++) {
97                     PackageDescription packageData = (PackageDescription) uninstallPackages.get(i);
98                     int progress = java.lang.Math.round((100*(i+1))/uninstallPackages.size());
99                     panel.setProgressValue(progress);
100                     panel.setProgressText(packageData.getPackageName());
101 
102                     installer.uninstallPackage(packageData);
103 
104                     if ( installData.isAbortedInstallation() ) {
105                         break;
106                     }
107                 }
108 
109                 if ( installData.isAbortedInstallation() ) {
110                     LogManager.setCommandsHeaderLine("Uninstallation aborted!");
111                     // undoing the uninstallation is not possible
112                 }
113 
114                 installer.postUninstallationOngoing();
115 
116                 String next = getNext();
117                 getSetupFrame().setCurrentPanel(next, false, true);
118             }
119          };
120 
121          t.start();
122 
123     }
124 
afterShow(boolean nextButtonPressed)125     public boolean afterShow(boolean nextButtonPressed) {
126         boolean repeatDialog = false;
127         getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_PREVIOUS);
128         getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_NEXT);
129         getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_CANCEL);
130 
131         InstallData data = InstallData.getInstance();
132 
133         if ( ! data.isAbortedInstallation() ) {
134             if (( data.isTypicalInstallation() ) || ( data.isMaskedCompleteUninstallation() )) {
135                 InfoDir.removeUninstallationFiles();
136             }
137         }
138 
139         return repeatDialog;
140     }
141 
142 }
143