@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); } }
private void loadInputsList() { clientApi .inputsApi() .list( new MethodCallback<List<Input>>() { @Override public void onFailure(Method method, Throwable exception) { md.error(MDS, "Error loading Inputs list. Try refreshing browser."); } @Override public void onSuccess(Method method, List<Input> inputs) { Map<String, Integer> imap = new TreeMap<String, Integer>(); for (Input i : inputs) { String s = i.getName() + " - " + i.getComment(); if (s.length() > 64) { s = s.substring(0, 64) + "..."; } imap.put(s, i.getId()); } cellInput.setOptions(imap); dataGrid.redraw(); } }); }
@UiHandler("btnRefresh") void refreshRecords(ClickEvent e) { recordStore.getList().clear(); clientApi .iitemsApi() .list( new MethodCallback<List<InputItem>>() { @Override public void onFailure(Method method, Throwable e) { md.error(MDS, "Error loading user data", e); } @Override public void onSuccess(Method method, List<InputItem> recs) { Collections.sort( recs, new Comparator<InputItem>() { @Override public int compare(InputItem o1, InputItem o2) { return o1.getName().compareTo(o2.getName()); } }); recordStore.getList().addAll(recs); md.clear(MDS); } }); // TODO not sure it should be here (or: should it be loaded in sequential way ?) loadInputsList(); loadTxFormsList(); }
private void loadTxFormsList() { clientApi .transformsApi() .list( new MethodCallback<List<Transform>>() { @Override public void onFailure(Method method, Throwable exception) { md.error(MDS, "Error loading TxForms list. Try refreshing browser."); } @Override public void onSuccess(Method method, List<Transform> txforms) { Map<String, Integer> tmap = new TreeMap<String, Integer>(); for (Transform t : txforms) { String s = t.getName() + " - " + t.getComment(); if (s.length() > 64) { s = s.substring(0, 64) + "..."; } tmap.put(s, t.getId()); } cellTxForm.setOptions(tmap); dataGrid.redraw(); } }); }