com.google.gwt.user.client.rpc.AsyncCallback Java Examples
The following examples show how to use
com.google.gwt.user.client.rpc.AsyncCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataSourceStoreImpl.java From core with GNU Lesser General Public License v2.1 | 6 votes |
public void loadXADataSources(final AsyncCallback<List<XADataSource>> callback) { AddressBinding address = xadsMetaData.getAddress(); ModelNode operation = address.asSubresource(baseadress.getAdress()); operation.get(OP).set(READ_CHILDREN_RESOURCES_OPERATION); dispatcher.execute(new DMRAction(operation), new SimpleCallback<DMRResponse>() { @Override public void onSuccess(DMRResponse result) { ModelNode response = result.get(); if (response.isFailure()) { callback.onFailure(new RuntimeException(response.getFailureDescription())); } else { List<XADataSource> datasources = xaDataSourceAdapter.fromDMRList(response.get(RESULT).asList()); callback.onSuccess(datasources); } } }); }
Example #2
Source File: MenuRightsPanel.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
public void onApply() { // Apply all rights menu.setRights(this.getRights()); SecurityService.Instance.get().applyRights(menu, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { Log.serverError(caught); } @Override public void onSuccess(Void result) { Log.info(I18N.message("appliedrightsmenu"), null); } }); }
Example #3
Source File: TeachingRequestDetailPage.java From unitime with Apache License 2.0 | 6 votes |
public void showRequestDetail(Long id) { iAssignmentTable.clearTable(1); LoadingWidget.getInstance().show(MESSAGES.waitLoadTeachingRequestDetail()); ToolBox.setMaxHeight(iScroll.getElement().getStyle(), Math.round(0.9 * Window.getClientHeight()) + "px"); RPC.execute(new TeachingRequestDetailRequest(id), new AsyncCallback<TeachingRequestInfo>() { @Override public void onFailure(Throwable caught) { LoadingWidget.getInstance().hide(); UniTimeNotifications.error(MESSAGES.failedToLoadTeachingRequestDetail(caught.getMessage()), caught); ToolBox.checkAccess(caught); } @Override public void onSuccess(TeachingRequestInfo result) { LoadingWidget.getInstance().hide(); populate(result, null, null); GwtHint.hideHint(); center(); RootPanel.getBodyElement().getStyle().setOverflow(Overflow.HIDDEN); } }); }
Example #4
Source File: SecurityUser.java From document-management-system with GNU General Public License v2.0 | 6 votes |
/** * Gets the ungranted users by filter */ public void getFilteredUngrantedUsers(String filter) { if (uuid != null) { resetUnassigned(); authService.getFilteredUngrantedUsers(uuid, filter, new AsyncCallback<List<GWTGrantedUser>>() { @Override public void onSuccess(List<GWTGrantedUser> result) { for (GWTGrantedUser gu : result) { unassignedUser.addRow(gu.getUser(), false); } } @Override public void onFailure(Throwable caught) { Main.get().showError("GetUngrantedUsers", caught); } }); } }
Example #5
Source File: ReservationEdit.java From unitime with Apache License 2.0 | 6 votes |
@Override public void execute(final AsyncCallback<Boolean> callback) { RPC.execute(new ReservationDefaultExpirationDatesRpcRequest(), new AsyncCallback<DefaultExpirationDates>() { @Override public void onFailure(Throwable caught) { callback.onFailure(caught); } @Override public void onSuccess(DefaultExpirationDates result) { iExpirations = result; if (iExpirations.hasInclusive()) iInclusive.setItemText(0, iExpirations.isInclusive() ? MESSAGES.reservationInclusiveDefaultTrue() : MESSAGES.reservationInclusiveDefaultFalse()); callback.onSuccess(true); } }); }
Example #6
Source File: FolderNavigator.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
/** * Moves the currently selected folder to the new parent folder * * @param targetFolderId The parent folder */ public void moveTo(final long targetFolderId) { long[] ids = getSelectedIds(); for (long id : ids) { TreeNode node = getTree().find("folderId", (Object) id); getTree().remove(node); } FolderService.Instance.get().move(ids, targetFolderId, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { Log.serverError(caught); Log.warn(I18N.message("operationnotallowed"), null); } @Override public void onSuccess(Void ret) { TreeNode target = getTree().find("folderId", Long.toString(targetFolderId)); if (target != null) getTree().reloadChildren(target); } }); }
Example #7
Source File: DefaultCommandController.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onFailure(Throwable caught) { if (caught instanceof StatusCodeException) { GWT.reportUncaughtException(caught); } else { for (Request request : this.requests) { if (request.param.getCallbacks().isEmpty()) { GWT.reportUncaughtException(caught); } for (AsyncCallback requestCallback : request.param.getCallbacks()) { requestCallback.onFailure(caught); } } if (this.callback != null) { this.callback.onFailure(caught); } } }
Example #8
Source File: DeploymentBrowseContentPresenter.java From core with GNU Lesser General Public License v2.1 | 6 votes |
private void browseContent() { Operation operation = new Operation.Builder(BROWSE_CONTENT, new ResourceAddress().add("deployment", deploymentName)) .build(); dispatcher.execute(new DMRAction(operation), new AsyncCallback<DMRResponse>() { @Override public void onFailure(final Throwable caught) { Console.error(Console.CONSTANTS.unableToReadDeployment(), caught.getMessage()); } @Override public void onSuccess(final DMRResponse response) { ModelNode result = response.get(); if (result.isFailure()) { Console.error(Console.CONSTANTS.unableToReadDeployment(), result.getFailureDescription()); } else { List<ModelNode> res = result.get(RESULT).asList(); getView().browseContent(res); } } }); }
Example #9
Source File: WorkflowNoteEditor.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
private void onSave() { if (!noteForm.validate()) return; WorkflowService.Instance.get().addNote(parentDialog.getWorkflow().getSelectedTask().getId(), message.getValue().toString(), new AsyncCallback<Long>() { @Override public void onFailure(Throwable caught) { Log.serverError(caught); } @Override public void onSuccess(Long noteId) { parentDialog.refreshAndSelectNotesTab(); destroy(); } }); }
Example #10
Source File: TeachingRequestsWidget.java From unitime with Apache License 2.0 | 6 votes |
protected void init() { RPC.execute(new TeachingRequestsPagePropertiesRequest(), new AsyncCallback<TeachingRequestsPagePropertiesResponse>() { @Override public void onFailure(Throwable caught) { iHeader.setErrorMessage(MESSAGES.failedToInitialize(caught.getMessage())); iHeader.setCollapsible(null); UniTimeNotifications.error(MESSAGES.failedToInitialize(caught.getMessage()), caught); ToolBox.checkAccess(caught); } @Override public void onSuccess(TeachingRequestsPagePropertiesResponse result) { iTable = new TeachingRequestsTable() { @Override protected void onAssignmentChanged(List<AssignmentInfo> assignments) { if (iTable.isVisible()) refresh(); } }; iTable.setProperties(result); iTable.setVisible(false); addRow(iTable); populate(); } }); }
Example #11
Source File: WebServicesStore.java From core with GNU Lesser General Public License v2.1 | 6 votes |
private void read(final String childType, final List<Property> list, final Dispatcher.Channel channel) { final ModelNode op = readChildResourcesOp(childType); dispatcher.execute(new DMRAction(op), new AsyncCallback<DMRResponse>() { @Override public void onFailure(Throwable caught) { channel.nack(caught); } @Override public void onSuccess(DMRResponse dmrResponse) { ModelNode response = dmrResponse.get(); if (response.isFailure()) { channel.nack(new RuntimeException("Failed to read child resources using " + op + ": " + response.getFailureDescription())); } else { list.clear(); list.addAll(response.get(RESULT).asPropertyList()); channel.ack(); } } }); }
Example #12
Source File: DiagramBuilder.java From EasyML with Apache License 2.0 | 6 votes |
/** load a dataset widget according to a node from graph-describe.xml */ private void setupDatasetWidget(final OozieDatasetNode node,final DiagramController dcontroller) { datasetSrv.load(node.getModuleId(), new AsyncCallback<Dataset>() { @Override public void onFailure(Throwable e) { Window.alert(e.getMessage()); } @Override public void onSuccess(Dataset dataset) { logger.info("setup dataset:" + dataset.getName()); // create widget according to moduleId DatasetWidget widget = new DatasetWidget(dataset, node.getId()); widget.getOutNodeShapes().get(0).setFileId(node.getFile()); dcontroller.addWidget(widget, node.getX(), node.getY()); logger.info("setup dataset success"); } }); }
Example #13
Source File: WebServicesStore.java From core with GNU Lesser General Public License v2.1 | 6 votes |
private void readConfig(final AddressTemplate configAddress, final Dispatcher.Channel channel) { final ModelNode op = readConfigOp(configAddress); dispatcher.execute(new DMRAction(op), new AsyncCallback<DMRResponse>() { @Override public void onFailure(Throwable caught) { channel.nack(caught); } @Override public void onSuccess(DMRResponse dmrResponse) { ModelNode response = dmrResponse.get(); if (response.isFailure()) { channel.nack(new RuntimeException("Failed to read child resources using " + op + ": " + response.getFailureDescription())); } else { ModelNode result = response.get(RESULT); currentConfig = result; channel.ack(); } } }); }
Example #14
Source File: WorkflowDialog.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
public void onStart(final long[] ids) { if (!form.validate()) return; ListGridRecord selection = workflow.getSelectedRecord(); WorkflowService.Instance.get().startWorkflow(selection.getAttributeAsString("name"), selection.getAttributeAsString("description"), tag.getValueAsString(), ids, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { Log.serverError(caught); } @Override public void onSuccess(Void result) { Log.info(I18N.message("event.workflow.start"), null); destroy(); } }); }
Example #15
Source File: DBController.java From EasyML with Apache License 2.0 | 5 votes |
/** * Save dataset to the database. * * @param panel * @param saveDatasetPanel * @param dataset * @param grid * @return If submit is success */ public boolean submitSaveDataset2DB(final PreviewPopupPanel panel, final SaveDatasetPanel saveDatasetPanel , final Dataset dataset, final DescribeGrid grid) { String name = grid.getText("Name"); if (name == null || "".equals(name)) { Window.alert("Name could not be empty!"); return false; } String category = grid.getText("Category"); if(category == null || "".equals(category) || category.equals("Choose Category")){ Window.alert("Category could not be empty!"); return false; } datasetBinder.sync(grid, dataset); if (dataset == null) return false; datasetSrv.save(grid.asDataset(dataset), dataset.getPath(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { logger.info(caught.getMessage()); } @Override public void onSuccess(Void result) { Window.alert("save data set succeeded!"); saveDatasetPanel.hide(); panel.show(); panel.center(); } }); return true; }
Example #16
Source File: SesRequestManager.java From SensorWebClient with GNU General Public License v2.0 | 5 votes |
public void getStations() { AsyncCallback<SesClientResponse> callback = new AsyncCallback<SesClientResponse>() { @Override public void onFailure(Throwable arg0) { getToasterInstance().addErrorMessage(i18n.failedGetStations()); } @Override public void onSuccess(SesClientResponse response) { getMainEventBus().fireEvent(new InformUserEvent(response)); } }; sesTimeseriesService.getStations(callback); }
Example #17
Source File: VMMetricsPresenter.java From core with GNU Lesser General Public License v2.1 | 5 votes |
public void loadVMStatus() { getView().clearSamples(); loadMetricCmd.execute(new AsyncCallback<CompositeVMMetric>() { @Override public void onFailure(Throwable caught) { Console.warning(caught.getMessage()); } @Override public void onSuccess(CompositeVMMetric result) { getView().setHeap(new Metric( result.getHeap().getMax(), result.getHeap().getUsed(), result.getHeap().getCommitted(), result.getHeap().getInit() )); getView().setNonHeap(new Metric( result.getNonHeap().getMax(), result.getNonHeap().getUsed(), result.getNonHeap().getCommitted(), result.getNonHeap().getInit() )); getView().setThreads(new Metric( result.getThreads().getCount(), result.getThreads().getDaemonCount() )); getView().setOSMetric(result.getOs()); getView().setRuntimeMetric(result.getRuntime()); } }); }
Example #18
Source File: DataSourceStoreImpl.java From core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void deletePoolConfig(boolean isXA, final String dsName, final AsyncCallback<ResponseWrapper<Boolean>> callback) { Map<String, Object> resetValues = new HashMap<String, Object>(); resetValues.put("minPoolSize", 0); resetValues.put("maxPoolSize", 20); resetValues.put("poolStrictMin", false); resetValues.put("poolPrefill", false); savePoolConfig(isXA, dsName, resetValues, callback); }
Example #19
Source File: ChatPanel.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
protected void onPost(String message) { if (message == null || message.trim().isEmpty()) return; ChatService.Instance.get().post(message, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { Log.serverError(caught); } @Override public void onSuccess(Void arg) { postForm.clearValue("post"); } }); }
Example #20
Source File: WordCloudDetailApp.java From swcv with MIT License | 5 votes |
private void updateWordCloud(boolean useRandomSetting) { final DialogBox shadow = AppUtils.createShadow(); shadow.center(); shadow.show(); final DialogBox loadingBox = AppUtils.createLoadingBox(); loadingBox.show(); loadingBox.center(); if (useRandomSetting) setting.setRandomSetting(); service.updateWordCloud(id, inputText, setting, new AsyncCallback<WordCloud>() { public void onSuccess(WordCloud cloud) { loadingBox.hide(); shadow.hide(); initializeContentPanel(cloud); initializeSettingPanel(cloud); } public void onFailure(Throwable caught) { loadingBox.hide(); DialogBox errorBox = AppUtils.createErrorBox(caught, shadow); errorBox.center(); errorBox.show(); } }); }
Example #21
Source File: AssignmentHistoryPage.java From unitime with Apache License 2.0 | 5 votes |
protected void search(final AsyncCallback<Boolean> callback) { final AssignmentHistoryRequest request = new AssignmentHistoryRequest(); request.setFilter(iFilter.getValue()); iFilter.getFooter().clearMessage(); for (int row = iPanel.getRowCount() - 1; row > 0; row--) iPanel.removeRow(row); iFilter.getFooter().showLoading(); iFilter.getFooter().setEnabled("search", false); LoadingWidget.showLoading(MESSAGES.waitLoadingData()); RPC.execute(request, new AsyncCallback<AssignmentHistoryResponse>() { @Override public void onFailure(Throwable caught) { LoadingWidget.hideLoading(); iFilter.getFooter().setErrorMessage(MESSAGES.failedToLoadAssignmentHistory(caught.getMessage())); UniTimeNotifications.error(MESSAGES.failedToLoadAssignmentHistory(caught.getMessage()), caught); iFilter.getFooter().setEnabled("search", true); if (callback != null) callback.onFailure(caught); } @Override public void onSuccess(AssignmentHistoryResponse result) { LoadingWidget.hideLoading(); iFilter.getFooter().clearMessage(); populate(request.getFilter(), result); iFilter.getFooter().setEnabled("search", true); if (callback != null) callback.onSuccess(!result.getRows().isEmpty()); } }); }
Example #22
Source File: EventAdd.java From unitime with Apache License 2.0 | 5 votes |
public void checkEnrollments(final List<RelatedObjectInterface> relatedObjects, final List<MeetingInterface> meetings) { if (relatedObjects == null || relatedObjects.isEmpty() || getEventType() != EventType.Course) { iForm.getRowFormatter().setVisible(iEnrollmentRow, false); iForm.getRowFormatter().setVisible(iEnrollmentRow + 1, false); } else { iForm.getRowFormatter().setVisible(iEnrollmentRow, true); iForm.getRowFormatter().setVisible(iEnrollmentRow + 1, true); if (relatedObjects.equals(iLastRelatedObjects) && meetings.equals(iLastMeetings)) return; iEnrollmentHeader.showLoading(); iLastMeetings = meetings; iLastRelatedObjects = relatedObjects; RPC.execute(EventEnrollmentsRpcRequest.getEnrollmentsForRelatedObjects(relatedObjects, meetings, iEvent.getId(), iProperties.getSessionId()), new AsyncCallback<GwtRpcResponseList<ClassAssignmentInterface.Enrollment>>() { @Override public void onFailure(Throwable caught) { if (relatedObjects.equals(iLastRelatedObjects) && meetings.equals(iLastMeetings)) { iEnrollments.clear(); UniTimeNotifications.error(MESSAGES.failedNoEnrollments(caught.getMessage()), caught); } } @Override public void onSuccess(GwtRpcResponseList<Enrollment> result) { if (relatedObjects.equals(iLastRelatedObjects) && meetings.equals(iLastMeetings)) { iEnrollmentHeader.clearMessage(); iEnrollments.clear(); iEnrollments.populate(result, null); } } }); } }
Example #23
Source File: ServerGroupDAOImpl.java From core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void loadProperties(ServerGroupRecord group, final AsyncCallback<List<PropertyRecord>> callback) { final ModelNode operation = new ModelNode(); operation.get(OP).set(ModelDescriptionConstants.READ_CHILDREN_RESOURCES_OPERATION); operation.get(ADDRESS).add("server-group", group.getName()); operation.get(CHILD_TYPE).set("system-property"); dispatcher.execute(new DMRAction(operation), new SimpleCallback<DMRResponse>() { @Override public void onSuccess(DMRResponse dmrResponse) { ModelNode result = dmrResponse.get(); List<Property> properties = result.get(RESULT).asPropertyList(); List<PropertyRecord> records = new ArrayList<PropertyRecord>(properties.size()); for(Property prop : properties) { PropertyRecord record = factory.property().as(); record.setKey(prop.getName()); ModelNode payload = prop.getValue().asObject(); record.setValue(payload.get("value").asString()); record.setBootTime(payload.get("boot-time").asBoolean()); records.add(record); } callback.onSuccess(records); } }); }
Example #24
Source File: OnlineSectioningTest.java From unitime with Apache License 2.0 | 5 votes |
private void listCourseOfferings(final String course, final Callback<Collection<CourseAssignment>> callback) { debug("listCourseOfferings(" + course + ")"); iSectioningService.listCourseOfferings(iSessionId, null, course, 20, new AsyncCallback<Collection<CourseAssignment>>() { @Override public void onFailure(Throwable caught) { warn(" listCourseOfferings(" + course + ") failed: " + caught.getMessage()); callback.execute(null, caught); } @Override public void onSuccess(Collection<CourseAssignment> result) { callback.execute(result, null); } }); }
Example #25
Source File: KeystoreUploader.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
public KeystoreUploader(TenantKeystorePanel keystorePanel) { setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON); this.keystorePanel = keystorePanel; setTitle(I18N.message("uploadkeystore")); setWidth(420); setHeight(190); setCanDragResize(true); setIsModal(true); setShowModalMask(true); centerInPage(); layout.setMembersMargin(2); layout.setMargin(2); // Create a new uploader panel and attach it to the window uploader = new MultiUploader(); uploader.setMaximumFiles(1); uploader.setStyleName("upload"); uploader.setFileInputPrefix("LDOC"); uploader.setWidth("400px"); uploader.reset(); uploader.setHeight("40px"); // Add a finish handler which will load the image once the upload // finishes uploader.addOnFinishUploadHandler(onFinishUploaderHandler); sendButton = new IButton(I18N.message("send")); sendButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { @Override public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) { onSend(); } }); prepareForm(); layout.addMember(form); layout.addMember(uploader); layout.addMember(sendButton); addItem(layout); // Cleanup the upload folder DocumentService.Instance.get().cleanUploadedFileFolder(new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(Void result) { } }); }
Example #26
Source File: RulesController.java From geofence with GNU General Public License v2.0 | 4 votes |
/** * On rule priority up. * * @param event * the event */ private void onRulePriorityUp(AppEvent event) { if (tabWidget != null) { Object tabData = event.getData(); if (tabData instanceof RuleModel) { RuleModel model = (RuleModel) tabData; RulesTabItem rulesTabItem = (RulesTabItem) tabWidget.getItemByItemId(RULES_TAB_ITEM_ID); final RuleGridWidget rulesInfoWidget = rulesTabItem.getRuleManagementWidget().getRulesInfo(); final Grid<RuleModel> grid = rulesInfoWidget.getGrid(); List<RuleModel> rules = new ArrayList<RuleModel>(grid.getStore().getModels()); if (model.getPriority() > 0) { int indexUp = rules.lastIndexOf(model); RuleModel rup = null; RuleModel rupup = null; rup = ((RuleModel) (rules.get(indexUp))); if ((indexUp - 1) >= 0) { rupup = ((RuleModel) (rules.get(indexUp - 1))); } if (rupup != null) { rulesManagerServiceRemote.swap(rup.getId(), rupup.getId(), new AsyncCallback<Void>() { public void onFailure(Throwable caught) { Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, new String[] { I18nProvider.getMessages().ruleServiceName(), I18nProvider.getMessages().ruleFetchFailureMessage() }); } public void onSuccess(Void result) { grid.getStore().getLoader().setSortDir(SortDir.ASC); grid.getStore().getLoader().setSortField( BeanKeyValue.PRIORITY.getValue()); grid.getStore().getLoader().load(); Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, new String[] { I18nProvider.getMessages().ruleServiceName(), I18nProvider.getMessages().ruleFetchSuccessMessage() }); } }); } } } } }
Example #27
Source File: UserInfo.java From document-management-system with GNU General Public License v2.0 | 4 votes |
/** * getPendingChatRoomUser */ private void getPendingChatRoomUser() { getPendingChatRoomUser = true; if (chatConnected) { chatService.getPendingChatRoomUser(new AsyncCallback<List<String>>() { @Override public void onSuccess(List<String> result) { for (String room : result) { ChatRoomPopup chatRoomPopup = new ChatRoomPopup("", room); chatRoomPopup.center(); chatRoomPopup.getPendingMessage(room); addChatRoom(chatRoomPopup); } getPendingChatRoomUser = false; new Timer() { @Override public void run() { getPendingChatRoomUser(); } }.schedule(NEW_ROOM_REFRESHING_TIME); } @Override public void onFailure(Throwable caught) { Log.error(UserInfo.class + ".getPendingChatRoomUser().onFailure(" + caught + ")"); getPendingChatRoomUser = false; if (caught instanceof StatusCodeException && ((StatusCodeException) caught).getStatusCode() == 0) { new Timer() { @Override public void run() { getPendingChatRoomUser(); } }.schedule(NEW_ROOM_REFRESHING_TIME); } else { Main.get().showError("UserInfo.getPendingChatRoomUser", caught); } } }); } else { getPendingChatRoomUser = false; } }
Example #28
Source File: FilterBox.java From unitime with Apache License 2.0 | 4 votes |
@Override public void getSuggestions(List<Chip> chips, String text, AsyncCallback<Collection<Suggestion>> callback) { callback.onSuccess(null); }
Example #29
Source File: ChangePassword.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
public ChangePassword() { super(); GUIUser user = Session.get().getUser(); setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON); setTitle(I18N.message("changepassword")); setWidth(300); setIsModal(true); setShowModalMask(true); centerInPage(); setAutoSize(true); final ValuesManager vm = new ValuesManager(); final DynamicForm form = new DynamicForm(); form.setValuesManager(vm); form.setWidth(350); form.setMargin(5); PasswordItem password = new PasswordItem(); password.setName(PASSWORD); password.setTitle(I18N.message(PASSWORD)); password.setRequired(true); MatchesFieldValidator equalsValidator = new MatchesFieldValidator(); equalsValidator.setOtherField(NEWPASSWORDAGAIN); equalsValidator.setErrorMessage(I18N.message("passwordnotmatch")); LengthRangeValidator sizeValidator = new LengthRangeValidator(); sizeValidator .setErrorMessage(I18N.message("errorfieldminlenght", Integer.toString(user.getPasswordMinLenght()))); sizeValidator.setMin(user.getPasswordMinLenght()); PasswordItem newPass = new PasswordItem(); newPass.setName(NEWPASSWORD); newPass.setTitle(I18N.message(NEWPASSWORD)); newPass.setRequired(true); newPass.setValidators(equalsValidator, sizeValidator); PasswordItem newPassAgain = new PasswordItem(); newPassAgain.setName(NEWPASSWORDAGAIN); newPassAgain.setTitle(I18N.message(NEWPASSWORDAGAIN)); newPassAgain.setWrapTitle(false); newPassAgain.setRequired(true); final ButtonItem apply = new ButtonItem(); apply.setTitle(I18N.message("apply")); apply.setAutoFit(true); apply.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { vm.validate(); if (!vm.hasErrors()) { if (vm.getValueAsString(PASSWORD).equals(vm.getValueAsString(NEWPASSWORD))) { Map<String, String> errors = new HashMap<String, String>(); errors.put(NEWPASSWORD, I18N.message("useanotherpassword")); vm.setErrors(errors, true); return; } apply.setDisabled(true); SecurityService.Instance.get().changePassword(user.getId(), user.getId(), vm.getValueAsString(PASSWORD), vm.getValueAsString(NEWPASSWORD), false, new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { apply.setDisabled(false); SC.warn(caught.getMessage()); } @Override public void onSuccess(Integer ret) { apply.setDisabled(false); if (ret.intValue() > 0) { // Alert the user and maintain the popup // opened if (ret == 1) SC.warn(I18N.message("wrongpassword")); else if (ret == 2) SC.warn(I18N.message("passwdnotnotified")); else SC.warn(I18N.message("genericerror")); } else { SC.say(I18N.message("yourpasswordhaschanged")); Log.info(I18N.message("event.user.passwordchanged"), null); } // Close the popup ChangePassword.this.destroy(); } }); } } }); form.setFields(password, newPass, newPassAgain, apply); addItem(form); }
Example #30
Source File: RepositoriesPanel.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void onDraw() { body.setMembers(new StoragesPanel()); // The Folders Tab Tab foldersTab = new Tab(); foldersTab.setTitle(I18N.message("folders")); foldersForm.setWidth(400); foldersForm.setColWidths(1, "*"); foldersForm.setTitleOrientation(TitleOrientation.LEFT); foldersTab.setPane(foldersForm); tabs.addTab(foldersTab); SettingService.Instance.get().loadSettingsByNames( new String[] { "conf.dbdir", "conf.exportdir", "conf.importdir", "conf.logdir", "conf.plugindir", "conf.userdir" }, new AsyncCallback<GUIParameter[]>() { @Override public void onFailure(Throwable caught) { Log.serverError(caught); } @Override public void onSuccess(GUIParameter[] folderParameters) { List<FormItem> items = new ArrayList<FormItem>(); for (GUIParameter f : folderParameters) { TextItem item = ItemFactory.newTextItem(f.getName(), f.getName().substring(f.getName().indexOf('.') + 1), f.getValue()); item.setValue(f.getValue()); item.setRequired(true); item.setWidth(400); items.add(item); } ButtonItem save = new ButtonItem("save", I18N.message("save")); save.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() { @Override public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) { onSaveFolders(); } }); items.add(save); save.setDisabled(Session.get().isDemo() && Session.get().getUser().getId() == 1); foldersForm.setItems(items.toArray(new FormItem[0])); } }); }