SlideShare a Scribd company logo
1 of 40
Download to read offline
Wednesday, November 2, 11
CUSTOM COMPONENTS
                            Sven Brunken



             sven@sencha.com               @svenbrunken




Wednesday, November 2, 11
Overview
                                    Widget vs Component
                            Important methods of the Widget class
                                 When to use the Cell class?
                              Important methods of the Cell class
                                         Questions




Wednesday, November 2, 11
Which Class To Start
                            From?




Wednesday, November 2, 11
Widget
       Build on top of a DOM Element
       Listens to browser events
       Needs to be attached and detached for event handling
       Does not solve the different sizing boxes
       Can fire custom events through its HandlerManager




Wednesday, November 2, 11
Component
       Extends the Widget class and so inherits all its features
       Solves the different sizing boxes
       Can be disabled directly
       Can be positioned




Wednesday, November 2, 11
Important Methods




Wednesday, November 2, 11
sinkEvents()
       Defines which events can be listened to
       Events not sunk cannot be listened to



   public void sinkEvents(int eventBitsToAdd) {
     if (isOrWasAttached()) {
       DOM.sinkEvents(getElement(), eventBitsToAdd|DOM.getEventsSunk(getElement()));
     } else {
       eventsToSink |= eventBitsToAdd;
     }
   }




Wednesday, November 2, 11
onAttach()
       Removes the event listener
       Mandatory to enable browser event handling
       Attaches the event listener of all its children widgets

                            protected void onAttach() {
                              attached = true;
                              DOM.setEventListener(getElement(), this);
                              int bitsToAdd = eventsToSink;
                              eventsToSink = -1;
                              if (bitsToAdd > 0) {
                                sinkEvents(bitsToAdd);
                              }
                              doAttachChildren();
                              onLoad();
                              AttachEvent.fire(this, true);
                            }


Wednesday, November 2, 11
onDetach()
       Removes the event listener added from onAttach()
       Browser events are no longer handled for this Widget
       Prevents memory leaks
       Detaches the event listener for all its children widgets

                            protected void onDetach() {
                              try {
                                onUnload();
                                AttachEvent.fire(this, false);
                              } finally {
                                try {
                                  doDetachChildren();
                                } finally {
                                  DOM.setEventListener(getElement(), null);
                                  attached = false;
                                }
                              }
                            }
Wednesday, November 2, 11
fireEvent()
       Fires a custom event through the HandlerManager
       Other classes could listen to these events



                            public void fireEvent(GwtEvent<?> event) {
                              if (handlerManager != null) {
                                handlerManager.fireEvent(event);
                              }
                            }




Wednesday, November 2, 11
onBrowserEvent()
       Only called when a Widget is attached
       Gets called with the browser event that occurred
       Refires the browser event through the HandlerManager




                public void onBrowserEvent(Event event) {
                  DomEvent.fireNativeEvent(event, this, this.getElement());
                }




Wednesday, November 2, 11
setElement()
       Sets the element for this Widget
       Mandatory to be called
       An Element can only be set once and not changed
       Needs to be called before calling getElement()




             protected void setElement(Element elem) {
               assert (element == null) : SETELEMENT_TWICE_ERROR;
               this.element = elem;
             }




Wednesday, November 2, 11
How To Start?




Wednesday, November 2, 11
Gathering Information
       What is the purpose of my custom widget?
       Which browser events are required?
       Can I extend an already existing class?




       Do I understand all my requirements?




Wednesday, November 2, 11
Implementation




Wednesday, November 2, 11
The Class
       Extending Component to overcome different sizing models




                            public class SquareWidget extends Component {

                            }




Wednesday, November 2, 11
Constructor
       Setting the Element
       Defining the events we want to listen to



           public SquareWidget(Data data) {
             this.data = data;
             SquareWidgetTemplate t = GWT.create(SquareWidgetTemplate.class);
             setElement(XDOM.create(t.render(data)));

                sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONCLICK);

                setPixelSize(100, 100);
           }




