Java Code Examples for com.google.gwt.dom.client.DivElement#as()

The following examples show how to use com.google.gwt.dom.client.DivElement#as() . 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: GanttWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
/**
 * Add new StepWidget into content area.
 *
 * @param stepIndex
 *            Index of step (0 based) (not element index in container)
 * @param widget
 * @param updateAffectedSteps
 *            Updates position of affected steps. Usually it means steps
 *            below the target.
 */
public void addStep(int stepIndex, StepWidget stepWidget, boolean updateAffectedSteps) {
    DivElement bar = DivElement.as(stepWidget.getElement());

    boolean newStep = !bar.hasParentElement();
    boolean moving = !newStep && getStepIndex(stepWidget) != stepIndex;
    boolean insertDOM = newStep || moving;

    if (insertDOM) {
        insert(stepIndex + getAdditonalContentElementCount(), stepWidget);
    }

    deferredUpdateStepTop(stepIndex, updateAffectedSteps, bar, insertDOM);

    if (newStep) {
        registerBarEventListener(bar);
    }
}
 
Example 2
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
public GanttWidget() {

        setElement(DivElement.as(DOM.createDiv()));
        setStyleName(STYLE_GANTT);

        nowElement.setClassName(STYLE_NOW_ELEMENT);

        moveElement.setClassName(STYLE_MOVE_ELEMENT);
        // not visible by default
        moveElement.getStyle().setDisplay(Display.NONE);

        timeline = GWT.create(TimelineWidget.class);

        container = DivElement.as(DOM.createDiv());
        container.setClassName(STYLE_GANTT_CONTAINER);

        content = DivElement.as(DOM.createDiv());
        content.setClassName(STYLE_GANTT_CONTENT);
        container.appendChild(content);

        content.appendChild(moveElement);
        content.appendChild(nowElement);

        scrollbarSpacer = DivElement.as(DOM.createDiv());
        scrollbarSpacer.getStyle().setHeight(AbstractNativeScrollbar.getNativeScrollbarHeight(), Unit.PX);
        scrollbarSpacer.getStyle().setDisplay(Display.NONE);

        getElement().appendChild(timeline.getElement());
        getElement().appendChild(container);
        getElement().appendChild(scrollbarSpacer);
    }
 
Example 3
Source File: AbstractStepWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
public AbstractStepWidget() {
    DivElement bar = DivElement.as(DOM.createDiv());
    bar.setClassName(STYLE_BAR);
    setElement(bar);

    caption = DivElement.as(DOM.createDiv());
    caption.setClassName(STYLE_BAR_LABEL);
    bar.appendChild(caption);

    // hide by default
    bar.getStyle().setVisibility(Visibility.HIDDEN);
}
 
Example 4
Source File: TimelineWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
private DivElement createSpacerBlock(String className) {
    DivElement block = DivElement.as(DOM.createDiv());
    block.setClassName(STYLE_ROW + " " + STYLE_YEAR);
    block.addClassName(STYLE_SPACER);
    block.setInnerText(" ");
    block.getStyle().setDisplay(Display.NONE); // not visible by default
    spacerBlocks.add(block);
    return block;
}
 
Example 5
Source File: TimelineWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
private DivElement createTimelineBlock(String key, String text, String styleSuffix, BlockRowData rowData) {
    DivElement div = DivElement.as(DOM.createDiv());
    div.setClassName(STYLE_ROW + " " + styleSuffix);
    div.setInnerText(text);
    rowData.setBlockLength(key, 1);
    rowData.setBlock(key, div);
    return div;
}
 
Example 6
Source File: TimelineWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
private int calculateResolutionMinWidth() {

        boolean removeResolutionDiv = false;
        if (!resolutionDiv.hasParentElement()) {
            removeResolutionDiv = true;
            getElement().appendChild(resolutionDiv);
        }
        DivElement resBlockMeasure = DivElement.as(DOM.createDiv());
        if (resolution == Resolution.Week) {
            // configurable with '.col.w.measure' selector
            resBlockMeasure.setClassName(STYLE_COL + " " + STYLE_WEEK + " " + STYLE_MEASURE);
        } else {
            // measure for text 'MM'
            resBlockMeasure.setInnerText("MM");
            // configurable with '.col.measure' selector
            resBlockMeasure.setClassName(STYLE_COL + " " + STYLE_MEASURE);
        }
        resolutionDiv.appendChild(resBlockMeasure);
        int width = resBlockMeasure.getClientWidth();
        if (resolution == Resolution.Week) {
            // divide given width by number of days in week
            width = width / DAYS_IN_WEEK;
        }
        width = (width < resolutionWeekDayblockWidth) ? resolutionWeekDayblockWidth : width;
        resBlockMeasure.removeFromParent();
        if (removeResolutionDiv) {
            resolutionDiv.removeFromParent();
        }
        return width;
    }
 
