Example usage for com.google.gwt.dom.client Element getStyle

List of usage examples for com.google.gwt.dom.client Element getStyle

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Element getStyle.

Prototype

@Override
    public Style getStyle() 

Source Link

Usage

From source file:bufferings.ktr.wjr.client.ui.widget.WjrTabPanel.java

License:Apache License

/**
 * Selects the tab and show its contents.
 * /*from w  ww .ja  va  2  s .  c  o  m*/
 * @param index
 *          The index of the tab to show.
 */
public void selectTab(int index) {
    checkIndex(index);
    if (index == selectedIndex) {
        return;
    }

    BeforeSelectionEvent<Integer> event = BeforeSelectionEvent.fire(this, index);
    if ((event != null) && event.isCanceled()) {
        return;
    }

    if (selectedIndex != -1) {
        Widget child = children.get(selectedIndex);
        Element container = panel.getWidgetContainerElement(child);
        container.getStyle().setDisplay(Display.NONE);
        child.setVisible(false);
        tabs.get(selectedIndex).setSelected(false);
    }

    Widget child = children.get(index);
    Element container = panel.getWidgetContainerElement(child);
    container.getStyle().clearDisplay();
    child.setVisible(true);
    tabs.get(index).setSelected(true);
    selectedIndex = index;

    SelectionEvent.fire(this, index);
}

From source file:ca.concordia.ivocab.client.Page.java

License:Apache License

public Page(PageTransitionPanel parent, Controls controls, ControlBar.Resources resources) {
    super(parent.getContainerElement());
    Element myElem = getElement();

    controlBar = new ControlBar(myElem, resources, controls);
    contentElement = Document.get().createDivElement();
    myElem.appendChild(contentElement);/*from  w  w w .  j av  a2 s  . c om*/
    parent.addPage(this);
    myElem.getStyle().setProperty("cssFloat", "left");
}

From source file:ca.concordia.ivocab.client.PageTransitionPanel.java

License:Apache License

/**
 * Handles when we transition between portrait and landscape modes.
 *///  w  w w.ja  va2 s.  c o  m
public void doResize() {
    int windowWidth = DomUtils.getWindow().getWidth();
    Element elem = getElement();
    elem.getStyle().setPropertyPx("width", windowWidth);

    for (int i = 0, n = pages.size(); i < n; i++) {
        pages.get(i).setWidth(windowWidth);
    }

    getElement().setPropertyInt("scrollLeft", windowWidth * currentPageIndex);
}

From source file:cc.alcina.framework.gwt.client.gwittir.widget.TextArea.java

License:Apache License

@Override
public void setValue(String value) {
    setStyleName("empty", CommonUtils.isNullOrEmpty(value));
    String old = this.getValue();
    this.setText(value);
    if (ensureAllLinesVisible) {
        Scheduler.get().scheduleDeferred(() -> {
            Element element = this.base.getElement();
            element.getStyle().setProperty("height", "auto");
            int scrollHeight = element.getScrollHeight();
            element.getStyle().setHeight(scrollHeight, Unit.PX);
        });// w ww  .jav a 2  s  .com
    }
    if (this.getValue() != old
            && (this.getValue() == null || (this.getValue() != null && !this.getValue().equals(old)))) {
        this.changes.firePropertyChange("value", old, this.getValue());
    }
}

From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

public static boolean isVisibleAncestorChain(Element e) {
    if (e == null || e.getOwnerDocument() == null) {
        return false;
    }/*  w ww  .jav a 2  s  .c o  m*/
    Element documentElement = e.getOwnerDocument().getDocumentElement();
    while (e != documentElement) {
        if (!UIObject.isVisible(e)) {
            return false;
        }
        if ("hidden".equals(e.getStyle().getVisibility())) {
            return false;
        }
        Element old = e;
        e = e.getParentElement();
        // detached
        if (e == null) {
            return false;
        }
    }
    return true;
}

From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

public static void setOpacity(Widget w, int opacityPercent) {
    Element e = w.getElement();
    String opacity = opacityPercent == 100 ? "1.0" : "0." + CommonUtils.padTwo(opacityPercent);
    e.getStyle().setProperty("opacity", opacity);
}

From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

private static void morphSplitPanel(SplitLayoutPanel splitPanel, Widget keepChild, boolean restore) {
    final String zeroSize = "0px";
    boolean hsp = isDirectionalLayoutPanel(splitPanel, true);
    for (int index = 0; index < splitPanel.getWidgetCount(); index++) {
        Widget w = splitPanel.getWidget(index);
        if (CommonUtils.simpleClassName(w.getClass()).contains("Splitter")) {
            w.setVisible(restore);/*from   w  w  w  .  j a  v a2s  . c om*/
        } else {
            Element container = splitPanel.getWidgetContainerElement(w);
            container.getStyle().setDisplay(restore || keepChild == w ? Display.BLOCK : Display.NONE);
        }
    }
    if (!restore) {
        morphedWidgets.add(splitPanel);
    }
}