Wednesday, November 2, 11
onBrowserEvent()
       Contains our event handling logic
       Should call the super method

                        @Override
                        public void onBrowserEvent(Event event) {
                          super.onBrowserEvent(event);

                            if (event.getTypeInt() == Event.ONMOUSEOUT) {
                              onMouseOut(event);
                            } else if (event.getTypeInt() == Event.ONMOUSEOVER) {
                              onMouseOver(event);
                            } else if (event.getTypeInt() == Event.ONCLICK) {
                              onClick(event);
                            }
                        }

Wednesday, November 2, 11
onMouseOver()
       getRelatedEventTarget returns the Element coming from
       Setting the mouse over value




      private void onMouseOver(Event event) {
        EventTarget t = event.getRelatedEventTarget();
        if (t == null || Element.is(t) && !getElement().isOrHasChild(Element.as(t))) {
          String s = SafeHtmlUtils.fromString(data.getMouseOverName()).asString();
          getContentElement().setInnerHTML(s);
        }
      }




Wednesday, November 2, 11
onMouseOut()
       getRelatedEventTarget returns the Element moving to
       Clearing the background color
       Setting the standard value again


             private void onMouseOut(Event event) {
               EventTarget t = event.getRelatedEventTarget();
               if (t == null
                   || (Element.is(t) && !getElement().isOrHasChild(Element.as(t)))) {
                 getElement().getStyle().clearBackgroundColor();

                     String s = SafeHtmlUtils.fromString(data.getName()).asString();
                     getContentElement().setInnerHTML(s);
                 }
             }




Wednesday, November 2, 11
onClick()
       Sets the different background color




                            private void onClick(Event event) {
                              getElement().getStyle().setBackgroundColor("red");
                            }




Wednesday, November 2, 11
Demonstration




Wednesday, November 2, 11
But, Do We Really
                            Require a Widget?




Wednesday, November 2, 11
Introducing Cell
       Cells can handle browser events
       Cells can be used in data components
       Widgets cannot be used there
       Cells render a lot faster




Wednesday, November 2, 11
Context of the Cell
       Contains the relevant row and column index
       Important when used in data widgets
       Contains the key representing the value




Wednesday, November 2, 11
Important Methods




Wednesday, November 2, 11
onBrowserEvent()
       Gets called when an event for this cell occurred
       Gets passed in the parent Element
       Cell on its own does not know anything where it is displayed
       One Cell can be displayed in many places




             void onBrowserEvent(Context context, Element parent, C value,
                 NativeEvent event, ValueUpdater<C> valueUpdater);




Wednesday, November 2, 11
render()
       Called when a Cell should be rendered
       The output should be written to the SafeHtmlBuilder




                void render(Context context, C value, SafeHtmlBuilder sb);




Wednesday, November 2, 11
getConsumedEvents()
       Returns the events this cell requires
       Cannot change in the lifecycle of a Cell




                            Set<String> getConsumedEvents();




Wednesday, November 2, 11
Implementation




Wednesday, November 2, 11
The Class
       Extending AbstractCell
       Implementing the Cell interface directly works too



                        public class SquareCell extends AbstractCell<Data> {

                        }




Wednesday, November 2, 11
Constructor
       Defining the events this cell listens to




                            public SquareCell() {
                              super("click", "mouseover", "mouseout");
                            }




Wednesday, November 2, 11
onBrowserEvent()
       Contains our event handling logic

                public void onBrowserEvent(Context context, Element parent, Data value,
                    NativeEvent event, ValueUpdater<Data> valueUpdater) {
                  Element t = parent.getFirstChildElement();
                  Element target = event.getEventTarget().cast();
                  if (!t.isOrHasChild(target)) {
                    return;
                  }

                    if ("mouseout".equals(event.getType())) {
                      onMouseOut(context, parent, value, event);
                    } else if ("mouseover".equals(event.getType())) {
                      onMouseOver(context, parent, value, event);
                    } else if ("click".equals(event.getType())) {
                      onClick(context, parent, value, event);
                    }
                }
