1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.adt.internal.wizards.exportgradle;
18 
19 import com.android.ide.eclipse.adt.internal.wizards.exportgradle.ExportStatus.FileStatus;
20 import com.google.common.collect.Multimap;
21 
22 import org.eclipse.jface.dialogs.Dialog;
23 import org.eclipse.jface.wizard.WizardPage;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Text;
28 
29 import java.io.File;
30 import java.util.Collection;
31 
32 /**
33  * Final page to review the result of the export.
34  */
35 public class FinalPage extends WizardPage {
36 
37     private final ProjectSetupBuilder mBuilder;
38     private ExportStatus mStatus;
39 
40     private Text mText;
41 
FinalPage(ProjectSetupBuilder builder)42     public FinalPage(ProjectSetupBuilder builder) {
43         super("FinalPage"); //$NON-NLS-1$
44         mBuilder = builder;
45         setPageComplete(true);
46         setTitle(ExportMessages.PageTitle);
47         setDescription(ExportMessages.PageDescription);
48     }
49 
50     @Override
createControl(Composite parent)51     public void createControl(Composite parent) {
52         initializeDialogUnits(parent);
53 
54         mText = new Text(parent, SWT.MULTI | SWT.READ_ONLY);
55         mText.setLayoutData(new GridData(GridData.FILL_BOTH
56                 | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
57 
58         setControl(mText);
59         Dialog.applyDialogFont(parent);
60     }
61 
62     @Override
setVisible(boolean visible)63     public void setVisible(boolean visible) {
64         super.setVisible(visible);
65         if (visible) {
66             mStatus = mBuilder.getStatus();
67             mBuilder.setCanFinish(!mStatus.hasError());
68             mBuilder.setCanGenerate(false);
69 
70             StringBuilder sb = new StringBuilder();
71             if (mStatus.hasError()) {
72                 sb.append("There was an error!").append("\n\n");
73 
74                 String errorMsg = mStatus.getErrorMessage();
75                 if (errorMsg != null) {
76                     sb.append(errorMsg);
77                 }
78 
79                 Multimap<FileStatus, File> fileStatusMap = mStatus.getFileStatus();
80                 Collection<File> files = fileStatusMap.values();
81                 if (files != null) {
82                     sb.append("\n\n").append("Error on files:").append('\n');
83                     for (File file : files) {
84                         sb.append("\n").append(file.getAbsolutePath());
85                     }
86                 }
87             } else {
88                 sb.append("Export successful.\n\n");
89 
90                 int count = mBuilder.getModuleCount();
91                 if (count > 1) {
92                     sb.append(String.format("Exported %s modules", count)).append('\n');
93                     sb.append(String.format(
94                             "Root folder: %s", mBuilder.getCommonRoot().toOSString()));
95                 } else {
96                     sb.append("Exported project: ").append(mBuilder.getCommonRoot().toOSString());
97                 }
98 
99                 sb.append("\n\n").append("Choose 'Import Non-Android Studio project' in Android Studio").append('\n');
100                 sb.append("and select the following file:").append("\n\t");
101 
102                 File bGradle = new File(
103                         mBuilder.getCommonRoot().toFile(), BuildFileCreator.BUILD_FILE);
104                 sb.append(bGradle.getAbsolutePath());
105 
106                 sb.append("\n\n").append("Do NOT import the Eclipse project itself!");
107             }
108 
109             mText.setText(sb.toString());
110         }
111     }
112 }