1 package org.argeo.people.ui.dialogs;
2
3 import static org.argeo.eclipse.ui.EclipseUiUtils.isEmpty;
4
5 import javax.jcr.Node;
6 import javax.jcr.PropertyType;
7
8 import org.argeo.connect.ui.ConnectUiUtils;
9 import org.argeo.connect.util.ConnectJcrUtils;
10 import org.argeo.eclipse.ui.EclipseUiUtils;
11 import org.argeo.people.PeopleException;
12 import org.argeo.people.PeopleNames;
13 import org.argeo.people.ui.PeopleMsg;
14 import org.eclipse.jface.dialogs.MessageDialog;
15 import org.eclipse.jface.wizard.Wizard;
16 import org.eclipse.jface.wizard.WizardPage;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.ModifyEvent;
19 import org.eclipse.swt.events.ModifyListener;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Text;
24
25
26 public class NewPersonWizard extends Wizard implements PeopleNames {
27
28
29
30 private Node person;
31
32
33 protected Text lastNameTxt;
34 protected Text firstNameTxt;
35
36
37
38 public NewPersonWizard(Node person) {
39 this.person = person;
40 }
41
42 @Override
43 public void addPages() {
44 try {
45 MainInfoPage page = new MainInfoPage("Main page");
46 addPage(page);
47 } catch (Exception e) {
48 throw new PeopleException("Cannot add page to wizard", e);
49 }
50 setWindowTitle(PeopleMsg.personWizardWindowTitle.lead());
51 }
52
53
54
55
56
57 @Override
58 public boolean performFinish() {
59 String lastName = lastNameTxt.getText();
60 String firstName = firstNameTxt.getText();
61
62
63 if (EclipseUiUtils.isEmpty(lastName) && EclipseUiUtils.isEmpty(firstName)) {
64 MessageDialog.openError(getShell(), "Non-valid information",
65 "Please enter at least a name that is not empty.");
66 return false;
67 } else {
68 ConnectJcrUtils.setJcrProperty(person, PEOPLE_LAST_NAME, PropertyType.STRING, lastName);
69 ConnectJcrUtils.setJcrProperty(person, PEOPLE_FIRST_NAME, PropertyType.STRING, firstName);
70 String fullName = firstName + " " + lastName;
71
72 ConnectJcrUtils.setJcrProperty(person, PEOPLE_DISPLAY_NAME, PropertyType.STRING, fullName);
73
74
75
76 return true;
77 }
78 }
79
80 @Override
81 public boolean performCancel() {
82 return true;
83 }
84
85 @Override
86 public boolean canFinish() {
87 String lastName = lastNameTxt.getText();
88 String firstName = firstNameTxt.getText();
89 if (isEmpty(lastName) && isEmpty(firstName)) {
90 return false;
91 } else
92 return true;
93 }
94
95 protected class MainInfoPage extends WizardPage {
96 private static final long serialVersionUID = 1L;
97
98 public MainInfoPage(String pageName) {
99 super(pageName);
100 setTitle(PeopleMsg.personWizardPageTitle.lead());
101
102 }
103
104 public void createControl(Composite parent) {
105 parent.setLayout(new GridLayout(2, false));
106
107
108 ConnectUiUtils.createBoldLabel(parent, PeopleMsg.firstName.lead());
109 firstNameTxt = new Text(parent, SWT.BORDER);
110
111 firstNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
112
113
114 ConnectUiUtils.createBoldLabel(parent, PeopleMsg.lastName.lead());
115 lastNameTxt = new Text(parent, SWT.BORDER);
116
117 lastNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141 ModifyListener ml = new ModifyListener() {
142 private static final long serialVersionUID = -1628130380128946886L;
143
144 @Override
145 public void modifyText(ModifyEvent event) {
146 getContainer().updateButtons();
147 }
148 };
149
150 firstNameTxt.addModifyListener(ml);
151 lastNameTxt.addModifyListener(ml);
152
153
154
155 setControl(firstNameTxt);
156 firstNameTxt.setFocus();
157 }
158 }
159 }