Java Code Examples for com.google.gwt.dom.client.Element#addClassName()

The following examples show how to use com.google.gwt.dom.client.Element#addClassName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DomUtil.java    From mapper with Apache License 2.0 6 votes vote down vote up
public static WritableProperty<Boolean> hasClass(final Element el, final String cls) {
  return new WritableProperty<Boolean>() {
    private boolean myValue;

    @Override
    public void set(Boolean value) {
      if (myValue == value) return;
      if (value) {
        el.addClassName(cls);
      } else {
        el.removeClassName(cls);
      }
      myValue = value;
    }
  };
}
 
Example 2
Source File: CubaTreeTableWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void initCellWithText(String text, char align, String style, boolean textIsHTML,
                                boolean sorted, String description, TableCellElement td) {
    super.initCellWithText(text, align, style, textIsHTML, sorted, description, td);

    Element tdElement = td.cast();
    Tools.textSelectionEnable(tdElement, _delegate.textSelectionEnabled);

    if ((_delegate.clickableColumns != null && _delegate.clickableColumns.contains(currentColumnKey))
            || (_delegate.clickableTableColumns != null && _delegate.clickableTableColumns.contains(currentColumnKey))) {
        tdElement.addClassName(CUBA_TABLE_CLICKABLE_CELL_CONTENT);
        Element wrapperElement = tdElement.getFirstChildElement();
        final Element clickableSpan = DOM.createSpan().cast();
        clickableSpan.setClassName(CUBA_TABLE_CLICKABLE_CELL_STYLE);

        clickableSpan.setInnerText(wrapperElement.getInnerText());

        wrapperElement.removeAllChildren();
        DOM.appendChild(wrapperElement, clickableSpan);
    }

    if (_delegate.multiLineCells) {
        Style wrapperStyle = tdElement.getFirstChildElement().getStyle();
        wrapperStyle.setWhiteSpace(Style.WhiteSpace.PRE_LINE);
    }
}
 
Example 3
Source File: EditorImpl.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Removes the various editor bits on the document
 */
private void updateDocumentEditState(boolean editing) {
  Element topLevel = getDocumentHtmlElement();
  // Set property to some arbitrary non-null value if we're in editing mode.
  full().getDocumentElement().setProperty(AnnotationPainter.DOCUMENT_MODE, editing);

  topLevel.removeClassName(WAVE_EDITOR_EDIT_ON);
  topLevel.removeClassName(WAVE_EDITOR_EDIT_OFF);
  topLevel.addClassName(editing ? WAVE_EDITOR_EDIT_ON : WAVE_EDITOR_EDIT_OFF);

  AnnotationPainter.maybeScheduleRepaint(content.getContext(), 0, mutable().size());
  DomHelper.setContentEditable(topLevel, editing, true);

  for (ContentElement element : elementsWithDisplayEditModes) {
    if (element.getParentElement() != null) {
      DisplayEditModeHandler.onEditModeChange(element, editing);
    } else {
      elementsWithDisplayEditModes.remove(element);
    }
  }
}
 
Example 4
Source File: DiffManager.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Apply styles and other rendering properties to an element to make it look
 * and behave like a diff marker, without actually registering it as such.
 *
 * @param element
 * @param type
 */
public static void styleElement(Element element, DiffType type, String author, long version,
    long timestamp) {
  switch (type) {
    case INSERT:
      element.addClassName(resources.css().insert());
      element.addClassName("inserted-text");
      element.addClassName("author-" + author);
      break;
    case DELETE:
      element.addClassName(resources.css().delete());
      element.addClassName("deleted-text");
      element.addClassName("author-" + author);
      NodeManager.setTransparency(element, Skip.DEEP);
      element.setAttribute("contentEditable", "false");
      break;
  }
}
 
Example 5
Source File: ViewComponentClientCriterion.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Highlights the valid drop targets configured for the criterion.
 *
 * @param configuration
 *            for the accept criterion to retrieve the configured drop hint
 *            areas.
 */
