|
Lines 39-44
Link Here
|
| 39 |
import org.eclipse.jface.viewers.LabelProvider; |
39 |
import org.eclipse.jface.viewers.LabelProvider; |
| 40 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
40 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 41 |
import org.eclipse.jface.viewers.Viewer; |
41 |
import org.eclipse.jface.viewers.Viewer; |
|
|
42 |
import org.eclipse.jface.viewers.ViewerFilter; |
| 42 |
import org.eclipse.jface.viewers.ViewerSorter; |
43 |
import org.eclipse.jface.viewers.ViewerSorter; |
| 43 |
import org.eclipse.jface.wizard.IWizardPage; |
44 |
import org.eclipse.jface.wizard.IWizardPage; |
| 44 |
import org.eclipse.jface.wizard.WizardPage; |
45 |
import org.eclipse.jface.wizard.WizardPage; |
|
Lines 58-63
Link Here
|
| 58 |
import org.eclipse.swt.SWT; |
59 |
import org.eclipse.swt.SWT; |
| 59 |
import org.eclipse.swt.events.KeyAdapter; |
60 |
import org.eclipse.swt.events.KeyAdapter; |
| 60 |
import org.eclipse.swt.events.KeyEvent; |
61 |
import org.eclipse.swt.events.KeyEvent; |
|
|
62 |
import org.eclipse.swt.events.KeyListener; |
| 63 |
import org.eclipse.swt.events.SelectionAdapter; |
| 61 |
import org.eclipse.swt.events.SelectionEvent; |
64 |
import org.eclipse.swt.events.SelectionEvent; |
| 62 |
import org.eclipse.swt.events.SelectionListener; |
65 |
import org.eclipse.swt.events.SelectionListener; |
| 63 |
import org.eclipse.swt.graphics.Color; |
66 |
import org.eclipse.swt.graphics.Color; |
|
Lines 67-78
Link Here
|
| 67 |
import org.eclipse.swt.widgets.Button; |
70 |
import org.eclipse.swt.widgets.Button; |
| 68 |
import org.eclipse.swt.widgets.Composite; |
71 |
import org.eclipse.swt.widgets.Composite; |
| 69 |
import org.eclipse.swt.widgets.Control; |
72 |
import org.eclipse.swt.widgets.Control; |
| 70 |
import org.eclipse.swt.widgets.Display; |
|
|
| 71 |
import org.eclipse.swt.widgets.Label; |
73 |
import org.eclipse.swt.widgets.Label; |
| 72 |
import org.eclipse.swt.widgets.TableColumn; |
74 |
import org.eclipse.swt.widgets.TableColumn; |
| 73 |
import org.eclipse.swt.widgets.TableItem; |
75 |
import org.eclipse.swt.widgets.TableItem; |
|
|
76 |
import org.eclipse.swt.widgets.Text; |
| 74 |
import org.eclipse.ui.PlatformUI; |
77 |
import org.eclipse.ui.PlatformUI; |
| 75 |
import org.eclipse.ui.help.IWorkbenchHelpSystem; |
78 |
import org.eclipse.ui.help.IWorkbenchHelpSystem; |
|
|
79 |
import org.eclipse.ui.internal.navigator.StringMatcher; |
| 76 |
|
80 |
|
| 77 |
public class TablesSelectorWizardPage extends WizardPage { |
81 |
public class TablesSelectorWizardPage extends WizardPage { |
| 78 |
|
82 |
|
|
Lines 90-95
Link Here
|
| 90 |
private Button refreshTablesButton; |
94 |
private Button refreshTablesButton; |
| 91 |
private Button selectAllButton; |
95 |
private Button selectAllButton; |
| 92 |
private Button deselectAllButton; |
96 |
private Button deselectAllButton; |
|
|
97 |
private Text searchText; |
| 98 |
private TableFilter filter; |
| 93 |
|
99 |
|
| 94 |
private WorkspaceJob fetchTablesJob; |
100 |
private WorkspaceJob fetchTablesJob; |
| 95 |
protected final ResourceManager resourceManager; |
101 |
protected final ResourceManager resourceManager; |
|
Lines 192-201
Link Here
|
| 192 |
tableLabel.setLayoutData(gridData); |
198 |
tableLabel.setLayoutData(gridData); |
| 193 |
tableLabel.setText(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_tables ); |
199 |
tableLabel.setText(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_tables ); |
| 194 |
|
200 |
|
|
|
201 |
this.searchText = this.buildSearchText(parent); |
| 202 |
|
| 203 |
// build two empty labels to align the components |
| 204 |
new Label(parent, SWT.NONE); |
| 205 |
new Label(parent, SWT.NONE); |
| 206 |
|
| 195 |
TableLayoutComposite layout = new TableLayoutComposite(parent, SWT.NONE); |
207 |
TableLayoutComposite layout = new TableLayoutComposite(parent, SWT.NONE); |
| 196 |
this.addColumnLayoutData(layout); |
208 |
this.addColumnLayoutData(layout); |
| 197 |
|
209 |
|
|
|
210 |
filter = new TableFilter(); |
| 198 |
this.tableTable = this.buildCheckboxTableViewer(this.buildTable(layout)); |
211 |
this.tableTable = this.buildCheckboxTableViewer(this.buildTable(layout)); |
|
|
212 |
this.tableTable.addFilter(filter); |
| 199 |
|
213 |
|
| 200 |
this.createButtonComposite(parent); |
214 |
this.createButtonComposite(parent); |
| 201 |
this.initTablesSelectionControl(this.possibleTables()); |
215 |
this.initTablesSelectionControl(this.possibleTables()); |
|
Lines 454-459
Link Here
|
| 454 |
return new TableTableContentProvider(); |
468 |
return new TableTableContentProvider(); |
| 455 |
} |
469 |
} |
| 456 |
|
470 |
|
|
|
471 |
private Text buildSearchText(Composite parent) { |
| 472 |
GridData gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); |
| 473 |
Text text = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL); |
| 474 |
text.setMessage(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_tableSearch); |
| 475 |
text.setLayoutData(gridData); |
| 476 |
text.addSelectionListener(this.buildClearSearchTextSelectionListener()); |
| 477 |
text.addKeyListener(this.buildSearchTextKeyListener()); |
| 478 |
return text; |
| 479 |
} |
| 480 |
|
| 457 |
// ********** listeners callbacks ********** |
481 |
// ********** listeners callbacks ********** |
| 458 |
|
482 |
|
| 459 |
private void handleTablesListSelectionChanged(SelectionChangedEvent event) { |
483 |
private void handleTablesListSelectionChanged(SelectionChangedEvent event) { |
|
Lines 534-539
Link Here
|
| 534 |
|
558 |
|
| 535 |
public void widgetSelected(SelectionEvent e) { |
559 |
public void widgetSelected(SelectionEvent e) { |
| 536 |
refreshTables(); |
560 |
refreshTables(); |
|
|
561 |
} |
| 562 |
}; |
| 563 |
} |
| 564 |
|
| 565 |
private SelectionListener buildClearSearchTextSelectionListener() { |
| 566 |
return new SelectionAdapter() { |
| 567 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 568 |
filter.setPattern(""); |
| 569 |
tableTable.refresh(); |
| 570 |
} |
| 571 |
}; |
| 572 |
} |
| 573 |
|
| 574 |
private KeyListener buildSearchTextKeyListener() { |
| 575 |
return new KeyAdapter() { |
| 576 |
public void keyReleased(KeyEvent event) { |
| 577 |
filter.setPattern(searchText.getText()); |
| 578 |
tableTable.refresh(); |
| 537 |
} |
579 |
} |
| 538 |
}; |
580 |
}; |
| 539 |
} |
581 |
} |
|
Lines 764-767
Link Here
|
| 764 |
return ((Collection<?>) inputElement).toArray(); |
806 |
return ((Collection<?>) inputElement).toArray(); |
| 765 |
} |
807 |
} |
| 766 |
} |
808 |
} |
| 767 |
} |
809 |
|
|
|
810 |
private class TableFilter extends ViewerFilter { |
| 811 |
|
| 812 |
private String pattern; |
| 813 |
private StringMatcher matcher; |
| 814 |
private static final String ALL = "*"; //$NON-NLS-1$ |
| 815 |
|
| 816 |
/** |
| 817 |
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
| 818 |
*/ |
| 819 |
@Override |
| 820 |
public boolean select (Viewer viewer, Object parentElement, Object element) { |
| 821 |
Table table = (Table) element; |
| 822 |
if (pattern == null || pattern.length() == 0) { |
| 823 |
return true; |
| 824 |
} |
| 825 |
// if a table is previously selected, it will show up |
| 826 |
// in the viewer along with the list of tables filtered out |
| 827 |
if (tableTable.getChecked(table)) { |
| 828 |
return true; |
| 829 |
} |
| 830 |
if (matcher.match(table.getName())) { |
| 831 |
return true; |
| 832 |
} |
| 833 |
return false; |
| 834 |
} |
| 835 |
|
| 836 |
/** |
| 837 |
* Set the pattern to filter out tables for the table viewer |
| 838 |
* <p> |
| 839 |
* The following characters have special meaning: |
| 840 |
* ? => any character |
| 841 |
* * => any string |
| 842 |
* </p> |
| 843 |
* @param newPattern the new search pattern |
| 844 |
*/ |
| 845 |
protected void setPattern(String newPattern) { |
| 846 |
if (newPattern == null || newPattern.trim().length() == 0) { |
| 847 |
matcher = new StringMatcher(ALL, true, false); |
| 848 |
} else { |
| 849 |
pattern = newPattern + ALL; |
| 850 |
matcher = new StringMatcher(pattern, true, false); |
| 851 |
} |
| 852 |
} |
| 853 |
} |
| 854 |
} |