@Inject public HelloWorldViewPresenter(final HelloWorldView helloWorldView) { this.helloWorldView = helloWorldView; ScriptInjector.fromUrl(GWT.getModuleBaseURL() + Constants.JAVASCRIPT_FILE_ID) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(final Void result) { Log.info(HelloWorldViewPresenter.class, Constants.JAVASCRIPT_FILE_ID + " loaded."); sayHello("Hello from Java Script!"); } @Override public void onFailure(final Exception e) { Log.error( HelloWorldViewPresenter.class, "Unable to load " + Constants.JAVASCRIPT_FILE_ID, e); } }) .inject(); }
public void onModuleLoad() { ScriptInjector.fromUrl(GWT.getModuleBaseURL()+"bower_components/webcomponents-lite.min.js").setWindow(ScriptInjector.TOP_WINDOW).setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { LOGGER.info("injection success"); importPolymer(); } @Override public void onFailure(Exception reason) { } }).inject(); LOGGER.info("Initializing Layout client UI module ..."); new ModuleConfigurator().configureModule(new LayoutUIModuleConfiguration()); }
private void injectDocReadyAndC8OCoreScripts(final String convertigoMachineUrl) { final String convertigoStudioJsUrl = convertigoMachineUrl + "/convertigo/studio/js/"; // First, inject docready.js = $(document).ready() (but native JS function) final String docReadyJsUrl = convertigoStudioJsUrl + "libs/docready.js"; ScriptInjector .fromUrl(docReadyJsUrl) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { // ... then convertigo.js and main.js injectC8OCoreScripts(convertigoStudioJsUrl); } @Override public void onFailure(Exception reason) { Window.alert(formatScriptInjectFailure(docReadyJsUrl, convertigoMachineUrl)); } }) .inject(); }
public static void init() { if(init) return; init = true; String javaScript = "ammo.js"; final String js = GWT.getModuleBaseForStaticFiles() + javaScript; ScriptInjector.fromUrl(js).setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception e) { GWT.log("inject " + js + " failure " + e); } @Override public void onSuccess(Void ok) { Bullet.initVariables(); } }).setWindow(ScriptInjector.TOP_WINDOW).inject(); }
private void injectJqueryScript() { // Workaround: https://goo.gl/1OrFqj ScriptInjector.fromUrl(JQUERY_UI_URL).setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception reason) { logger.info("Script load failed Info: " + reason); } @Override public void onSuccess(Void result) { logger.info("JQuery for Select loaded successful!"); init(); } }).setRemoveTag(true).setWindow(ScriptInjector.TOP_WINDOW).inject(); }
public void setCurrentLocationIfSupported() { Geolocation.getIfSupported().getCurrentPosition( new Callback<Position, PositionError>() { @Override public void onSuccess(Position result) { Position.Coordinates coordinates = result.getCoordinates(); LatLng center = LatLng.newInstance(coordinates.getLatitude(), coordinates.getLongitude()); getMapWidget().setCenter(center); } @Override public void onFailure(PositionError reason) { Window.alert(Texts.MSG_LOCATION_NOT_SUPPORTED); } }); }
/** * Request an access token from an OAuth 2.0 provider. * * <p> * If it can be determined that the user has already granted access, and the * token has not yet expired, and that the token will not expire soon, the * existing token will be passed to the callback. * </p> * * <p> * Otherwise, a popup window will be displayed which may prompt the user to * grant access. If the user has already granted access the popup will * immediately close and the token will be passed to the callback. If access * hasn't been granted, the user will be prompted, and when they grant, the * token will be passed to the callback. * </p> * * @param req Request for authentication. * @param callback Callback to pass the token to when access has been granted. */ public void login(AuthRequest req, final Callback<String, Throwable> callback) { lastRequest = req; lastCallback = callback; String authUrl = req.toUrl(urlCodex) + "&redirect_uri=" + urlCodex.encode(oauthWindowUrl); // Try to look up the token we have stored. final TokenInfo info = getToken(req); if (info == null || info.expires == null || expiringSoon(info)) { // Token wasn't found, or doesn't have an expiration, or is expired or // expiring soon. Requesting access will refresh the token. doLogin(authUrl, callback); } else { // Token was found and is good, immediately execute the callback with the // access token. scheduler.scheduleDeferred(new ScheduledCommand() { @Override public void execute() { callback.onSuccess(info.accessToken); } }); } }
private void addFoursquareAuth() { // Since the auth flow requires opening a popup window, it must be started // as a direct result of a user action, such as clicking a button or link. // Otherwise, a browser's popup blocker may block the popup. Button button = new Button("Authenticate with Foursquare"); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { final AuthRequest req = new AuthRequest(FOURSQUARE_AUTH_URL, FOURSQUARE_CLIENT_ID); AUTH.login(req, new Callback<String, Throwable>() { @Override public void onSuccess(String token) { Window.alert("Got an OAuth token:\n" + token + "\n" + "Token expires in " + AUTH.expiresIn(req) + " ms\n"); } @Override public void onFailure(Throwable caught) { Window.alert("Error:\n" + caught.getMessage()); } }); } }); RootPanel.get().add(button); }
private void addDailymotionAuth() { // Since the auth flow requires opening a popup window, it must be started // as a direct result of a user action, such as clicking a button or link. // Otherwise, a browser's popup blocker may block the popup. Button button = new Button("Authenticate with Dailymotion"); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { final AuthRequest req = new AuthRequest(DAILYMOTION_AUTH_URL, DAILYMOTION_CLIENT_ID); AUTH.login(req, new Callback<String, Throwable>() { @Override public void onSuccess(String token) { Window.alert("Got an OAuth token:\n" + token + "\n" + "Token expires in " + AUTH.expiresIn(req) + " ms\n"); } @Override public void onFailure(Throwable caught) { Window.alert("Error:\n" + caught.getMessage()); } }); } }); RootPanel.get().add(button); }
private void addWindowsLiveAuth() { // Since the auth flow requires opening a popup window, it must be started // as a direct result of a user action, such as clicking a button or link. // Otherwise, a browser's popup blocker may block the popup. Button button = new Button("Authenticate with Windows Live"); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { final AuthRequest req = new AuthRequest(WINDOWS_LIVE_AUTH_URL, WINDOWS_LIVE_CLIENT_ID) .withScopes(WINDOWS_LIVE_BASIC_SCOPE); AUTH.login(req, new Callback<String, Throwable>() { @Override public void onSuccess(String token) { Window.alert("Got an OAuth token:\n" + token + "\n" + "Token expires in " + AUTH.expiresIn(req) + " ms\n"); } @Override public void onFailure(Throwable caught) { Window.alert("Error:\n" + caught.getMessage()); } }); } }); RootPanel.get().add(button); }
private void addPremiumSupportHelpAction() { // userVoice init ScriptInjector.fromUrl(resources.userVoice().getSafeUri().asString()) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(Void aVoid) { // add action actionManager.registerAction( localizationConstant.createSupportTicketAction(), createSupportTicketAction); helpGroup.addSeparator(); helpGroup.add(createSupportTicketAction); } @Override public void onFailure(Exception e) { Log.error(getClass(), "Unable to inject UserVoice", e); } }) .inject(); }
@Override public void inject (final OnCompletion oc) { final String js = GWT.getModuleBaseForStaticFiles() + "freetype.js"; ScriptInjector.fromUrl(js).setCallback(new Callback<Void, Exception>() { @Override public void onFailure (Exception reason) { error = true; GWT.log("Exception injecting " + js, reason); oc.run(); } @Override public void onSuccess (Void result) { success = true; GWT.log("Success injecting js."); oc.run(); } }).setWindow(ScriptInjector.TOP_WINDOW).inject(); }
private static void injectScriptOneAfterAnother(final List<String> pathAsList) { ScriptInjector.fromUrl(pathAsList.remove(0)) .setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception reason) { } @Override public void onSuccess(Void result) { if (!pathAsList.isEmpty()) { injectScriptOneAfterAnother(pathAsList); } } }) .inject(); }
public void executeScript(final String script, final String engine, final String nodeUrl, final Callback<String, String> syncCallBack) { rm.executeNodeScript(LoginModel.getInstance().getSessionId(), script, engine, nodeUrl, new AsyncCallback<String>() { public void onFailure(Throwable caught) { LogModel.getInstance() .logImportantMessage("Failed to execute a script " + script + " on " + nodeUrl + " : " + JSONUtils.getJsonErrorMessage(caught)); syncCallBack.onFailure(JSONUtils.getJsonErrorMessage(caught)); } public void onSuccess(String result) { syncCallBack.onSuccess(parseScriptResult(result)); } }); }
@Override public <R> Promise<R> send(final Unmarshallable<R> unmarshaller) { return CallbackPromiseHelper.createFromCallback( new CallbackPromiseHelper.Call<R, Throwable>() { @Override public void makeCall(final Callback<R, Throwable> callback) { send( new AsyncRequestCallback<R>(unmarshaller) { @Override protected void onSuccess(R result) { callback.onSuccess(result); } @Override protected void onFailure(Throwable exception) { callback.onFailure(exception); } }); } }); }
/** * Sends an HTTP request based on the current {@link AsyncRequest} configuration. * * @return promise that may be resolved with the {@link Void} or rejected in case request error */ public Promise<Void> send() { return CallbackPromiseHelper.createFromCallback( new CallbackPromiseHelper.Call<Void, Throwable>() { @Override public void makeCall(final Callback<Void, Throwable> callback) { send( new AsyncRequestCallback<Void>() { @Override protected void onSuccess(Void result) { callback.onSuccess(null); } @Override protected void onFailure(Throwable exception) { callback.onFailure(exception); } }); } }); }
/** * Sends an HTTP request based on the current {@link AsyncRequest} configuration. * * @param unmarshaller unmarshaller that should be used to deserialize a response * @return promise that may be resolved with the deserialized response value or rejected in case * request error */ public <R> Promise<R> send(final Unmarshallable<R> unmarshaller) { return CallbackPromiseHelper.createFromCallback( new CallbackPromiseHelper.Call<R, Throwable>() { @Override public void makeCall(final Callback<R, Throwable> callback) { send( new AsyncRequestCallback<R>(unmarshaller) { @Override protected void onSuccess(R result) { callback.onSuccess(result); } @Override protected void onFailure(Throwable exception) { callback.onFailure(exception); } }); } }); }
@Override public Promise<Void> promise(final ActionEvent event) { if (event.getParameters() == null || event.getParameters().get(SHOW_HIDDEN_FILES_PARAM_ID) == null) { return Promises.reject( JsPromiseError.create( "Mandatory parameter" + SHOW_HIDDEN_FILES_PARAM_ID + " is not specified")); } final String showHiddenFilesKey = event.getParameters().get(SHOW_HIDDEN_FILES_PARAM_ID); final boolean isShowHiddenFiles = Boolean.valueOf(showHiddenFilesKey); final CallbackPromiseHelper.Call<Void, Throwable> call = new CallbackPromiseHelper.Call<Void, Throwable>() { @Override public void makeCall(final Callback<Void, Throwable> callback) { projectExplorerPresenter.showHiddenFiles(isShowHiddenFiles); callback.onSuccess(null); } }; return createFromCallback(call); }
private void injectTerminal(RequireJsLoader rJsLoader, final AsyncCallback<Void> callback) { rJsLoader.require( new Callback<JavaScriptObject[], Throwable>() { @Override public void onFailure(Throwable reason) { callback.onFailure(reason); } @Override public void onSuccess(JavaScriptObject[] result) { callback.onSuccess(null); } }, new String[] {"term/xterm"}, new String[] {"Xterm"}); }
@Inject public ActivityTrackingExtension(AppContext appContext) { ScriptInjector.fromUrl("/_app/activity.js") .setWindow(TOP_WINDOW) .setCallback( new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { init(appContext.getMasterApiEndpoint(), appContext.getWorkspaceId()); } @Override public void onFailure(Exception reason) {} private native void init(String restContext, String wsId) /*-{ $wnd.ActivityTracker.init(restContext, wsId); }-*/; }) .inject(); }
public Promise<Void> injectCompareWidget(final AsyncCallback<Void> callback) { loadCompareTheme(); return AsyncPromiseHelper.createFromAsyncRequest( call -> requireJsLoader.require( new Callback<JavaScriptObject[], Throwable>() { @Override public void onFailure(Throwable reason) { callback.onFailure(reason); } @Override public void onSuccess(JavaScriptObject[] result) { callback.onSuccess(null); } }, new String[] {"built-compare/built-compare-amd.min"}, new String[] {GIT_COMPARE_MODULE})); }
private void prepareTemplate(DigitalObject templateObj, DescriptionMetadata templateDesc) { if (templateDesc != null) { prepareDescription(getCurrent(), templateDesc); return ; } ModsCustomDataSource.getInstance().fetchDescription(templateObj, new Callback<DescriptionMetadata, String>() { @Override public void onFailure(String reason) { stop(reason); } @Override public void onSuccess(DescriptionMetadata result) { templateDescriptions[getTemplateIndex()] = result; prepareDescription(getCurrent(), result); } }, false); }
private void initSearchList(String[] pids) { expect(); SearchDataSource.getInstance().find(pids, new Callback<ResultSet, Void>() { @Override public void onFailure(Void reason) { searchList = new RecordList(); release(); } @Override public void onSuccess(ResultSet result) { searchList = result; release(); } }); }
private void basicFetch(Criteria criteria, final Callback<ResultSet, Void> callback) { final ResultSet resultSet = new ResultSet(this); resultSet.setCriteria(criteria); resultSet.setFetchMode(FetchMode.BASIC); // resultSet.setCriteriaPolicy(CriteriaPolicy.DROPONCHANGE); // server resource returns full result in case of SearchType.PIDS query if (resultSet.lengthIsKnown()) { callback.onSuccess(resultSet); } else { final HandlerRegistration[] handler = new HandlerRegistration[1]; handler[0] = resultSet.addDataArrivedHandler(new DataArrivedHandler() { @Override public void onDataArrived(DataArrivedEvent event) { handler[0].removeHandler(); callback.onSuccess(resultSet); } }); resultSet.get(0); } }
public static void getModels(boolean reload, final Callback<ResultSet, Void> callback) { final ResultSet models = getModels(reload); if (models.lengthIsKnown()) { callback.onSuccess(models); } else { final HandlerRegistration[] handler = new HandlerRegistration[1]; handler[0] = models.addDataArrivedHandler(new DataArrivedHandler() { @Override public void onDataArrived(DataArrivedEvent event) { handler[0].removeHandler(); callback.onSuccess(models); } }); } }
private void askForExportOptions(String[] pids) { if (pids == null || pids.length == 0) { return ; } Record export = new Record(); export.setAttribute(ExportResourceApi.DESA_PID_PARAM, pids); ExportOptionsWidget.showOptions(export, new Callback<Record, Void>() { @Override public void onFailure(Void reason) { // no-op } @Override public void onSuccess(Record result) { exportOrValidate(result); } }); }
private void fetchSiblings(final String pid) { SearchDataSource.getInstance().findParent(pid, null, new Callback<ResultSet, Void>() { @Override public void onFailure(Void reason) { } @Override public void onSuccess(ResultSet result) { if (result.isEmpty()) { SC.warn(i18n.DigitalObjectNavigateAction_NoParent_Msg()); } else { Record parent = result.first(); DigitalObject parentObj = DigitalObject.createOrNull(parent); if (parentObj != null) { scheduleFetchSiblings(parentObj.getPid(), pid); } } } }); }
private void validate(final Validatable validable, final Record[] digitalObjects) { if (digitalObjects != null && digitalObjects.length > 0) { // ensure models are fetched MetaModelDataSource.getModels(false, new Callback<ResultSet, Void>() { @Override public void onFailure(Void reason) { } @Override public void onSuccess(ResultSet result) { new ValidateTask(validable, digitalObjects).execute(); } }); } else { // no-op } }
private void loadParentSelection(final String pid, String batchId) { if (pid == null && batchId == null) { selectionView.setSelection(null); return ; } SearchDataSource.getInstance().findParent(pid, batchId, new Callback<ResultSet, Void>() { @Override public void onFailure(Void reason) { } @Override public void onSuccess(ResultSet result) { if (result.isEmpty()) { selectionView.setSelection(null); } else { newParent = oldParent = result.first(); selectionView.setSelection(newParent); } loadFailed = false; } }); }
private void submitLoginForm() { boolean ok1 = username.validate(true); boolean ok2 = password.validate(true); if(ok1 && ok2) { UserCredentials credentials = new UserCredentials(); credentials.setName(username.getValue()); credentials.setPassword(password.getValue()); UserREST.login(credentials, new Callback<UserSession, Throwable>() { @Override public void onFailure(Throwable reason) { AppNotification.notifyFailure(reason.getMessage()); } @Override public void onSuccess(UserSession session) { toggleLoginLogoutButtons(); username.setValue(null); password.setValue(null); loginform.hide(); } }); } }
private void submitPublishForm() { String label = softwarelabel.getValue(); if(softwarelabel.validate(true)) { Software tmpsw = new Software(); tmpsw.setLabel(label); this.api.publishSoftware(tmpsw, new Callback<Software, Throwable>() { public void onSuccess(Software sw) { // Add item to list SoftwareSummary newsw = new SoftwareSummary(sw); newsw.setExternalRepositoryId(SoftwareREST.LOCAL); addToList(newsw); updateList(); // Go to the new item History.newItem(NameTokens.publish + "/" + sw.getName()); publishdialog.hide(); softwarelabel.setValue(null); } @Override public void onFailure(Throwable exception) { } }); } }
@UiHandler("facets") void onFacetSelection(FacetSelectionEvent event) { final List<String> loaded = new ArrayList<String>(); final List<SoftwareSummary> facetList = new ArrayList<SoftwareSummary>(); for(final String sname : apis.keySet()) { SoftwareREST sapi = apis.get(sname); sapi.getSoftwareListFaceted(facets.getFacets(), new Callback<List<SoftwareSummary>, Throwable>() { @Override public void onSuccess(List<SoftwareSummary> list) { facetList.addAll(list); loaded.add(sname); if(loaded.size() == apis.size()) { filteredSoftwareIdMap.clear(); for(SoftwareSummary flist: facetList) filteredSoftwareIdMap.put(flist.getId(), true); updateList(); } } @Override public void onFailure(Throwable reason) { } }); } }
private void initAgents() { this.api.getEnumerationsForType(KBConstants.PROVNS() + "Agent", new Callback<List<MetadataEnumeration>, Throwable>() { @Override public void onSuccess(List<MetadataEnumeration> list) { Collections.sort(list, metacompare); listProvider.getList().clear(); listProvider.getList().addAll(list); listProvider.flush(); initMaterial(); Window.scrollTo(0, 0); } @Override public void onFailure(Throwable reason) { } }); }
private void setPermButtonVisibility() { this.api.getPermissionFeatureEnabled(new Callback<Boolean, Throwable>() { @Override public void onFailure(Throwable reason) { permbutton.setVisible(false); } @Override public void onSuccess(Boolean permEnabled) { UserSession session = SessionStorage.getSession(); if(permEnabled && ((session != null && session.getRoles().contains("admin")) || software.getPermission().ownernameExists(loggedinuser))) { permbutton.setVisible(true); } } }); }
private void setPermissionList() { this.api.getPermissionTypes(new Callback<List<String>, Throwable>() { @Override public void onFailure(Throwable reason) { AppNotification.notifyFailure(reason.getMessage()); } @Override public void onSuccess(List<String> list) { for(String name : list) { Option opt = new Option(); opt.setText(name); opt.setValue(name); permlist.add(opt); } permlist.refresh(); } }); }
private void setUserList() { UserREST.getUsers(new Callback<List<String>, Throwable>() { @Override public void onFailure(Throwable reason) { AppNotification.notifyFailure(reason.getMessage()); } @Override public void onSuccess(List<String> list) { int i=0; for(String name : list) { userlist.addItem(name); if(name.equals(username)) userlist.setItemSelected(i, true); i++; } } }); }
@UiHandler("deletebutton") public void onDelete(ClickEvent event) { final String name = this.username; if (Window.confirm("Are you sure you want to delete user " + name + "?")) { UserREST.deleteUser(name, new Callback<Void, Throwable>() { @Override public void onFailure(Throwable reason) { AppNotification.notifyFailure("Could not delete: "+reason.getMessage()); } @Override public void onSuccess(Void result) { AppNotification.notifySuccess(name + " deleted", 1000); History.replaceItem(History.getToken()); } }); } }
private void initSoftware(String softwarename) { loading.setVisible(true); this.api.getSoftware(softwarename, new Callback<Software, Throwable>() { @Override public void onSuccess(Software sw) { software = sw; initSoftwareRDF(); loading.setVisible(false); if(vocabulary != null) showSoftware(software); } @Override public void onFailure(Throwable exception) { GWT.log("Error fetching Software", exception); } }, false); }