]> git.argeo.org Git - gpl/argeo-suite.git/blob - core/org.argeo.suite.ui/src/org/argeo/suite/ui/dialogs/NewPersonWizard.java
Support embedding videos.
[gpl/argeo-suite.git] / core / org.argeo.suite.ui / src / org / argeo / suite / ui / dialogs / NewPersonWizard.java
1 package org.argeo.suite.ui.dialogs;
2
3 import static org.argeo.eclipse.ui.EclipseUiUtils.isEmpty;
4
5 import javax.jcr.Node;
6
7 import org.argeo.eclipse.ui.EclipseUiUtils;
8 import org.argeo.suite.ui.SuiteMsg;
9 import org.argeo.suite.ui.SuiteUiUtils;
10 import org.eclipse.jface.dialogs.MessageDialog;
11 import org.eclipse.jface.wizard.Wizard;
12 import org.eclipse.jface.wizard.WizardPage;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.ModifyEvent;
15 import org.eclipse.swt.events.ModifyListener;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Text;
20
21 /** Ask first & last name. Update the passed node on finish */
22 public class NewPersonWizard extends Wizard {
23 // private final static Log log = LogFactory.getLog(NewPersonWizard.class);
24
25 // Context
26 private Node person;
27
28 // This page widgets
29 protected Text lastNameTxt;
30 protected Text firstNameTxt;
31 // private Button useDistinctDisplayNameBtn;
32 // private Text displayNameTxt;
33
34 public NewPersonWizard(Node person) {
35 this.person = person;
36 }
37
38 @Override
39 public void addPages() {
40 try {
41 MainInfoPage page = new MainInfoPage("Main page");
42 addPage(page);
43 } catch (Exception e) {
44 throw new RuntimeException("Cannot add page to wizard", e);
45 }
46 setWindowTitle(SuiteMsg.personWizardWindowTitle.lead());
47 }
48
49 /**
50 * Called when the user click on 'Finish' in the wizard. The task is then
51 * created and the corresponding session saved.
52 */
53 @Override
54 public boolean performFinish() {
55 String lastName = lastNameTxt.getText();
56 String firstName = firstNameTxt.getText();
57 // String displayName = displayNameTxt.getText();
58 // boolean useDistinct = useDistinctDisplayNameBtn.getSelection();
59 if (EclipseUiUtils.isEmpty(lastName) && EclipseUiUtils.isEmpty(firstName)) {
60 MessageDialog.openError(getShell(), "Non-valid information",
61 "Please enter at least a name that is not empty.");
62 return false;
63 } else {
64 // ConnectJcrUtils.setJcrProperty(person, PEOPLE_LAST_NAME, PropertyType.STRING, lastName);
65 // ConnectJcrUtils.setJcrProperty(person, PEOPLE_FIRST_NAME, PropertyType.STRING, firstName);
66 // String fullName = firstName + " " + lastName;
67 // ConnectJcrUtils.setJcrProperty(person, PEOPLE_DISPLAY_NAME, PropertyType.STRING, fullName);
68 return true;
69 }
70 }
71
72 @Override
73 public boolean performCancel() {
74 return true;
75 }
76
77 @Override
78 public boolean canFinish() {
79 String lastName = lastNameTxt.getText();
80 String firstName = firstNameTxt.getText();
81 if (isEmpty(lastName) && isEmpty(firstName)) {
82 return false;
83 } else
84 return true;
85 }
86
87 protected class MainInfoPage extends WizardPage {
88 private static final long serialVersionUID = 1L;
89
90 public MainInfoPage(String pageName) {
91 super(pageName);
92 setTitle(SuiteMsg.personWizardPageTitle.lead());
93 // setMessage("Please enter a last name and/or a first name.");
94 }
95
96 public void createControl(Composite parent) {
97 parent.setLayout(new GridLayout(2, false));
98
99 // FirstName
100 SuiteUiUtils.createBoldLabel(parent, SuiteMsg.firstName);
101 firstNameTxt = new Text(parent, SWT.BORDER);
102 // firstNameTxt.setMessage("a first name");
103 firstNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
104
105 // LastName
106 SuiteUiUtils.createBoldLabel(parent, SuiteMsg.lastName);
107 lastNameTxt = new Text(parent, SWT.BORDER);
108 // lastNameTxt.setMessage("a last name");
109 lastNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
110
111 // Display Name
112 // useDistinctDisplayNameBtn = new Button(parent, SWT.CHECK);
113 // useDistinctDisplayNameBtn.setText("Define a disting display name");
114 // useDistinctDisplayNameBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
115 // true, false, 2, 1));
116 //
117 // ConnectWorkbenchUtils.createBoldLabel(parent, "Display Name");
118 // displayNameTxt = new Text(parent, SWT.BORDER);
119 // displayNameTxt.setMessage("an optional display name");
120 // displayNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
121 // false));
122 // displayNameTxt.setEnabled(false);
123 //
124 // useDistinctDisplayNameBtn.addSelectionListener(new SelectionAdapter() {
125 // private static final long serialVersionUID = 1L;
126 //
127 // @Override
128 // public void widgetSelected(SelectionEvent e) {
129 // displayNameTxt.setEnabled(useDistinctDisplayNameBtn.getSelection());
130 // }
131 // });
132
133 ModifyListener ml = new ModifyListener() {
134 private static final long serialVersionUID = -1628130380128946886L;
135
136 @Override
137 public void modifyText(ModifyEvent event) {
138 getContainer().updateButtons();
139 }
140 };
141
142 firstNameTxt.addModifyListener(ml);
143 lastNameTxt.addModifyListener(ml);
144 // displayNameTxt.addModifyListener(ml);
145
146 // Don't forget this.
147 setControl(firstNameTxt);
148 firstNameTxt.setFocus();
149 }
150 }
151 }