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.Ode.java
License:Open Source License
/** * Main entry point for Ode. Setting up the UI and the web service * connections.//from w w w . j ava 2s . c om */ @Override public void onModuleLoad() { Tracking.trackPageview(); // Handler for any otherwise unhandled exceptions GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { @Override public void onUncaughtException(Throwable e) { OdeLog.xlog(e); if (AppInventorFeatures.sendBugReports()) { if (Window.confirm(MESSAGES.internalErrorReportBug())) { Window.open(BugReport.getBugReportLink(e), "_blank", ""); } } else { // Display a confirm dialog with error msg and if 'ok' open the debugging view if (Window.confirm(MESSAGES.internalErrorClickOkDebuggingView())) { Ode.getInstance().switchToDebuggingView(); } } } }); // Define bridge methods to Javascript JsonpConnection.defineBridgeMethod(); // Initialize global Ode instance instance = this; // Let's see if we were started with a repo= parameter which points to a template templatePath = Window.Location.getParameter("repo"); if (templatePath != null) { OdeLog.wlog("Got a template path of " + templatePath); templateLoadingFlag = true; } // Let's see if we were started with a galleryId= parameter which points to a template galleryId = Window.Location.getParameter("galleryId"); if (galleryId != null) { OdeLog.wlog("Got a galleryId of " + galleryId); galleryIdLoadingFlag = true; } // Get user information. OdeAsyncCallback<Config> callback = new OdeAsyncCallback<Config>( // failure message MESSAGES.serverUnavailable()) { @Override public void onSuccess(Config result) { config = result; user = result.getUser(); isReadOnly = user.isReadOnly(); // If user hasn't accepted terms of service, ask them to. if (!user.getUserTosAccepted() && !isReadOnly) { // We expect that the redirect to the TOS page should be handled // by the onFailure method below. The server should return a // "forbidden" error if the TOS wasn't accepted. ErrorReporter.reportError(MESSAGES.serverUnavailable()); return; } splashConfig = result.getSplashConfig(); if (result.getRendezvousServer() != null) { setRendezvousServer(result.getRendezvousServer()); } else { setRendezvousServer(YaVersion.RENDEZVOUS_SERVER); } userSettings = new UserSettings(user); // Gallery settings gallerySettings = new GallerySettings(); //gallerySettings.loadGallerySettings(); loadGallerySettings(); // Initialize project and editor managers // The project manager loads the user's projects asynchronously projectManager = new ProjectManager(); projectManager.addProjectManagerEventListener(new ProjectManagerEventAdapter() { @Override public void onProjectsLoaded() { projectManager.removeProjectManagerEventListener(this); // This handles any built-in templates stored in /war // Retrieve template data stored in war/templates folder and // and save it for later use in TemplateUploadWizard OdeAsyncCallback<String> templateCallback = new OdeAsyncCallback<String>( // failure message MESSAGES.createProjectError()) { @Override public void onSuccess(String json) { // Save the templateData TemplateUploadWizard.initializeBuiltInTemplates(json); // Here we call userSettings.loadSettings, but the settings are actually loaded // asynchronously, so this loadSettings call will return before they are loaded. // After the user settings have been loaded, openPreviousProject will be called. // We have to call this after the builtin templates have been loaded otherwise // we will get a NPF. userSettings.loadSettings(); } }; Ode.getInstance().getProjectService().retrieveTemplateData( TemplateUploadWizard.TEMPLATES_ROOT_DIRECTORY, templateCallback); } }); editorManager = new EditorManager(); // Initialize UI initializeUi(); topPanel.showUserEmail(user.getUserEmail()); } @Override public void onFailure(Throwable caught) { if (caught instanceof StatusCodeException) { StatusCodeException e = (StatusCodeException) caught; int statusCode = e.getStatusCode(); switch (statusCode) { case Response.SC_UNAUTHORIZED: // unauthorized => not on whitelist // getEncodedResponse() gives us the message that we wrote in // OdeAuthFilter.writeWhitelistErrorMessage(). Window.alert(e.getEncodedResponse()); return; case Response.SC_FORBIDDEN: // forbidden => need tos accept Window.open("/" + ServerLayout.YA_TOS_FORM, "_self", null); return; case Response.SC_PRECONDITION_FAILED: String locale = Window.Location.getParameter("locale"); if (locale == null || locale.equals("")) { Window.Location.replace("/login/"); } else { Window.Location.replace("/login/?locale=" + locale); } return; // likely not reached } } super.onFailure(caught); } }; // The call below begins an asynchronous read of the user's settings // When the settings are finished reading, various settings parsers // will be called on the returned JSON object. They will call various // other functions in this module, including openPreviousProject (the // previous project ID is stored in the settings) as well as the splash // screen displaying functions below. // // TODO(user): ODE makes too many RPC requests at startup time. Currently // we do 3 RPCs + 1 per project + 1 per open file. We should bundle some of // those with each other or with the initial HTML transfer. // // This call also stores our sessionId in the backend. This will be checked // when we go to save a file and if different file saving will be disabled // Newer sessions invalidate older sessions. userInfoService.getSystemConfig(sessionId, callback); History.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { openProject(event.getValue()); } }); // load project based on current url // TODO(sharon): Seems like a possible race condition here if the onValueChange // handler defined above gets called before the getSystemConfig call sets // userSettings. // The following line causes problems with GWT debugging, and commenting // it out doesn't seem to break things. //History.fireCurrentHistoryState(); }
From source file:com.google.appinventor.client.widgets.boxes.Box.java
License:Open Source License
/** * Creates a new box.//from w w w . jav a 2 s. c o m * * @param caption box caption * @param height box initial height in pixel * @param minimizable indicates whether box can be minimized * @param removable indicates whether box can be closed/removed * @param startMinimized indicates whether box should always start minimized * @param bodyPadding indicates whether box should have padding * @param highlightCaption indicates whether caption should be highlighted * until user has "seen" it (interacts with the box) */ protected Box(String caption, int height, boolean minimizable, boolean removable, boolean startMinimized, boolean bodyPadding, boolean highlightCaption) { this.height = height; this.restoreHeight = height; this.startMinimized = startMinimized; this.highlightCaption = highlightCaption; captionLabel = new Label(caption, false); captionAlreadySeen = false; if (highlightCaption) { captionLabel.setStylePrimaryName("ode-Box-header-caption-highlighted"); } else { captionLabel.setStylePrimaryName("ode-Box-header-caption"); } header = new HandlerPanel(); header.add(captionLabel); header.setWidth("100%"); headerContainer = new DockPanel(); headerContainer.setStylePrimaryName("ode-Box-header"); headerContainer.setWidth("100%"); headerContainer.add(header, DockPanel.LINE_START); Images images = Ode.getImageBundle(); if (removable) { PushButton closeButton = Ode.createPushButton(images.boxClose(), MESSAGES.hdrClose(), new ClickHandler() { @Override public void onClick(ClickEvent event) { // TODO(user) - remove the box Window.alert("Not implemented yet!"); } }); headerContainer.add(closeButton, DockPanel.LINE_END); headerContainer.setCellWidth(closeButton, (closeButton.getOffsetWidth() + HEADER_CONTROL_PADDING) + "px"); } if (!minimizable) { minimizeButton = null; } else { minimizeButton = Ode.createPushButton(images.boxMinimize(), MESSAGES.hdrMinimize(), new ClickHandler() { @Override public void onClick(ClickEvent event) { if (isMinimized()) { restore(); } else { minimize(); } } }); headerContainer.add(minimizeButton, DockPanel.LINE_END); headerContainer.setCellWidth(minimizeButton, (minimizeButton.getOffsetWidth() + HEADER_CONTROL_PADDING) + "px"); } if (minimizable || removable) { menuButton = Ode.createPushButton(images.boxMenu(), MESSAGES.hdrSettings(), new ClickHandler() { @Override public void onClick(ClickEvent event) { final ContextMenu contextMenu = new ContextMenu(); contextMenu.addItem(MESSAGES.cmMinimize(), new Command() { @Override public void execute() { if (!isMinimized()) { minimize(); } } }); contextMenu.addItem(MESSAGES.cmRestore(), new Command() { @Override public void execute() { if (isMinimized()) { restore(); } } }); if (!variableHeightBoxes) { contextMenu.addItem(MESSAGES.cmResize(), new Command() { @Override public void execute() { restore(); final ResizeControl resizeControl = new ResizeControl(); resizeControl.setPopupPositionAndShow(new PopupPanel.PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { // SouthEast int left = menuButton.getAbsoluteLeft() + menuButton.getOffsetWidth() - offsetWidth; int top = menuButton.getAbsoluteTop() + menuButton.getOffsetHeight(); resizeControl.setPopupPosition(left, top); } }); } }); } contextMenu.setPopupPositionAndShow(new PopupPanel.PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { // SouthEast int left = menuButton.getAbsoluteLeft() + menuButton.getOffsetWidth() - offsetWidth; int top = menuButton.getAbsoluteTop() + menuButton.getOffsetHeight(); contextMenu.setPopupPosition(left, top); } }); } }); headerContainer.add(menuButton, DockPanel.LINE_END); headerContainer.setCellWidth(menuButton, (menuButton.getOffsetWidth() + HEADER_CONTROL_PADDING) + "px"); } else { menuButton = null; } body = new SimplePanel(); body.setSize("100%", "100%"); scrollPanel = new ScrollPanel(); scrollPanel.setStylePrimaryName("ode-Box-body"); if (bodyPadding) { scrollPanel.addStyleName("ode-Box-body-padding"); } scrollPanel.add(body); FlowPanel boxContainer = new FlowPanel(); boxContainer.setStyleName("ode-Box-content"); boxContainer.add(headerContainer); boxContainer.add(scrollPanel); setStylePrimaryName("ode-Box"); setWidget(boxContainer); }
From source file:com.google.appinventor.client.widgets.properties.TextPropertyEditorBase.java
License:Open Source License
private void validateText() { String text = textEdit.getText(); try {// www . jav a 2s .c o m validate(text); property.setValue(text); } catch (InvalidTextException e) { String error = e.getMessage(); if (error == null || error.isEmpty()) { error = MESSAGES.malformedInputError(); } Window.alert(error); updateValue(); // Restore previous property value. } }
From source file:com.google.appinventor.client.wizards.ComponentImportWizard.java
License:Open Source License
public ComponentImportWizard() { super(MESSAGES.componentImportWizardCaption(), true, false); final CellTable compTable = createCompTable(); final FileUpload fileUpload = createFileUpload(); final Grid urlGrid = createUrlGrid(); final TabPanel tabPanel = new TabPanel(); tabPanel.add(fileUpload, "From my computer"); tabPanel.add(urlGrid, "URL"); tabPanel.selectTab(FROM_MY_COMPUTER_TAB); tabPanel.addStyleName("ode-Tabpanel"); VerticalPanel panel = new VerticalPanel(); panel.add(tabPanel);/* www .j a va 2s . c o m*/ addPage(panel); getConfirmButton().setText("Import"); setPagePanelHeight(150); setPixelSize(200, 150); setStylePrimaryName("ode-DialogBox"); initFinishCommand(new Command() { @Override public void execute() { final long projectId = ode.getCurrentYoungAndroidProjectId(); final Project project = ode.getProjectManager().getProject(projectId); final YoungAndroidAssetsFolder assetsFolderNode = ((YoungAndroidProjectNode) project.getRootNode()) .getAssetsFolder(); if (tabPanel.getTabBar().getSelectedTab() == URL_TAB) { TextBox urlTextBox = (TextBox) urlGrid.getWidget(1, 0); String url = urlTextBox.getText(); if (url.trim().isEmpty()) { Window.alert(MESSAGES.noUrlError()); return; } ode.getComponentService().importComponentToProject(url, projectId, assetsFolderNode.getFileId(), new ImportComponentCallback()); } else if (tabPanel.getTabBar().getSelectedTab() == FROM_MY_COMPUTER_TAB) { if (!fileUpload.getFilename().endsWith(COMPONENT_ARCHIVE_EXTENSION)) { Window.alert(MESSAGES.notComponentArchiveError()); return; } String url = GWT.getModuleBaseURL() + ServerLayout.UPLOAD_SERVLET + "/" + ServerLayout.UPLOAD_COMPONENT + "/" + trimLeadingPath(fileUpload.getFilename()); Uploader.getInstance().upload(fileUpload, url, new OdeAsyncCallback<UploadResponse>() { @Override public void onSuccess(UploadResponse uploadResponse) { String toImport = uploadResponse.getInfo(); ode.getComponentService().importComponentToProject(toImport, projectId, assetsFolderNode.getFileId(), new ImportComponentCallback()); } }); return; } } private String trimLeadingPath(String filename) { // Strip leading path off filename. // We need to support both Unix ('/') and Windows ('\\') separators. return filename.substring(Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\')) + 1); } }); }
From source file:com.google.appinventor.client.wizards.ComponentUploadWizard.java
License:Open Source License
public ComponentUploadWizard() { super(MESSAGES.componentUploadWizardCaption(), true, false); final FileUpload uploadWiget = new FileUpload(); uploadWiget.setName(ServerLayout.UPLOAD_COMPONENT_ARCHIVE_FORM_ELEMENT); VerticalPanel panel = new VerticalPanel(); panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); panel.add(uploadWiget);// w w w . j a v a2s . co m addPage(panel); setStylePrimaryName("ode-DialogBox"); initFinishCommand(new Command() { @Override public void execute() { if (!uploadWiget.getFilename().endsWith(COMPONENT_ARCHIVE_EXTENSION)) { Window.alert(MESSAGES.notComponentArchiveError()); return; } String url = GWT.getModuleBaseURL() + ServerLayout.UPLOAD_SERVLET + "/" + ServerLayout.UPLOAD_COMPONENT + "/" + trimLeadingPath(uploadWiget.getFilename()); Uploader.getInstance().upload(uploadWiget, url, new OdeAsyncCallback<UploadResponse>() { @Override public void onSuccess(UploadResponse uploadResponse) { Component component = Component.valueOf(uploadResponse.getInfo()); ErrorReporter.reportInfo("Uploaded successfully"); } }); } private String trimLeadingPath(String filename) { // Strip leading path off filename. // We need to support both Unix ('/') and Windows ('\\') separators. return filename.substring(Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\')) + 1); } }); }
From source file:com.google.appinventor.client.wizards.DownloadUserSourceWizard.java
License:Open Source License
public DownloadUserSourceWizard() { super(MESSAGES.downloadUserSourceDialogTitle(), true, false); // Initialize the UI setStylePrimaryName("ode-DialogBox"); userIdTextBox = new LabeledTextBox(MESSAGES.userIdLabel()); userIdTextBox.getTextBox().addKeyUpHandler(new KeyUpHandler() { @Override/*from w w w. j a v a 2 s . c om*/ public void onKeyUp(KeyUpEvent event) { int keyCode = event.getNativeKeyCode(); if (keyCode == KeyCodes.KEY_ENTER) { handleOkClick(); } else if (keyCode == KeyCodes.KEY_ESCAPE) { handleCancelClick(); } } }); projectIdTextBox = new LabeledTextBox(MESSAGES.projectIdLabel()); projectIdTextBox.getTextBox().addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { int keyCode = event.getNativeKeyCode(); if (keyCode == KeyCodes.KEY_ENTER) { handleOkClick(); } else if (keyCode == KeyCodes.KEY_ESCAPE) { handleCancelClick(); } } }); VerticalPanel page = new VerticalPanel(); page.add(userIdTextBox); page.add(projectIdTextBox); addPage(page); // Create finish command (do the download) initFinishCommand(new Command() { @Override public void execute() { String projectId = projectIdTextBox.getText(); String userId = userIdTextBox.getText(); if (!projectId.isEmpty() && !userId.isEmpty()) { Downloader.getInstance().download(ServerLayout.DOWNLOAD_SERVLET_BASE + ServerLayout.DOWNLOAD_USER_PROJECT_SOURCE + "/" + projectId + "/" + userId); } else { Window.alert(MESSAGES.invalidUserIdOrProjectIdError()); new DownloadUserSourceWizard().center(); return; } } }); }
From source file:com.google.appinventor.client.wizards.InputTemplateUrlWizard.java
License:Open Source License
/** * Creates a new YoungAndroid project wizard. *//*from w w w. j av a 2 s .co m*/ public InputTemplateUrlWizard(final NewUrlDialogCallback callback) { super(MESSAGES.inputNewUrlCaption(), true, true); // Initialize the UI. setStylePrimaryName("ode-DialogBox"); HorizontalPanel panel = new HorizontalPanel(); urlTextBox = new LabeledTextBox(MESSAGES.newUrlLabel()); urlTextBox.getTextBox().setWidth("250px"); urlTextBox.getTextBox().addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { int keyCode = event.getNativeKeyCode(); if (keyCode == KeyCodes.KEY_ENTER) { handleOkClick(); } else if (keyCode == KeyCodes.KEY_ESCAPE) { handleCancelClick(); } } }); VerticalPanel page = new VerticalPanel(); panel.add(urlTextBox); page.add(panel); addPage(page); // Create finish command (create a new Young Android project). initFinishCommand(new Command() { @Override public void execute() { String hostUrl = urlTextBox.getText(); if (TemplateUploadWizard.hasUrl(hostUrl)) { Window.alert("The Url " + hostUrl + " already exists."); } else { callback.updateTemplateOptions(hostUrl); } } }); }
From source file:com.google.appinventor.client.wizards.KeystoreUploadWizard.java
License:Open Source License
/** * Creates a new keystore upload wizard. *//*from w w w .j a v a 2 s.c om*/ public KeystoreUploadWizard(final Command callbackAfterUpload) { super(MESSAGES.keystoreUploadWizardCaption(), true, false); // Initialize UI final FileUpload upload = new FileUpload(); upload.setName(ServerLayout.UPLOAD_USERFILE_FORM_ELEMENT); setStylePrimaryName("ode-DialogBox"); VerticalPanel panel = new VerticalPanel(); panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); panel.add(upload); addPage(panel); // Create finish command (upload a keystore) initFinishCommand(new Command() { @Override public void execute() { String filename = upload.getFilename(); if (filename.endsWith(KEYSTORE_EXTENSION)) { String uploadUrl = GWT.getModuleBaseURL() + ServerLayout.UPLOAD_SERVLET + "/" + ServerLayout.UPLOAD_USERFILE + "/" + StorageUtil.ANDROID_KEYSTORE_FILENAME; Uploader.getInstance().upload(upload, uploadUrl, new OdeAsyncCallback<UploadResponse>( // failure message MESSAGES.keystoreUploadError()) { @Override public void onSuccess(UploadResponse uploadResponse) { switch (uploadResponse.getStatus()) { case SUCCESS: if (callbackAfterUpload != null) { callbackAfterUpload.execute(); } break; default: ErrorReporter.reportError(MESSAGES.keystoreUploadError()); break; } } }); } else { Window.alert(MESSAGES.notKeystoreError()); center(); } } }); }
From source file:com.google.appinventor.client.wizards.ProjectUploadWizard.java
License:Open Source License
/** * Creates a new project upload wizard./*from w w w . ja va 2 s .c o m*/ */ public ProjectUploadWizard() { super(MESSAGES.projectUploadWizardCaption(), true, false); // Initialize UI final FileUpload upload = new FileUpload(); upload.setName(ServerLayout.UPLOAD_PROJECT_ARCHIVE_FORM_ELEMENT); setStylePrimaryName("ode-DialogBox"); VerticalPanel panel = new VerticalPanel(); panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); panel.add(upload); addPage(panel); // Create finish command (upload a project archive) initFinishCommand(new Command() { @Override public void execute() { String filename = upload.getFilename(); if (filename.endsWith(PROJECT_ARCHIVE_EXTENSION)) { // Strip extension and leading path off filename. We need to support both Unix ('/') and // Windows ('\\') path separators. File.pathSeparator is not available in GWT. filename = filename.substring(0, filename.length() - PROJECT_ARCHIVE_EXTENSION.length()) .substring(Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\')) + 1); // Make sure the project name is legal and unique. if (!TextValidators.checkNewProjectName(filename)) { return; } String uploadUrl = GWT.getModuleBaseURL() + ServerLayout.UPLOAD_SERVLET + "/" + ServerLayout.UPLOAD_PROJECT + "/" + filename; Uploader.getInstance().upload(upload, uploadUrl, new OdeAsyncCallback<UploadResponse>( // failure message MESSAGES.projectUploadError()) { @Override public void onSuccess(UploadResponse uploadResponse) { switch (uploadResponse.getStatus()) { case SUCCESS: String info = uploadResponse.getInfo(); UserProject userProject = UserProject.valueOf(info); Ode ode = Ode.getInstance(); Project uploadedProject = ode.getProjectManager().addProject(userProject); ode.openYoungAndroidProjectInDesigner(uploadedProject); break; case NOT_PROJECT_ARCHIVE: // This may be a "severe" error; but in the // interest of reducing the number of red errors, the // line has been changed to report info not an error. // This error is triggered when the user attempts to // upload a zip file that is not a project. ErrorReporter.reportInfo(MESSAGES.notProjectArchiveError()); break; default: ErrorReporter.reportError(MESSAGES.projectUploadError()); break; } } }); } else { Window.alert(MESSAGES.notProjectArchiveError()); center(); } } }); }
From source file:com.google.appinventor.client.wizards.TemplateUploadWizard.java
License:Open Source License
/** * Creates a new project from a Zip file and lists it in the ProjectView. * * @param projectName project name/*ww w. ja va2 s . c o m*/ * @param onSuccessCommand command to be executed after process creation * succeeds (can be {@code null}) */ public void createProjectFromExistingZip(final String projectName, final NewProjectCommand onSuccessCommand) { // Callback for updating the project explorer after the project is created on the back-end final Ode ode = Ode.getInstance(); final OdeAsyncCallback<UserProject> callback = new OdeAsyncCallback<UserProject>( // failure message MESSAGES.createProjectError()) { @Override public void onSuccess(UserProject projectInfo) { // Update project explorer -- i.e., display in project view if (projectInfo == null) { Window.alert( "This template has no aia file. Creating a new project with name = " + projectName); ode.getProjectService().newProject(YoungAndroidProjectNode.YOUNG_ANDROID_PROJECT_TYPE, projectName, new NewYoungAndroidProjectParameters(projectName), this); return; } Project project = ode.getProjectManager().addProject(projectInfo); if (onSuccessCommand != null) { onSuccessCommand.execute(project); } } }; // Use project RPC service to create the project on back end using String pathToZip = ""; if (usingExternalTemplate) { String zipUrl = templateHostUrl + TEMPLATES_ROOT_DIRECTORY + projectName + "/" + projectName + PROJECT_ARCHIVE_ENCODED_EXTENSION; RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, zipUrl); try { Request response = builder.sendRequest(null, new RequestCallback() { @Override public void onError(Request request, Throwable exception) { Window.alert("Unable to load Project Template Data"); } @Override public void onResponseReceived(Request request, Response response) { ode.getProjectService().newProjectFromExternalTemplate(projectName, response.getText(), callback); } }); } catch (RequestException e) { Window.alert("Error fetching project zip file template."); } } else { pathToZip = TEMPLATES_ROOT_DIRECTORY + projectName + "/" + projectName + PROJECT_ARCHIVE_EXTENSION; ode.getProjectService().newProjectFromTemplate(projectName, pathToZip, callback); } }