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.List;
21
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.FocusAdapter;
24 import org.eclipse.swt.events.FocusEvent;
25 import org.eclipse.swt.events.SelectionAdapter;
26 import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.events.VerifyEvent;
28 import org.eclipse.swt.events.VerifyListener;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Group;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.swt.widgets.Text;
36
37 import pl.edu.agh.cast.importer.wizard.util.Messages;
38 import pl.edu.agh.cast.importer.wizard.utils.AbstractWizardPageHelper;
39
40
41
42
43
44
45 public class FixedWidthColumnSelectionPageComposite extends Composite {
46
47 private Group filePreviewGroup;
48
49 private Label createLineLbl;
50
51 private Label deleteLineLbl;
52
53 private ColumnBreaksSelectionComposite columnBreaksSelectionComposite;
54
55 private Composite instructionsComposite;
56
57 private Composite optionsComposite;
58
59 private Text commentCharTxt;
60
61 private Button commentCharChbox;
62
63 private FixedWidthColumnSelectionPage mediator;
64
65
66
67
68
69
70
71
72
73
74
75 public FixedWidthColumnSelectionPageComposite(Composite parent, int style, FixedWidthColumnSelectionPage mediator) {
76 super(parent, style);
77 this.mediator = mediator;
78 initGUI();
79 }
80
81 private void initGUI() {
82 GridLayout thisLayout = new GridLayout();
83 this.setLayout(thisLayout);
84 this.setSize(800, 600);
85
86 instructionsComposite = new Composite(this, SWT.NONE);
87 GridLayout instructionsCompositeLayout = new GridLayout();
88 instructionsCompositeLayout.makeColumnsEqualWidth = true;
89 GridData instructionsCompositeLData = new GridData();
90 instructionsCompositeLData.grabExcessHorizontalSpace = true;
91 instructionsCompositeLData.verticalAlignment = GridData.FILL;
92 instructionsCompositeLData.horizontalAlignment = GridData.FILL;
93 instructionsComposite.setLayoutData(instructionsCompositeLData);
94 instructionsComposite.setLayout(instructionsCompositeLayout);
95
96 createLineLbl = new Label(instructionsComposite, SWT.NONE);
97 createLineLbl.setText(Messages.FixedWidthColumnSelectionPageComposite_CreateColumnBreakLbl);
98
99 deleteLineLbl = new Label(instructionsComposite, SWT.NONE);
100 deleteLineLbl.setText(Messages.FixedWidthColumnSelectionPageComposite_DeleteColumnBreakLbl);
101
102 optionsComposite = new Composite(this, SWT.NONE);
103 GridLayout optionsCompositeLayout = new GridLayout();
104 optionsCompositeLayout.numColumns = 2;
105 optionsCompositeLayout.makeColumnsEqualWidth = true;
106 optionsCompositeLayout.horizontalSpacing = 20;
107 optionsCompositeLayout.verticalSpacing = 10;
108 GridData optionsCompositeLData = new GridData();
109 optionsCompositeLData.grabExcessVerticalSpace = true;
110 optionsCompositeLData.grabExcessHorizontalSpace = true;
111 optionsComposite.setLayout(optionsCompositeLayout);
112 optionsComposite.setLayoutData(optionsCompositeLData);
113
114 commentCharChbox = new Button(optionsComposite, SWT.CHECK | SWT.LEFT);
115 commentCharChbox.setText(Messages.DelimiterSelectionPageComposite_CommentChar);
116 GridData commentCharChboxLData = new GridData();
117 commentCharChboxLData.horizontalAlignment = GridData.FILL;
118 commentCharChboxLData.grabExcessHorizontalSpace = true;
119 commentCharChbox.setLayoutData(commentCharChboxLData);
120 commentCharChbox.setToolTipText(Messages.DelimiterSelectionPageComposite_CommentCharTooltip);
121 commentCharChbox.addSelectionListener(new SelectionAdapter() {
122 @Override
123 public void widgetSelected(SelectionEvent event) {
124 handleCommentCharValueChanged();
125 }
126 });
127
128 commentCharTxt = new Text(optionsComposite, SWT.BORDER);
129 GridData commentCharTxtLData = new GridData();
130 commentCharTxtLData.heightHint = 15;
131 commentCharTxtLData.horizontalAlignment = GridData.FILL;
132 commentCharTxtLData.grabExcessHorizontalSpace = true;
133 commentCharTxt.setLayoutData(commentCharTxtLData);
134 commentCharTxt.setEnabled(false);
135 commentCharTxt.addVerifyListener(new VerifyListener() {
136 public void verifyText(VerifyEvent event) {
137 AbstractWizardPageHelper.handleCommentCharVerification(event);
138 }
139 });
140 commentCharTxt.addFocusListener(new FocusAdapter() {
141 public void focusLost(FocusEvent e) {
142 handleCommentCharValueChanged();
143 }
144 });
145
146 filePreviewGroup = new Group(this, SWT.NONE);
147 GridLayout filePreviewGroupLayout = new GridLayout();
148 GridData filePreviewGroupLData = new GridData();
149 filePreviewGroupLData.horizontalSpan = 3;
150 filePreviewGroupLData.verticalAlignment = GridData.FILL;
151 filePreviewGroupLData.horizontalAlignment = GridData.FILL;
152 filePreviewGroupLData.minimumWidth = 550;
153 filePreviewGroupLData.minimumHeight = 150;
154 filePreviewGroupLData.grabExcessVerticalSpace = true;
155 filePreviewGroupLData.grabExcessHorizontalSpace = true;
156 filePreviewGroup.setLayout(filePreviewGroupLayout);
157 filePreviewGroup.setLayoutData(filePreviewGroupLData);
158 filePreviewGroup.setText(Messages.FixedWidthColumnSelectionPageComposite_FilePreview);
159
160 GridData columnBreaksSelectionCompositeLData = new GridData();
161 columnBreaksSelectionCompositeLData.grabExcessHorizontalSpace = true;
162 columnBreaksSelectionCompositeLData.grabExcessVerticalSpace = true;
163 columnBreaksSelectionCompositeLData.horizontalAlignment = GridData.FILL;
164 columnBreaksSelectionCompositeLData.verticalAlignment = GridData.FILL;
165 columnBreaksSelectionCompositeLData.heightHint = 400;
166 columnBreaksSelectionComposite = new ColumnBreaksSelectionComposite(filePreviewGroup);
167 columnBreaksSelectionComposite.setLayoutData(columnBreaksSelectionCompositeLData);
168
169 }
170
171
172
173
174
175
176
177 private void handleCommentCharValueChanged() {
178 if (commentCharChbox.getSelection()) {
179 commentCharTxt.setEnabled(true);
180 } else {
181 commentCharTxt.setEnabled(false);
182 }
183 mediator.notifyCommentOptionChanged();
184 }
185
186
187
188
189
190
191
192 void refreshFilePreviewGroupLabel(String selectedFilePath) {
193 if (selectedFilePath != null && selectedFilePath.length() > 0) {
194 final StringBuilder sb = new StringBuilder();
195 sb.append(Messages.InitImportPageComposite_FilePreview);
196 sb.append(": ");
197 sb.append(selectedFilePath);
198 filePreviewGroup.setText(sb.toString());
199 }
200 }
201
202
203
204
205
206
207
208
209
210 void refreshFilePreview(List<String> lines, List<Integer> cutLinePoints) {
211 columnBreaksSelectionComposite.showFilePreview(lines, cutLinePoints);
212 }
213
214
215
216
217
218
219
220
221
222
223
224
225 String getCommentCharOptionValue() {
226 final String commentChar = commentCharTxt.getText();
227 if (commentCharChbox.getSelection() && commentChar != null && !commentChar.isEmpty()) {
228 return commentCharTxt.getText();
229 }
230 return null;
231 }
232
233 List<Integer> getColumnBeaksIndices() {
234 return columnBreaksSelectionComposite.getColumnBreaksIndices();
235 }
236
237
238 }