private List<Long> models2Ids(List<BeanModel> models) { List<Long> ids = new ArrayList<Long>(); for (Iterator<BeanModel> iterator = models.iterator(); iterator.hasNext(); ) { BeanModel beanModel = (BeanModel) iterator.next(); ids.add(((Container) beanModel.getBean()).getId()); } return ids; }
@Override protected void asyncUpdate(BeanModel beanModel) { final BeanModel targetBeanModel = beanModel; // System.out.println("Before update: " + targetBeanModel.getProperties()); updateDeleteReasonService.updateDeleteReason( (DeleteReasonInstance) beanModel.getBean(), new AsyncCallback<UpdateResponse<DeleteReasonInstance>>() { public void onFailure(Throwable caught) { // Show the RPC error message to the user if (caught instanceof IllegalArgumentException) MessageBox.alert("Alert", caught.getMessage(), null); else { MessageBox.alert("Alert", "Delete reason update failed unexpectedly.", null); System.out.println(caught.getClass().getName()); System.out.println(caught.getMessage()); } } public void onSuccess(UpdateResponse<DeleteReasonInstance> updateResponse) { DeleteReasonInstance updatedDeleteReason = (DeleteReasonInstance) updateResponse.getInstance(); DeleteReasonInstance storeInstance = targetBeanModel.getBean(); storeInstance.setNewRecord(false); // If this user is newly created, back-populate the id if (storeInstance.getCreatedDatetime() == null) { storeInstance.setCreatedDatetime(updatedDeleteReason.getCreatedDatetime()); } } }); }
public DeviceContentWizardForm(Component wrapper, BeanModel deviceBeanModel) { super(); this.wrapper = wrapper; this.device = deviceBeanModel.getBean(); setHeight(240); init(); }
private ContentPanel createScreenPairList(GroupRef groupRef) { TouchPanelDefinition touchPanel = groupRef.getPanel().getTouchPanelDefinition(); ContentPanel screenContainer = new ContentPanel(); screenContainer.setHeaderVisible(false); screenContainer.setWidth(260); screenContainer.setHeight(150); screenContainer.setLayout(new FitLayout()); // overflow-auto style is for IE hack. screenContainer.addStyleName("overflow-auto"); screenPairListView = new CheckBoxListView<BeanModel>(); ListStore<BeanModel> store = new ListStore<BeanModel>(); List<BeanModel> otherModels = new ArrayList<BeanModel>(); List<BeanModel> screenPairModels = BeanModelDataBase.screenTable.loadAll(); List<BeanModel> selectedModels = new ArrayList<BeanModel>(); for (ScreenPairRef screenRef : groupRef.getGroup().getScreenRefs()) { selectedModels.add(screenRef.getScreen().getBeanModel()); } for (BeanModel screenPairModel : screenPairModels) { if (((ScreenPair) screenPairModel.getBean()).getTouchPanelDefinition().equals(touchPanel)) { store.add(screenPairModel); screenPairListView.getSelectionModel().select(screenPairModel, true); } else if (((ScreenPair) screenPairModel.getBean()) .getTouchPanelDefinition() .getCanvas() .equals(touchPanel.getCanvas())) { otherModels.add(screenPairModel); } } store.add(otherModels); for (BeanModel selectedModel : selectedModels) { screenPairListView.setChecked(selectedModel, true); } screenPairListView.setStore(store); screenPairListView.setDisplayProperty("panelName"); screenPairListView.setStyleAttribute("overflow", "auto"); screenPairListView.setSelectStyle("screen-view-item-sel"); screenContainer.add(screenPairListView); return screenContainer; }
@Override protected void asyncUpdate(BeanModel beanModel) { if (store.getKeyProvider() == null) { System.out.println("Set key provider"); store.setKeyProvider(new SimpleKeyProvider("userName")); } final BeanModel targetBeanModel = beanModel; // System.out.println("Before update: " + targetBeanModel.getProperties()); updateUserService.updateUser( (UserInstance) beanModel.getBean(), new AsyncCallback<UpdateResponse<UserInstance>>() { public void onFailure(Throwable caught) { // Show the RPC error message to the user if (caught instanceof IllegalArgumentException) MessageBox.alert("Alert", caught.getMessage(), null); else { MessageBox.alert("Alert", "User update failed unexpectedly.", null); System.out.println(caught.getClass().getName()); System.out.println(caught.getMessage()); } } public void onSuccess(UpdateResponse<UserInstance> updateResponse) { UserInstance updatedUser = (UserInstance) updateResponse.getInstance(); UserInstance storeInstance = targetBeanModel.getBean(); storeInstance.setNewRecord(false); if (storeInstance.getId() == null) storeInstance.setId(updatedUser.getId()); storeInstance.setNewRecord(false); storeInstance.setResetPassword(false); if (updatedUser.getCreatedDatetime() != null) storeInstance.setCreatedDatetime(updatedUser.getCreatedDatetime()); grid.getView().refresh(false); if (updateResponse.getMessage() != null && updateResponse.getMessage().length() > 0) MessageBox.info("Please Note...", updateResponse.getMessage(), null); } }); UserInstance targetInstance = targetBeanModel.getBean(); targetInstance.setResetPassword(false); }
private void createFields() { GroupRef groupRef = (GroupRef) groupRefBeanModel.getBean(); nameField = new TextField<String>(); nameField.setName("name"); nameField.setFieldLabel("Name"); nameField.setAllowBlank(false); if (groupRef.getGroup().getName() != null) { nameField.setValue(groupRef.getGroup().getName()); } AdapterField screenField = new AdapterField(createScreenPairList(groupRef)); screenField.setFieldLabel("Screen"); form.add(nameField); form.add(screenField); }
private void save() { final AsyncCallback<Long> newCallback = new AsyncCallback<Long>() { @Override public void onFailure(Throwable caught) { MessageBox.alert("警告", "发生错误,请刷新!", null); } @Override public void onSuccess(Long result) { if (result == 0) { MessageBox.alert("提醒", "已存在相同条目(单位代码相同),添加失败", null); } else { Container newItem = (Container) beanModel.getBean(); newItem.setId(result); store.insert(beanModel, 0); store.commitChanges(); MessageBox.info("提示", "添加成功!", null); formPanel.setReadOnly(true); saveButton.setVisible(false); cancelButton.setVisible(false); updateButton.setVisible(true); updateButton.disable(); resetButton.setVisible(true); resetButton.disable(); if (permitedEnterprise.getCanAdd()) { addButton.enable(); } else { addButton.disable(); } } } }; getBusinessService().saveContainer((Container) beanModel.getBean(), newCallback); }
protected String getCodeDescription(String value, ListStore<BeanModel> store) { BeanModel model = store.findModel(value); if (model != null && model.get("description") != null) return model.get("description").toString(); return value; }
@Override public void componentSelected(ButtonEvent ce) { List<BeanModel> selectedModels = deviceContentTree.getSelectionModel().getSelectedItems(); for (BeanModel beanModel : selectedModels) { if (beanModel.getBean() instanceof DeviceCommand) { List<CommandRefItem> commandRefItems = device.getCommandRefItems(); for (CommandRefItem commandRefItem : commandRefItems) { if (commandRefItem.getDeviceCommand() == beanModel.getBean()) { MessageBox.alert( "Warn", "The command cann't be delete, because it was refrenced by other sensor, switch or slider.", null); return; } } device.getDeviceCommands().remove(beanModel.getBean()); } else if (beanModel.getBean() instanceof Sensor) { List<SensorRefItem> sensorRefItems = device.getSensorRefItems(); for (SensorRefItem sensorRefItem : sensorRefItems) { if (sensorRefItem.getSensor() == beanModel.getBean()) { MessageBox.alert( "Warn", "The sensor cann't be delete, because it was refrenced by other switch or slider.", null); return; } } device.getSensors().remove(beanModel.getBean()); } else if (beanModel.getBean() instanceof Slider) { device.getSliders().remove(beanModel.getBean()); } else if (beanModel.getBean() instanceof Switch) { deviceContentTree.getStore().remove(beanModel); device.getSwitchs().remove(beanModel.getBean()); } deviceContentTree.getStore().remove(beanModel); } }