Merged refactoring from development branch.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / account / user / handler / ToggleUserEnablementHandler.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.account.user.handler;
12
13 import org.eclipse.core.commands.AbstractHandler;
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.core.commands.common.NotDefinedException;
17 import org.eclipse.jface.viewers.StructuredSelection;
18 import org.eclipse.ui.handlers.HandlerUtil;
19
20 import eu.etaxonomy.cdm.model.common.User;
21 import eu.etaxonomy.taxeditor.account.user.operation.ToggleUserEnablementOperation;
22 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
23 import eu.etaxonomy.taxeditor.store.StoreUtil;
24 import eu.etaxonomy.taxeditor.view.user.UserView;
25
26 /**
27 * <p>ToggleUserEnablementHandler class.</p>
28 *
29 * @author n.hoffmann
30 * @created 02.07.2009
31 * @version 1.0
32 */
33 public class ToggleUserEnablementHandler extends AbstractHandler {
34
35 /* (non-Javadoc)
36 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
37 */
38 /** {@inheritDoc} */
39 public Object execute(ExecutionEvent event) throws ExecutionException {
40
41 StructuredSelection menuSelection = (StructuredSelection) HandlerUtil.getActiveMenuSelection(event);
42
43 for (Object object : menuSelection.toArray()){
44
45 User user = (User) object;
46
47 // TODO refresh the list -> set postOperationEnabled to the real deal
48 UserView userManagerView = (UserView) HandlerUtil.getActivePart(event);
49
50 AbstractPostOperation operation = null;
51 try {
52 operation = new ToggleUserEnablementOperation(event.getCommand().getName(),
53 StoreUtil.getUndoContext(), user, userManagerView, userManagerView);
54
55 StoreUtil.executeOperation(operation);
56 } catch (NotDefinedException e) {
57 StoreUtil.warn(this.getClass(), "Command name not set");
58 }
59 }
60
61 return null;
62 }
63 }