Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page formatting and small correction in examples #271

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions src/main/markdown/articles/testing_methodologies_using_gwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class MeetingSummaryLabelTest extends GWTTestCase {

// Add tests here
}

```

The only visible difference is that all GWTTestCases must override an abstract method called `getModuleName`, which returns a String containing the name of your GWT code module as defined in your application's module XML file.
Expand Down Expand Up @@ -111,7 +110,7 @@ public class PresenterTest extends TestCase {
verify(scheduler);
verify(view);

assertEquals("Should have updated the model's capacity", 225, meeting.getCapacity());
assertEquals("Should have updated the model's capacity", 225, meeting.getCapacity());
}
}

Expand Down Expand Up @@ -150,10 +149,10 @@ public class Presenter {
}

/**
* Callback when the view's capacity text box changes
*
* @param textField the capacity TextBox widget
*/
* Callback when the view's capacity text box changes
*
* @param textField the capacity TextBox widget
*/
public void requiredCapacityChanged(HasText textField) {
meeting.setCapacity(Integer.parseInt(textField.getText()));
if (!roomScheduler.canAcceptCapacityFor(meeting)) {
Expand All @@ -180,18 +179,17 @@ package com.google.gwt.user.client.ui;
public interface HasText {

/**
* Gets this object's text.
*/
* Gets this object's text.
*/
String getText();

/**
* Sets this object's text.
*
* @param text the object's new text
*/
* Sets this object's text.
*
* @param text the object's new text
*/
void setText(String text);
}

```

This simple interface is used by many GWT components and allows manipulation of a widget's text contents, including the TextBox in our example. This interface is extremely useful for testing because we don't need to pass in a real TextBox. Thus we avoid instantiating a text input in the DOM, requiring our test to extend GWTTestCase to run in a real browser. In this example, I've made a very simple fake implementation which wraps a String:
Expand All @@ -212,7 +210,6 @@ public class FakeTextContainer implements HasText {
this.text = text;
}
}

```

Finally, let's take a look at our view implementation:
Expand Down Expand Up @@ -250,7 +247,6 @@ public class MeetingViewWidget extends Composite implements MeetingView {
saveButton.setEnabled(false);
}
}

```

And lastly, the Meeting class code, for completeness:
Expand All @@ -267,7 +263,6 @@ public class Meeting {
this.capacity = capacity;
}
}

```

As you can see, there's not much logic here. Most of the code is involved in setting up the event listeners and configuring the display widgets. So how do we test it in a GWTTestCase?
Expand Down
26 changes: 13 additions & 13 deletions src/main/markdown/doc/latest/DevGuideCodingBasicsDelayed.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ To create a timer, create a new instance of the Timer class and then override th

```
Timer timer = new Timer() {
public void run() {
Window.alert ("Timer expired!");
}
};
public void run() {
Window.alert("Timer expired!");
}
};

// Execute the timer to expire 2 seconds in the future
timer.schedule(2000);
// Execute the timer to expire 2 seconds in the future
timer.schedule(2000);
```

Notice that the timer will not have a chance to execute the run() method until after control returns to the JavaScript event loop.
Expand Down Expand Up @@ -169,14 +169,14 @@ it to [Scheduler.scheduleDeferred](/javadoc/latest/com/google/gwt/core/client/Sc
```
TextBox dataEntry;

// Set the focus on the widget after setup completes.
Scheduler.get().scheduleDeferred(new Command() {
public void execute () {
dataEntry.setFocus();
}
});
// Set the focus on the widget after setup completes.
Scheduler.get().scheduleDeferred(new Command() {
public void execute () {
dataEntry.setFocus();
}
});