Example 7
Source File: TimelineWidget.java    From gantt with Apache License 2.0 4 votes vote down vote up
/**
 * <p>
 * Updates the content of this widget. Builds the time-line and calculates
 * width and heights for the content (calls in the end
 * {@link #updateWidths()}). This should be called explicitly. Otherwise the
 * widget will be empty.
 * <p>
 * Date values should always follow specification in {@link Date#getTime()}.
 * Start and end date is always required.
 *
 * @param resolution
 *            Resolution enum (not null)
 * @param startDate
 *            Time-line's start date in milliseconds. (not null)
 * @param endDate
 *            Time-line's end date in milliseconds. (not null)
 * @param firstDayOfRange
 *            First day of the whole range. Allowed values are 1-7. 1 is
 *            Sunday. Required with {@link Resolution#Week}.
 * @param firstHourOfRange
 *            First hour of the range. Allowed values are 0-23. Required
 *            with {@link Resolution#Hour}.
 * @param localeDataProvider
 *            Data provider for locale specific data. month names, first day
 *            of week etc.
 *
 */
public void update(Resolution resolution, long startDate, long endDate, int firstDayOfRange, int firstHourOfRange,
        LocaleDataProvider localeDataProvider) {
    if (localeDataProvider == null) {
        GWT.log(getClass().getSimpleName() + " requires LocaleDataProvider. Can't complete update(...) operation.");
        return;
    }
    if (isChanged(resolution, startDate, endDate, localeDataProvider.getFirstDayOfWeek(), firstDayOfRange,
            firstHourOfRange, localeDataProvider.getLocale())) {
        clear();
        GWT.log(getClass().getSimpleName() + " content cleared.");
    } else {
        return;
    }

    GWT.log(getClass().getSimpleName() + " Updating content.");

    injectStyle();
    injectLeftStyle();

    if (styleElementForLeft != null) {
        StyleInjector.setContents(styleElementForLeft, "." + STYLE_COL + " { position: relative; left: 0px; }");
    }

    this.localeDataProvider = localeDataProvider;
    locale = localeDataProvider.getLocale();
    this.resolution = resolution;
    this.startDate = startDate;
    this.endDate = endDate;
    normalStartDate = toNormalDate(startDate);
    normalEndDate = toNormalDate(endDate);
    // Required with Resolution.Week.
    firstDayOfWeek = localeDataProvider.getFirstDayOfWeek();
    lastDayOfWeek = (firstDayOfWeek == 1) ? 7 : Math.max((firstDayOfWeek - 1) % 8, 1);
    this.firstDayOfRange = firstDayOfRange;
    this.firstHourOfRange = firstHourOfRange;
    monthNames = localeDataProvider.getMonthNames();
    weekdayNames = localeDataProvider.getWeekdayNames();
    resolutionDiv = DivElement.as(DOM.createDiv());
    resolutionDiv.setClassName(STYLE_ROW + " " + STYLE_RESOLUTION);

    if (minResolutionWidth < 0) {
        minResolutionWidth = calculateResolutionMinWidth();
    }

    if (resolution == Resolution.Day || resolution == Resolution.Week) {
        prepareTimelineForDayResolution(startDate, endDate);
    } else if (resolution == Resolution.Hour) {
        prepareTimelineForHourResolution(startDate, endDate);
    } else {
        GWT.log(getClass().getSimpleName() + " resolution " + (resolution != null ? resolution.name() : "null")
                + " is not supported");
        return;
    }

    if (isYearRowVisible()) {
        appendTimelineBlocks(yearRowData, STYLE_YEAR);
    }
    if (isMonthRowVisible()) {
        appendTimelineBlocks(monthRowData, STYLE_MONTH);
    }
    if (isDayRowVisible()) {
        appendTimelineBlocks(dayRowData, STYLE_DAY);
    }
    getElement().appendChild(resolutionDiv);

    GWT.log(getClass().getSimpleName() + " Constructed content.");

    updateWidths();

    GWT.log(getClass().getSimpleName() + " is updated for resolution " + resolution.name() + ".");
}
 
Example 8
Source File: TimelineWidget.java    From gantt with Apache License 2.0 4 votes vote down vote up
private DivElement createResolutionBlock() {
    DivElement resBlock = DivElement.as(DOM.createDiv());
    resBlock.setClassName("col");
    return resBlock;
}