Class BaseWidget

All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsWidget, LogicalStructure
Direct Known Subclasses:
Canvas, DrawItem, PointerSettings, Sound

public class BaseWidget extends Widget implements HasHandlers, LogicalStructure
Base class for Canvas and DrawItem.
  • Field Details

    • id

      protected String id
    • config

      protected JavaScriptObject config
    • scClassName

      protected String scClassName
    • configOnly

      protected boolean configOnly
    • factoryProperties

      protected Map<String,Object> factoryProperties
    • factoryCreated

      protected boolean factoryCreated
    • nativeObject

      public NativeObject nativeObject
  • Constructor Details

    • BaseWidget

      public BaseWidget()
    • BaseWidget

      public BaseWidget(JavaScriptObject jsObj)
    • BaseWidget

      public BaseWidget(String id)
  • Method Details

    • getOrCreateRef

      public static BaseWidget getOrCreateRef(JavaScriptObject jsObj)
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, Canvas defaults)
      Changes the defaults for Canvas AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - Canvas defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, FormItem defaults)
      Changes the defaults for FormItem AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - FormItem defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • create

      protected JavaScriptObject create()
    • setDefaultProperties

      public static void setDefaultProperties(BaseWidget baseWidgetProperties)
      Class level method to set the default properties of this class. If set, then all existing and subsequently created instances of this class will automatically have default properties corresponding to the properties set on the SmartGWT class instance passed to this function before its underlying SmartClient JS object was created. This is a powerful feature that eliminates the need for users to create a separate hierarchy of subclasses that only alter the default properties of this class. Can also be used for skinning / styling purposes.

      Note: This method is intended for setting default attributes only and will affect all instances of the underlying class (including those automatically generated in JavaScript). This method should not be used to apply standard EventHandlers or override methods for a class - use a custom subclass instead. Calling this method after instances have been created can result in undefined behavior, since it bypasses any setters and a class instance may have already examined a particular property and not be expecting any changes through this route.

      Parameters:
      baseWidgetProperties - properties that should be used as new defaults when instances of this class are created
      See Also:
    • getById

      public static BaseWidget getById(String ID)
      Retrieve a BaseWidget by its global ID.
      Parameters:
      ID - global ID of the BaseWidget
      Returns:
      the Canvas, or null if not found
    • getByJSObject

      public static BaseWidget getByJSObject(JavaScriptObject jsObj)
      Retrieve a BaseWidget from its JavaScriptObject.
      Parameters:
      jsObj - SmartClient object associated with Canvas
      Returns:
      the BaseWidget, or null if not found
    • setFactoryCreated

      public void setFactoryCreated(boolean createdByBeanFactory)
    • isFactoryCreated

      public boolean isFactoryCreated()
    • doAddHandler

      protected final <H extends EventHandler> HandlerRegistration doAddHandler(H handler, GwtEvent.Type<H> type)
      Adds this handler to the widget.
      Type Parameters:
      H - the type of handler to add
      Parameters:
      type - the event type
      handler - the handler
      Returns:
      HandlerRegistration used to remove the handler
    • getHandlerCount

      public int getHandlerCount(GwtEvent.Type<?> type)
      Overrides:
      getHandlerCount in class Widget
    • setJavaScriptObject

      public void setJavaScriptObject(JavaScriptObject jsObj)
    • getRef

      public static BaseWidget getRef(JavaScriptObject jsObj)
    • hasAutoAssignedID

      public static boolean hasAutoAssignedID(JavaScriptObject jsObj)
    • getClassName

      public String getClassName()
      Returns the javascript class name.
      Returns:
    • getScClassName

      public String getScClassName()
      Get the name of the underlying SmartClient class
      Returns:
      the SmartClient class name
    • setScClassName

      public void setScClassName(String scClassName)
      Set the name of the underlying SmartClient class. This is an advanced setting.
      Parameters:
      scClassName - the SmartClient class
    • doInit

      protected final void doInit()
    • onInit

      protected void onInit()
    • onBind

      protected void onBind()
    • isConfigOnly

      public boolean isConfigOnly()
    • setConfigOnly

      public void setConfigOnly(boolean configOnly)
    • setDragTracker

      protected boolean setDragTracker()
    • getInnerHTML

      public String getInnerHTML()
      Return the inner HTML for this canvas. Called when the canvas is drawn or redrawn; override to customize.

      Note : Canvas.setRedrawOnResize(java.lang.Boolean) should be set to true for components whose inner HTML will not automatically reflow to fit the component's new size.

      Returns:
      HTML contents of this canvas
    • draw

      public void draw()
      Draws the widget on the page.&#010
    • destroy

      public void destroy()
      Permanently destroy a Canvas and all of it's children / members, recursively.

      Like Canvas.clear() calling destroy() removes all HTML for the component; unlike clear(), a destroyed Canvas is permanently unusable: it cannot be draw()'n again and cannot be referenced by its global ID. This method also removes all JavaScript references to the Canvas outside of application code, making it eligible for garbage collection (though developers will need to release any references to the canvas held in application code themselves).

      Any attempt to call a method on a destroyed Canvas will generally result in an error. If your application is forced to hold onto Canvas's that might be destroy()d without warning, you can avoid errors by checking for the Canvas.getDestroyed() property. If you override certain Canvas methods, your code may be called while a Canvas is being destroy()d; in this case you can avoid extra work (and possibly errors) by checking for the +Canvas.getDestroying() property.

      Note that destroy() should not be called directly in event handling code for this canvas. For this reason, wherever possible we recommend using Canvas.markForDestroy() instead of calling this method directly.

      Note: This is an override point

    • doOnRender

      public void doOnRender(Function function)
    • addDrawHandler

      public HandlerRegistration addDrawHandler(DrawHandler handler)
    • onDraw

      protected void onDraw()
    • onDestroy

      protected void onDestroy()
    • setPosition

      public void setPosition(String position)
    • setHtmlElement

      public BaseWidget setHtmlElement(Element element)
    • getDOM

      public Element getDOM()
    • getID

      public String getID()
    • internalSetID

      protected final void internalSetID(JavaScriptObject jsObj)
    • internalSetID

      protected final void internalSetID(String id, boolean autoAssigned)
    • setID

      public BaseWidget setID(String id)
    • getConfig

      public JavaScriptObject getConfig()
    • setConfig

      public void setConfig(JavaScriptObject config)
    • isCreated

      public boolean isCreated()
    • isDrawn

      public Boolean isDrawn()
      Returns the boolean true if the widget has been completely drawn, and false otherwise.
      Returns:
      true if drawn, false if not drawn
      See Also:
    • getJsObj

      public JavaScriptObject getJsObj()
    • getOrCreateJsObj

      public JavaScriptObject getOrCreateJsObj()
    • completeCreation

      public void completeCreation()
      Commits a widget to being an actual live instance instead of being used as a configuration template with various APIs that accept a properties object.

      A widget will be automatically instantiated in some circumstances, such as:

      • when it's drawn
      • when it's added as a member of a Layout or child of a parent widget
      • when it's asked to perform any kind of network request (e.g. listGrid.fetchData(), etc.)

      In general, completeCreation() will also occur automatically as a result of methods that require the object to derive or calculate any kind of value. The object will remain in the uncreated state (still usable as just a configuration object) as long as the only methods that are called either set properties or retrieve properties previously set.

      Note that if the object has already been used as a configuration template, say by being passed to a method such as Canvas.changeAutoChildDfaults() as the properties object argument, then it is an error to call this method.

      For a discussion of when a widget should be treated as a properties object rather than a live instance, see SmartGWT Properties.

    • applyFactoryProperties

      public void applyFactoryProperties()
    • getAttribute

      public String getAttribute(String attribute)
    • getAttributeAsString

      protected String getAttributeAsString(String property)
    • getAttributeAsStringArray

      protected String[] getAttributeAsStringArray(String property)
    • getAttributeAsIntArray

      protected int[] getAttributeAsIntArray(String property)
    • getAttributeAsFloatArray

      protected Float[] getAttributeAsFloatArray(String property)
    • getAttributeAsDate

      protected Date getAttributeAsDate(String property)
    • getAttributeAsDateArray

      protected Date[] getAttributeAsDateArray(String property)
    • getAttributeAsInt

      protected Integer getAttributeAsInt(String property)
    • getAttributeAsDouble

      protected Double getAttributeAsDouble(String property)
    • getAttributeAsElement

      protected Element getAttributeAsElement(String property)
    • getAttributeAsJavaScriptObject

      protected JavaScriptObject getAttributeAsJavaScriptObject(String property)
    • getAttributeAsObject

      protected Object getAttributeAsObject(String property)
    • getAttributeAsFloat

      protected Float getAttributeAsFloat(String property)
    • getAttributeAsBoolean

      protected Boolean getAttributeAsBoolean(String property)
    • getAttributeAsMap

      protected Map getAttributeAsMap(String property)
    • getAttributeAsRecord

      protected Record getAttributeAsRecord(String property)
    • errorIfNotCreated

      protected void errorIfNotCreated(String property) throws IllegalStateException
      Throws:
      IllegalStateException
    • error

      protected void error(String message) throws IllegalStateException
      Throws:
      IllegalStateException
    • setAttribute

      protected BaseWidget setAttribute(String attribute, String value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, ValueEnum value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, BaseWidget value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, Map value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, int[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, float[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, double[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, Float[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, DataClass value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, DataClass[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, JavaScriptObject[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, BaseClass[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, BaseWidget[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, float value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, double value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, Integer value, boolean allowPostCreate)
    • setNullProperty

      public void setNullProperty(String property)
    • setProperty

      public void setProperty(String property, String value)
    • setProperty

      public void setProperty(String property, boolean value)
    • setProperty

      public void setProperty(String property, int value)
    • setProperty

      public void setProperty(String property, float value)
    • setProperty

      public void setProperty(String property, double value)
    • setProperty

      public void setProperty(String property, Element value)
    • setProperty

      public void setProperty(String property, JavaScriptObject value)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, Date value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, JavaScriptObject value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, String[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, Object[] value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, Boolean value, boolean allowPostCreate)
    • setAttribute

      protected BaseWidget setAttribute(String attribute, Element value, boolean allowPostCreate)
    • setTitle

      public void setTitle(String title)
      Overrides:
      setTitle in class UIObject
    • getTitle

      public String getTitle()
      Overrides:
      getTitle in class UIObject
    • toString

      public String toString()
      Overrides:
      toString in class UIObject
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • setLogicalStructure

      public LogicalStructureObject setLogicalStructure(LogicalStructureObject s)
      Specified by:
      setLogicalStructure in interface LogicalStructure
    • initNativeObject

      public void initNativeObject()
      Specified by:
      initNativeObject in interface LogicalStructure
    • addDynamicProperty

      public void addDynamicProperty(String propertyName, String source)
      Sets up the value of propertyName to be dynamically derived from the ruleScope, by either a simple DataPath into the ruleScope, an AdvancedCriteria built against DataPaths, or via a textual or numeric formula using the ruleScope as available formula inputs.

      The dataPath, criteria, or formula is evaluated immediately when addDynamicProperty() is called, then re-evaluated every time the ruleScope changes. An AdvancedCriteria will always evaluate to boolean true or false, and a UserSummary to a string.

      It is invalid usage to use addDynamicProperty() on a property that is not runtime settable. However, addDynamicProperty() will not throw an error or log a warning if this is done.

      If a property is already dynamic and addDynamicProperty() is called again, the new dynamic behavior replaces the old. If a property should no longer be dynamic, call clearDynamicProperty().

      Dynamic properties can also be declared together via dynamicProperties.

      Note that you may convert a simple criteria to an AdvancedCriteria by calling DataSource.convertCriteria().

      Parameters:
      propertyName - name of a settable property on this instance. See Identifier
      source - a DataPath.
      See Also:
    • addDynamicProperty

      public void addDynamicProperty(String propertyName, UserFormula formula)
      Sets up the value of propertyName to be dynamically derived from the ruleScope, by either a simple DataPath into the ruleScope, an AdvancedCriteria built against DataPaths, or via a textual or numeric formula using the ruleScope as available formula inputs.

      The dataPath, criteria, or formula is evaluated immediately when addDynamicProperty() is called, then re-evaluated every time the ruleScope changes. An AdvancedCriteria will always evaluate to boolean true or false, and a UserSummary to a string.

      It is invalid usage to use addDynamicProperty() on a property that is not runtime settable. However, addDynamicProperty() will not throw an error or log a warning if this is done.

      If a property is already dynamic and addDynamicProperty() is called again, the new dynamic behavior replaces the old. If a property should no longer be dynamic, call clearDynamicProperty().

      Dynamic properties can also be declared together via dynamicProperties.

      Note that you may convert a simple criteria to an AdvancedCriteria by calling DataSource.convertCriteria().

      Parameters:
      propertyName - name of a settable property on this instance. See Identifier
      formula - a UserFormula
      See Also:
    • addDynamicProperty

      public void addDynamicProperty(String propertyName, UserSummary summary)
      Sets up the value of propertyName to be dynamically derived from the ruleScope, by either a simple DataPath into the ruleScope, an AdvancedCriteria built against DataPaths, or via a textual or numeric formula using the ruleScope as available formula inputs.

      The dataPath, criteria, or formula is evaluated immediately when addDynamicProperty() is called, then re-evaluated every time the ruleScope changes. An AdvancedCriteria will always evaluate to boolean true or false, and a UserSummary to a string.

      It is invalid usage to use addDynamicProperty() on a property that is not runtime settable. However, addDynamicProperty() will not throw an error or log a warning if this is done.

      If a property is already dynamic and addDynamicProperty() is called again, the new dynamic behavior replaces the old. If a property should no longer be dynamic, call clearDynamicProperty().

      Dynamic properties can also be declared together via dynamicProperties.

      Note that you may convert a simple criteria to an AdvancedCriteria by calling DataSource.convertCriteria().

      Parameters:
      propertyName - name of a settable property on this instance. See Identifier
      summary - a UserSummary
      See Also:
    • addDynamicProperty

      public void addDynamicProperty(String propertyName, AdvancedCriteria criteria)
      Sets up the value of propertyName to be dynamically derived from the ruleScope, by either a simple DataPath into the ruleScope, an AdvancedCriteria built against DataPaths, or via a textual or numeric formula using the ruleScope as available formula inputs.

      The dataPath, criteria, or formula is evaluated immediately when addDynamicProperty() is called, then re-evaluated every time the ruleScope changes. An AdvancedCriteria will always evaluate to boolean true or false, and a UserSummary to a string.

      It is invalid usage to use addDynamicProperty() on a property that is not runtime settable. However, addDynamicProperty() will not throw an error or log a warning if this is done.

      If a property is already dynamic and addDynamicProperty() is called again, the new dynamic behavior replaces the old. If a property should no longer be dynamic, call clearDynamicProperty().

      Dynamic properties can also be declared together via dynamicProperties.

      Note that you may convert a simple criteria to an AdvancedCriteria by calling DataSource.convertCriteria().

      Parameters:
      propertyName - name of a settable property on this instance. See Identifier
      criteria - an AdvancedCriteria
      See Also:
    • clearDynamicProperty

      public void clearDynamicProperty(String propertyName)
      Clears a dynamic property previously established via addDynamicProperty(java.lang.String,java.lang.String).

      If the property is not currently dynamic, nothing will be done (and no warning logged).

      The current value of the property will not be changed by this call.

      Parameters:
      propertyName - name of the dynamic property to clear
    • hasDynamicProperty

      public boolean hasDynamicProperty(String propertyName)
      Returns true if the property is dynamic.
      Parameters:
      propertyName - name of the dynamic property to check
      Returns:
      boolean true if the property is dynamic
    • setLogicalStructure

      public LogicalStructureObject setLogicalStructure(BaseWidgetLogicalStructure s)
      Setter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
    • getLogicalStructure

      public LogicalStructureObject getLogicalStructure()
      Getter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
      Specified by:
      getLogicalStructure in interface LogicalStructure