Example usage for com.google.gwt.user.client.ui Widget getStylePrimaryName

List of usage examples for com.google.gwt.user.client.ui Widget getStylePrimaryName

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Widget getStylePrimaryName.

Prototype

public String getStylePrimaryName() 

Source Link

Document

Gets the primary style name associated with the object.

Usage

From source file:com.vaadin.terminal.gwt.client.ApplicationConnection.java

License:Open Source License

/**
 * Update generic component features.//from  w  ww  . j a  va  2 s  .  co m
 * 
 * <h2>Selecting correct implementation</h2>
 * 
 * <p>
 * The implementation of a component depends on many properties, including
 * styles, component features, etc. Sometimes the user changes those
 * properties after the component has been created. Calling this method in
 * the beginning of your updateFromUIDL -method automatically replaces your
 * component with more appropriate if the requested implementation changes.
 * </p>
 * 
 * <h2>Caption, icon, error messages and description</h2>
 * 
 * <p>
 * Component can delegate management of caption, icon, error messages and
 * description to parent layout. This is optional an should be decided by
 * component author
 * </p>
 * 
 * <h2>Component visibility and disabling</h2>
 * 
 * This method will manage component visibility automatically and if
 * component is an instanceof FocusWidget, also handle component disabling
 * when needed.
 * 
 * @param component
 *            Widget to be updated, expected to implement an instance of
 *            Paintable
 * @param uidl
 *            UIDL to be painted
 * @param manageCaption
 *            True if you want to delegate caption, icon, description and
 *            error message management to parent.
 * 
 * @return Returns true iff no further painting is needed by caller
 */
public boolean updateComponent(Widget component, UIDL uidl, boolean manageCaption) {
    String pid = getPid(component.getElement());
    if (pid == null) {
        VConsole.error("Trying to update an unregistered component: " + Util.getSimpleName(component));
        return true;
    }

    ComponentDetail componentDetail = idToPaintableDetail.get(pid);

    if (componentDetail == null) {
        VConsole.error("ComponentDetail not found for " + Util.getSimpleName(component) + " with PID " + pid
                + ". This should not happen.");
        return true;
    }

    // If the server request that a cached instance should be used, do
    // nothing
    if (uidl.getBooleanAttribute("cached")) {
        return true;
    }

    // register the listened events by the server-side to the event-handler
    // of the component
    componentDetail.registerEventListenersFromUIDL(uidl);

    // Visibility
    boolean visible = !uidl.getBooleanAttribute("invisible");
    boolean wasVisible = component.isVisible();
    component.setVisible(visible);
    if (wasVisible != visible) {
        // Changed invisibile <-> visible
        if (wasVisible && manageCaption) {
            // Must hide caption when component is hidden
            final Container parent = Util.getLayout(component);
            if (parent != null) {
                parent.updateCaption((Paintable) component, uidl);
            }

        }
    }

    if (configuration.useDebugIdInDOM() && uidl.getId().startsWith("PID_S")) {
        DOM.setElementProperty(component.getElement(), "id", uidl.getId().substring(5));
    }

    if (!visible) {
        // component is invisible, delete old size to notify parent, if
        // later make visible
        componentDetail.setOffsetSize(null);
        return true;
    }

    // Switch to correct implementation if needed
    if (!widgetSet.isCorrectImplementation(component, uidl, configuration)) {
        final Widget w = (Widget) widgetSet.createWidget(uidl, configuration);
        // deferred binding check TODO change isCorrectImplementation to use
        // stored detected class, making this innecessary
        if (w.getClass() != component.getClass()) {
            final Container parent = Util.getLayout(component);
            if (parent != null) {
                parent.replaceChildComponent(component, w);
                unregisterPaintable((Paintable) component);
                registerPaintable(uidl.getId(), (Paintable) w);
                ((Paintable) w).updateFromUIDL(uidl, this);
                return true;
            }
        }
    }

    boolean enabled = !uidl.getBooleanAttribute("disabled");
    if (uidl.hasAttribute("tabindex") && component instanceof Focusable) {
        ((Focusable) component).setTabIndex(uidl.getIntAttribute("tabindex"));
    }
    /*
     * Disabled state may affect (override) tabindex so the order must be
     * first setting tabindex, then enabled state.
     */
    if (component instanceof FocusWidget) {
        FocusWidget fw = (FocusWidget) component;
        fw.setEnabled(enabled);
    }

    StringBuffer styleBuf = new StringBuffer();
    final String primaryName = component.getStylePrimaryName();
    styleBuf.append(primaryName);

    // first disabling and read-only status
    if (!enabled) {
        styleBuf.append(" ");
        styleBuf.append(DISABLED_CLASSNAME);
    }
    if (uidl.getBooleanAttribute("readonly")) {
        styleBuf.append(" ");
        styleBuf.append("v-readonly");
    }

    // add additional styles as css classes, prefixed with component default
    // stylename
    if (uidl.hasAttribute("style")) {
        final String[] styles = uidl.getStringAttribute("style").split(" ");
        for (int i = 0; i < styles.length; i++) {
            styleBuf.append(" ");
            styleBuf.append(primaryName);
            styleBuf.append("-");
            styleBuf.append(styles[i]);
            styleBuf.append(" ");
            styleBuf.append(styles[i]);
        }
    }

    // add modified classname to Fields
    if (uidl.hasAttribute("modified") && component instanceof Field) {
        styleBuf.append(" ");
        styleBuf.append(MODIFIED_CLASSNAME);
    }

    TooltipInfo tooltipInfo = componentDetail.getTooltipInfo(null);
    // Update tooltip
    if (uidl.hasAttribute(ATTRIBUTE_DESCRIPTION)) {
        tooltipInfo.setTitle(uidl.getStringAttribute(ATTRIBUTE_DESCRIPTION));
    } else {
        tooltipInfo.setTitle(null);
    }

    // add error classname to components w/ error
    if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
        tooltipInfo.setErrorUidl(uidl.getErrors());
        styleBuf.append(" ");
        styleBuf.append(primaryName);
        styleBuf.append(ERROR_CLASSNAME_EXT);
    } else {
        tooltipInfo.setErrorUidl(null);
    }

    // add required style to required components
    if (uidl.hasAttribute("required")) {
        styleBuf.append(" ");
        styleBuf.append(primaryName);
        styleBuf.append(REQUIRED_CLASSNAME_EXT);
    }

    // Styles + disabled & readonly
    component.setStyleName(styleBuf.toString());

    // Set captions
    if (manageCaption) {
        final Container parent = Util.getLayout(component);
        if (parent != null) {
            parent.updateCaption((Paintable) component, uidl);
        }
    }
    /*
     * updateComponentSize need to be after caption update so caption can be
     * taken into account
     */

    updateComponentSize(componentDetail, uidl);

    return false;
}