dataEntry = new TextBox();
dataEntry = new TextBox();
```

## Avoiding Slow Script Warnings: the IncrementalCommand class<a id="incremental"></a>
Expand Down
46 changes: 23 additions & 23 deletions src/main/markdown/doc/latest/DevGuideCodingBasicsFormatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,36 @@ For most cases, you probably want to use the default decimal format:

```
NumberFormat fmt = NumberFormat.getDecimalFormat();
double value = 12345.6789;
String formatted = fmt.format(value);
// Prints 1,2345.6789 in the default locale
GWT.log("Formatted string is" + formatted, null);
double value = 12345.6789;
String formatted = fmt.format(value);
// Prints 1,2345.6789 in the default locale
GWT.log("Formatted string is" + formatted, null);
```

The class can also be used to convert a numeric string back into a double:

```
double value = NumberFormat.getDecimalFormat().parse("12345.6789");
GWT.log("Parsed value is" + value, null);
GWT.log("Parsed value is" + value, null);
```

The `NumberFormat` class also provides defaults for scientific notation:

```
double value = 12345.6789;
String formatted = NumberFormat.getScientificFormat().format(value);
// prints 1.2345E4 in the default locale
GWT.log("Formatted string is" + formatted, null);
String formatted = NumberFormat.getScientificFormat().format(value);
// prints 1.2345E4 in the default locale
GWT.log("Formatted string is" + formatted, null);
```

Note that you can also specify your own pattern for formatting numbers. In the example below, we want to show 6 digits of precision on the right hand side of the decimal and
format the left hand side with zeroes up to the hundred thousands place:

```
double value = 12345.6789;
String formatted = NumberFormat.getFormat("000000.000000").format(value);
// prints 012345.678900 in the default locale
GWT.log("Formatted string is" + formatted, null);
String formatted = NumberFormat.getFormat("000000.000000").format(value);
// prints 012345.678900 in the default locale
GWT.log("Formatted string is" + formatted, null);
```

Here are the most commonly used pattern symbols for decimal formats:
Expand Down Expand Up @@ -86,23 +86,23 @@ For the `DateTimeFormat` class, there are a large number of default formats defi
```
Date today = new Date();

// prints Tue Dec 18 12:01:26 GMT-500 2007 in the default locale.
GWT.log(today.toString(), null);
// prints Tue Dec 18 12:01:26 GMT-500 2007 in the default locale.
GWT.log(today.toString(), null);

// prints 12/18/07 in the default locale
GWT.log(DateTimeFormat.getShortDateFormat().format(today), null);
// prints 12/18/07 in the default locale
GWT.log(DateTimeFormat.getShortDateFormat().format(today), null);

// prints December 18, 2007 in the default locale
GWT.log(DateTimeFormat.getLongDateFormat().format(today), null);
// prints December 18, 2007 in the default locale
GWT.log(DateTimeFormat.getLongDateFormat().format(today), null);

// prints 12:01 PM in the default locale
GWT.log(DateTimeFormat.getShortTimeFormat().format(today), null);
// prints 12:01 PM in the default locale
GWT.log(DateTimeFormat.getShortTimeFormat().format(today), null);

// prints 12:01:26 PM GMT-05:00 in the default locale
GWT.log(DateTimeFormat.getLongTimeFormat().format(today), null);
// prints 12:01:26 PM GMT-05:00 in the default locale
GWT.log(DateTimeFormat.getLongTimeFormat().format(today), null);

// prints Dec 18, 2007 12:01:26 PM in the default locale
GWT.log(DateTimeFormat.getMediumDateTimeFormat().format(today), null);
// prints Dec 18, 2007 12:01:26 PM in the default locale
GWT.log(DateTimeFormat.getMediumDateTimeFormat().format(today), null);
```

Like the `NumberFormat` class, you can also use this class to parse a date from a `String` into a `Date` representation. You also have the option of using
Expand Down
33 changes: 16 additions & 17 deletions src/main/markdown/doc/latest/DevGuideCodingBasicsJSNI.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public static native int badExample() /*-{
return "Not A Number";
}-*/;

public void onClick () {
try {
int myValue = badExample();
GWT.log("Got value " + myValue, null);
} catch (Exception e) {
GWT.log("JSNI method badExample() threw an exception:", e);
}
}
public void onClick() {
try {
int myValue = badExample();
GWT.log("Got value " + myValue, null);
} catch (Exception e) {
GWT.log("JSNI method badExample() threw an exception:", e);
}
}
```

