13
13
14
14
import java .io .IOException ;
15
15
import java .lang .reflect .InvocationTargetException ;
16
+ import java .util .ArrayList ;
16
17
import java .util .Comparator ;
17
18
import java .util .List ;
18
19
import java .util .concurrent .TimeoutException ;
25
26
import org .eclipse .codewind .core .internal .ProcessHelper .ProcessResult ;
26
27
import org .eclipse .codewind .core .internal .connection .CodewindConnection ;
27
28
import org .eclipse .codewind .core .internal .console .ProjectTemplateInfo ;
29
+ import org .eclipse .codewind .core .internal .constants .ProjectLanguage ;
30
+ import org .eclipse .codewind .core .internal .constants .ProjectType ;
31
+ import org .eclipse .codewind .ui .CodewindUIPlugin ;
28
32
import org .eclipse .codewind .ui .internal .messages .Messages ;
29
33
import org .eclipse .codewind .ui .internal .views .ViewHelper ;
30
34
import org .eclipse .core .resources .IProject ;
41
45
import org .eclipse .swt .events .ModifyListener ;
42
46
import org .eclipse .swt .events .SelectionAdapter ;
43
47
import org .eclipse .swt .events .SelectionEvent ;
48
+ import org .eclipse .swt .graphics .Point ;
44
49
import org .eclipse .swt .layout .GridData ;
45
50
import org .eclipse .swt .layout .GridLayout ;
51
+ import org .eclipse .swt .widgets .Button ;
46
52
import org .eclipse .swt .widgets .Composite ;
53
+ import org .eclipse .swt .widgets .Control ;
54
+ import org .eclipse .swt .widgets .Display ;
47
55
import org .eclipse .swt .widgets .Event ;
48
56
import org .eclipse .swt .widgets .Group ;
49
57
import org .eclipse .swt .widgets .Label ;
50
58
import org .eclipse .swt .widgets .Listener ;
59
+ import org .eclipse .swt .widgets .Menu ;
60
+ import org .eclipse .swt .widgets .MenuItem ;
61
+ import org .eclipse .swt .widgets .Shell ;
51
62
import org .eclipse .swt .widgets .Table ;
52
63
import org .eclipse .swt .widgets .TableColumn ;
53
64
import org .eclipse .swt .widgets .TableItem ;
@@ -65,6 +76,7 @@ public class NewCodewindProjectPage extends WizardPage {
65
76
private Table selectionTable ;
66
77
private Text descriptionLabel ;
67
78
private Text projectNameText ;
79
+ private List <Integer > styleList = new ArrayList <Integer >();
68
80
69
81
protected NewCodewindProjectPage (CodewindConnection connection , List <ProjectTemplateInfo > templateList ) {
70
82
super (Messages .NewProjectPage_ShellTitle );
@@ -137,12 +149,20 @@ private void createContents(Composite parent) {
137
149
layout .marginWidth = 8 ;
138
150
layout .horizontalSpacing = 7 ;
139
151
layout .verticalSpacing = 7 ;
152
+ layout .numColumns = 2 ;
140
153
templateGroup .setLayout (layout );
141
154
templateGroup .setLayoutData (new GridData (GridData .FILL , GridData .FILL , true , false , 2 , 1 ));
142
155
156
+ // Style selection button
157
+ final Button styleButton = new Button (templateGroup , SWT .PUSH | SWT .RIGHT_TO_LEFT );
158
+ styleButton .setText ("Select Styles" );
159
+ styleButton .setToolTipText ("Select the styles to work with" );
160
+ styleButton .setImage (CodewindUIPlugin .getImage (CodewindUIPlugin .MENU_DOWN_ICON ));
161
+ styleButton .setLayoutData (new GridData (GridData .BEGINNING , GridData .BEGINNING , false , false ));
162
+
143
163
// Filter text
144
164
filterText = new Text (templateGroup , SWT .BORDER );
145
- filterText .setLayoutData (new GridData (SWT .FILL , SWT .FILL , true , false , 2 , 1 ));
165
+ filterText .setLayoutData (new GridData (SWT .FILL , SWT .FILL , true , false ));
146
166
filterText .setMessage (Messages .NewProjectPage_FilterMessage );
147
167
148
168
// Table
@@ -152,29 +172,38 @@ private void createContents(Composite parent) {
152
172
selectionTable .setLayoutData (data );
153
173
154
174
// Columns
155
- final TableColumn featureColumn = new TableColumn (selectionTable , SWT .NONE );
156
- featureColumn .setText (Messages .NewProjectPage_TypeColumn );
157
- featureColumn .setResizable (true );
158
- featureColumn .addSelectionListener (new SelectionAdapter () {
175
+ final TableColumn templateColumn = new TableColumn (selectionTable , SWT .NONE );
176
+ templateColumn .setText (Messages .NewProjectPage_TemplateColumn );
177
+ templateColumn .setResizable (true );
178
+ templateColumn .addSelectionListener (new SelectionAdapter () {
179
+ @ Override
180
+ public void widgetSelected (SelectionEvent event ) {
181
+ sortTable (selectionTable , templateColumn );
182
+ }
183
+ });
184
+ final TableColumn typeColumn = new TableColumn (selectionTable , SWT .NONE );
185
+ typeColumn .setText (Messages .NewProjectPage_TypeColumn );
186
+ typeColumn .setResizable (true );
187
+ typeColumn .addSelectionListener (new SelectionAdapter () {
159
188
@ Override
160
189
public void widgetSelected (SelectionEvent event ) {
161
- sortTable (selectionTable , featureColumn );
190
+ sortTable (selectionTable , typeColumn );
162
191
}
163
192
});
164
- final TableColumn nameColumn = new TableColumn (selectionTable , SWT .NONE );
165
- nameColumn .setText (Messages .NewProjectPage_LanguageColumn );
166
- nameColumn .setResizable (true );
167
- nameColumn .addSelectionListener (new SelectionAdapter () {
193
+ final TableColumn languageColumn = new TableColumn (selectionTable , SWT .NONE );
194
+ languageColumn .setText (Messages .NewProjectPage_LanguageColumn );
195
+ languageColumn .setResizable (true );
196
+ languageColumn .addSelectionListener (new SelectionAdapter () {
168
197
@ Override
169
198
public void widgetSelected (SelectionEvent event ) {
170
- sortTable (selectionTable , nameColumn );
199
+ sortTable (selectionTable , languageColumn );
171
200
}
172
201
});
173
202
174
203
selectionTable .setHeaderVisible (true );
175
204
selectionTable .setLinesVisible (false );
176
205
selectionTable .setSortDirection (SWT .DOWN );
177
- selectionTable .setSortColumn (featureColumn );
206
+ selectionTable .setSortColumn (templateColumn );
178
207
179
208
createItems (selectionTable , "" );
180
209
@@ -188,7 +217,7 @@ public void widgetSelected(SelectionEvent event) {
188
217
descriptionLabel .setForeground (templateGroup .getForeground ());
189
218
descriptionScroll .setContent (descriptionLabel );
190
219
191
- data = new GridData (GridData .FILL , GridData .FILL , true , false );
220
+ data = new GridData (GridData .FILL , GridData .FILL , true , false , 2 , 1 );
192
221
int lineHeight = filterText .computeSize (SWT .DEFAULT , SWT .DEFAULT ).y ;
193
222
data .heightHint = lineHeight * 2 ;
194
223
data .horizontalSpan = 2 ;
@@ -199,6 +228,17 @@ public void widgetSelected(SelectionEvent event) {
199
228
descriptionScroll .setForeground (templateGroup .getForeground ());
200
229
201
230
// Listeners
231
+ final Shell shell = getShell ();
232
+ styleButton .addSelectionListener (new SelectionAdapter () {
233
+ @ Override
234
+ public void widgetSelected (SelectionEvent e ) {
235
+ final Menu menu = new Menu (shell , SWT .POP_UP );
236
+ fillFilterMenu (menu );
237
+ displayDropdownMenu (styleButton , menu , true );
238
+ menu .dispose ();
239
+ }
240
+ });
241
+
202
242
filterText .addModifyListener (new ModifyListener () {
203
243
@ Override
204
244
public void modifyText (ModifyEvent event ) {
@@ -303,18 +343,20 @@ private void createItems(Table table, String filter) {
303
343
// Create the items for the table.
304
344
table .removeAll ();
305
345
pattern .setPattern ("*" + filter + "*" );
306
- for (ProjectTemplateInfo template : templateList ) {
307
- String type = template .getLabel ();
308
- String language = template .getLanguage ();
309
- if (pattern .matches (type ) || (language != null && pattern .matches (language ))) {
346
+ for (ProjectTemplateInfo templateInfo : templateList ) {
347
+ String template = templateInfo .getLabel ();
348
+ String type = ProjectType .getDisplayName (templateInfo .getProjectType ());
349
+ String language = ProjectLanguage .getDisplayName (templateInfo .getLanguage ());
350
+ if (pattern .matches (template ) || (type != null && pattern .matches (type )) || (language != null && pattern .matches (language ))) {
310
351
TableItem item = new TableItem (table , SWT .NONE );
311
352
item .setForeground (table .getForeground ());
312
353
item .setBackground (table .getBackground ());
313
- item .setText (0 , type );
354
+ item .setText (0 , template );
355
+ item .setText (1 , type );
314
356
if (language != null ) {
315
- item .setText (1 , language );
357
+ item .setText (2 , language );
316
358
}
317
- item .setData (template );
359
+ item .setData (templateInfo );
318
360
}
319
361
}
320
362
}
@@ -476,4 +518,52 @@ private void getTemplates() {
476
518
Logger .logError ("An error occurred trying to get the list of templates" , e ); //$NON-NLS-1$
477
519
}
478
520
}
521
+
522
+ protected void fillFilterMenu (final Menu menu ) {
523
+ final SelectionAdapter listener = new SelectionAdapter () {
524
+ @ Override
525
+ public void widgetSelected (SelectionEvent event ) {
526
+ MenuItem item = (MenuItem ) event .getSource ();
527
+ if (item .getSelection ()) {
528
+ if (item .getData () == null ) {
529
+ styleList .clear ();
530
+ } else {
531
+ styleList .add ((Integer )item .getData ());
532
+ }
533
+ } else {
534
+ if (item .getData () != null ) {
535
+ styleList .remove (item .getData ());
536
+ }
537
+ }
538
+ // Update template list
539
+ }
540
+ };
541
+
542
+ MenuItem item ;
543
+ item = new MenuItem (menu , SWT .CHECK );
544
+ item .setText ("All Styles" );
545
+ item .setSelection (styleList .isEmpty ());
546
+ item .addSelectionListener (listener );
547
+ for (int i = 1 ; i < 5 ; i ++) {
548
+ item = new MenuItem (menu , SWT .CHECK );
549
+ item .setText ("Style" + i );
550
+ item .setData (new Integer (i ));
551
+ item .setSelection (styleList .contains (item .getData ()));
552
+ item .addSelectionListener (listener );
553
+ }
554
+ }
555
+
556
+ protected void displayDropdownMenu (Control anchor , Menu menu , boolean subtractWidth ) {
557
+ Point size = anchor .getSize ();
558
+ Point point = anchor .toDisplay (0 , size .y );
559
+ menu .setLocation (point .x - (subtractWidth ? size .x : 0 ), point .y );
560
+ menu .setVisible (true );
561
+
562
+ while (!menu .isDisposed () && menu .isVisible ()) {
563
+ Display display = menu .getShell ().getDisplay ();
564
+ if (!display .readAndDispatch ()) {
565
+ display .sleep ();
566
+ }
567
+ }
568
+ }
479
569
}
0 commit comments