1 package org
.argeo
.security
.ui
.admin
.internal
;
3 import java
.util
.HashMap
;
6 import javax
.transaction
.Status
;
7 import javax
.transaction
.UserTransaction
;
9 import org
.argeo
.ArgeoException
;
10 import org
.argeo
.security
.ui
.admin
.SecurityAdminPlugin
;
11 import org
.eclipse
.ui
.AbstractSourceProvider
;
12 import org
.eclipse
.ui
.ISources
;
14 /** Centralize interaction with the UserTransaction among the UI */
15 public class UserTransactionProvider
extends AbstractSourceProvider
{
16 public final static String TRANSACTION_STATE
= SecurityAdminPlugin
.PLUGIN_ID
17 + ".userTransactionState";
18 public final static String STATUS_ACTIVE
= "status.active";
19 public final static String STATUS_NO_TRANSACTION
= "status.noTransaction";
21 private String transactionState
= STATUS_NO_TRANSACTION
;
23 /* DEPENDENCY INJECTION */
24 private UserTransaction userTransaction
;
27 public String
[] getProvidedSourceNames() {
28 return new String
[] { TRANSACTION_STATE
};
32 public Map
<String
, String
> getCurrentState() {
33 Map
<String
, String
> currentState
= new HashMap
<String
, String
>(1);
34 // TODO implement asking to the UserTransaction
35 // String transactionState = isActive ? STATUS_ACTIVE :
36 // STATUS_NO_TRANSACTION;
37 currentState
.put(TRANSACTION_STATE
, transactionState
);
42 public void dispose() {
45 /** Publish the ability to change the state. */
46 public void setUserTransactionState(String newState
) {
47 transactionState
= newState
;
48 // fireSourceChanged(ISources.WORKBENCH, TRANSACTION_STATE,
52 private void refreshState() {
54 if (userTransaction
!= null) {
55 if (userTransaction
.getStatus() == Status
.STATUS_NO_TRANSACTION
)
56 transactionState
= STATUS_NO_TRANSACTION
;
57 else if (userTransaction
.getStatus() == Status
.STATUS_ACTIVE
)
58 transactionState
= STATUS_ACTIVE
;
59 fireSourceChanged(ISources
.WORKBENCH
, TRANSACTION_STATE
,
62 } catch (Exception e
) {
63 throw new ArgeoException("Unable to begin transaction", e
);
67 /** Publish the ability to notify a state change */
68 public void fireTransactionStateChange() {
72 /** FIXME: Rather inject the UserTransaction. */
74 public void setUserTransaction(UserTransaction userTransaction
) {
75 this.userTransaction
= userTransaction
;