Wednesday, November 2, 11
onMouseOver()
       getRelatedEventTarget returns the Element coming from
       Setting the mouse over value



         private void onMouseOver(Context context, Element parent, Data value,
             NativeEvent event) {
           Element fc = parent.getFirstChildElement();
           EventTarget t = event.getRelatedEventTarget();
           if (t == null || (Element.is(t) && !fc.isOrHasChild(Element.as(t)))) {
             String s = SafeHtmlUtils.fromString(value.getMouseOverName()).asString();
             getContentElement(parent).setInnerHTML(s);
           }
         }




Wednesday, November 2, 11
onMouseOut()
       getRelatedEventTarget returns the Element moving to
       Clearing the background color
       Setting the standard value again
          private void onMouseOut(Context context, Element parent, Data value,
              NativeEvent event) {
            Element fc = parent.getFirstChildElement();
            EventTarget t = event.getRelatedEventTarget();
            if (t == null || (Element.is(t) && !fc.isOrHasChild(Element.as(t)))) {
              fc.getStyle().clearBackgroundColor();
              String s = SafeHtmlUtils.fromString(value.getName()).asString();
              getContentElement(parent).setInnerHTML(s);
            }
          }




Wednesday, November 2, 11
onClick()
       Sets the different background color




           private void onClick(Context context, Element parent, Data value,
               NativeEvent event) {
             parent.getFirstChildElement().getStyle().setBackgroundColor("red");
           }




Wednesday, November 2, 11
Demonstration




Wednesday, November 2, 11
Questions




Wednesday, November 2, 11
Thank You!




Wednesday, November 2, 11

More Related Content

What's hot

Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.Yonatan Levin
 
Advanced Akka For Architects
Advanced Akka For ArchitectsAdvanced Akka For Architects
Advanced Akka For ArchitectsLightbend
 
Save System in Garden of the Sea: How to save the state of an open-ended gard...
Save System in Garden of the Sea: How to save the state of an open-ended gard...Save System in Garden of the Sea: How to save the state of an open-ended gard...
Save System in Garden of the Sea: How to save the state of an open-ended gard...DevGAMM Conference
 
YUI3 Modules
YUI3 ModulesYUI3 Modules
YUI3 Modulesa_pipkin
 
Ejercicio sql server vs visual .net
Ejercicio sql server vs visual .netEjercicio sql server vs visual .net
Ejercicio sql server vs visual .netAyuda Universidad
 
Kivy Talk Python Meetup Innsbruck 2017.04.25
Kivy Talk Python Meetup Innsbruck 2017.04.25Kivy Talk Python Meetup Innsbruck 2017.04.25
Kivy Talk Python Meetup Innsbruck 2017.04.25Robert Niederreiter
 
The Ring programming language version 1.6 book - Part 72 of 189
The Ring programming language version 1.6 book - Part 72 of 189The Ring programming language version 1.6 book - Part 72 of 189
The Ring programming language version 1.6 book - Part 72 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 66 of 180
The Ring programming language version 1.5.1 book - Part 66 of 180The Ring programming language version 1.5.1 book - Part 66 of 180
The Ring programming language version 1.5.1 book - Part 66 of 180Mahmoud Samir Fayed
 

What's hot (18)

Unity3 d devfest-2014
Unity3 d devfest-2014Unity3 d devfest-2014
Unity3 d devfest-2014
 
Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.
 
Ms Ajax Dom Event Class
Ms Ajax Dom Event ClassMs Ajax Dom Event Class
Ms Ajax Dom Event Class
 
Advanced Akka For Architects
Advanced Akka For ArchitectsAdvanced Akka For Architects
Advanced Akka For Architects
 
Data Storage
Data StorageData Storage
Data Storage
 
Ouce2013-RBEM-WS
Ouce2013-RBEM-WSOuce2013-RBEM-WS
Ouce2013-RBEM-WS
 
OUCE2013-RBEM-PT
OUCE2013-RBEM-PTOUCE2013-RBEM-PT
OUCE2013-RBEM-PT
 
What's new in CDI 2.0
What's new in CDI 2.0What's new in CDI 2.0
What's new in CDI 2.0
 
Metode
MetodeMetode
Metode
 
Network
NetworkNetwork
Network
 
