]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserTransactionHandler.java
Plug automatic refresh of the transaction edition commands.
[lgpl/argeo-commons.git] / org.argeo.security.ui.admin / src / org / argeo / security / ui / admin / commands / UserTransactionHandler.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security.ui.admin.commands;
17
18 import javax.transaction.Status;
19 import javax.transaction.UserTransaction;
20
21 import org.argeo.ArgeoException;
22 import org.argeo.security.ui.admin.SecurityAdminPlugin;
23 import org.argeo.security.ui.admin.internal.UiAdminUtils;
24 import org.eclipse.core.commands.AbstractHandler;
25 import org.eclipse.core.commands.ExecutionEvent;
26 import org.eclipse.core.commands.ExecutionException;
27
28 /** Manage the transaction that is bound to the current perspective */
29 public class UserTransactionHandler extends AbstractHandler {
30 public final static String ID = SecurityAdminPlugin.PLUGIN_ID
31 + ".userTransactionHandler";
32
33 public final static String PARAM_COMMAND_ID = "param.commandId";
34
35 public final static String TRANSACTION_BEGIN = "transaction.begin";
36 public final static String TRANSACTION_COMMIT = "transaction.commit";
37 public final static String TRANSACTION_ROLLBACK = "transaction.rollback";
38
39 private UserTransaction userTransaction;
40
41 public Object execute(ExecutionEvent event) throws ExecutionException {
42
43 String commandId = event.getParameter(PARAM_COMMAND_ID);
44 try {
45 if (TRANSACTION_BEGIN.equals(commandId)) {
46 if (userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION)
47 throw new ArgeoException("A transaction already exists");
48 else
49 userTransaction.begin();
50 } else if (TRANSACTION_COMMIT.equals(commandId)) {
51 if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION)
52 throw new ArgeoException("No transaction.");
53 else
54 userTransaction.commit();
55 } else if (TRANSACTION_ROLLBACK.equals(commandId)) {
56 if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION)
57 throw new ArgeoException("No transaction to rollback.");
58 else
59 userTransaction.rollback();
60 }
61 UiAdminUtils.notifyTransactionStateChange(userTransaction);
62 } catch (ArgeoException e) {
63 throw e;
64 } catch (Exception e) {
65 throw new ArgeoException("Unable to call " + commandId + " on "
66 + userTransaction, e);
67 }
68 //
69 // IWorkbenchWindow iww = HandlerUtil.getActiveWorkbenchWindow(event);
70 // if (iww == null)
71 // return null;
72 // IWorkbenchPage activePage = iww.getActivePage();
73 // IWorkbenchPart part = activePage.getActivePart();
74 // if (part instanceof UsersView)
75 // ((UsersView) part).refresh();
76 // else if (part instanceof GroupsView)
77 // ((GroupsView) part).refresh();
78 return null;
79 }
80
81 public void setUserTransaction(UserTransaction userTransaction) {
82 this.userTransaction = userTransaction;
83 }
84 }