This example compiles as Java, and its syntax is verified by the GWT compiler
Expand Down Expand Up @@ -208,7 +208,7 @@ public class JSNIExample {

## Calling a Java Method from Handwritten JavaScript<a id="calling"></a>

Sometimes you need to access a method or constructor defined in GWT from outside JavaScript code. This code might be hand-written and included in another java script file, or
Sometimes you need to access a method or constructor defined in GWT from outside JavaScript code. This code might be hand-written and included in another JavaScript file, or
it could be a part of a third party library. In this case, the GWT compiler will not get a chance to build an interface between your JavaScript code and the GWT generated
JavaScript directly.

Expand All @@ -218,14 +218,13 @@ JavaScript code.
```
package mypackage;

public MyUtilityClass
{
public static int computeLoanInterest(int amt, float interestRate,
int term) { ... }
public static native void exportStaticMethod() /*-{
$wnd.computeLoanInterest =
$entry(@mypackage.MyUtilityClass::computeLoanInterest(IFI));
}-*/;
public class MyUtilityClass {
public static int computeLoanInterest(int amt, float interestRate,
int term) { ... }
public static native void exportStaticMethod() /*-{
$wnd.computeLoanInterest =
$entry(@mypackage.MyUtilityClass::computeLoanInterest(IFI));
}-*/;
}
```

Expand Down
22 changes: 13 additions & 9 deletions src/main/markdown/doc/latest/DevGuideCodingBasicsJsInterop.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ JsInterop is one of the core features of GWT 2.8. As the name suggests, JsIntero
JsInterop can be used to expose a Java type to be used externally from a JavaScript script (aka a non-native type). This can be achieved by annotating the type with `@JsType`. This annotation exposes all the public non-static fields and methods, and tells the GWT compiler that the type is to be exported to a JavaScript type. Annotating a class with `@JsType` is equivalent to annotating all its public non-static methods with `@JsMethod`, its constructor with `@JsConstructor` (only one `@JsConstructor` is allowed to exist, more details can be found [in the javadoc](http://www.gwtproject.org/javadoc/latest/jsinterop/annotations/JsConstructor.html)), and all its public non-static fields with `@JsProperty`, so no need to add them explicity.

Additionally, `@JsType` can be fine-tuned using the following properties:

* name: customizes the name of the type. The default is to keep the Java type name.
* namespace: specifies the JavaScript namespace of the type. The default is the current package of the type. To export a top-level type, the `JsPackage.GLOBAL` constant can be used.

Expand All @@ -21,22 +22,25 @@ package com.gwt.example;
@JsType
public class MyClass {

public String name;
public String name;

public MyClass(String name) {
this.name = name;
}
public MyClass(String name) {
this.name = name;
}

public void sayHello() {
return "Hello" + this.name;
}
public String sayHello() {
return "Hello " + this.name;
}
}
```

From the JS script, the object can be used as a JS object:

```javascript
//the package name serves as a JS namespace
// Note that exporting of Java Objects to JavaScript to be accessed by their
// namespace (e.g. this sample) requires -generateJsInteropExports flag.

// the package name serves as a JS namespace
var aClass = new com.gwt.example.MyClass('World');

console.log(aClass.sayHello());
Expand Down Expand Up @@ -204,4 +208,4 @@ The full example is available at https://github.com/zak905/jsinterop-leaflet

JsInterop specifications:
https://docs.google.com/document/d/10fmlEYIHcyead_4R1S5wKGs1t2I7Fnp_PaNaa7XTEk0/edit#
GWT 2.8.0 and JsInterop: http://www.luigibifulco.it/blog/en/blog/gwt-2-8-0-jsinterop
GWT 2.8.0 and JsInterop: http://www.luigibifulco.it/blog/en/blog/gwt-2-8-0-jsinterop
12 changes: 6 additions & 6 deletions src/main/markdown/doc/latest/DevGuideI18nMessages.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ The following code implements an alert dialog by substituting values into the me

```
public interface ErrorMessages extends Messages {
String permissionDenied(int errorCode, String username);
}
ErrorMessages msgs = GWT.create(ErrorMessages.class)
String permissionDenied(int errorCode, String username);
}
ErrorMessages msgs = GWT.create(ErrorMessages.class)

void permissionDenied(int errorVal, String loginId) {
Window.alert(msgs.permissionDenied(errorVal, loginId));
}
void permissionDenied(int errorVal, String loginId) {
Window.alert(msgs.permissionDenied(errorVal, loginId));
}
```

**Caution:** Be advised that the rules for using quotes may be a bit confusing. Refer to the [MessageFormat](http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html) javadoc for more details.
Expand Down
2 changes: 1 addition & 1 deletion src/main/markdown/doc/latest/DevGuideI18nPluralForms.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ value in a properties file.

See the next item for another use of Exact Values.

## Offsets<a id="Offsets"><a>
## Offsets<a id="Offsets"></a>

In some cases, you may want to alter the count before applying the plural
rules to it. For example, if you are saying `"Bob, Joe, and 3 others ate
Expand Down
Loading