1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.importer.wizard.page;
19
20 import java.io.File;
21
22 import org.eclipse.jface.wizard.IWizardPage;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.widgets.Composite;
25
26 import pl.edu.agh.cast.importer.base.data.DataRow;
27 import pl.edu.agh.cast.importer.base.data.ITabularData;
28 import pl.edu.agh.cast.importer.base.template.IImportTemplate;
29 import pl.edu.agh.cast.importer.base.util.ConversionPreviewGenerator;
30 import pl.edu.agh.cast.importer.wizard.strategy.ApplyTemplateWizardStrategy;
31 import pl.edu.agh.cast.importer.wizard.strategy.CreateTemplateWizardStrategy;
32 import pl.edu.agh.cast.importer.wizard.strategy.IImportWizardStrategy;
33 import pl.edu.agh.cast.importer.wizard.strategy.UseTemplateWizardStrategy;
34 import pl.edu.agh.cast.importer.wizard.strategy.WithoutTemplateWizardStrategy;
35 import pl.edu.agh.cast.importer.wizard.util.Messages;
36
37
38
39
40
41
42
43 public class InitImportPage extends AbstractImportWizardPage {
44 private InitImportPageComposite composite;
45
46 private WithoutTemplateWizardStrategy withoutTemplateStrategy = new WithoutTemplateWizardStrategy();
47
48 private ApplyTemplateWizardStrategy applyTemplateStrategy = new ApplyTemplateWizardStrategy();
49
50 private UseTemplateWizardStrategy useTemplateStrategy = new UseTemplateWizardStrategy();
51
52 private CreateTemplateWizardStrategy createTemplateStrategy = new CreateTemplateWizardStrategy();
53
54
55
56
57 public InitImportPage() {
58 super(Messages.ImporterWizard_InitImportPageTitle, Messages.ImporterWizard_InitImportPageDescription);
59 }
60
61
62
63
64
65
66 public void createControl(Composite parent) {
67 composite = new InitImportPageComposite(parent, SWT.NULL, this);
68 setControl(composite);
69 }
70
71 protected boolean isComplete() {
72 if (!isImportFileValid()) {
73 return false;
74 }
75 if (getSelectedImportStrategy() == applyTemplateStrategy && getImportProcess().getTemplate() == null) {
76 return false;
77 }
78 return true;
79 }
80
81
82
83
84
85
86
87
88
89
90
91
92 @Override
93 public IWizardPage getNextPage() {
94 getImportWizard().setImportStrategy(getSelectedImportStrategy());
95 return super.getNextPage();
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 public IImportWizardStrategy getSelectedImportStrategy() {
112 IImportWizardStrategy strategy;
113
114 if (composite == null) {
115 return null;
116 }
117
118 if (composite.isImportWithoutTemplateSelected()) {
119 strategy = withoutTemplateStrategy;
120 } else if (composite.isImportUseTemplateSelected()) {
121 strategy = useTemplateStrategy;
122 } else if (composite.isImportApplyTemplateSelected()) {
123 strategy = applyTemplateStrategy;
124 } else if (composite.isCreateTemplateSelected()) {
125 strategy = createTemplateStrategy;
126 } else {
127 throw new IllegalStateException("One of import strategies must be selected");
128 }
129
130 return strategy;
131 }
132
133
134
135
136
137
138
139 public void notifyTemplateSelection(IImportTemplate selectedTemplate) {
140 getImportProcess().setTemplate(selectedTemplate);
141 widgetModified();
142 }
143
144
145
146
147
148
149
150 public void notifyFilePathChange(String filePath) {
151 getImportProcess().setFilePath(filePath);
152 widgetModified();
153 }
154
155
156
157
158 public void notifyWizardStrategySelection() {
159 getImportWizard().setImportStrategy(getSelectedImportStrategy());
160 widgetModified();
161 }
162
163
164
165
166
167
168 public ITabularData<DataRow> getTemplateConversionPreview() {
169 if (getImportProcess().getTemplate() != null && getImportProcess().getFilePath() != null) {
170 final ConversionPreviewGenerator previewGenerator = new ConversionPreviewGenerator();
171 ITabularData<DataRow> preview = previewGenerator.generatePreview(getImportProcess().getTemplate(),
172 getImportProcess().getFilePath());
173
174 return preview;
175 }
176 return null;
177 }
178
179
180
181
182
183
184 private boolean isImportFileValid() {
185 if (getImportProcess().getFilePath() != null && new File(getImportProcess().getFilePath()).isFile()) {
186 return true;
187 }
188 return false;
189 }
190
191
192
193 }