4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
UserSettings.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz
4  * File: UserSettings.java
5  * Description: Backbean for page with list of user settings
6  */
7 
8 /**
9  * @file UserSettings.java
10  *
11  * @brief Backbean for page with list of user settings
12  */
13 
14 package cz.vutbr.fit.knot.annotations.web;
18 import java.io.Serializable;
19 import java.util.List;
20 import javax.faces.bean.ManagedBean;
21 import javax.faces.bean.SessionScoped;
22 import javax.faces.component.html.HtmlDataTable;
23 
24 /**
25  * Backbean for page with list of user settings
26  *
27  * @brief Backbean for page with list of user settings
28  * @author Martin Petr (xpetrm05)
29  */
30 @ManagedBean
31 @SessionScoped
32 public class UserSettings implements Serializable{
33  /**
34  * Table asociated with list of settings
35  */
36  private HtmlDataTable listTable;
37  /**
38  * Setting from table
39  */
40  private Settings setting = null;
41 
42  /**
43  * Constructor
44  */
45  public UserSettings() {
46  }
47 
48  /**
49  * Gets table asociated with list of settings
50  *
51  * @return Returns table asociated with list of settings
52  */
53  public HtmlDataTable getListTable() {
54  return listTable;
55  }
56 
57  /**
58  * Sets table asociated with list of settings
59  *
60  * @param listTable Table asociated with list of settings
61  */
62  public void setListTable(HtmlDataTable listTable) {
63  this.listTable = listTable;
64  }
65 
66  /**
67  * Gets actual setting selected in table
68  *
69  * @return Returns selected setting
70  */
71  public Settings getSetting() {
72  return setting;
73  }
74 
75  /**
76  * Sets actual setting selected in table
77  *
78  * @param setting Actual setting
79  */
80  public void setSetting(Settings setting) {
81  this.setting = setting;
82  }
83 
84  /**
85  * Gets list of all existing user settings
86  *
87  * @return Returns list of all existing user settings
88  */
89  public List<Settings> getSettings(){
90  if(SessionManager.getSession().getEditedUser() != null){
91  User actualUser = SessionManager.getSession().getEditedUser();
92 
93  Object[] params = {"userId",actualUser.getId()};
94  @SuppressWarnings("unchecked")
95  List<Settings> settingsList = AppBean.getPersistenceManager().queryDB("Settings.findByUser",params);
96  return settingsList;
97  }
98  return null;
99  }
100 
101  /**
102  * Action listener for edit user setting in table
103  *
104  * @return Returns page outcome to go to editing page
105  */
106  public String actionEdit(){
107  // get selected row from table
108  setting = (Settings) listTable.getRowData();
109  // pass selected setting through the session
110  SessionManager.getSession().setEditedSetting(setting);
111  SessionManager.getSession().setFormBackup(null);
112  if(setting.isStyleSetting()) {
113  SessionManager.getSession().setComeFrom("editUserASSetting");
114  return "editUserASSetting";
115  }else return "editUserSetting";
116  }
117 
118  /**
119  * Action listener for new annotation style user setting in table
120  *
121  * @return Returns page outcome to go to creating page
122  */
123  public String actionAddUserASSettings(){
124  SessionManager.getSession().setComeFrom("addUserASSetting");
125  return "addUserASSetting";
126  }
127 
128  /**
129  * Action listener for delete user setting in table
130  *
131  * @return Returns page outcome to go to deleting page
132  */
133  public String actionDelete(){
134  // get selected row from table
135  setting = (Settings) listTable.getRowData();
136  // pass selected setting through the session
137  SessionManager.getSession().setEditedSetting(setting);
138  SessionManager.getSession().setFormBackup(null);
139  if(setting.isStyleSetting()) {
140  SessionManager.getSession().setComeFrom("deleteUserASSetting");
141  return "deleteUserASSetting";
142  }else return "deleteUserSetting";
143  }
144 
145  /**
146  * Action listener for cancel action
147  *
148  * @return Returns page outcome (identificator of next page or null to stay here)
149  */
150  public String actionCancel(){
151  SessionManager.getSession().setEditedUser(null);
152  return "cancel";
153  }
154 }
Class for manipulating with session.
void setListTable(HtmlDataTable listTable)
Singleton for storing global variables.
Definition: AppBean.java:47
Class representing parameter of user settings.
Definition: Settings.java:45
Class representing user.
Definition: User.java:51
Backbean for page with list of user settings.