View Javadoc
1   /*
2    * Copyright 2018-2022 Medical Information Systems Research Group (https://medical.zcu.cz),
3    * Department of Computer Science and Engineering, University of West Bohemia.
4    * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5    *
6    * Author Petr Vcelak (vcelak@kiv.zcu.cz).
7    *
8    * This file is part of MRECore project.
9    *
10   * MRECore is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as published by
12   * the Free Software Foundation, either version 3 of the License.
13   *
14   * MRECore is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with MRECore. If not, see <http://www.gnu.org/licenses/>.
21   */
22  package cz.zcu.mre.data.datatable;
23  
24  import jakarta.servlet.http.HttpServletRequest;
25  
26  /**
27   * The Class DataTableColumnSpecs.
28   *
29   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
30   */
31  public final class DataTableColumnSpecs {
32  
33      /**
34       * The index.
35       */
36      private int index;
37  
38      /**
39       * The data.
40       */
41      private String data;
42  
43      /**
44       * The name.
45       */
46      private String name;
47  
48      /**
49       * The searchable.
50       */
51      private boolean searchable;
52  
53      /**
54       * The orderable.
55       */
56      private boolean orderable;
57  
58      /**
59       * The search.
60       */
61      private String search;
62  
63      /**
64       * The regex.
65       */
66      private boolean regex;
67  
68      /**
69       * The sort dir.
70       */
71      private String sortDir;
72  
73      /**
74       * Instantiates a new data table column specs.
75       *
76       * @param request the request
77       * @param i the i
78       */
79      public DataTableColumnSpecs(HttpServletRequest request, int i) {
80          this.setIndex(i);
81          prepareColumnSpecs(request, i);
82      }
83  
84      /**
85       * Prepare column specs.
86       *
87       * @param request the request
88       * @param i the i
89       */
90      private void prepareColumnSpecs(HttpServletRequest request, int i) {
91  
92          this.setData(request.getParameter("columns[" + i + "][data]"));
93          this.setName(request.getParameter("columns[" + i + "][name]"));
94          this.setOrderable(Boolean.valueOf(request.getParameter("columns[" + i + "][orderable]")));
95          this.setRegex(Boolean.valueOf(request.getParameter("columns[" + i + "][search][regex]")));
96          this.setSearch(request.getParameter("columns[" + i + "][search][value]"));
97          this.setSearchable(Boolean.valueOf(request.getParameter("columns[" + i + "][searchable]")));
98  
99          int sortableCol = Integer.parseInt(request.getParameter("order[0][column]"));
100         String sortDirection = request.getParameter("order[0][dir]");
101 
102         if (i == sortableCol) {
103             this.setSortDir(sortDirection);
104         }
105     }
106 
107     public int getIndex() {
108         return index;
109     }
110 
111     public void setIndex(int index) {
112         this.index = index;
113     }
114 
115     public String getData() {
116         return data;
117     }
118 
119     public void setData(String data) {
120         this.data = data;
121     }
122 
123     public String getName() {
124         return name;
125     }
126 
127     public void setName(String name) {
128         this.name = name;
129     }
130 
131     public boolean isSearchable() {
132         return searchable;
133     }
134 
135     public void setSearchable(boolean searchable) {
136         this.searchable = searchable;
137     }
138 
139     public boolean isOrderable() {
140         return orderable;
141     }
142 
143     public void setOrderable(boolean orderable) {
144         this.orderable = orderable;
145     }
146 
147     public String getSearch() {
148         return search;
149     }
150 
151     public void setSearch(String search) {
152         this.search = search;
153     }
154 
155     public boolean isRegex() {
156         return regex;
157     }
158 
159     public void setRegex(boolean regex) {
160         this.regex = regex;
161     }
162 
163     public String getSortDir() {
164         return sortDir;
165     }
166 
167     public void setSortDir(String sortDir) {
168         this.sortDir = sortDir;
169     }
170 
171     @Override
172     public String toString() {
173         return "DataTableColumnSpecs{" + "index=" + index + ", data=" + data + ", name=" + name + ", searchable=" + searchable + ", orderable=" + orderable + ", search=" + search + ", regex=" + regex + ", sortDir=" + sortDir + '}';
174     }
175 
176 }