List of usage examples for com.google.gwt.user.client Window alert
public static void alert(String msg)
From source file:com.google.appinventor.client.wizards.TemplateUploadWizard.java
License:Open Source License
/** * Helper method for opening a project given its Url * @param url A string of the form "http://... .asc * @param onSuccessCommand/*from w w w . j a v a2s . co m*/ */ private static void openTemplateProject(String url, final NewProjectCommand onSuccessCommand) { final Ode ode = Ode.getInstance(); // This Async callback is called after the project is input and created final OdeAsyncCallback<UserProject> callback = new OdeAsyncCallback<UserProject>( // failure message MESSAGES.createProjectError()) { @Override public void onSuccess(UserProject projectInfo) { // This just adds the new project to the project manager, not to AppEngine Project project = ode.getProjectManager().addProject(projectInfo); // And this opens the project if (onSuccessCommand != null) { onSuccessCommand.execute(project); } } }; final String projectName; if (url.endsWith(".asc")) { projectName = url.substring(1 + url.lastIndexOf("/"), url.lastIndexOf(".")); } else { return; } // If project of the same name already exists, just open it if (!TextValidators.checkNewProjectName(projectName)) { Project project = ode.getProjectManager().getProject(projectName); if (onSuccessCommand != null) { onSuccessCommand.execute(project); } return; // Don't retrieve the template if the project is a duplicate } // Here's where we retrieve the template data // Do a GET to retrieve data at url RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); try { Request response = builder.sendRequest(null, new RequestCallback() { @Override public void onError(Request request, Throwable exception) { Window.alert("Unable to load Project Template Data"); } // Response received from the GET @Override public void onResponseReceived(Request request, Response response) { // The response.getText is the zip data used to create a new project. // The callback opens the project ode.getProjectService().newProjectFromExternalTemplate(projectName, response.getText(), callback); } }); } catch (RequestException e) { Window.alert("Error fetching template file."); } }
From source file:com.google.appinventor.client.wizards.TemplateUploadWizard.java
License:Open Source License
/** * Called from ProjectToolbar when user selects a set of external templates. It uses * JsonP to retrieve a json file from an external server. * * @param hostUrl, Url of the host -- e.g., http://localhost:85/ *///from w w w .ja v a2 s. c om public static void retrieveExternalTemplateData(final String hostUrl) { String url = hostUrl + TEMPLATES_ROOT_DIRECTORY + EXTERNAL_JSON_FILE; RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); try { Request response = builder.sendRequest(null, new RequestCallback() { @Override public void onError(Request request, Throwable exception) { Window.alert("Unable to load Project Template Data."); if (instance != null) { instance.populateTemplateDialog(null); } } @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() != Response.SC_OK) { Window.alert("Unable to load Project Template Data."); return; } ArrayList<TemplateInfo> externalTemplates = new ArrayList<TemplateInfo>(); JSONValue jsonVal = JSONParser.parseLenient(response.getText()); JSONArray jsonArr = jsonVal.isArray(); for (int i = 0; i < jsonArr.size(); i++) { JSONValue entry1 = jsonArr.get(i); JSONObject entry = entry1.isObject(); externalTemplates.add(new TemplateInfo(entry.get("name").isString().stringValue(), entry.get("subtitle").isString().stringValue(), entry.get("description").isString().stringValue(), entry.get("screenshot").isString().stringValue(), entry.get("thumbnail").isString().stringValue())); } if (externalTemplates.size() == 0) { Window.alert("Unable to retrieve templates for host = " + hostUrl + "."); return; } addNewTemplateHost(hostUrl, externalTemplates); } }); } catch (RequestException e) { Window.alert("Error fetching external template."); } }
From source file:com.google.appinventor.client.wizards.UrlImportWizard.java
License:Open Source License
public UrlImportWizard(final FolderNode assetsFolder, OnImportListener listener) { super(MESSAGES.urlImportWizardCaption(), true, false); listeners.add(listener);//w ww . j a v a 2 s . c o m final Grid urlGrid = createUrlGrid(); VerticalPanel panel = new VerticalPanel(); panel.add(urlGrid); addPage(panel); getConfirmButton().setText("Import"); setPagePanelHeight(150); setPixelSize(200, 150); setStylePrimaryName("ode-DialogBox"); initFinishCommand(new Command() { @Override public void execute() { Ode ode = Ode.getInstance(); final long projectId = ode.getCurrentYoungAndroidProjectId(); final Project project = ode.getProjectManager().getProject(projectId); TextBox urlTextBox = (TextBox) urlGrid.getWidget(1, 0); String url = urlTextBox.getText(); if (url.trim().isEmpty()) { Window.alert(MESSAGES.noUrlError()); return; } ode.getProjectService().importMedia(ode.getSessionId(), projectId, url, true, new OdeAsyncCallback<TextFile>() { @Override public void onSuccess(TextFile file) { ProjectNode node = new YoungAndroidAssetNode(assetsFolder.getFileId(), file.getFileName().replaceFirst("assets/", "")); project.addNode(assetsFolder, node); byte[] content = Base64Util.decodeLines(file.getContent()); for (OnImportListener l : listeners) { l.onSuccess(content); } listeners.clear(); } }); } }); }
From source file:com.google.appinventor.client.youngandroid.TextValidators.java
License:Open Source License
/** * Determines whether the given project name is valid, displaying an alert * if it is not. In order to be valid, the project name must satisfy * {@link #isValidIdentifier(String)} and not be a duplicate of an existing * project name for the same user.//from w ww .jav a2s. c o m * * @param projectName the project name to validate * @return {@code true} if the project name is valid, {@code false} otherwise */ public static boolean checkNewProjectName(String projectName) { // Check the format of the project name if (!isValidIdentifier(projectName)) { Window.alert(MESSAGES.malformedProjectNameError()); return false; } // Check that project does not already exist if (Ode.getInstance().getProjectManager().getProject(projectName) != null) { Window.alert(MESSAGES.duplicateProjectNameError(projectName)); return false; } return true; }
From source file:com.google.appinventor.client.youngandroid.TextValidators.java
License:Open Source License
public static boolean checkNewComponentName(String componentName) { // Check that it meets the formatting requirements. if (!TextValidators.isValidComponentIdentifier(componentName)) { Window.alert(MESSAGES.malformedComponentNameError()); return false; }//from w ww . j a v a2s. c o m long projectId = Ode.getInstance().getCurrentYoungAndroidProjectId(); if (projectId == 0) { // Check we have a current Project return false; } YaProjectEditor editor = (YaProjectEditor) Ode.getInstance().getEditorManager() .getOpenProjectEditor(projectId); // Check that it's unique. final List<String> names = editor.getComponentInstances(); if (names.contains(componentName)) { Window.alert(MESSAGES.sameAsComponentInstanceNameError()); return false; } // Check that it is a variable name used in the Yail code if (YAIL_NAMES.contains(componentName)) { Window.alert(MESSAGES.badComponentNameError()); return false; } //Check that it is not a Component type name SimpleComponentDatabase COMPONENT_DATABASE = SimpleComponentDatabase.getInstance(projectId); if (COMPONENT_DATABASE.isComponent(componentName)) { Window.alert(MESSAGES.duplicateComponentNameError()); return false; } return true; }
From source file:com.google.appinventor.client.youngandroid.YoungAndroidFormUpgrader.java
License:Open Source License
/** * Upgrades the given sourceProperties if necessary. * * @param sourceProperties the properties from the source file * @return true if the sourceProperties was upgraded, false otherwise *//*w ww. ja va 2s. c om*/ public static boolean upgradeSourceProperties(Map<String, JSONValue> sourceProperties) { StringBuilder upgradeDetails = new StringBuilder(); try { int srcYaVersion = getSrcYaVersion(sourceProperties); if (needToUpgrade(srcYaVersion)) { Map<String, JSONValue> formProperties = sourceProperties.get("Properties").asObject() .getProperties(); upgradeComponent(srcYaVersion, formProperties, upgradeDetails); // The sourceProperties were upgraded. Update the version number. setSrcYaVersion(sourceProperties); if (upgradeDetails.length() > 0) { Window.alert(MESSAGES.projectWasUpgraded(upgradeDetails.toString())); } return true; } } catch (LoadException e) { // This shouldn't happen. If it does it's our fault, not the user's fault. Window.alert(MESSAGES.unexpectedProblem(e.getMessage())); OdeLog.xlog(e); } return false; }
From source file:com.google.appinventor.client.youngandroid.YoungAndroidFormUpgrader.java
License:Open Source License
private static boolean needToUpgrade(int srcYaVersion) { // Compare the source file's YoungAndroid version with the system's YoungAndroid version. final int sysYaVersion = YaVersion.YOUNG_ANDROID_VERSION; if (srcYaVersion > sysYaVersion) { // The source file's version is newer than the system's version. // This can happen if the user is using (or in the past has used) a non-production version of // App Inventor. // This can also happen if the user is connected to a new version of App Inventor and then // later is connected to an old version of App Inventor. // We'll try to load the project but there may be compatibility issues if the project uses // future components or other features that the current system doesn't understand. Window.alert(MESSAGES.newerVersionProject()); return false; }//from w w w. jav a 2s. c om if (srcYaVersion == 0) { // The source file doesn't have a YoungAndroid version number. // There are two situations that cause this: // 1. The project may have been downloaded from alpha (androidblocks.googlelabs.com) and // uploaded to beta (appinventor.googlelabs.com), which is illegal. // 2. The project may have been created with beta (appinventor.googlelabs.com) before we // started putting version numbers into the source file, which is legal, and nothing // really changed between version 0 and version 1. // // For a limited time, we assume #2, show a warning, and proceed. // TODO(lizlooney) - after the limited time is up (when we think that all appinventor // projects have been upgraded), we may decide to refuse to load the project. Window.alert(MESSAGES.veryOldProject()); } return (srcYaVersion < sysYaVersion); }
From source file:com.google.appinventor.client.youngandroid.YoungAndroidFormUpgrader.java
License:Open Source License
private static int upgradeActivityStarterProperties(Map<String, JSONValue> componentProperties, int srcCompVersion) { if (srcCompVersion < 2) { // The ActivityStarter.DataType, ActivityStarter.ResultType, and ActivityStarter.ResultUri // properties were added. // The ActivityStarter.ResolveActivity method was added. // The ActivityStarter.ActivityError event was added. // No properties need to be modified to upgrade to version 2. srcCompVersion = 2;/*from w w w.j ava2 s . c o m*/ } if (srcCompVersion < 3) { // The ActivityStarter.ActivityError event was marked userVisible false and is no longer // used. // No properties need to be modified to upgrade to version 3. srcCompVersion = 3; } if (srcCompVersion < 4) { // The ActivityStarter.StartActivity method was modified to provide the parent Form's // screen animation type. // No properties need to be modified to upgrade to version 4. srcCompVersion = 4; } if (srcCompVersion < 5) { // The ActivityStarter.ActivityCanceled event was added. // No properties need to be modified to upgrade to version 5. srcCompVersion = 5; } if (srcCompVersion < 6) { // Extras property was added to accept a list of key-value pairs to put to the intent String defaultValue = ""; boolean sendWarning = false; if (componentProperties.containsKey("ExtraKey")) { String extraKeyValue = componentProperties.get("ExtraKey").asString().getString(); if (!extraKeyValue.equals(defaultValue)) { sendWarning = true; } } if (componentProperties.containsKey("ExtraValue")) { String extraValueValue = componentProperties.get("ExtraValue").asString().getString(); if (!extraValueValue.equals(defaultValue)) { sendWarning = true; } } if (sendWarning) { Window.alert(MESSAGES.extraKeyValueWarning()); } srcCompVersion = 6; } return srcCompVersion; }
From source file:com.google.code.gwt.database.sample.hellodatabase.client.HelloDatabase.java
License:Apache License
/** * This is the entry point method.//from w w w.java2 s . co m */ public void onModuleLoad() { if (!Database.isSupported()) { Window.alert("HTML 5 Database is NOT supported in this browser!"); return; } // Create the dialog box final DialogBox dialogBox = new DialogBox(); dialogBox.setText("Welcome to GWT Database Demo!"); dialogBox.setAnimationEnabled(true); Button closeButton = new Button("close", new ClickHandler() { public void onClick(ClickEvent event) { dialogBox.hide(); } }); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.setWidth("100%"); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER); final VerticalPanel clickedData = new VerticalPanel(); dialogVPanel.add(clickedData); dialogVPanel.add(closeButton); dialogBox.setWidget(dialogVPanel); Image img = new Image("http://code.google.com/webtoolkit/logo-185x175.png"); Button addClickButton = new Button("Add Click", new ClickHandler() { public void onClick(ClickEvent event) { dbService.insertClick(new Date(), new RowIdListCallback() { public void onFailure(DataServiceException error) { Window.alert("Failed to add click! " + error); } public void onSuccess(final List<Integer> rowIds) { dbService.getClicks(new ListCallback<ClickRow>() { public void onFailure(DataServiceException error) { Window.alert("Failed to query clicks! " + error); } public void onSuccess(List<ClickRow> result) { clickedData.clear(); clickedData.add(new Label("Last click insert ID: " + rowIds.get(0))); for (ClickRow row : result) { clickedData.add(new Label("Clicked on " + row.getClicked())); } dialogBox.center(); dialogBox.show(); } }); } }); } }); Button getCountButton = new Button("Get Counts", new ClickHandler() { public void onClick(ClickEvent event) { getCount(); } }); vPanel = new VerticalPanel(); // We can add style names. vPanel.addStyleName("widePanel"); vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER); vPanel.add(img); vPanel.add(addClickButton); vPanel.add(getCountButton); // Add image and button to the RootPanel RootPanel.get().add(vPanel); // Create table 'clickcount' if it doesn't exist already: dbService.initTable(new VoidCallback() { public void onFailure(DataServiceException error) { Window.alert("Failed to initialize table! " + error); } public void onSuccess() { Window.alert("Database initialized successfully."); getCount(); } }); getVersion(); }
From source file:com.google.code.gwt.database.sample.hellodatabase.client.HelloDatabase.java
License:Apache License
private void getVersion() { dbService.getSqliteVersion(new ScalarCallback<String>() { public void onFailure(DataServiceException error) { Window.alert("Failed to get SQLite version! " + error); }/* w ww . jav a2s . c o m*/ public void onSuccess(String result) { vPanel.add(new Label("SQLite version: " + result)); } }); }