fixes #1407
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / user / wizard / UserWizard.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.user.wizard;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.core.commands.operations.IUndoableOperation;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.jface.wizard.Wizard;
17
18 import eu.etaxonomy.cdm.model.common.User;
19 import eu.etaxonomy.taxeditor.operations.CreateUserOperation;
20 import eu.etaxonomy.taxeditor.operations.EditUserOperation;
21 import eu.etaxonomy.taxeditor.store.StoreUtil;
22 import eu.etaxonomy.taxeditor.user.view.UserManagerView;
23
24 /**
25 * @author n.hoffmann
26 * @created 02.07.2009
27 * @version 1.0
28 */
29 public class UserWizard extends Wizard {
30 private static final Logger logger = Logger.getLogger(UserWizard.class);
31 private User user;
32 private UserWizardPage page;
33 private UserManagerView view;
34 private boolean createMode;
35
36 public UserWizard(UserManagerView view){
37 this.view = view;
38 setWindowTitle("User Wizard");
39 createMode = true;
40 }
41
42 public UserWizard(UserManagerView view, User user){
43 this(view);
44 if(user != null){
45 this.user = user;
46 createMode = false;
47 }
48 }
49
50 /* (non-Javadoc)
51 * @see org.eclipse.jface.wizard.Wizard#addPages()
52 */
53 @Override
54 public void addPages() {
55 super.addPages();
56
57 page = new UserWizardPage(user);
58
59 addPage(page);
60
61 }
62
63 /* (non-Javadoc)
64 * @see org.eclipse.jface.wizard.Wizard#performFinish()
65 */
66 @Override
67 public boolean performFinish() {
68
69 IUndoableOperation operation;
70 if(createMode){
71 operation = new CreateUserOperation("Create User",
72 StoreUtil.getUndoContext(), page.getUser(), view, view);
73 }else{
74 operation = new EditUserOperation("Edit User",
75 StoreUtil.getUndoContext(), page.getUser(), view, view);
76 }
77
78 return StoreUtil.executeOperation(operation) == Status.OK_STATUS ? true : false;
79 }
80
81 }