Squeak browser plugin and JavaScript

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Squeak browser plugin and JavaScript

Rob Withers-2


--------------------------------------------------
From: "Bert Freudenberg" <[hidden email]>
Sent: Tuesday, September 07, 2010 6:15 AM
To: "The general-purpose Squeak developers list"
<[hidden email]>
Subject: Re: [squeak-dev] Squeak browser plugin and JavaScript

>
> On 07.09.2010, at 04:05, Rob Withers wrote:
>
>>
>>
>> --------------------------------------------------
>> From: "Bert Freudenberg" <[hidden email]>
>> Sent: Monday, September 06, 2010 1:17 PM
>> To: "The general-purpose Squeak developers list"
>> <[hidden email]>
>> Subject: Re: [squeak-dev] Squeak browser plugin and JavaScript
>>
>>> (un-cc'ing vmdev)
>>>
>>> On 06.09.2010, at 15:02, Rob Withers wrote:
>>>
>>>> Hi Bert,
>>>>
>>>> I should start by explaining why I think the use of JavaScript is
>>>> desirable. JS enables client side UI and behaviors.   It is back to fat
>>>> client, with a server publishing the UI and the content, but the UI
>>>> runs in the client.  JS supports client-side behaviors to respond to
>>>> mouse over, hover, move?, click, selection, etc.  It is a professional
>>>> look and feel and accepted industry wide - broad support in modern
>>>> browsers.
>>>>
>>>> Let's look at the alternatives you mention, and please correct me if I
>>>> have the wrong read on it:
>>>>
>>>> 1) HTML/DOM - no client side behavior.  Not a robust UI.   All static
>>>> elements.
>>>
>>> Huh? All you do in Javascript is manipulating the DOM. Unless you draw
>>> your own UI using the HTML Canvas object.
>>>
>>
>> I don't understand this.  Could you explain what you mean when you say
>> "All you do in Javascript is manipulating the DOM".  I realize a DOM
>> comes from the servlet
>
> Err, no. The DOM lets you manipulate HTML:
>
> http://www.w3schools.com/htmldom/
>
> The DOM is JS's view of the HTML page, and it can manipulate it. That's
> all there is to it (if you cut through the piles of marketing bs). It's a
> very simple idea, and as often, those are the powerful ones ;)
>
> E.g. if you want to hide or show a control in JS you change attributes on
> the DOM which the browser then renders.
>
>> , but there are all these objects that are created and interact (to mouse
>> events, timers, other events).  It talks to the server with DOM but the
>> behavior is more than just manipulating the DOM, isn't it?
>
> This has nothing whatsoever to do with a server. As I pointed out earlier
> ;)
>

Right, nothing to do with the server.  I see now what you are talking about.
My problem seeing this is that GWT does nothing with a DOM.  It is all about
adding window classes to panels and installing action handlers.   When this
is translated to Javascript, it must create code that manipulates the DOM,
but I don't see it in the Java layer.

As an example, here is a widget that allows you to pick a satellite and
coverage area.

public class CoverageAreaPicker extends Composite {
  DisclosurePanel panel = new DisclosurePanel();
  Area area;
  ArrayList<SatellitePicker> satellitePickers = new
ArrayList<SatellitePicker>();
  FlexTable satelliteTable = new FlexTable();
  boolean hasOpened = false;

  public CoverageAreaPicker(final Area area) {
    this.area = area;
    final Anchor header = new Anchor(area + "\u25ba");
    panel.setHeader(header);
    panel.add(satelliteTable);
    initWidget(panel);
    setStyleName("area");

    panel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
      public void onOpen(OpenEvent<DisclosurePanel> event) {
        header.setText(area + "\u25bc");
        if(!hasOpened) {//Retrieve transponder information once from the
model.
          getTransponders(area, new AsyncCallback<Map<Satellite,
List<Transponder>>>() {
            public void onFailure(Throwable caught) {
              Window.alert("Failed to get transponders for coverage area " +
area);
            }
            public void onSuccess(Map<Satellite, List<Transponder>> result)
{
              int index = 0;
              for(Satellite sat:result.keySet()) {
                SatellitePicker picker = new SatellitePicker(sat);
                satelliteTable.setWidget(0, index++, picker);
                if(index % 2 != 0)
                  picker.addStyleDependentName("even");
                satellitePickers.add(picker);
                picker.renderTable(result.get(sat).toArray(new
Transponder[0]));
                applySelections();
                applyAvailabilityFilters();
                hasOpened = true;
              }
            }
          });
        }
      }
    });

    panel.addCloseHandler(new CloseHandler<DisclosurePanel>() {
      public void onClose(CloseEvent<DisclosurePanel> event) {
        header.setText(area + "\u25ba");
      }
    });
  }

  public void open() {
    panel.setOpen(true);
  }

  public SatellitePicker getSatellitePicker(Satellite sat) {
    for(SatellitePicker picker:satellitePickers) {
      if(picker.satellite == sat)
        return picker;
    }
    return null;
  }
}

