Esempio n. 1
0
  /**
   * Check if an element need to change from a style group to another.
   *
   * <p>When an element can have potentially changed style due to some of its attributes (ui.class
   * for example), instead of removing it then reading it, use this method to move the element from
   * its current style group to a potentially different style group.
   *
   * <p>Explanation of this method : checking the style of an element may be done by removing it
   * ({@link #removeElement(Element)}) and then re-adding it ( {@link #addElement(Element)}). This
   * must be done by the element since it knows when to check this. However you cannot only remove
   * and add, since the style group inside which the element is can have events occurring on it, and
   * these events must be passed from its old style to its new style. This method does all this
   * information passing.
   *
   * @param element The element to move.
   */
  public void checkElementStyleGroup(Element element) {
    StyleGroup oldGroup = getGroup(getElementGroup(element));

    // Get the old element "dynamic" status.

    boolean isDyn = oldGroup.isElementDynamic(element);

    // Get the old event set for the given element.

    StyleGroup.ElementEvents events = null;

    if (oldGroup != null) events = oldGroup.getEventsFor(element);

    // Remove the element from its old style and add it to insert it in the
    // correct style.

    removeElement(element);
    addElement_(element);

    // Eventually push the events on the new style group.

    StyleGroup newGroup = getGroup(getElementGroup(element));

    if (newGroup != null && events != null) {
      for (String event : events.events) pushEventFor(element, event);
    }

    for (StyleGroupListener listener : listeners)
      listener.elementStyleChanged(element, oldGroup, newGroup);

    // Eventually set the element as dynamic, if it was.

    if (newGroup != null && isDyn) newGroup.pushElementAsDynamic(element);
  }
Esempio n. 2
0
  /**
   * Add an element and bind it to its style group. The group is created if needed.
   *
   * @param element The element to add.
   * @return The style group where the element was added.
   */
  public StyleGroup addElement(Element element) {
    StyleGroup group = addElement_(element);

    for (StyleGroupListener listener : listeners)
      listener.elementStyleChanged(element, null, group);

    return group;
  }