1 package org
.argeo
.security
.ui
.admin
.internal
.providers
;
3 import java
.util
.HashMap
;
6 import javax
.transaction
.Status
;
7 import javax
.transaction
.UserTransaction
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.ArgeoException
;
12 import org
.argeo
.security
.ui
.admin
.SecurityAdminPlugin
;
13 import org
.eclipse
.swt
.SWTException
;
14 import org
.eclipse
.ui
.AbstractSourceProvider
;
15 import org
.eclipse
.ui
.ISources
;
17 /** Observe and notify UI on UserTransaction state changes */
18 public class UserTransactionProvider
extends AbstractSourceProvider
{
19 private final static Log log
= LogFactory
20 .getLog(UserTransactionProvider
.class);
22 public final static String TRANSACTION_STATE
= SecurityAdminPlugin
.PLUGIN_ID
23 + ".userTransactionState";
24 public final static String STATUS_ACTIVE
= "status.active";
25 public final static String STATUS_NO_TRANSACTION
= "status.noTransaction";
27 /* DEPENDENCY INJECTION */
28 private UserTransaction userTransaction
;
31 public String
[] getProvidedSourceNames() {
32 return new String
[] { TRANSACTION_STATE
};
36 public Map
<String
, String
> getCurrentState() {
37 Map
<String
, String
> currentState
= new HashMap
<String
, String
>(1);
38 currentState
.put(TRANSACTION_STATE
, getInternalCurrentState());
43 public void dispose() {
46 private String
getInternalCurrentState() {
48 String transactionState
;
49 if (userTransaction
.getStatus() == Status
.STATUS_NO_TRANSACTION
)
50 transactionState
= STATUS_NO_TRANSACTION
;
52 // if (userTransaction.getStatus() == Status.STATUS_ACTIVE)
53 transactionState
= STATUS_ACTIVE
;
54 return transactionState
;
55 } catch (Exception e
) {
56 throw new ArgeoException("Unable to begin transaction", e
);
60 /** Publishes the ability to notify a state change */
61 public void fireTransactionStateChange() {
63 fireSourceChanged(ISources
.WORKBENCH
, TRANSACTION_STATE
,
64 getInternalCurrentState());
65 } catch (SWTException e
) {
67 log
.warn("Cannot fire transaction state change event: "
72 /* DEPENDENCY INJECTION */
73 public void setUserTransaction(UserTransaction userTransaction
) {
74 this.userTransaction
= userTransaction
;