1 package ru.indvdum.mywork.vaadin; |
|
2 |
|
3 import static ru.indvdum.mywork.MyWork.EM; |
|
4 |
|
5 import java.util.List; |
|
6 |
|
7 import javax.persistence.Query; |
|
8 |
|
9 import ru.indvdum.mywork.openjpa.model.Day; |
|
10 import ru.indvdum.mywork.openjpa.model.Task; |
|
11 import ru.indvdum.mywork.openjpa.model.Work; |
|
12 |
|
13 import com.vaadin.Application; |
|
14 import com.vaadin.addon.jpacontainer.EntityContainer; |
|
15 import com.vaadin.addon.jpacontainer.EntityProvider; |
|
16 import com.vaadin.addon.jpacontainer.HierarchicalEntityContainer; |
|
17 import com.vaadin.addon.jpacontainer.JPAContainer; |
|
18 import com.vaadin.addon.jpacontainer.provider.BatchableLocalEntityProvider; |
|
19 import com.vaadin.addon.jpacontainer.provider.CachingBatchableLocalEntityProvider; |
|
20 import com.vaadin.addon.jpacontainer.provider.CachingLocalEntityProvider; |
|
21 import com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider; |
|
22 import com.vaadin.addon.jpacontainer.provider.LocalEntityProvider; |
|
23 import com.vaadin.ui.Alignment; |
|
24 import com.vaadin.ui.Button; |
|
25 import com.vaadin.ui.HorizontalLayout; |
|
26 import com.vaadin.ui.MenuBar; |
|
27 import com.vaadin.ui.TabSheet; |
|
28 import com.vaadin.ui.Table; |
|
29 import com.vaadin.ui.VerticalLayout; |
|
30 import com.vaadin.ui.Window; |
|
31 import com.vaadin.ui.Button.ClickEvent; |
|
32 import com.vaadin.ui.Button.ClickListener; |
|
33 import com.vaadin.ui.MenuBar.Command; |
|
34 import com.vaadin.ui.MenuBar.MenuItem; |
|
35 |
|
36 /** |
|
37 * @author indvdum |
|
38 * 12.08.2011 17:31:53 |
|
39 * |
|
40 */ |
|
41 public class MyWorkApplication extends Application { |
|
42 |
|
43 private MyWorkApplication thisObject = this; |
|
44 private Table dayTable = null; |
|
45 private Table taskTable = null; |
|
46 private Table workTable = null; |
|
47 |
|
48 private Command newDayCommand = new Command() { |
|
49 public void menuSelected(MenuItem selectedItem) { |
|
50 EditDayDialog dialog = null; |
|
51 try { |
|
52 dialog = new EditDayDialog(thisObject, null); |
|
53 } catch (Exception e) { |
|
54 e.printStackTrace(); |
|
55 } |
|
56 getMainWindow().addWindow(dialog); |
|
57 } |
|
58 }; |
|
59 private Command newTaskCommand = new Command() { |
|
60 public void menuSelected(MenuItem selectedItem) { |
|
61 EditTaskDialog dialog = null; |
|
62 try { |
|
63 dialog = new EditTaskDialog(thisObject, null); |
|
64 } catch (Exception e) { |
|
65 e.printStackTrace(); |
|
66 } |
|
67 getMainWindow().addWindow(dialog); |
|
68 } |
|
69 }; |
|
70 private Command newWorkCommand = new Command() { |
|
71 public void menuSelected(MenuItem selectedItem) { |
|
72 EditWorkDialog dialog = null; |
|
73 try { |
|
74 dialog = new EditWorkDialog(thisObject, null); |
|
75 } catch (Exception e) { |
|
76 e.printStackTrace(); |
|
77 } |
|
78 getMainWindow().addWindow(dialog); |
|
79 } |
|
80 }; |
|
81 private Command editDayCommand = new Command() { |
|
82 public void menuSelected(MenuItem selectedItem) { |
|
83 EditDayDialog dialog = null; |
|
84 Day day = EM.find(Day.class, dayTable.getValue()); |
|
85 if(day == null) |
|
86 return; |
|
87 try { |
|
88 dialog = new EditDayDialog(thisObject, day); |
|
89 } catch (Exception e) { |
|
90 e.printStackTrace(); |
|
91 } |
|
92 getMainWindow().addWindow(dialog); |
|
93 } |
|
94 }; |
|
95 private Command editTaskCommand = new Command() { |
|
96 public void menuSelected(MenuItem selectedItem) { |
|
97 EditTaskDialog dialog = null; |
|
98 Task task = EM.find(Task.class, taskTable.getValue()); |
|
99 if(task == null) |
|
100 return; |
|
101 try { |
|
102 dialog = new EditTaskDialog(thisObject, task); |
|
103 } catch (Exception e) { |
|
104 e.printStackTrace(); |
|
105 } |
|
106 getMainWindow().addWindow(dialog); |
|
107 } |
|
108 }; |
|
109 private Command editWorkCommand = new Command() { |
|
110 public void menuSelected(MenuItem selectedItem) { |
|
111 EditWorkDialog dialog = null; |
|
112 Work work = EM.find(Work.class, workTable.getValue()); |
|
113 if(work == null) |
|
114 return; |
|
115 try { |
|
116 dialog = new EditWorkDialog(thisObject, work); |
|
117 } catch (Exception e) { |
|
118 e.printStackTrace(); |
|
119 } |
|
120 getMainWindow().addWindow(dialog); |
|
121 } |
|
122 }; |
|
123 |
|
124 @Override |
|
125 public void init() { |
|
126 Window window = new Window(); |
|
127 setMainWindow(window); |
|
128 |
|
129 TabSheet tabSheet = new TabSheet(); |
|
130 tabSheet.setSizeFull(); |
|
131 window.setContent(tabSheet); |
|
132 |
|
133 VerticalLayout vlMain = new VerticalLayout(); |
|
134 vlMain.setSizeFull(); |
|
135 vlMain.setMargin(true); |
|
136 vlMain.setSpacing(true); |
|
137 tabSheet.addTab(vlMain, "Main page", null); |
|
138 |
|
139 MenuBar menuBar = new MenuBar(); |
|
140 MenuItem file = menuBar.addItem("File", null); |
|
141 MenuItem newItem = file.addItem("New", null); |
|
142 newItem.addItem("Day...", newDayCommand); |
|
143 newItem.addItem("Task...", newTaskCommand); |
|
144 newItem.addItem("Work...", newWorkCommand); |
|
145 MenuItem edit = menuBar.addItem("Edit", null); |
|
146 edit.addItem("Day...", editDayCommand); |
|
147 edit.addItem("Task...", editTaskCommand); |
|
148 edit.addItem("Work...", editWorkCommand); |
|
149 vlMain.addComponent(menuBar); |
|
150 |
|
151 LocalEntityProvider dayProvider = new CachingLocalEntityProvider(Day.class); |
|
152 dayProvider.setEntityManager(EM); |
|
153 JPAContainer<Day> dayContainer = new JPAContainer(Day.class); |
|
154 dayContainer.setEntityProvider(dayProvider); |
|
155 |
|
156 dayTable = new Table(); |
|
157 dayTable.setSelectable(true); |
|
158 dayTable.setEditable(false); |
|
159 dayTable.setImmediate(true); |
|
160 dayTable.setSizeFull(); |
|
161 dayTable.setContainerDataSource(dayContainer); |
|
162 dayTable.setVisibleColumns(new String[]{ |
|
163 "formattedDay", |
|
164 "startWork", |
|
165 "endWork", |
|
166 "hours", |
|
167 }); |
|
168 dayTable.setSortContainerPropertyId("day"); |
|
169 dayTable.setColumnHeaders(new String[]{ |
|
170 "day", |
|
171 "startWork", |
|
172 "endWork", |
|
173 "hours", |
|
174 }); |
|
175 vlMain.addComponent(dayTable); |
|
176 vlMain.setExpandRatio(dayTable, 1f); |
|
177 |
|
178 LocalEntityProvider taskProvider = new CachingLocalEntityProvider(Task.class); |
|
179 taskProvider.setEntityManager(EM); |
|
180 JPAContainer<Task> taskContainer = new JPAContainer(Task.class); |
|
181 taskContainer.setEntityProvider(taskProvider); |
|
182 |
|
183 taskTable = new Table(); |
|
184 taskTable.setSelectable(true); |
|
185 taskTable.setEditable(false); |
|
186 taskTable.setImmediate(true); |
|
187 taskTable.setSizeFull(); |
|
188 taskTable.setContainerDataSource(taskContainer); |
|
189 taskTable.setVisibleColumns(new String[]{ |
|
190 "name", |
|
191 "description", |
|
192 }); |
|
193 taskTable.setColumnWidth("description", 300); |
|
194 vlMain.addComponent(taskTable); |
|
195 vlMain.setExpandRatio(taskTable, 1f); |
|
196 |
|
197 LocalEntityProvider workProvider = new CachingLocalEntityProvider(Work.class); |
|
198 workProvider.setEntityManager(EM); |
|
199 JPAContainer<Task> workContainer = new JPAContainer(Work.class); |
|
200 workContainer.setEntityProvider(workProvider); |
|
201 |
|
202 workTable = new Table(); |
|
203 workTable.setSelectable(false); |
|
204 workTable.setEditable(false); |
|
205 workTable.setImmediate(true); |
|
206 workTable.setSizeFull(); |
|
207 workTable.setContainerDataSource(workContainer); |
|
208 workTable.setVisibleColumns(new String[]{ |
|
209 "day", |
|
210 "task", |
|
211 "hours", |
|
212 "result", |
|
213 }); |
|
214 workTable.setColumnWidth("result", 200); |
|
215 workTable.setSortContainerPropertyId("day"); |
|
216 vlMain.addComponent(workTable); |
|
217 vlMain.setExpandRatio(workTable, 1f); |
|
218 } |
|
219 |
|
220 public Table getDayTable() { |
|
221 return dayTable; |
|
222 } |
|
223 |
|
224 public Table getTaskTable() { |
|
225 return taskTable; |
|
226 } |
|
227 |
|
228 public Table getWorkTable() { |
|
229 return workTable; |
|
230 } |
|
231 } |
|