|
Абстрагирование UI
#38500191
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
Участник
Откуда: Санкт-Петербург
Сообщения: 668
|
|
А это "прикладной" код ( работа с контейнером данных не вынесена в API, поэтому пришлось "разврапить" таблицу и написать то, чего тут быть не должно )
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219.
package test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.Align;
import com.vaadin.ui.Table.ColumnHeaderMode;
import cs.core.client.api.annotations.Bind;
import cs.core.client.api.annotations.Cleanup;
import cs.core.client.api.annotations.Init;
import cs.core.client.api.annotations.Invoker;
import cs.core.client.api.annotations.Service;
import cs.core.client.api.common.CSIcon;
import cs.core.client.api.component.ComponentContext;
import cs.core.client.api.composition.base.CSElement;
import cs.core.client.api.composition.widgets.CSButton;
import cs.core.client.api.composition.widgets.CSLayout;
import cs.core.client.api.composition.widgets.CSTable;
import cs.core.client.api.services.Application;
import cs.core.client.api.services.ApplicationFactory;
import cs.core.client.api.services.Facade;
import cs.core.client.impl.data.model.BeanPropertyModel;
import cs.core.client.vaadin.composition.widgets.VTable;
import cs.core.client.vaadin.data.BeanViewContainer;
import cs.customsPrototype.CustomReportsFacade;
import cs.customsPrototype.Edorepin;
import cs.customsPrototype.query.EdorepinSearchQuery;
public class TestComponent implements Serializable {
private static final long serialVersionUID = 1L;
@Bind
private ComponentContext ctx;
@Bind("content")
private CSLayout content;
@Bind("toolbarButton1")
private CSButton toolbarButton1;
@Bind("toolbarButton2")
private CSButton toolbarButton2;
@Bind("toolbarButton3")
private CSButton toolbarButton3;
@Bind("toolbarButton4")
private CSButton toolbarButton4;
@Service(ApplicationFactory.class)
private ApplicationFactory factory;
@Service(Application.class)
private Application app;
@Service(Facade.class)
private Facade facade;
@Bind("tab")
private CSTable table;
private Table vt;
private BeanViewContainer<Long, Edorepin> cont;
private EdorepinSearchQuery query;
private void initColumn(Table table, BeanPropertyModel model) {
String pid = model.getId();
vt.setColumnHeader(pid, model.getCaption() == "" ? model.getId() : model.getCaption());
vt.setColumnCollapsible(pid, true);
vt.setColumnCollapsed(pid, !model.isVisible() );
vt.setColumnAlignment(pid, Align.LEFT);
}
@Init
public void init() throws Exception {
vt = ((VTable) table).getInternalObject();
cont = new BeanViewContainer<Long, Edorepin>(Edorepin.class);
CustomReportsFacade f = facade.getInterface(CustomReportsFacade.class);
query = f.createQuery(CustomReportsFacade.QUERY_SEARCH);
vt.setContainerDataSource(cont);
vt.setColumnHeaderMode(ColumnHeaderMode.EXPLICIT);
vt.setVisibleColumns(cont.getModel().getAccessiblePropertyNames());
for (BeanPropertyModel pmod : cont.getModel().getAccessiblePropertyModel() ) {
initColumn(vt, pmod);
}
vt.setItemCaptionMode(ItemCaptionMode.PROPERTY);
vt.setItemCaptionPropertyId( "fam" );
if (cont.getItemsCount() > 0)
vt.setValue(cont.firstItemId());
toolbarButton1.setIcon(factory.createIcon(CSIcon.Library.ICON_OPEN));
toolbarButton1.setIconOnly(true);
toolbarButton1.setDescription(toolbarButton1.getCaption());
// toolbarButton1.setEnabled(false);
toolbarButton2.setIcon(factory.createIcon(CSIcon.Library.ICON_NEW));
toolbarButton2.setIconOnly(true);
toolbarButton2.setDescription(toolbarButton2.getCaption());
toolbarButton3.setIcon(factory.createIcon(CSIcon.Library.ICON_DELETE));
toolbarButton3.setIconOnly(true);
toolbarButton3.setDescription(toolbarButton3.getCaption());
toolbarButton4.setIcon(factory.createIcon(CSIcon.Library.ICON_PRINT));
toolbarButton4.setIconOnly(true);
toolbarButton4.setDescription(toolbarButton4.getCaption());
}
@Invoker({ @Invoker.For(id = "toolbarButton1", eventType = CSButton.ClickNotify), })
public void onToolbarButton1Click(CSElement sender) throws Exception {
app.ShowWindow(factory.createComponent(TestComponent1.class), "Второй");
}
@Invoker({ @Invoker.For(id = "toolbarButton2", eventType = CSButton.ClickNotify), })
public void onToolbarButton2Click(CSElement sender) throws Exception {
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, -6);
Calendar c1 = Calendar.getInstance();
query.setDateFrom(c.getTime());
query.setDateTo(c1.getTime());
CustomReportsFacade f = facade.getInterface(CustomReportsFacade.class);
List<Edorepin> ls = f.queryEntities(query);
cont.addBeans(ls);
}
@Invoker({ @Invoker.For(id = "toolbarButton3", eventType = CSButton.ClickNotify), })
public void onToolbarButton3Click(CSElement sender) {
ArrayList<Long> a = new ArrayList<Long>();
a.add(1832L);
a.add(1841L);
// cont.removeBeans( a );
//Object del = vt.getValue();
//cont.removeBean((Long)del);
// TODO: move to table implementation
if (vt.getValue() != null) {
Object del = vt.getValue();
Object afterSelectId = vt.nextItemId(del);
boolean needScroll = false;
if (afterSelectId == null) {
afterSelectId = vt.prevItemId(del);
needScroll = true;
}
if (afterSelectId != null)
vt.setValue(afterSelectId);
cont.removeBean((Long)del);
if (needScroll) {
// vt.setCurrentPageFirstItemIndex(pindex);
vt.setCurrentPageFirstItemId(afterSelectId);
}
// vt.setCurrentPageFirstItemIndex(pindex);
}
}
@Invoker({ @Invoker.For(id = "toolbarButton4", eventType = CSButton.ClickNotify), })
public void onToolbarButton4Click(CSElement sender) throws Exception {
// Serialize
FileOutputStream fout = new FileOutputStream("E:\\container.bin");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(cont);
FileInputStream streamIn = new FileInputStream("E:\\container.bin");
ObjectInputStream objectinputstream = new ObjectInputStream(streamIn);
cont = (BeanViewContainer<Long, Edorepin>) objectinputstream.readObject();
vt.setContainerDataSource(cont);
Object[] columns = cont.getModel().getAccessiblePropertyNames();
vt.setVisibleColumns( columns );
for (Object idObj : columns ) {
String propertyId = (String) idObj;
vt.setColumnHeader(propertyId, cont.getModel().getPropertyModel(propertyId).getCaption());
vt.setColumnCollapsed(propertyId,
!cont.getModel().getPropertyModel(propertyId).isVisible() );
}
}
@Invoker({ @Invoker.For(id = "maximizeButton", eventType = CSButton.ClickNotify), })
public void onMaximizeClick(CSElement sender) throws Exception {
}
@Cleanup
public void cleanup() {
}
}
+ композиция в XML
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.
<?xml version="1.0" encoding="UTF-8"?>
<c:composition xmlns:c="composition"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="composition ../cs/core/client/api/composition/composition-schema.xsd ">
<c:declare >
<c:actionList>
<c:action />
</c:actionList>
</c:declare>
<c:content id="content" placement="vertical" width="850px" height="650px"
margin="false" spacing="false" >
<c:toolbar>
<c:button id="maximizeButton" title="Развернуть" />
<c:button id="toolbarButton1" title="Открыть" />
<c:button id="toolbarButton2" title="Создать" />
<c:button id="toolbarButton3" title="Удалить" />
<c:button id="toolbarButton4" title="Печать" />
<c:button id="toolbarButton5" title="Закрыть" />
</c:toolbar>
<c:table id="tab" height="100%" width="100%" expandRatio="1" />
</c:content>
</c:composition>
|
|
|