source: trunk/de.ugoe.cs.swe.exercises/src/de/ugoe/cs/swe/exercises/lecturer/LecturerEditDialog.java @ 19

Last change on this file since 19 was 19, checked in by zeiss, 15 years ago
  • Property svn:mime-type set to text/plain
File size: 3.9 KB
Line 
1package de.ugoe.cs.swe.exercises.lecturer;
2
3import org.eclipse.jface.dialogs.IMessageProvider;
4import org.eclipse.jface.dialogs.TitleAreaDialog;
5import org.eclipse.jface.resource.JFaceResources;
6import org.eclipse.swt.SWT;
7import org.eclipse.swt.events.SelectionAdapter;
8import org.eclipse.swt.events.SelectionEvent;
9import org.eclipse.swt.layout.GridData;
10import org.eclipse.swt.layout.GridLayout;
11import org.eclipse.swt.widgets.Button;
12import org.eclipse.swt.widgets.Composite;
13import org.eclipse.swt.widgets.Control;
14import org.eclipse.swt.widgets.Label;
15import org.eclipse.swt.widgets.Shell;
16import org.eclipse.swt.widgets.Text;
17
18public class LecturerEditDialog extends TitleAreaDialog {
19
20        private Text editTitle;
21        private Text editFirstName;
22        private Text editLastName;
23        private String[] lecturer = new String[4];
24        private Shell shell;
25
26        public String[] getLecturer() {
27                return lecturer;
28        }
29
30        public LecturerEditDialog(Shell parentShell) {
31                super(parentShell);
32                super.setShellStyle(0);
33                this.shell = parentShell;
34                shell.setEnabled(false);
35        }
36
37        @Override
38        protected Control createContents(Composite parent) {
39                Control contents = super.createContents(parent);
40                setTitle("Edit a lecturer");
41                setMessage("Edit the lecturers data", IMessageProvider.INFORMATION);
42                return contents;
43        }
44
45        @Override
46        protected Control createDialogArea(Composite parent) {
47
48                GridLayout layout = new GridLayout();
49                layout.numColumns = 2;
50                parent.setLayout(layout);
51                Label labelTitle = new Label(parent, SWT.NONE);
52                labelTitle.setText("Title");
53                Text textboxTitle = new Text(parent, SWT.BORDER);
54                textboxTitle.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
55                                | GridData.HORIZONTAL_ALIGN_FILL));
56        //      textboxTitle.setText(ViewLecturer.getEditTitle());
57                editTitle = textboxTitle;
58                Label labelFirstName = new Label(parent, SWT.NONE);
59                labelFirstName.setText("First name");
60                Text textboxFirstName = new Text(parent, SWT.BORDER);
61                textboxFirstName.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
62                                | GridData.HORIZONTAL_ALIGN_FILL));
63        //      textboxFirstName.setText(ViewLecturer.getEditFirstName());
64                editFirstName = textboxFirstName;
65                Label labelLastName = new Label(parent, SWT.NONE);
66                labelLastName.setText("Last name");
67                Text textboxLastName = new Text(parent, SWT.BORDER);
68                textboxLastName.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
69                                | GridData.HORIZONTAL_ALIGN_FILL));
70        //      textboxLastName.setText(ViewLecturer.getEditLastName());
71                //TODO: 3 kommentare ausklammern
72                editLastName = textboxLastName;
73
74                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
75                gd.horizontalSpan = 1;
76
77                return parent;
78
79        }
80
81        @Override
82        protected void createButtonsForButtonBar(Composite parent) {
83                ((GridLayout) parent.getLayout()).numColumns = 2;
84
85                GridData buttonlayout = new GridData(SWT.LEFT, SWT.BEGINNING, false,
86                                false);
87                buttonlayout.minimumWidth = 200;
88
89                Button buttonOk = new Button(parent, SWT.PUSH);
90                buttonOk.setText("OK");
91                buttonOk.setFont(JFaceResources.getDialogFont());
92                buttonOk.setLayoutData(buttonlayout);
93                buttonOk.addSelectionListener(new SelectionAdapter() {
94                        @Override
95                        public void widgetSelected(SelectionEvent e) {
96                                if (editTitle.getText().length() != 0
97                                                && editFirstName.getText().length() != 0
98                                                && editLastName.getText().length() != 0) {
99                                        lecturer[0] = "1";
100                                        lecturer[1] = editTitle.getText();
101                                        lecturer[2] = editFirstName.getText();
102                                        lecturer[3] = editLastName.getText();
103                                        shell.setEnabled(true);
104                                        close();
105
106                                } else {
107                                        setErrorMessage("Field can't be empty");
108                                }
109                        }
110                });
111                Button buttonCancel = new Button(parent, SWT.PUSH);
112                buttonCancel.setText("Cancel");
113                buttonCancel.setFont(JFaceResources.getDialogFont());
114                buttonCancel.setLayoutData(buttonlayout);
115                buttonCancel.addSelectionListener(new SelectionAdapter() {
116                        @Override
117                        public void widgetSelected(SelectionEvent e) {
118                                shell.setEnabled(true);
119                                close();
120                        }
121                });
122        }
123}
Note: See TracBrowser for help on using the repository browser.