performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / operations / ToggleUserEnablementOperation.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.operations;
12
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18
19 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
20 import eu.etaxonomy.cdm.model.common.User;
21 import eu.etaxonomy.taxeditor.store.CdmStore;
22
23 /**
24 * <p>ToggleUserEnablementOperation class.</p>
25 *
26 * @author n.hoffmann
27 * @created 02.07.2009
28 * @version 1.0
29 */
30 public class ToggleUserEnablementOperation extends AbstractPersistentPostOperation {
31
32 private User user;
33
34 /**
35 * <p>Constructor for ToggleUserEnablementOperation.</p>
36 *
37 * @param label a {@link java.lang.String} object.
38 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
39 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
40 * @param user a {@link eu.etaxonomy.cdm.model.common.User} object.
41 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
42 */
43 public ToggleUserEnablementOperation(String label, IUndoContext undoContext,
44 User user, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
45 super(label, undoContext, postOperationEnabled, conversationEnabled);
46 this.user = user;
47 }
48
49 /* (non-Javadoc)
50 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
51 */
52 /** {@inheritDoc} */
53 @Override
54 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
55 throws ExecutionException {
56
57 bind();
58 monitor.worked(20);
59
60 user.setEnabled(! user.isEnabled());
61
62 CdmStore.getUserService().saveOrUpdate(user);
63 monitor.worked(40);
64
65 return postExecute(null);
66 }
67
68 /* (non-Javadoc)
69 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
70 */
71 /** {@inheritDoc} */
72 @Override
73 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
74 throws ExecutionException {
75 return execute(monitor, info);
76 }
77
78 /* (non-Javadoc)
79 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
80 */
81 /** {@inheritDoc} */
82 @Override
83 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
84 throws ExecutionException {
85 bind();
86 CdmStore.getUserService().createUser(user);
87 return postExecute(null);
88 }
89 }