Save System in Garden of the Sea: How to save the state of an open-ended gard...
Save System in Garden of the Sea: How to save the state of an open-ended gard...Save System in Garden of the Sea: How to save the state of an open-ended gard...
Save System in Garden of the Sea: How to save the state of an open-ended gard...
 
YUI3 Modules
YUI3 ModulesYUI3 Modules
YUI3 Modules
 
Ejercicio sql server vs visual .net
Ejercicio sql server vs visual .netEjercicio sql server vs visual .net
Ejercicio sql server vs visual .net
 
Kivy Talk Python Meetup Innsbruck 2017.04.25
Kivy Talk Python Meetup Innsbruck 2017.04.25Kivy Talk Python Meetup Innsbruck 2017.04.25
Kivy Talk Python Meetup Innsbruck 2017.04.25
 
menu strip - visual basic
menu strip - visual basicmenu strip - visual basic
menu strip - visual basic
 
The Ring programming language version 1.6 book - Part 72 of 189
The Ring programming language version 1.6 book - Part 72 of 189The Ring programming language version 1.6 book - Part 72 of 189
The Ring programming language version 1.6 book - Part 72 of 189
 
Final_Project
Final_ProjectFinal_Project
Final_Project
 
The Ring programming language version 1.5.1 book - Part 66 of 180
The Ring programming language version 1.5.1 book - Part 66 of 180The Ring programming language version 1.5.1 book - Part 66 of 180
The Ring programming language version 1.5.1 book - Part 66 of 180
 

Similar to Custom Components: Widget vs Cell Class

Ext GWT 3.0 Data Binding and Editors
Ext GWT 3.0 Data Binding and EditorsExt GWT 3.0 Data Binding and Editors
Ext GWT 3.0 Data Binding and EditorsSencha
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Androidgreenrobot
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.pptusama537223
 
A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014Matthias Noback
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programmingSynapseindiappsdevelopment
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2PRN USM
 
Java gui event
Java gui eventJava gui event
Java gui eventSoftNutx
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intentadmin220812
 
Using UIBinder with Ext GWT 3.0
Using UIBinder with Ext GWT 3.0Using UIBinder with Ext GWT 3.0
Using UIBinder with Ext GWT 3.0Sencha
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationSamuel ROZE
 
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014Matthias Noback
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handlingAmol Gaikwad
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5sotlsoc
 
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdfJEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdfMarlouFelixIIICunana
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - eventsroxlu
 

Similar to Custom Components: Widget vs Cell Class (20)

Javascript Browser Events.pdf
Javascript Browser Events.pdfJavascript Browser Events.pdf
Javascript Browser Events.pdf
 
Ext GWT 3.0 Data Binding and Editors
Ext GWT 3.0 Data Binding and EditorsExt GWT 3.0 Data Binding and Editors
Ext GWT 3.0 Data Binding and Editors
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Android
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
 
Events
EventsEvents
Events
 
A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
 
Java gui event
Java gui eventJava gui event
Java gui event
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intent
 
Using UIBinder with Ext GWT 3.0
Using UIBinder with Ext GWT 3.0Using UIBinder with Ext GWT 3.0
Using UIBinder with Ext GWT 3.0
 
GreenRobot-Eventbus
GreenRobot-EventbusGreenRobot-Eventbus
GreenRobot-Eventbus
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdfJEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
 
Ext J S Observable
Ext J S ObservableExt J S Observable
Ext J S Observable
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
 
Events - Part 2
Events - Part 2Events - Part 2
Events - Part 2
 

More from Sencha

Breathe New Life into Your Existing JavaScript Applications with Web Components
Breathe New Life into Your Existing JavaScript Applications with Web ComponentsBreathe New Life into Your Existing JavaScript Applications with Web Components
Breathe New Life into Your Existing JavaScript Applications with Web ComponentsSencha
 
Ext JS 6.6 Highlights
Ext JS 6.6 HighlightsExt JS 6.6 Highlights
Ext JS 6.6 HighlightsSencha
 
Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...
Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...
Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...Sencha
 
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd Sencha
 
