View Javadoc
1   package org.argeo.people.ui.dialogs;
2   
3   import static org.argeo.eclipse.ui.EclipseUiUtils.isEmpty;
4   
5   import javax.jcr.Node;
6   
7   import org.argeo.connect.ui.ConnectUiUtils;
8   import org.argeo.eclipse.ui.EclipseUiUtils;
9   import org.argeo.people.PeopleException;
10  import org.argeo.people.PeopleNames;
11  import org.eclipse.jface.dialogs.MessageDialog;
12  import org.eclipse.jface.wizard.Wizard;
13  import org.eclipse.jface.wizard.WizardPage;
14  import org.eclipse.swt.SWT;
15  import org.eclipse.swt.events.ModifyEvent;
16  import org.eclipse.swt.events.ModifyListener;
17  import org.eclipse.swt.layout.GridData;
18  import org.eclipse.swt.layout.GridLayout;
19  import org.eclipse.swt.widgets.Composite;
20  import org.eclipse.swt.widgets.Text;
21  
22  /** Ask first & last name. Update the passed node on finish */
23  @Deprecated
24  class NewMailingListWizard extends Wizard implements PeopleNames {
25  	// private final static Log log = LogFactory.getLog(NewPersonWizard.class);
26  
27  	// Context
28  	@SuppressWarnings("unused")
29  	private Node mailingList;
30  
31  	// This page widgets
32  	protected Text nameTxt;
33  
34  	public NewMailingListWizard(Node mailingList) {
35  		this.mailingList = mailingList;
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 PeopleException("Cannot add page to wizard", e);
45  		}
46  		setWindowTitle("New Mailing List");
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 name = nameTxt.getText();
56  		if (EclipseUiUtils.isEmpty(name)) {
57  			MessageDialog.openError(getShell(), "Non-valid information", "Please enter a name that is not empty.");
58  			return false;
59  		} else {
60  			// TODO implement this
61  			return true;
62  		}
63  	}
64  
65  	@Override
66  	public boolean performCancel() {
67  		return true;
68  	}
69  
70  	@Override
71  	public boolean canFinish() {
72  		String name = nameTxt.getText();
73  		if (isEmpty(name)) {
74  			return false;
75  		} else
76  			return true;
77  	}
78  
79  	protected class MainInfoPage extends WizardPage {
80  		private static final long serialVersionUID = 1L;
81  
82  		public MainInfoPage(String pageName) {
83  			super(pageName);
84  			setTitle("Create a mailing list");
85  			setMessage("Please enter a name for the list to create");
86  		}
87  
88  		public void createControl(Composite parent) {
89  			parent.setLayout(new GridLayout(2, false));
90  
91  			// LastName
92  			ConnectUiUtils.createBoldLabel(parent, "Mailing list name");
93  			nameTxt = new Text(parent, SWT.BORDER);
94  			nameTxt.setMessage("a label");
95  			nameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
96  
97  			ModifyListener ml = new ModifyListener() {
98  				private static final long serialVersionUID = -1628130380128946886L;
99  
100 				@Override
101 				public void modifyText(ModifyEvent event) {
102 					getContainer().updateButtons();
103 				}
104 			};
105 
106 			nameTxt.addModifyListener(ml);
107 
108 			// Don't forget this.
109 			setControl(nameTxt);
110 			nameTxt.setFocus();
111 		}
112 	}
113 }