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.util.LinkedList;
21 import java.util.List;
22
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.widgets.Composite;
25
26 import pl.edu.agh.cast.importer.base.data.RawTabularData;
27 import pl.edu.agh.cast.importer.base.tokenizer.ITokenizerOption;
28 import pl.edu.agh.cast.importer.base.tokenizer.TokenizerOption;
29 import pl.edu.agh.cast.importer.base.tokenizer.fixedwidth.FixedWidthTokenizer;
30 import pl.edu.agh.cast.importer.wizard.util.Messages;
31
32
33
34
35
36
37 public class FixedWidthColumnSelectionPage extends AbstractImportWizardPage {
38
39 private FixedWidthColumnSelectionPageComposite composite;
40
41 private String filePathCache;
42
43
44
45
46 public FixedWidthColumnSelectionPage() {
47 super(Messages.ImporterWizard_FixedWidthColumnSelectionPageTitle,
48 Messages.ImporterWizard_FixedWidthColumnSelectionPageDescription);
49 }
50
51
52
53
54
55
56
57
58
59
60
61
62 @Override
63 public void createControl(Composite parent) {
64 composite = new FixedWidthColumnSelectionPageComposite(parent, SWT.NULL, this);
65 setControl(composite);
66
67 refreshSelectedData();
68 }
69
70 @Override
71 protected boolean isComplete() {
72 return true;
73 }
74
75
76
77
78
79
80 @Override
81 public void initPage() {
82 refreshSelectedData();
83 }
84
85
86
87
88
89
90 @Override
91 public void refreshImportData() {
92 getImportProcess().setTokenizerOptions(getSelectedTokenizerOptions());
93 }
94
95
96
97
98
99
100
101
102
103 private void refreshSelectedData() {
104 if (composite == null) {
105 return;
106 }
107
108 if (filePathCache != null && getImportProcess().getFilePath().equals(filePathCache)) {
109 refreshImportData();
110 }
111
112 final RawTabularData preview = getImportProcess().getTokenizePreview();
113 composite.refreshFilePreviewGroupLabel(getImportProcess().getFilePath());
114 final FixedWidthTokenizer tokenizer = (FixedWidthTokenizer)getImportProcess().getTokenizer();
115 composite.refreshFilePreview(tokenizer.getInputFileLines().subList(0, preview.size()), tokenizer
116 .getLineCutPoints());
117
118 filePathCache = getImportProcess().getFilePath();
119 }
120
121
122
123
124 void notifyCommentOptionChanged() {
125 refreshSelectedData();
126 }
127
128 private List<ITokenizerOption> getSelectedTokenizerOptions() {
129 final List<ITokenizerOption> options = new LinkedList<ITokenizerOption>();
130
131 if (composite.getCommentCharOptionValue() != null) {
132 options.add(new TokenizerOption(FixedWidthTokenizer.COMMENT_CHAR_OPTION_NAME, composite
133 .getCommentCharOptionValue()));
134 }
135
136 options.add(new TokenizerOption(FixedWidthTokenizer.CUT_POINTS_OPTION_NAME, FixedWidthTokenizer
137 .pointListToString(composite.getColumnBeaksIndices())));
138
139 return options;
140 }
141
142
143 }