Sencha Roadshow 2017: Best Practices for Implementing Continuous Web App Testing
Sencha Roadshow 2017: Best Practices for Implementing Continuous Web App TestingSencha Roadshow 2017: Best Practices for Implementing Continuous Web App Testing
Sencha Roadshow 2017: Best Practices for Implementing Continuous Web App TestingSencha
 
Sencha Roadshow 2017: What's New in Sencha Test
Sencha Roadshow 2017: What's New in Sencha TestSencha Roadshow 2017: What's New in Sencha Test
Sencha Roadshow 2017: What's New in Sencha TestSencha
 
Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...
Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...
Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...Sencha
 
Sencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
Sencha Roadshow 2017: Modernizing the Ext JS Class System and ToolingSencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
Sencha Roadshow 2017: Modernizing the Ext JS Class System and ToolingSencha
 
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App Sencha
 
Sencha Roadshow 2017: Mobile First or Desktop First
Sencha Roadshow 2017: Mobile First or Desktop FirstSencha Roadshow 2017: Mobile First or Desktop First
Sencha Roadshow 2017: Mobile First or Desktop FirstSencha
 
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and BeyondSencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and BeyondSencha
 
Leveraging React and GraphQL to Create a Performant, Scalable Data Grid
Leveraging React and GraphQL to Create a Performant, Scalable Data GridLeveraging React and GraphQL to Create a Performant, Scalable Data Grid
Leveraging React and GraphQL to Create a Performant, Scalable Data GridSencha
 
Learn Key Insights from The State of Web Application Testing Research Report
Learn Key Insights from The State of Web Application Testing Research ReportLearn Key Insights from The State of Web Application Testing Research Report
Learn Key Insights from The State of Web Application Testing Research ReportSencha
 
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React AppsIntroducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React AppsSencha
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSencha
 
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...Sencha
 
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...Sencha
 
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSencha
 
Ext JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell SimeonsExt JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell SimeonsSencha
 
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...Sencha
 

More from Sencha (20)

Breathe New Life into Your Existing JavaScript Applications with Web Components
Breathe New Life into Your Existing JavaScript Applications with Web ComponentsBreathe New Life into Your Existing JavaScript Applications with Web Components
Breathe New Life into Your Existing JavaScript Applications with Web Components
 
Ext JS 6.6 Highlights
Ext JS 6.6 HighlightsExt JS 6.6 Highlights
Ext JS 6.6 Highlights
 
Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...
Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...
Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...
 
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
 
Sencha Roadshow 2017: Best Practices for Implementing Continuous Web App Testing
Sencha Roadshow 2017: Best Practices for Implementing Continuous Web App TestingSencha Roadshow 2017: Best Practices for Implementing Continuous Web App Testing
Sencha Roadshow 2017: Best Practices for Implementing Continuous Web App Testing
 
Sencha Roadshow 2017: What's New in Sencha Test
Sencha Roadshow 2017: What's New in Sencha TestSencha Roadshow 2017: What's New in Sencha Test
Sencha Roadshow 2017: What's New in Sencha Test
 
Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...
Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...
Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...
 
Sencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
Sencha Roadshow 2017: Modernizing the Ext JS Class System and ToolingSencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
Sencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
 
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
 
Sencha Roadshow 2017: Mobile First or Desktop First
Sencha Roadshow 2017: Mobile First or Desktop FirstSencha Roadshow 2017: Mobile First or Desktop First
Sencha Roadshow 2017: Mobile First or Desktop First
 
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and BeyondSencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
 
Leveraging React and GraphQL to Create a Performant, Scalable Data Grid
Leveraging React and GraphQL to Create a Performant, Scalable Data GridLeveraging React and GraphQL to Create a Performant, Scalable Data Grid
Leveraging React and GraphQL to Create a Performant, Scalable Data Grid
 
Learn Key Insights from The State of Web Application Testing Research Report
Learn Key Insights from The State of Web Application Testing Research ReportLearn Key Insights from The State of Web Application Testing Research Report
Learn Key Insights from The State of Web Application Testing Research Report
 
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React AppsIntroducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
 
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
 
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
 
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
 
