2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.security
.ui
.admin
.commands
;
18 import javax
.transaction
.Status
;
19 import javax
.transaction
.UserTransaction
;
21 import org
.argeo
.ArgeoException
;
22 import org
.argeo
.security
.ui
.admin
.SecurityAdminPlugin
;
23 import org
.eclipse
.core
.commands
.AbstractHandler
;
24 import org
.eclipse
.core
.commands
.ExecutionEvent
;
25 import org
.eclipse
.core
.commands
.ExecutionException
;
27 /** Manage the transaction that is bound to the current perspective */
28 public class UserTransactionHandler
extends AbstractHandler
{
29 public final static String ID
= SecurityAdminPlugin
.PLUGIN_ID
30 + ".userTransactionHandler";
32 public final static String PARAM_COMMAND_ID
= "param.commandId";
34 public final static String TRANSACTION_BEGIN
= "transaction.begin";
35 public final static String TRANSACTION_COMMIT
= "transaction.commit";
36 public final static String TRANSACTION_ROLLBACK
= "transaction.rollback";
38 private UserTransaction userTransaction
;
40 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
42 String commandId
= event
.getParameter(PARAM_COMMAND_ID
);
44 if (TRANSACTION_BEGIN
.equals(commandId
)) {
45 if (userTransaction
.getStatus() != Status
.STATUS_NO_TRANSACTION
)
46 throw new ArgeoException("A transaction already exists");
48 userTransaction
.begin();
49 } else if (TRANSACTION_COMMIT
.equals(commandId
)) {
50 if (userTransaction
.getStatus() == Status
.STATUS_NO_TRANSACTION
)
51 throw new ArgeoException("No transaction.");
53 userTransaction
.commit();
54 } else if (TRANSACTION_ROLLBACK
.equals(commandId
)) {
55 if (userTransaction
.getStatus() == Status
.STATUS_NO_TRANSACTION
)
56 throw new ArgeoException("No transaction to rollback.");
58 userTransaction
.rollback();
60 } catch (ArgeoException e
) {
62 } catch (Exception e
) {
63 throw new ArgeoException("Unable to call " + commandId
+ " on "
64 + userTransaction
, e
);
67 // IWorkbenchWindow iww = HandlerUtil.getActiveWorkbenchWindow(event);
70 // IWorkbenchPage activePage = iww.getActivePage();
71 // IWorkbenchPart part = activePage.getActivePart();
72 // if (part instanceof UsersView)
73 // ((UsersView) part).refresh();
74 // else if (part instanceof GroupsView)
75 // ((GroupsView) part).refresh();
79 public void setUserTransaction(UserTransaction userTransaction
) {
80 this.userTransaction
= userTransaction
;