Now this puppy is added to an outer panel, from the ChannelPicker object.
There are methods called here to the out scope, like #applySelections(), and
#applyAvailabilityFilters().

This CoverageAreaPicker builds a panel (DisclosurePanel) and to that adds a
header and a satelliteTable (FlexTable).  Then is calls initWidget and sets
the style name.  The style name is used in the css to control layout.

 It installs two handlers: OpenHandler and CloseHandler.  The OpenHandler
calls
    getTransponders(area, new AsyncCallback<Map<Satellite,
List<Transponder>>>() {
and builds an anonymous class implementing onFailure and onSuccess.

In onSuccess, it adds a SatellitePicker to the satelliteTable.

So, it does seem to be building a DOM, with adding panels, tables and other
classes to each other, and it is setting properties, and adding callbacks,
but it isn't very visible as a DOM.

Rob

> - Bert -
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Squeak browser plugin and JavaScript

Bert Freudenberg
On 07.09.2010, at 13:38, Rob Withers wrote:
> So, it does seem to be building a DOM, with adding panels, tables and other classes to each other, and it is setting properties, and adding callbacks, but it isn't very visible as a DOM.
>
> Rob

Well, you would have to look at the JS code that this translates to. Manipulating the DOM is the low-level way to interact with the browser, but often that is hidden in layers of framework code.

If you get your framework done, its users also would not have to worry about how exactly this interacts with the browser. Typically only the framework developers are dealing with this layer. Of course you can choose to layer your stuff on top of another framework. Saves quite some time and effort, but may be less efficient.

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: Squeak browser plugin and JavaScript

Rob Withers-2


--------------------------------------------------
From: "Bert Freudenberg" <[hidden email]>
Sent: Tuesday, September 07, 2010 8:20 AM
To: "The general-purpose Squeak developers list"
<[hidden email]>
Subject: Re: [squeak-dev] Squeak browser plugin and JavaScript

> On 07.09.2010, at 13:38, Rob Withers wrote:
>> So, it does seem to be building a DOM, with adding panels, tables and
>> other classes to each other, and it is setting properties, and adding
>> callbacks, but it isn't very visible as a DOM.
>>
>> Rob
>
> Well, you would have to look at the JS code that this translates to.
> Manipulating the DOM is the low-level way to interact with the browser,
> but often that is hidden in layers of framework code.

Ok, I looked into the GWT framework a bit (I am brand new to it) and there
are classes like

* UIObject (sets style name for css and title),
* UIObject subclass Widget (accepts DOMEvents and dispatches them),
* Widget subclass Composite (holds a Widget "The composite is useful for
creating a single widget out of an aggregate of multiple other widgets
contained in a single panel.")
* Widget subclass Panel subclass ComplexPanel subclass CellPanel subclass
VerticalPanel
* Composite subclass DisclosurePanel (used in the example I gave) which
holds a VerticalPanel.

As you can see there is a robust framework in Java to support this tool.
There are DOMEvents.  We would need the same sort of framework in Squeak, as
you mention.

>
> If you get your framework done, its users also would not have to worry
> about how exactly this interacts with the browser. Typically only the
> framework developers are dealing with this layer. Of course you can choose
> to layer your stuff on top of another framework. Saves quite some time and
> effort, but may be less efficient.
>

Ok, so I think what we are discussing in this thread is 2 tools:

1) a Squeak framework to model and generate a UI in Javascript.  As I have
yet to find time to look at some of the suggested packages, I don't know
which apply to this tool (Clamato, Lively, ST2JS).  I don't think OMeta
plays here.

2) A Javascript to bytecode engine such that Javascript will be Jitted and
run on the vm.  Somehow the vm will display to any browser and react to it's
events.  I think OMeta plays here as a Javascript compiler.

I WANT BOTH TOOLS!

I want to position my framework, SqueakElib, on the browser plugins for
secure, distributed objects available to SqueakJSUI/Javascript framework
elements.

Rob


Reply | Threaded
Open this post in threaded view
|

Re: The Gromit Project [was: Squeak browser plugin and JavaScript]

Hannes Hirzel
In reply to this post by Casey Ransberger-2
On 9/6/10, Dan Ingalls <[hidden email]> wrote:

Great to see your post with interesting news, Dan.

  If there is significant
> interest, it would be fairly easy slide the OMeta work up a bit in
> our schedule.
>
> - Dan
>

OMeta, yes.
I'd like to compile JavaScript to Smalltalk in Squeak (and maybe the
other way round as well)

--Hannes

12