Ext JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell SimeonsExt JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell Simeons
 
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Custom Components: Widget vs Cell Class

  • 2. CUSTOM COMPONENTS Sven Brunken sven@sencha.com @svenbrunken Wednesday, November 2, 11
  • 3. Overview Widget vs Component Important methods of the Widget class When to use the Cell class? Important methods of the Cell class Questions Wednesday, November 2, 11
  • 4. Which Class To Start From? Wednesday, November 2, 11
  • 5. Widget Build on top of a DOM Element Listens to browser events Needs to be attached and detached for event handling Does not solve the different sizing boxes Can fire custom events through its HandlerManager Wednesday, November 2, 11
  • 6. Component Extends the Widget class and so inherits all its features Solves the different sizing boxes Can be disabled directly Can be positioned Wednesday, November 2, 11
  • 8. sinkEvents() Defines which events can be listened to Events not sunk cannot be listened to public void sinkEvents(int eventBitsToAdd) { if (isOrWasAttached()) { DOM.sinkEvents(getElement(), eventBitsToAdd|DOM.getEventsSunk(getElement())); } else { eventsToSink |= eventBitsToAdd; } } Wednesday, November 2, 11
  • 9. onAttach() Removes the event listener Mandatory to enable browser event handling Attaches the event listener of all its children widgets protected void onAttach() { attached = true; DOM.setEventListener(getElement(), this); int bitsToAdd = eventsToSink; eventsToSink = -1; if (bitsToAdd > 0) { sinkEvents(bitsToAdd); } doAttachChildren(); onLoad(); AttachEvent.fire(this, true); } Wednesday, November 2, 11
  • 10. onDetach() Removes the event listener added from onAttach() Browser events are no longer handled for this Widget Prevents memory leaks Detaches the event listener for all its children widgets protected void onDetach() { try { onUnload(); AttachEvent.fire(this, false); } finally { try { doDetachChildren(); } finally { DOM.setEventListener(getElement(), null); attached = false; } } } Wednesday, November 2, 11
  • 11. fireEvent() Fires a custom event through the HandlerManager Other classes could listen to these events public void fireEvent(GwtEvent<?> event) { if (handlerManager != null) { handlerManager.fireEvent(event); } } Wednesday, November 2, 11
  • 12. onBrowserEvent() Only called when a Widget is attached Gets called with the browser event that occurred Refires the browser event through the HandlerManager public void onBrowserEvent(Event event) { DomEvent.fireNativeEvent(event, this, this.getElement()); } Wednesday, November 2, 11
  • 13. setElement() Sets the element for this Widget Mandatory to be called An Element can only be set once and not changed Needs to be called before calling getElement() protected void setElement(Element elem) { assert (element == null) : SETELEMENT_TWICE_ERROR; this.element = elem; } Wednesday, November 2, 11
  • 14. How To Start? Wednesday, November 2, 11
  • 15. Gathering Information What is the purpose of my custom widget? Which browser events are required? Can I extend an already existing class? Do I understand all my requirements? Wednesday, November 2, 11
  • 17. The Class Extending Component to overcome different sizing models public class SquareWidget extends Component { } Wednesday, November 2, 11
  • 18. Constructor Setting the Element Defining the events we want to listen to public SquareWidget(Data data) { this.data = data; SquareWidgetTemplate t = GWT.create(SquareWidgetTemplate.class); setElement(XDOM.create(t.render(data))); sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONCLICK); setPixelSize(100, 100); } Wednesday, November 2, 11
  • 19. onBrowserEvent() Contains our event handling logic Should call the super method @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (event.getTypeInt() == Event.ONMOUSEOUT) { onMouseOut(event); } else if (event.getTypeInt() == Event.ONMOUSEOVER) { onMouseOver(event); } else if (event.getTypeInt() == Event.ONCLICK) { onClick(event); } } Wednesday, November 2, 11
  • 20. onMouseOver() getRelatedEventTarget returns the Element coming from Setting the mouse over value private void onMouseOver(Event event) { EventTarget t = event.getRelatedEventTarget(); if (t == null || Element.is(t) && !getElement().isOrHasChild(Element.as(t))) { String s = SafeHtmlUtils.fromString(data.getMouseOverName()).asString(); getContentElement().setInnerHTML(s); } } Wednesday, November 2, 11
  • 21. onMouseOut() getRelatedEventTarget returns the Element moving to Clearing the background color Setting the standard value again private void onMouseOut(Event event) { EventTarget t = event.getRelatedEventTarget(); if (t == null || (Element.is(t) && !getElement().isOrHasChild(Element.as(t)))) { getElement().getStyle().clearBackgroundColor(); String s = SafeHtmlUtils.fromString(data.getName()).asString(); getContentElement().setInnerHTML(s); } } Wednesday, November 2, 11
  • 22. onClick() Sets the different background color private void onClick(Event event) { getElement().getStyle().setBackgroundColor("red"); } Wednesday, November 2, 11
  • 24. But, Do We Really Require a Widget? Wednesday, November 2, 11
  • 25. Introducing Cell Cells can handle browser events Cells can be used in data components Widgets cannot be used there Cells render a lot faster Wednesday, November 2, 11
  • 26. Context of the Cell Contains the relevant row and column index Important when used in data widgets Contains the key representing the value Wednesday, November 2, 11
  • 28. onBrowserEvent() Gets called when an event for this cell occurred Gets passed in the parent Element Cell on its own does not know anything where it is displayed One Cell can be displayed in many places void onBrowserEvent(Context context, Element parent, C value, NativeEvent event, ValueUpdater<C> valueUpdater); Wednesday, November 2, 11
  • 29. render() Called when a Cell should be rendered The output should be written to the SafeHtmlBuilder void render(Context context, C value, SafeHtmlBuilder sb); Wednesday, November 2, 11
  • 30. getConsumedEvents() Returns the events this cell requires Cannot change in the lifecycle of a Cell Set<String> getConsumedEvents(); Wednesday, November 2, 11
  • 32. The Class Extending AbstractCell Implementing the Cell interface directly works too public class SquareCell extends AbstractCell<Data> { } Wednesday, November 2, 11
  • 33. Constructor Defining the events this cell listens to public SquareCell() { super("click", "mouseover", "mouseout"); } Wednesday, November 2, 11
  • 34. onBrowserEvent() Contains our event handling logic public void onBrowserEvent(Context context, Element parent, Data value, NativeEvent event, ValueUpdater<Data> valueUpdater) { Element t = parent.getFirstChildElement(); Element target = event.getEventTarget().cast(); if (!t.isOrHasChild(target)) { return; } if ("mouseout".equals(event.getType())) { onMouseOut(context, parent, value, event); } else if ("mouseover".equals(event.getType())) { onMouseOver(context, parent, value, event); } else if ("click".equals(event.getType())) { onClick(context, parent, value, event); } } Wednesday, November 2, 11
  • 35. onMouseOver() getRelatedEventTarget returns the Element coming from Setting the mouse over value private void onMouseOver(Context context, Element parent, Data value, NativeEvent event) { Element fc = parent.getFirstChildElement(); EventTarget t = event.getRelatedEventTarget(); if (t == null || (Element.is(t) && !fc.isOrHasChild(Element.as(t)))) { String s = SafeHtmlUtils.fromString(value.getMouseOverName()).asString(); getContentElement(parent).setInnerHTML(s); } } Wednesday, November 2, 11
  • 36. onMouseOut() getRelatedEventTarget returns the Element moving to Clearing the background color Setting the standard value again private void onMouseOut(Context context, Element parent, Data value, NativeEvent event) { Element fc = parent.getFirstChildElement(); EventTarget t = event.getRelatedEventTarget(); if (t == null || (Element.is(t) && !fc.isOrHasChild(Element.as(t)))) { fc.getStyle().clearBackgroundColor(); String s = SafeHtmlUtils.fromString(value.getName()).asString(); getContentElement(parent).setInnerHTML(s); } } Wednesday, November 2, 11
  • 37. onClick() Sets the different background color private void onClick(Context context, Element parent, Data value, NativeEvent event) { parent.getFirstChildElement().getStyle().setBackgroundColor("red"); } Wednesday, November 2, 11