// Exception squid:S1166 - Hide origin exception
// Exception squid:S2221 - This code is trans-coded to JavaScript, hence
// Exception semantics changes
// Exception squid:S2629 - not supported by GWT
@SuppressWarnings({ "squid:S1166", "squid:S2221", "squid:S2629" })
void showDropTargetHints(final UIDL configuration) {
    final int dropAreaCount = configuration.getIntAttribute(DROP_AREA_COUNT);
    for (int dropAreaIndex = 0; dropAreaIndex < dropAreaCount; dropAreaIndex++) {
        try {
            final String dropArea = configuration.getStringAttribute(DROP_AREA + dropAreaIndex);
            LOGGER.log(Level.FINE, "Hint Area: " + dropArea);

            final Element showHintFor = Document.get().getElementById(dropArea);
            if (showHintFor != null) {
                showHintFor.addClassName(HINT_AREA_STYLE);
            }
        } catch (final Exception e) {
            // log and continue
            LOGGER.log(Level.SEVERE, "Error highlighting drop targets: " + e.getLocalizedMessage());
        }
    }

}
 
Example 6
Source File: EditorImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Removes the various editor bits on the document
 */
private void updateDocumentEditState(boolean editing) {
  Element topLevel = getDocumentHtmlElement();
  // Set property to some arbitrary non-null value if we're in editing mode.
  full().getDocumentElement().setProperty(AnnotationPainter.DOCUMENT_MODE, editing);

  topLevel.removeClassName(WAVE_EDITOR_EDIT_ON);
  topLevel.removeClassName(WAVE_EDITOR_EDIT_OFF);
  topLevel.addClassName(editing ? WAVE_EDITOR_EDIT_ON : WAVE_EDITOR_EDIT_OFF);

  AnnotationPainter.maybeScheduleRepaint(content.getContext(), 0, mutable().size());
  DomHelper.setContentEditable(topLevel, editing, true);

  for (ContentElement element : elementsWithDisplayEditModes) {
    if (element.getParentElement() != null) {
      DisplayEditModeHandler.onEditModeChange(element, editing);
    } else {
      elementsWithDisplayEditModes.remove(element);
    }
  }
}
 
Example 7
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void addMovingStyles(Element bar) {
    if (bar == null) {
        return;
    }
    bar.addClassName(STYLE_MOVING);
    updateMoveElementFor(bar);
}
 
Example 8
Source File: VDDPanel.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Emphasisizes a container element
 * 
 * @param element
 */
protected void emphasis(Element element) {
    // Remove previous emphasis
    deEmphasis();

    // validate container
    if (element == null || !getElement().isOrHasChild(element)) {
        return;
    }

    currentEmphasis = element;
    element.addClassName(OVER);
}
 
Example 9
Source File: TimelineWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void fillWeekResolutionBlock(DivElement resBlock, boolean fillWeekBlock, Date date, int index,
        Weekday weekDay, boolean firstWeek,
        boolean lastBlock, int left, boolean even) {
    if (fillWeekBlock) {
        resBlock.setInnerText(formatWeekCaption(date));

        if (even) {
            resBlock.addClassName(STYLE_EVEN);
        } else {
            resBlock.removeClassName(STYLE_EVEN);
        }

        if (styleElementForLeft == null && isTimelineOverflowingHorizontally()) {
            resBlock.getStyle().setPosition(Position.RELATIVE);
            resBlock.getStyle().setLeft(left, Unit.PX);
        }

        resBlock.removeClassName(STYLE_FIRST);
        resBlock.removeClassName(STYLE_LAST);
    }

    if (firstWeek && (weekDay == Weekday.Last || lastBlock)) {
        Element firstEl = resolutionDiv.getFirstChildElement();
        if (!firstEl.hasClassName(STYLE_FIRST)) {
            firstEl.addClassName(STYLE_FIRST);
        }
    } else if (lastBlock) {
        Element lastEl = Element.as(resolutionDiv.getLastChild());
        if (!lastEl.hasClassName(STYLE_LAST)) {
            lastEl.addClassName(STYLE_LAST);
        }
    }
}
 
