GWT

StrataCode with GWT

GWT is Google's framework which compiles Java to Javascript. This framework was built before StrataCode's own Java to Javascript engine. It only reached the proof of concept phase before it was discontinued for several reasons:

Dynamic programming should be easy with Javascript as a runtime because it's dynamic but not with GWT. The Javascript code does not generate real types in Javascript code, obfuscates names, optimizes out code, and so patching that easily seems too complex. There's no usable Javascript apis for the generated code.

You cannot plug regular Java code into the simulator very easily given the class loader design. There was no easy way SC's dynamic code engine could fit. The compile times of GWT are very long.

Even to implement data binding, we had to generate code for all bindable properties and methods because there's no reflection. This meant code sizes would be bigger with GWT than without. It's not clear the GWT optimizations would get any of this back substantially.

Instead of finishing GWT, we now have the web framework and a new Java to JS engine built on StrataCode.

Nonethless, the GWT implementation could be resurrected and made into a decent integration if anyone wanted, despite the long compile times and lack of dynammic programming. I haven't been testing the GWT version so there's no doubt some tweaking required to get this to work again.

GWT applications extend the gwt.main layer.

package sc.example.unitConverter;

public example.unitConverter.gwtui extends model, gwt.main {


}

Annotation your GWTModule class with the @GWTModule annotation.

file: example/unitConverter/gwtui/UnitConverter.sc
@GWTModule 
UnitConverter {
   // Converts the value strings to/from numbers.  numberToString to defines
   // a reverse method so it can be used in 2-way bindings.
   object numberConverter extends sc.util.NumberConverter {
   }

   object mainView extends VerticalPanel {
      // Combo box to choose the current conversion algorithm
      object converterChoice extends CListBox {
         items := converters;
         visibleItemCount = 1; // Turns a list into a drop-down box
         selectedIndex = 0;
      }

      // currentConverter will always point to the selected item in the combo box
      Converter currentConverter := converters.get(converterChoice.selectedIndex);

      object unit1Panel extends FlowPanel {
         object unit1Label extends InlineLabel {
            text := currentConverter.unit1;  // Display's converter's "unit 1"
         }
         object unit1Field extends CTextBox {
            // Bind's text property to current converter's value1 after converter to/from string
            text :=: numberConverter.numberToString(currentConverter.value1);
         }
      }

      object unit2Panel extends FlowPanel {
         object unit2Label extends InlineLabel {
            text := currentConverter.unit2;
         }
         object unit2Field extends CTextBox {
            text :=: numberConverter.numberToString(currentConverter.value2);
         }
      }

      object errorLabel extends Label {
         // The number converter provides an error when an invalid number is supplied
         text := numberConverter.error;
      }
   }
}

The gwt.main layer defines a default index.html file. It includes the GWT script tags that load the compiled javascript files and defines an empty body.

Object children are by defalt added to the body tag of the page so there's nothing else we need to do. If you define your own index.html file to override the default, you can define HTML tags with id elements that match the object names.