From source file:cc.alcina.framework.gwt.client.widget.dialog.RelativePopupPanel.java

License:Apache License

/**
 * Sets the popup's position relative to the browser's client area. The
 * popup's position may be set before calling {@link #show()}.
 * // w ww  .j  ava2  s. c o m
 * @param left
 *            the left position, in pixels
 * @param top
 *            the top position, in pixels
 */
public void setPopupPosition(int left, int top) {
    // Save the position of the popup
    leftPosition = left;
    topPosition = top;
    // Account for the difference between absolute position and the
    // body's positioning context.
    left -= Document.get().getBodyOffsetLeft();
    top -= Document.get().getBodyOffsetTop();
    // Set the popup's position manually, allowing setPopupPosition() to be
    // called before show() is called (so a popup can be positioned without
    // it
    // 'jumping' on the screen).
    Element elem = getElement();
    elem.getStyle().setPropertyPx("left", left);
    elem.getStyle().setPropertyPx("top", top);
}

From source file:cc.alcina.framework.gwt.client.widget.RelativePopupValidationFeedback.java

License:Apache License

@Override
public void handleException(Object source, ValidationException exception) {
    final Widget w = (Widget) source;
    resolve(source);//from  w  w  w.java  2  s.  c o  m
    if (!DomUtils.isVisibleAncestorChain(w.getElement())) {
        return;
    }
    Widget suppressValidationFeedbackFor = RenderContext.get().getSuppressValidationFeedbackFor();
    if (suppressValidationFeedbackFor != null
            && suppressValidationFeedbackFor.getElement().isOrHasChild(w.getElement())) {
        return;
    }
    final RelativePopup p = new RelativePopup();
    p.setVisible(false);
    popups.put(source, p);
    WidgetByElementTracker.get().register(p);
    p.setStyleName("gwittir-ValidationPopup");
    if (getCss() != null) {
        p.addStyleName(getCss());
    }
    if (exception instanceof ProcessingServerValidationException) {
        ProcessingServerValidationException psve = (ProcessingServerValidationException) exception;
        FlowPanel fp = new FlowPanel();
        fp.setStyleName("gwittir-ServerValidation");
        fp.add(new InlineLabel(this.getMessage(exception)));
        p.add(fp);
        psve.setSourceWidget(source);
        psve.setFeedback(this);
    } else {
        p.add(renderExceptionWidget(exception));
    }
    int x = w.getAbsoluteLeft();
    int y = w.getAbsoluteTop();
    Widget pw = WidgetUtils.getPositioningParent(w);
    ComplexPanel cp = WidgetUtils.complexChildOrSelf(pw);
    if (!(pw instanceof RootPanel)) {
        x -= pw.getAbsoluteLeft();
        y -= pw.getAbsoluteTop();
    }
    cp.add(p);
    if (this.position == BOTTOM) {
        y += w.getOffsetHeight();
    } else if (this.position == RIGHT) {
        x += w.getOffsetWidth();
    } else if (this.position == LEFT) {
        x -= p.getOffsetWidth();
    } else if (this.position == TOP) {
        y -= p.getOffsetHeight();
    }
    Element h = p.getElement();
    Style style = h.getStyle();
    style.setPosition(Position.ABSOLUTE);
    style.setLeft(x, Unit.PX);
    style.setTop(y, Unit.PX);
    if (this.position == BOTTOM) {
        style.setWidth(w.getOffsetWidth(), Unit.PX);
    }
    p.setVisible(true);
    if (w instanceof SourcesPropertyChangeEvents) {
        // GWT.log("is PCE", null);
        PropertyChangeListener attachListener = new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                if (((Boolean) propertyChangeEvent.getNewValue()).booleanValue()) {
                    p.setVisible(true);
                } else {
                    p.setVisible(false);
                }
            }
        };
        listeners.put(w, attachListener);
        ((SourcesPropertyChangeEvents) w).addPropertyChangeListener("attached", attachListener);
        ((SourcesPropertyChangeEvents) w).addPropertyChangeListener("visible", attachListener);
    }
}

From source file:cc.kune.core.client.ui.ContentPosition.java

License:GNU Affero Public License

/**
 * Sets the position.//from   w w w.j  a v  a 2  s. co m
 *
 * @param element
 *          the element
 * @param wraptext
 *          the wraptext
 * @param position
 *          the position
 * @return the element
 */
public static Element setPosition(final Element element, final boolean wraptext, final String position) {
    if (!wraptext || position.equals(ContentPosition.CENTER)) {
        final com.google.gwt.user.client.Element divEl = DOM.createDiv();
        divEl.getStyle().setTextAlign(Style.TextAlign.valueOf(position));
        divEl.setInnerHTML(element.getString());
        return divEl;
    } else {
        element.getStyle().setFloat(Style.Float.valueOf(position));
        return element;
    }
}