Example 10
Source File: CubaVerticalSplitPanelWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Element createDockButtonContainer() {
    Element dockBtnContainer = DOM.createDiv();
    dockBtnContainer.getStyle().setZIndex(101);
    dockBtnContainer.getStyle().setPosition(Style.Position.ABSOLUTE);

    if (dockMode == SplitPanelDockMode.TOP) {
        dockBtnContainer.addClassName(SP_DOCK_UP);
    } else if (dockMode == SplitPanelDockMode.BOTTOM) {
        dockBtnContainer.addClassName(SP_DOCK_DOWN);
    }
    return dockBtnContainer;
}
 
Example 11
Source File: CubaHorizontalSplitPanelWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Element createDockButtonContainer() {
    Element dockBtnContainer = DOM.createDiv();
    dockBtnContainer.getStyle().setZIndex(101);
    dockBtnContainer.getStyle().setPosition(Style.Position.ABSOLUTE);

    if (dockMode == SplitPanelDockMode.LEFT) {
        dockBtnContainer.addClassName(SP_DOCK_LEFT);
    } else if (dockMode == SplitPanelDockMode.RIGHT) {
        dockBtnContainer.addClassName(SP_DOCK_RIGHT);
    }
    return dockBtnContainer;
}
 
Example 12
Source File: DataStore.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
private String getBlankImageUrl() {
	Element element = new Label().getElement().cast();
	element.addClassName("blankImage");
	RootPanel.get().getElement().appendChild(element);
	try {
		String url = Djvu_html5.getComputedStyleProperty(element, "background-image");
		url = url.replaceAll("^url\\(['\"]?(.*)['\"]\\)$", "$1");
		return url;
	} finally {
		RootPanel.get().getElement().removeChild(element);
	}
}
 
Example 13
Source File: Header.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void highlight(String name)
{
    toggleSubnavigation(name);

    com.google.gwt.user.client.Element target = linksPane.getElementById("header-links-ref");
    if(target!=null) // TODO: i think this cannot happen, does it?
    {
        NodeList<Node> childNodes = target.getChildNodes();
        for(int i=0; i<childNodes.getLength(); i++)
        {
            Node n = childNodes.getItem(i);
            if(Node.ELEMENT_NODE == n.getNodeType())
            {
                Element element = (Element) n;
                if(element.getId().equals("header-"+name))
                {
                    element.addClassName("header-link-selected");
                    element.setAttribute("aria-selected", "true");
                }
                else {
                    element.removeClassName("header-link-selected");
                    element.setAttribute("aria-selected", "false");
                }
            }
        }
    }
}
 
Example 14
Source File: Page.java    From requestor with Apache License 2.0 5 votes vote down vote up
private static void setPageElementText(String id, String title, boolean alignCenter) {
    final Element e = Document.get().getElementById(id);
    e.setInnerText(title);
    if (alignCenter) {
        e.addClassName("text-center");
    } else {
        e.removeClassName("text-center");
    }
}
 
Example 15
Source File: Tooltip.java    From jetpad-projectional-open-source with Apache License 2.0 4 votes vote down vote up
static void top(Element tooltip) {
  if (!isTooltip(tooltip)) return;
  tooltip.getStyle().clearMarginTop();
  tooltip.removeClassName(CSS.tooltipBottom());
  tooltip.addClassName(CSS.tooltipTop());
}
 
Example 16
Source File: DateCell.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
private void handleEventRange(final MouseEvent event) {

        if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
            return;
        }

        if (eventRangeStart >= 0) {

            int newY = event.getY();
            int fromY, toY;

            if (newY < eventRangeStart) {
                fromY = newY;
                toY = eventRangeStart;
            } else {
                fromY = eventRangeStart;
                toY = newY;
            }

            eventRangeStop = newY;

            Element main = getElement();
            NodeList<Node> nodes = main.getChildNodes();
            for (int i = 0; i < nodes.getLength(); i++) {

                Element c = (Element) nodes.getItem(i);

                if (Arrays.stream(slotElements).anyMatch(e -> e == c)) {

                    int elemStart = c.getOffsetTop();
                    int elemStop = elemStart + getSlotHeight();
                    if (elemStart >= fromY && elemStart <= toY) {
                        c.addClassName("v-daterange");
                    } else if (elemStop >= fromY && elemStop <= toY) {
                        c.addClassName("v-daterange");
                    } else if (elemStop >= fromY && elemStart <= toY) {
                        c.addClassName("v-daterange");
                    } else {
                        c.removeClassName("v-daterange");
                    }
                }
            }
        }

        event.preventDefault();
    }
 
