@UiHandler("btnOk") void saveChanges(ClickEvent e) { if (separator.isVisible()) { editMode(false); } if (removedRecs.size() > 0) { final InputItem rec = removedRecs.entrySet().iterator().next().getValue(); MethodCallback<Void> cb = new MethodCallback<Void>() { @Override public void onFailure(Method method, Throwable exception) { askRetry(rec, "Error removing record " + rec.getName() + ". Retry ?"); } @Override public void onSuccess(Method method, Void response) { removedRecs.remove(rec.getId()); saveChanges(null); } }; md.info(MDS, "Removing record " + rec.getName()); clientApi.iitemsApi().delete(rec.getId(), cb); } else if (changedRecs.size() > 0) { final InputItem rec = changedRecs.entrySet().iterator().next().getValue(); MethodCallback<Void> cb = new MethodCallback<Void>() { @Override public void onFailure(Method method, Throwable exception) { askRetry(rec, "Error updating user " + rec.getName() + ". Retry ?"); } @Override public void onSuccess(Method method, Void response) { changedRecs.remove(rec.getId()); saveChanges(null); } }; if (rec.getId() == 0) { md.info(MDS, "Creating user " + rec); clientApi.iitemsApi().create(rec, cb); } else { md.info(MDS, "Updating user " + rec); clientApi.iitemsApi().update(rec.getId(), rec, cb); } } else { refreshRecords(e); md.clear(MDS); } }
@UiHandler("btnCancel") void cancelChanges(ClickEvent e) { recordStore.getList().clear(); changedRecs.clear(); removedRecs.clear(); editMode(false); refreshRecords(e); md.clear(MDS); }
@UiHandler("btnRemove") void removeRecord(ClickEvent e) { InputItem user = selectionModel.getSelectedObject(); if (user != null) { changedRecs.remove(user.getId()); removedRecs.put(user.getId(), user); recordStore.getList().remove(user); editMode(true); } }
private void markChange(InputItem rec) { if (!changedRecs.containsKey(rec.getId())) { changedRecs.put(rec.getId(), rec); if (!separator.isVisible()) { md.info( MDS, "Some data has been changed. Click 'Save' or 'Cancel' when editing is finished."); editMode(true); } dataGrid.redraw(); } }
@Override public void render(Context context, InputItem rec, SafeHtmlBuilder sb) { boolean changed = changedRecs.containsKey(rec.getId()); String style = changed ? "color: red; font-weight: bold;" : "color: black; font-weight: normal"; sb.appendHtmlConstant("<span style=\"" + style + "\">"); sb.append(SafeHtmlUtils.fromString("" + rec.getId())); sb.appendHtmlConstant("</span>"); }
@UiHandler("btnAdd") void addRecord(ClickEvent e) { InputItem rec = new InputItem(); rec.setName("NEW"); String dt = ClientUtil.TSTAMP_FORMAT0.format(new Date()); rec.setTstart(ClientUtil.parseUnixTime(dt.substring(0, 7) + "-01 09:00:00")); rec.setTstop(ClientUtil.parseUnixTime("2020-01-01 17:00:00")); rec.setActive(1); rec.setTxFormid(0); rec.setInputId(0); rec.setComment(""); recordStore.getList().add(0, rec); changedRecs.put(rec.getId(), rec); editMode(true); }