From source file:fr.fg.client.openjwt.animation.ClassNameUpdater.java

License:Open Source License

public ClassNameUpdater(Widget widget, String classPrefix, double currentClass, double increment) {
    this(widget.getElement(), widget.getStylePrimaryName(), classPrefix, currentClass, increment);
}

From source file:org.gwtportlets.portlet.client.edit.DefaultWidgetEditor.java

License:Open Source License

/**
 * Create a menu item to prompt for a style for a widget and change it.
 *//*w  ww . j  a  v  a2 s  .c o  m*/
protected MenuItem createEnterStyleMenuItem(final PageEditor manager, final Widget widget) {
    MenuItem mi = new MenuItem("Enter Style Name", new Command() {
        public void execute() {
            String s = Window.prompt("Enter style name:", widget.getStylePrimaryName());
            if (s != null) {
                changeStyleName(manager, widget, s);
            }
        }
    });
    mi.setTitle("Capture new style name");
    return mi;
}

From source file:org.gwtportlets.portlet.client.edit.DefaultWidgetEditor.java

License:Open Source License

/**
 * Create a menu item to remove the primary style from the widget or
 * return null for no such option./*www  .  j  a v  a  2 s. c om*/
 */
protected MenuItem createRemoveStyleMenuItem(final PageEditor manager, final Widget widget) {
    String c = widget.getStylePrimaryName();
    if (c == null || c.length() == 0) {
        return null;
    }
    MenuItem mi = new MenuItem("Remove Style " + c, new Command() {
        public void execute() {
            changeStyleName(manager, widget, "");
        }
    });
    mi.setTitle("Remove style '" + c + "'");
    return mi;
}

From source file:org.unitime.timetable.gwt.client.widgets.FlowForm.java

License:Apache License

public int getCell(String text) {
    for (int i = 0; i < getWidgetCount(); i++) {
        Widget w = getWidget(i);
        if ("header-cell".equals(w.getStylePrimaryName()) && w instanceof HasText
                && text.equals(((HasText) w).getText())) {
            return 1 + i;
        }/*from w  w w.ja v  a2  s.com*/
    }
    return -1;
}