List of usage examples for com.google.gwt.user.client.ui HorizontalPanel add
@Override public void add(Widget w)
From source file:com.cognitivemedicine.metricsdashboard.client.dashboard.DashboardMainPanel.java
License:Apache License
private void initUi() { mainPanel = new VerticalPanel(); mainPanel.setWidth("300px"); mainPanel.setSpacing(4);/*from w w w. j av a 2 s.c o m*/ VerticalPanel titlePanel = new VerticalPanel(); titlePanel.setWidth("100%"); HorizontalPanel logoutPanel = new HorizontalPanel(); Image logoutImage = new Image(MdConstants.IMG_LOGOUT); logoutImage.getElement().getStyle().setCursor(Cursor.POINTER); logoutImage.setSize("16px", "16px"); logoutImage.setTitle("Log Out"); logoutImage.getElement().getStyle().setProperty("cursor", "hand"); logoutImage.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { controller.logOut(); } }); HTML logOutLabel = new HTML("<u><font size=-2>Log Out </font></u>"); logOutLabel.setHeight("10px"); // logOutLabel.setStyleName("logoutButton"); logOutLabel.setStylePrimaryName("logoutButton"); logOutLabel.getElement().getStyle().setProperty("right", "5px"); // logOutLabel.getElement().getStyle().setProperty("cursor", "hand"); logOutLabel.getElement().getStyle().setCursor(Cursor.POINTER); logOutLabel.setWidth("100%"); logOutLabel.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { controller.logOut(); } }); logoutPanel.add(logOutLabel); logoutPanel.add(logoutImage); logoutPanel.setSpacing(2); logoutPanel.setCellHorizontalAlignment(logoutImage, HasHorizontalAlignment.ALIGN_RIGHT); logoutPanel.setCellHorizontalAlignment(logOutLabel, HasHorizontalAlignment.ALIGN_RIGHT); titlePanel.getElement().getStyle().setProperty("marginLeft", "50"); titleLabel = new HTML("<font size=4> </font>"); titleLabel.getElement().setId("dashboardTitleLabel"); titlePanel.add(logoutPanel); titlePanel.add(titleLabel); titlePanel.setCellHorizontalAlignment(logoutPanel, HasHorizontalAlignment.ALIGN_RIGHT); DecoratorPanel titleDecor = new DecoratorPanel(); titleDecor.setWidth("250px"); titleDecor.setHeight("30px"); mainPanel.add(titlePanel); mainPanel.setCellVerticalAlignment(logOutLabel, HasVerticalAlignment.ALIGN_MIDDLE); mainPanel.setCellHorizontalAlignment(logOutLabel, HasHorizontalAlignment.ALIGN_RIGHT); mainPanel.setCellHorizontalAlignment(titleLabel, HasHorizontalAlignment.ALIGN_LEFT); mainPanel.setCellVerticalAlignment(titleLabel, HasVerticalAlignment.ALIGN_MIDDLE); Image image = new Image(MdConstants.IMG_TOOLS); image.setSize(MdConstants.IMG_SIZE, MdConstants.IMG_SIZE); adminConsoleButton = new PushButton(image); adminConsoleButton.getElement().setId("adminConsoleButton"); adminConsoleButton.setSize("50px", MdConstants.IMG_SIZE); adminConsoleButton.setTitle("Show Admin Console"); adminConsoleButton.setEnabled(false); adminConsoleButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { AdminConsole console = new AdminConsole(controller); } }); editorDecorator = new DecoratorPanel(); editorDecorator.setTitle("Dashboard Editor"); editorDecorator.setWidth("315px"); toolstripPanel = new DashboardToolStripBar(this); dashboardListBox = new ListBox(false); dashboardListBox.getElement().setId("dashboardListBox"); dashboardListBox.setWidth("295px"); dashboardListBox.setVisibleItemCount(10); dashboardListBox.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { dashboardListChanged(); } }); notesArea = new TextArea(); notesArea.setVisibleLines(2); notesArea.setWidth("290px"); notesArea.setHeight("50px"); notesArea.getElement().setId("notesTextArea"); VerticalPanel editorVerticalPanel = new VerticalPanel(); editorVerticalPanel.setSpacing(4); editorVerticalPanel.add(toolstripPanel); editorVerticalPanel.add(dashboardListBox); editorVerticalPanel.add(new HTML("<font size=-1><b>Dashboard Notes:</b></font></br>")); editorVerticalPanel.add(notesArea); editorVerticalPanel.setCellVerticalAlignment(toolstripPanel, HasVerticalAlignment.ALIGN_MIDDLE); editorVerticalPanel.setCellHorizontalAlignment(toolstripPanel, HasHorizontalAlignment.ALIGN_CENTER); editorDecorator.setWidget(editorVerticalPanel); settingsPanel = new DashboardSettingsPanel(this); mainPanel.add(editorDecorator); mainPanel.add(settingsPanel); // mainPanel.add(adminConsoleButton); mainPanel.setCellVerticalAlignment(editorDecorator, HasVerticalAlignment.ALIGN_MIDDLE); mainPanel.setCellHorizontalAlignment(editorDecorator, HasHorizontalAlignment.ALIGN_CENTER); mainPanel.setCellVerticalAlignment(settingsPanel, HasVerticalAlignment.ALIGN_TOP); mainPanel.setCellHorizontalAlignment(settingsPanel, HasHorizontalAlignment.ALIGN_CENTER); mainPanel.setCellVerticalAlignment(adminConsoleButton, HasVerticalAlignment.ALIGN_MIDDLE); mainPanel.setCellHorizontalAlignment(adminConsoleButton, HasHorizontalAlignment.ALIGN_CENTER); this.add(mainPanel); }
From source file:com.cognitivemedicine.metricsdashboard.client.dashboard.DashboardSettingsPanel.java
License:Apache License
private void init() { periodSetting = new SettingsOption("Period"); periodSetting.getElement().setId("periodSetting"); periodSetting.getList().getElement().setId("periodSettingListBox"); periodSetting.getCheckBox().getElement().setId("periodSettingCheckBox"); ListBox box = periodSetting.getList(); for (Period p : Period.values()) { box.addItem(p.getDisplayValue(), p.getSymbol()); }//from w w w. j av a 2s . com granularitySetting = new SettingsOption("Granularity"); granularitySetting.getElement().setId("granularitySetting"); granularitySetting.getList().getElement().setId("granularitySettingListBox"); granularitySetting.getCheckBox().getElement().setId("granularitySettingCheckBox"); box = granularitySetting.getList(); box.addItem("", ""); for (Granularity g : Granularity.values()) { box.addItem(g.getDisplayValue(), g.getSymbol()); } VerticalPanel settingsPanel = new VerticalPanel(); settingsPanel.setSpacing(8); settingsPanel.setWidth("290px"); Image helpImage = new Image(MdConstants.IMG_QUESTION_MARK); helpImage.setSize("20px", "20px"); helpImage.setTitle( "Dashboard level settings override individual chart settings for all charts in this dashboard."); HorizontalPanel labelPanel = new HorizontalPanel(); datetimePicker = new CalendarPicker("dashboard", false); datetimePicker.addDashboardSettingsUpdatedHandler(new DashboardSettingsUpdatedHandler()); labelPanel.add(new HTML("<b>Dashboard Settings</b>")); labelPanel.add(helpImage); labelPanel.add(new HTML("</br>")); settingsPanel.add(labelPanel); settingsPanel.add(new HTML("<hr>")); settingsPanel.add(periodSetting); settingsPanel.add(datetimePicker); settingsPanel.add(new HTML("<hr>")); settingsPanel.add(granularitySetting); // settingsPanel.add(new NumberSpinner(0)); this.setWidget(settingsPanel); }
From source file:com.cognitivemedicine.metricsdashboard.client.dialogs.AuthenticationDialog.java
License:Apache License
/** * Creates a consistent sized panel for form elements * //from ww w.java 2 s.co m * @param fieldName * @param widget * @return */ private HorizontalPanel createFormPanel(String fieldName, FocusWidget widget) { HorizontalPanel panel = new HorizontalPanel(); panel.setSpacing(4); HTML nameLabel = new HTML(fieldName + ": "); nameLabel.setWidth("115px"); // Weird workaround - the PasswordTextBoxes render wider than the ListBoxes, even when set to // the same size if (widget instanceof ListBox) { widget.setWidth("325px"); } else { widget.setWidth("315px"); } panel.add(nameLabel); panel.add(widget); panel.setCellHorizontalAlignment(nameLabel, HasHorizontalAlignment.ALIGN_RIGHT); return panel; }
From source file:com.cognitivemedicine.metricsdashboard.client.dialogs.CreateDashboardDialog.java
License:Apache License
private void init() { this.setWidth("375px"); this.setText("Create New Dashboard"); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.add(new HTML("<b>Name:</b>")); nameBox = new TextBox(); nameBox.getElement().setId("createDashboardNameTextBox"); nameBox.setWidth("290px"); nameBox.addKeyUpHandler(new KeyUpHandler() { @Override/*from w w w. j av a 2s .co m*/ public void onKeyUp(KeyUpEvent event) { createButton.setEnabled(nameBox.getValue().length() > 0); } }); notesArea = new TextArea(); notesArea.setWidth("290px"); notesArea.getElement().setId("createDashboardNotesArea"); dialogVPanel.add(nameBox); dialogVPanel.add(new HTML("<br><b>Dashboard Notes:</b>")); dialogVPanel.add(notesArea); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); // // Add a close button at the bottom of the dialog Image image = new Image(MdConstants.IMG_OK_CHECK); image.setSize(MdConstants.IMG_SIZE, MdConstants.IMG_SIZE); createButton = new PushButton(image); createButton.setEnabled(false); createButton.setSize(MdConstants.IMG_SIZE, MdConstants.IMG_SIZE); createButton.getElement().setId("createDashboardOkButton"); createButton.setTitle("Create new dashboard"); createButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { createButtonClicked(); } }); image = new Image(MdConstants.IMG_CANCEL_X); image.setSize(MdConstants.IMG_SIZE, MdConstants.IMG_SIZE); cancelButton = new PushButton(image); cancelButton.getElement().setId("createDashboardCancelButton"); cancelButton.setSize(MdConstants.IMG_SIZE, MdConstants.IMG_SIZE); cancelButton.setTitle("Cancel"); cancelButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { CreateDashboardDialog.this.hide(); } }); HorizontalPanel dialogButtonPanel = new HorizontalPanel(); dialogButtonPanel.setSpacing(8); dialogButtonPanel.add(createButton); dialogButtonPanel.add(cancelButton); dialogVPanel.add(dialogButtonPanel); dialogVPanel.setSpacing(4); dialogVPanel.setCellHorizontalAlignment(dialogButtonPanel, HasHorizontalAlignment.ALIGN_CENTER); dialogVPanel.setCellVerticalAlignment(dialogButtonPanel, HasVerticalAlignment.ALIGN_MIDDLE); this.setWidget(dialogVPanel); this.setGlassEnabled(true); this.setModal(true); this.center(); nameBox.setFocus(true); }
From source file:com.cognitivemedicine.metricsdashboard.client.dialogs.DeleteDashboardDialog.java
License:Apache License
private void init() { this.setWidth("300px"); this.setText("Delete Dashboard?"); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.setWidth("300px"); dialogVPanel.setSpacing(8);// w w w . j a v a2 s . c o m dialogVPanel.add(new HTML("Are you sure you'ld like to delete this Dashboard?</br></br><b>" + dashboardListBox.getItemText(dashboardListBox.getSelectedIndex()) + "</b>")); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER); Image image = new Image(MdConstants.IMG_OK_CHECK); image.setSize(MdConstants.IMG_SIZE, MdConstants.IMG_SIZE); PushButton okButton = new PushButton(image); okButton.getElement().setId("deleteDashboardOkButton"); okButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String dashboardId = dashboardListBox.getValue(dashboardListBox.getSelectedIndex()); parent.getController().deleteDashboard(dashboardId); DeleteDashboardDialog.this.hide(); } }); image = new Image(MdConstants.IMG_CANCEL_X); image.setSize(MdConstants.IMG_SIZE, MdConstants.IMG_SIZE); PushButton cancelButton = new PushButton(image); cancelButton.getElement().setId("deleteDashboardCancelButton"); cancelButton.setTitle("Cancel"); cancelButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { DeleteDashboardDialog.this.hide(); } }); HorizontalPanel dialogButtonPanel = new HorizontalPanel(); dialogButtonPanel.setSpacing(4); dialogButtonPanel.add(okButton); dialogButtonPanel.add(cancelButton); dialogVPanel.add(dialogButtonPanel); this.setWidget(dialogVPanel); this.setModal(true); this.setGlassEnabled(true); this.center(); }
From source file:com.cognitivemedicine.metricsdashboard.client.dialogs.SaveAsDashboardDialog.java
License:Apache License
private void init() { this.setWidth("300px"); // dialogBox.ensureDebugId("cwDialogBox"); this.setText("Save As"); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.add(new HTML("<b>Dashboard Name:</b>")); nameBox = new TextBox(); nameBox.setWidth("265px"); nameBox.setValue("Copy of " + existingTitle); nameBox.getElement().setId("saveAsNameBox"); nameBox.addKeyUpHandler(new KeyUpHandler() { @Override/*from ww w .j a v a2 s.com*/ public void onKeyUp(KeyUpEvent event) { createButton.setEnabled(nameBox.getValue().length() > 0); } }); dialogVPanel.add(nameBox); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); Image image = new Image(MdConstants.IMG_OK_CHECK); image.setSize(MdConstants.IMG_SIZE, MdConstants.IMG_SIZE); createButton = new PushButton(image); createButton.setTitle("Save Dashboard"); createButton.getElement().setId("saveAsOkButton"); createButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { createButtonClicked(); } }); image = new Image(MdConstants.IMG_CANCEL_X); image.setSize(MdConstants.IMG_SIZE, MdConstants.IMG_SIZE); cancelButton = new PushButton(image); cancelButton.setTitle("Cancel"); cancelButton.getElement().setId("saveAsOkButton"); cancelButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { SaveAsDashboardDialog.this.hide(); } }); HorizontalPanel dialogButtonPanel = new HorizontalPanel(); dialogVPanel.setSpacing(4); dialogButtonPanel.add(createButton); dialogButtonPanel.add(cancelButton); dialogVPanel.add(dialogButtonPanel); this.setGlassEnabled(true); this.setWidget(dialogVPanel); this.setModal(true); this.center(); nameBox.setFocus(true); nameBox.selectAll(); }
From source file:com.company.application.carrental.client.view.screens.DriverApplicationTab.java
private ADKPanel buildBasicTab() { formPanel = new ADKPanel("basicPanel"); VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.setHeight("700"); verticalPanel.setSpacing(2);//from w w w.j a va 2 s . c o m saveApplicationButton = new ADKButton("saveApplicationButton", "Save", new ADKButtonListener() { @Override public void componentSelected(ButtonEvent ce) { super.componentSelected(ce); DriverMasterClientDto masterClientDto = getApplicationFormData(); mediator.saveDriverApplication(masterClientDto); } }); ToolBar toolBar = new ToolBar(); // ADKCustomHelpList adkCustomHelpList = // new ADKCustomHelpList("driverApplicationHelpList", "Search Driver", // "car_rental", "driver_master", false, 100, 200); // toolBar.add(adkCustomHelpList); List<String> outputColumns = getDriverHelplistColumns(); driverAppHelpList = new ADKCustomHelpList("driverApplicationHelpList", "Search Driver", "car_rental", "driver_master", "Driver_FullName", "Driver_FullName", outputColumns, false, 100, 200); ((ColumnConfig) driverAppHelpList.getColumnsConfigList().get(0)).setHidden(true); EventType specialEvent = new EventType(800); driverAppHelpList.setSpecialEventOnGridSelection(true, specialEvent); driverAppHelpList.getHelpList().addListener(specialEvent, new Listener<BaseEvent>() { public void handleEvent(BaseEvent be) { mediator.searchDriverApplication((Integer) driverAppHelpList.getModelValue().get("Driver_Id")); } }); toolBar.add(driverAppHelpList); toolBar.add(new FillToolItem()); toolBar.add(saveApplicationButton); // toolBar.add(new ToolButton(ToolButton.REFRESH)); verticalPanel.add(toolBar); applicationNoTextField = new TextField(); applicationDateField = new DateField(); applicationStatusTextField = new TextField(); applicationRemarksTextField = new TextArea(); userTextField = new TextField(); HorizontalPanel appPanel = new HorizontalPanel(); appPanel.add(createTopFieldLabel(applicationNoTextField, "Application No")); appPanel.add(createTopFieldLabel(applicationDateField, "Application Date")); appPanel.add(createTopFieldLabel(applicationStatusTextField, "Application Status")); appPanel.add(createTopFieldLabel(applicationRemarksTextField, "Application Remarks")); appPanel.add(createTopFieldLabel(userTextField, "User")); FieldSet appFieldSet = new FieldSet(); appFieldSet.setHeadingText("Application"); appFieldSet.setCollapsible(true); appFieldSet.setWidth(850); appFieldSet.add(appPanel); verticalPanel.add(appFieldSet); fullNameTextField = new TextField<String>(); primaryContactTextField = new TextField(); currentAreaTextField = new TextField(); genderTextField = new TextField(); dobDateField = new DateField(); appPanel = new HorizontalPanel(); appPanel.setSpacing(10); appPanel.add(createTopFieldLabel(fullNameTextField, "Full Name")); appPanel.add(createTopFieldLabel(primaryContactTextField, "Primary Contact")); appPanel.add(createTopFieldLabel(currentAreaTextField, "Current Area")); // verticalPanel.add(appPanel); // // appPanel = new HorizontalPanel(); // appPanel.setSpacing(5); appPanel.add(createTopFieldLabel(genderTextField, "Gender")); appPanel.add(createTopFieldLabel(dobDateField, "DOB")); basicFieldSet = new FieldSet(); basicFieldSet.setHeadingText("Basic Details"); basicFieldSet.setCollapsible(true); basicFieldSet.setWidth(1000); basicFieldSet.add(appPanel); verticalPanel.add(basicFieldSet); licenseNoTextField = new TextField(); LicenseTypeProperties licenseTypeProperties = GWT.create(LicenseTypeProperties.class); ListStore store = new ListStore(licenseTypeProperties.value()); store.add(new CarType("LMV", "LMV")); store.add(new CarType("HMV", "HMV")); licenseTypeCombo = new ComboBox(store, licenseTypeProperties.name()); licenseExpiryDateField = new DateField(); appPanel = new HorizontalPanel(); appPanel.setSpacing(5); appPanel.add(createTopFieldLabel(licenseNoTextField, "License No")); appPanel.add(createTopFieldLabel(licenseTypeCombo, "License Type")); appPanel.add(createTopFieldLabel(licenseExpiryDateField, "License Expiry Date")); FieldSet licenseFieldSet = new FieldSet(); licenseFieldSet.setHeadingText("License"); // licenseFieldSet.setCollapsible(true); licenseFieldSet.setWidth(550); licenseFieldSet.setHeight(100); licenseFieldSet.add(appPanel); HorizontalPanel parentPanel = new HorizontalPanel(); parentPanel.setSpacing(5); parentPanel.add(licenseFieldSet); HorizontalPanel jobPrefPanel = new HorizontalPanel(); FieldSet indiFieldSet = new FieldSet(); indiFieldSet.setHeadingText("Individual"); indiFieldSet.add(buildJobPrefPanel()); jobPrefPanel.add(indiFieldSet); FieldSet companyFieldSet = new FieldSet(); companyFieldSet.setHeadingText("Company"); companyFieldSet.add(buildJobPrefPanel()); jobPrefPanel.add(companyFieldSet); FieldSet jobPrefFieldSet = new FieldSet(); jobPrefFieldSet.setHeadingText("Job Preference"); // jobPrefFieldSet.setCollapsible(true); jobPrefFieldSet.setWidth(600); jobPrefFieldSet.setHeight(100); jobPrefFieldSet.add(jobPrefPanel); parentPanel.add(jobPrefFieldSet); verticalPanel.add(parentPanel); TextField totalExpTextField = new TextField(); TextField curSalTextField = new TextField(); TextField expSalTextField = new TextField(); appPanel = new HorizontalPanel(); appPanel.setSpacing(5); appPanel.add(createTopFieldLabel(totalExpTextField, "Total Exp")); appPanel.add(createTopFieldLabel(curSalTextField, "Current Salary")); appPanel.add(createTopFieldLabel(expSalTextField, "Expected Salary")); // verticalPanel.add(appPanel); medicalHistoryTextArea = new TextArea(); eyeSightTextArea = new TextArea(); diabetesTextArea = new TextArea(); accidentHistoryTextArea = new TextArea(); // appPanel = new HorizontalPanel(); // appPanel.setSpacing(5); appPanel.add(createTopFieldLabel(medicalHistoryTextArea, "Medical History")); appPanel.add(createTopFieldLabel(eyeSightTextArea, "Eye Sight")); appPanel.add(createTopFieldLabel(diabetesTextArea, "Diabetes")); appPanel.add(createTopFieldLabel(accidentHistoryTextArea, "Accident History")); verticalPanel.add(appPanel); TextField driverRefNameTextField = new TextField(); TextField driverRefNoTextField = new TextField(); HorizontalLayoutContainer driverReferencePanel = new HorizontalLayoutContainer(); Margins margins = new Margins(0, 5, 0, 0); HorizontalLayoutData horizontalLayoutData = new HorizontalLayoutData(200, 100, margins); driverReferencePanel.add(createTopFieldLabel(driverRefNameTextField, "Driver Reference Name"), horizontalLayoutData); driverReferencePanel.add(createTopFieldLabel(driverRefNoTextField, "Driver Reference Number"), horizontalLayoutData); FieldSet driverReferenceFieldSet = new FieldSet(); driverReferenceFieldSet.setSize("450", "80"); driverReferenceFieldSet.setHeadingText("Driver Reference"); driverReferenceFieldSet.setCollapsible(true); driverReferenceFieldSet.add(driverReferencePanel); parentPanel = new HorizontalPanel(); parentPanel.setSpacing(5); parentPanel.add(buildCarType()); parentPanel.add(driverReferenceFieldSet); verticalPanel.add(parentPanel); formPanel.add(verticalPanel); return formPanel; }
From source file:com.company.application.carrental.client.view.screens.DriverApplicationTab.java
private HorizontalPanel buildJobPrefPanel() { CheckBox temporaryCheckBox = new CheckBox(); temporaryCheckBox.setBoxLabel("Temporary"); CheckBox permanentCheckBox = new CheckBox(); permanentCheckBox.setBoxLabel("Permanent"); CheckBox adhocCheckBox = new CheckBox(); adhocCheckBox.setBoxLabel("Adhoc"); HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.add(temporaryCheckBox); horizontalPanel.add(permanentCheckBox); horizontalPanel.add(adhocCheckBox);/*from ww w .j a v a2 s . c om*/ return horizontalPanel; }
From source file:com.connoisseur.menuapp.client.Authenticate.java
/** This is essentially the main method for the menu app. */ public static void go() { storage.clear(); // uncomment to completely reset app final DialogBox startupBox = new DialogBox(); // movable box that contains widgets startupBox.setAnimationEnabled(true); final VerticalPanel startupPanel = new VerticalPanel(); // can contain other widgets startupPanel.addStyleName("marginPanel"); // interacts with Menuapp.css startupPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER); // check to see if storage is supported if (storage != null) { // load viewer if license key and restID have been submitted before if (storage.getLength() > 0) { Viewer.loadViewer();//from w ww . j a v a 2s .com } // otherwise load authentication UI in order to receive input else { final Button submitButton = new Button("Submit"); // "Submit" appears on button submitButton.addStyleName("myButton"); // interacts with Menuapp.css final HorizontalPanel buttonPanel = new HorizontalPanel(); // used to center button buttonPanel.addStyleName("marginlessPanel"); // license widgets final Label licenseErrorLabel = new Label(); // dynamic text licenseErrorLabel.addStyleName("errorLabel"); // interacts with Menuapp.css final TextBox submitLicense = new TextBox(); // user can input text using this submitLicense.setText("license key..."); // default text to be seen on load // restaurant ID widgets final Label restErrorLabel = new Label(); restErrorLabel.addStyleName("errorLabel"); final TextBox submitRestID = new TextBox(); submitRestID.setText("restaurant ID..."); // organize UI startupPanel.add(new HTML("Please enter your license key:")); startupPanel.add(submitLicense); startupPanel.add(licenseErrorLabel); startupPanel.add(new HTML("<br>Please enter your restaurant ID:")); startupPanel.add(submitRestID); startupPanel.add(restErrorLabel); startupPanel.add(new HTML("<br>")); buttonPanel.add(submitButton); startupPanel.add(buttonPanel); // setup startupBox, which is what will be seen by the user startupBox.setWidget(startupPanel); // connects the two widgets startupBox.center(); // also shows the box // focus the cursor on submitLicense when startupBox appears submitLicense.setFocus(true); submitLicense.selectAll(); // create a handler for submitButton, submitLicense and submitRestID class MyHandler implements ClickHandler, KeyUpHandler { /** Fired when the user clicks submit. */ public void onClick(ClickEvent event) { submit(); } /** Fired when the user presses Enter in a submit field. */ public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) submit(); } /** Checks the submitted license key and restaurant ID for validity. Loads Viewer if valid. */ private void submit() { String license = submitLicense.getText(); // unused for now String restID = submitRestID.getText(); // not sure how to validate yet int returnFlag = 0; // so that both tests can be done licenseErrorLabel.setText(""); restErrorLabel.setText(""); // validate license String result = FieldVerifier.isValidLicenseKey(license); // from FieldVerifier.java if (!result.equals("")) { // error licenseErrorLabel.setText("You submitted an invalid license key."); submitLicense.selectAll(); returnFlag = 1; } // validate restID result = FieldVerifier.isValidRestaurantID(restID); if (!result.equals("")) { // error restErrorLabel.setText("You submitted an invalid restaurant ID."); submitRestID.selectAll(); returnFlag = 1; } // don't do anything until the errors are resolved if (returnFlag == 1) return; // clean up submitButton.setEnabled(false); submitLicense.setEnabled(false); submitRestID.setEnabled(false); startupBox.hide(); // set up storage storage.setItem("license", license); // secret key for security storage.setItem("restID", restID); // used for almost every call to the backend // show menu Viewer.loadViewer(); } } // MyHandler // attach the handler final MyHandler handler = new MyHandler(); submitButton.addClickHandler(handler); submitLicense.addKeyUpHandler(handler); submitRestID.addKeyUpHandler(handler); } // else load authentication UI } // if storage supported // storage is not supported, so report error else { startupPanel.add(new HTML("<font color=red>The app will not function because local<br>" + "storage is not supported on this platform.</font>")); startupBox.setWidget(startupPanel); startupBox.center(); } }
From source file:com.controlj.addon.gwttree.client.Dialog.java
License:Open Source License
private static Widget createButtonPanel(DialogBox dialogBox, Handler handler) { HorizontalPanel buttonPanel = new HorizontalPanel(); buttonPanel.setSpacing(15);//from www . j a v a2 s . c o m Button okButton = createButton("OK", dialogBox, false, handler); buttonPanel.add(okButton); Button cancelButton = createButton("Cancel", dialogBox, true, handler); buttonPanel.add(cancelButton); handler.setupButtons(okButton, cancelButton); return buttonPanel; }