fc5438caa2d0a1fb64d6c220a6396f21e1c5a04b
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / 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.user.handler;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.common.NotDefinedException;
18 import org.eclipse.jface.viewers.StructuredSelection;
19 import org.eclipse.ui.handlers.HandlerUtil;
20
21 import eu.etaxonomy.cdm.model.common.User;
22 import eu.etaxonomy.taxeditor.operations.AbstractPostOperation;
23 import eu.etaxonomy.taxeditor.operations.ToggleUserEnablementOperation;
24 import eu.etaxonomy.taxeditor.store.StoreUtil;
25 import eu.etaxonomy.taxeditor.user.view.UserManagerView;
26
27 /**
28 * @author n.hoffmann
29 * @created 02.07.2009
30 * @version 1.0
31 */
32 public class ToggleUserEnablementHandler extends AbstractHandler {
33 private static final Logger logger = Logger
34 .getLogger(ToggleUserEnablementHandler.class);
35
36 /* (non-Javadoc)
37 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
38 */
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 UserManagerView userManagerView = (UserManagerView) 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 logger.warn("Command name not set");
58 }
59 }
60
61 return null;
62 }
63 }