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

YUI3 Modules
YUI3 ModulesYUI3 Modules
YUI3 Modules
a_pipkin
 

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 Creating Ext GWT Extensions and Components

Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
PRN USM
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
sotlsoc
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
roxlu
 

Similar to Creating Ext GWT Extensions and Components (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

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

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

Creating Ext GWT Extensions and Components

  • 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