Example 17
Source File: BlipMetaDomImpl.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
public void setContent(Element document) {
  // Server-side document rendering is not correct - it leaves off the crucial
  // "document" class.
  document.addClassName("document");
  getContentContainer().getFirstChildElement().appendChild(document);
}
 
Example 18
Source File: Tooltip.java    From jetpad-projectional-open-source with Apache License 2.0 4 votes vote down vote up
static void bottom(Element tooltip) {
  if (!isTooltip(tooltip)) return;
  tooltip.getStyle().setMarginTop(PSEUDO_ELEMENT_HEIGHT, Style.Unit.PX);
  tooltip.removeClassName(CSS.tooltipTop());
  tooltip.addClassName(CSS.tooltipBottom());
}
 
Example 19
Source File: Animate.java    From gwtbootstrap3-extras with Apache License 2.0 4 votes vote down vote up
/**
 * Styles element with animation class. New class name is generated to customize count, duration and delay.
 * Style is removed on animation end (if not set to infinite).
 *
 * @param element Element to apply animation to.
 * @param animation Type of animation to apply.
 * @param count Number of animation repeats. 0 disables animation, any negative value set repeats to infinite.
 * @param duration Animation duration in ms. 0 disables animation, any negative value keeps default of original animation.
 * @param delay Delay before starting the animation loop in ms. Value <= 0 means no delay.
 * @param <T> Any object extending UIObject class (typically Widget).
 * @return Animation's CSS class name, which can be removed to stop animation.
 */
private static <T extends UIObject> String styleElement(Element element, String animation, int count, int duration, int delay) {

    if (!usedStyles.contains(animation + " " + getStyleNameFromAnimation(animation,count,duration,delay))) {

        String styleSheet = "." + getStyleNameFromAnimation(animation, count, duration, delay) + " {";

        // 1 is default, 0 disable animation, any negative -> infinite loop
        if (count >= 0) {

            styleSheet += "-webkit-animation-iteration-count: " + count + ";" +
                    "-moz-animation-iteration-count:" + count + ";" +
                    "-ms-animation-iteration-count:" + count + ";" +
                    "-o-animation-iteration-count:" + count + ";" +
                    "animation-iteration-count:" + count + ";";

        } else {

            styleSheet += "-webkit-animation-iteration-count: infinite;" +
                    "-moz-animation-iteration-count: infinite;" +
                    "-ms-animation-iteration-count: infinite;" +
                    "-o-animation-iteration-count: infinite;" +
                    "animation-iteration-count: infinite;";

        }

        // if not default (any negative -> use default)
        if (duration >= 0) {

            styleSheet += "-webkit-animation-duration: " + duration + "ms;" +
                    "-moz-animation-duration:" + duration + "ms;" +
                    "-ms-animation-duration:" + duration + "ms;" +
                    "-o-animation-duration:" + duration + "ms;" +
                    "animation-duration:" + duration + "ms;";

        }

        // if not default (any negative -> use default)
        if (delay >= 0) {

            styleSheet += "-webkit-animation-delay: " + delay + "ms;" +
                    "-moz-animation-delay:" + delay + "ms;" +
                    "-ms-animation-delay:" + delay + "ms;" +
                    "-o-animation-delay:" + delay + "ms;" +
                    "animation-delay:" + delay + "ms;";

        }

        styleSheet += "}";

        // inject new style
        StyleInjector.injectAtEnd(styleSheet, true);

        usedStyles.add(animation + " " + getStyleNameFromAnimation(animation, count, duration, delay));

    }

    // start animation
    element.addClassName(animation + " " + getStyleNameFromAnimation(animation,count,duration,delay));

    // remove animation on end so we could start it again
    // removeAnimationOnEnd(element, animation + " anim-"+count+"-"+duration+"-"+delay);

    return animation + " " + getStyleNameFromAnimation(animation,count,duration,delay);

}
 
Example 20
Source File: GwtEditorImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void setDefaultTextColors(Element element) {
  element.addClassName(GwtEditorSchemeKeys.TEXT + "_attr");
}