| 1 | package de.uka.ipd.sdq.pcm.dialogs.resource; |
| 2 | |
| 3 | |
| 4 | import org.eclipse.jface.dialogs.*; |
| 5 | import org.eclipse.swt.SWT; |
| 6 | import org.eclipse.swt.events.SelectionAdapter; |
| 7 | import org.eclipse.swt.events.SelectionEvent; |
| 8 | import org.eclipse.swt.layout.*; |
| 9 | import org.eclipse.swt.widgets.*; |
| 10 | |
| 11 | |
| 12 | import de.uka.ipd.sdq.pcm.resourceenvironment.SchedulingPolicy; |
| 13 | |
| 14 | public class SelectSchedulingPolicyElementDialog extends TitleAreaDialog{ |
| 15 | |
| 16 | private SchedulingPolicy policy = null; |
| 17 | private Button CANCELbutton; |
| 18 | |
| 19 | public SelectSchedulingPolicyElementDialog(Shell parentShell/*, SchedulingPolicy policy*/) { |
| 20 | super(parentShell); |
| 21 | //this.policy = policy; |
| 22 | } |
| 23 | |
| 24 | public boolean close() { |
| 25 | return super.close(); |
| 26 | } |
| 27 | |
| 28 | protected Control createContents(Composite parent) { |
| 29 | Control contents = super.createContents(parent); |
| 30 | |
| 31 | // Set the title |
| 32 | setTitle("Scheduling Policy"); |
| 33 | |
| 34 | // Set the message |
| 35 | setMessage("Select a scheduling policy", IMessageProvider.INFORMATION); |
| 36 | return contents; |
| 37 | } |
| 38 | |
| 39 | protected Control createDialogArea(Composite parent) { |
| 40 | Composite composite = (Composite) super.createDialogArea(parent); |
| 41 | |
| 42 | // Create a table |
| 43 | final Table table = new Table(composite, SWT.FULL_SELECTION | SWT.BORDER); |
| 44 | table.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 45 | |
| 46 | // Create two columns and show |
| 47 | TableColumn one = new TableColumn(table, SWT.LEFT); |
| 48 | one.setText("Scheduling Policy"); |
| 49 | |
| 50 | table.setHeaderVisible(true); |
| 51 | |
| 52 | // Add data to table |
| 53 | TableItem item; |
| 54 | for (SchedulingPolicy pol : SchedulingPolicy.VALUES) { |
| 55 | item = new TableItem(table, SWT.NONE); |
| 56 | item.setText(0,pol.getName()); |
| 57 | } |
| 58 | one.pack(); |
| 59 | |
| 60 | table.addListener(SWT.Selection, new Listener() { |
| 61 | public void handleEvent(Event e) { |
| 62 | TableItem[] selection = table.getSelection(); |
| 63 | policy = SchedulingPolicy.get(selection[0].getText()); |
| 64 | } |
| 65 | }); |
| 66 | table.addListener(SWT.DefaultSelection, new Listener() { |
| 67 | public void handleEvent(Event e) { |
| 68 | TableItem[] selection = table.getSelection(); |
| 69 | policy = SchedulingPolicy.get(selection[0].getText()); |
| 70 | close(); |
| 71 | } |
| 72 | }); |
| 73 | |
| 74 | return composite; |
| 75 | } |
| 76 | |
| 77 | protected void createButtonsForButtonBar(Composite parent) { |
| 78 | CANCELbutton = createButton(parent, IDialogConstants.CANCEL_ID, |
| 79 | IDialogConstants.CANCEL_LABEL, false); |
| 80 | CANCELbutton.addSelectionListener(new SelectionAdapter(){ |
| 81 | |
| 82 | /* (non-Javadoc) |
| 83 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 84 | */ |
| 85 | @Override |
| 86 | public void widgetSelected(SelectionEvent e) { |
| 87 | policy = null; |
| 88 | } |
| 89 | }); |
| 90 | createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); |
| 91 | } |
| 92 | |
| 93 | public SchedulingPolicy getResult() { |
| 94 | return policy; |
| 95 | } |
| 96 | |
| 97 | } |