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

Last change on this file since 3 was 3, checked in by zeiss, 15 years ago
  • Property svn:mime-type set to text/plain
File size: 4.1 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                parent.getShell().setSize(500, 240);
40                int x = shell.getLocation().x + (shell.getSize().x - parent.getShell().getSize().x)/2;
41                int y = shell.getLocation().y + (shell.getSize().y - parent.getShell().getSize().y)/2;
42                parent.getShell().setLocation(x, y);
43               
44                Control contents = super.createContents(parent);
45                setTitle("Edit a lecturer");
46                setMessage("Edit the lecturers data", IMessageProvider.INFORMATION);
47                return contents;
48        }
49
50        @Override
51        protected Control createDialogArea(Composite parent) {
52
53                GridLayout layout = new GridLayout();
54                layout.numColumns = 2;
55                parent.setLayout(layout);
56                Label labelTitle = new Label(parent, SWT.NONE);
57                labelTitle.setText("Title");
58                Text textboxTitle = new Text(parent, SWT.BORDER);
59                textboxTitle.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
60                                | GridData.HORIZONTAL_ALIGN_FILL));
61        //      textboxTitle.setText(ViewLecturer.getEditTitle());
62                editTitle = textboxTitle;
63                Label labelFirstName = new Label(parent, SWT.NONE);
64                labelFirstName.setText("First name");
65                Text textboxFirstName = new Text(parent, SWT.BORDER);
66                textboxFirstName.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
67                                | GridData.HORIZONTAL_ALIGN_FILL));
68        //      textboxFirstName.setText(ViewLecturer.getEditFirstName());
69                editFirstName = textboxFirstName;
70                Label labelLastName = new Label(parent, SWT.NONE);
71                labelLastName.setText("Last name");
72                Text textboxLastName = new Text(parent, SWT.BORDER);
73                textboxLastName.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
74                                | GridData.HORIZONTAL_ALIGN_FILL));
75        //      textboxLastName.setText(ViewLecturer.getEditLastName());
76                //TODO: 3 kommentare ausklammern
77                editLastName = textboxLastName;
78
79                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
80                gd.horizontalSpan = 1;
81
82                return parent;
83
84        }
85
86        @Override
87        protected void createButtonsForButtonBar(Composite parent) {
88                ((GridLayout) parent.getLayout()).numColumns = 2;
89
90                GridData buttonlayout = new GridData(SWT.LEFT, SWT.BEGINNING, false,
91                                false);
92                buttonlayout.minimumWidth = 200;
93
94                Button buttonOk = new Button(parent, SWT.PUSH);
95                buttonOk.setText("OK");
96                buttonOk.setFont(JFaceResources.getDialogFont());
97                buttonOk.setLayoutData(buttonlayout);
98                buttonOk.addSelectionListener(new SelectionAdapter() {
99                        @Override
100                        public void widgetSelected(SelectionEvent e) {
101                                if (editTitle.getText().length() != 0
102                                                && editFirstName.getText().length() != 0
103                                                && editLastName.getText().length() != 0) {
104                                        lecturer[0] = "1";
105                                        lecturer[1] = editTitle.getText();
106                                        lecturer[2] = editFirstName.getText();
107                                        lecturer[3] = editLastName.getText();
108                                        shell.setEnabled(true);
109                                        close();
110
111                                } else {
112                                        setErrorMessage("Field can't be empty");
113                                }
114                        }
115                });
116                Button buttonCancel = new Button(parent, SWT.PUSH);
117                buttonCancel.setText("Cancel");
118                buttonCancel.setFont(JFaceResources.getDialogFont());
119                buttonCancel.setLayoutData(buttonlayout);
120                buttonCancel.addSelectionListener(new SelectionAdapter() {
121                        @Override
122                        public void widgetSelected(SelectionEvent e) {
123                                shell.setEnabled(true);
124                                close();
125                        }
126                });
127        }
128}
Note: See TracBrowser for help on using the repository browser.