| 1 | package de.uka.ipd.sdq.sensorframework.dialogs.dataset; |
| 2 | |
| 3 | import org.eclipse.jface.wizard.WizardPage; |
| 4 | import org.eclipse.swt.SWT; |
| 5 | import org.eclipse.swt.events.SelectionEvent; |
| 6 | import org.eclipse.swt.events.SelectionListener; |
| 7 | import org.eclipse.swt.layout.GridData; |
| 8 | import org.eclipse.swt.layout.GridLayout; |
| 9 | import org.eclipse.swt.widgets.Combo; |
| 10 | import org.eclipse.swt.widgets.Composite; |
| 11 | import org.eclipse.swt.widgets.Label; |
| 12 | |
| 13 | public class WizardSelectDatasourcePage extends WizardPage { |
| 14 | |
| 15 | /**String constants for existing data sources */ |
| 16 | public static String MEMORY_DATASRC = "Memory Datasource"; |
| 17 | public static String FILE_DATASRC = "File Datasource"; |
| 18 | |
| 19 | private Combo myCombo; |
| 20 | protected String result = ""; |
| 21 | private String pageName; |
| 22 | private boolean memoryEntry, db40Entry, fileEntry; |
| 23 | |
| 24 | protected WizardSelectDatasourcePage(String pageName, boolean memoryEntry, |
| 25 | boolean db40Entry, boolean fileEntry) { |
| 26 | super(pageName); |
| 27 | this.pageName = pageName; |
| 28 | this.memoryEntry = memoryEntry; |
| 29 | this.db40Entry = db40Entry; |
| 30 | this.fileEntry = fileEntry; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | /* (non-Javadoc) |
| 35 | * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
| 36 | */ |
| 37 | public void createControl(Composite parent) { |
| 38 | |
| 39 | initializeDialogUnits(parent); |
| 40 | Composite topLevel = new Composite(parent, SWT.NONE); |
| 41 | topLevel.setLayout(new GridLayout()); |
| 42 | topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL |
| 43 | | GridData.HORIZONTAL_ALIGN_FILL)); |
| 44 | topLevel.setFont(parent.getFont()); |
| 45 | setControl(topLevel); |
| 46 | createPageContent(topLevel); |
| 47 | this.setPageComplete(false); |
| 48 | } |
| 49 | |
| 50 | private void createPageContent(Composite parent) { |
| 51 | Composite panel = new Composite(parent, SWT.NONE); |
| 52 | panel.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 53 | GridLayout layout = new GridLayout(); |
| 54 | panel.setLayout(layout); |
| 55 | |
| 56 | Label label = new Label(panel, SWT.NONE); |
| 57 | label.setText(pageName + ":"); |
| 58 | label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); |
| 59 | |
| 60 | myCombo = new Combo(panel, SWT.DROP_DOWN | SWT.READ_ONLY); |
| 61 | populateComboBox(); |
| 62 | myCombo.addSelectionListener(new SelectionListener() { |
| 63 | |
| 64 | public void widgetDefaultSelected(SelectionEvent e) { |
| 65 | WizardSelectDatasourcePage.this.result = myCombo.getText(); |
| 66 | WizardSelectDatasourcePage.this.setPageComplete(!myCombo |
| 67 | .getText().equals("")); |
| 68 | } |
| 69 | |
| 70 | public void widgetSelected(SelectionEvent e) { |
| 71 | WizardSelectDatasourcePage.this.result = myCombo.getText(); |
| 72 | WizardSelectDatasourcePage.this.setPageComplete(!myCombo |
| 73 | .getText().equals("")); |
| 74 | } |
| 75 | |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | private void populateComboBox() { |
| 80 | if (memoryEntry) |
| 81 | myCombo.add(MEMORY_DATASRC); |
| 82 | if (fileEntry) |
| 83 | myCombo.add(FILE_DATASRC); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /* (non-Javadoc) |
| 88 | * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage() |
| 89 | */ |
| 90 | @Override |
| 91 | public boolean canFlipToNextPage() { |
| 92 | boolean canFlip = !myCombo.getText().equals(""); |
| 93 | canFlip = canFlip |
| 94 | && (myCombo.getText().equals(FILE_DATASRC)); |
| 95 | |
| 96 | return super.canFlipToNextPage() && canFlip; |
| 97 | } |
| 98 | |
| 99 | public String getResult() { |
| 100 | return result; |
| 101 | } |
| 102 | } |