Java Code Examples for org.tltv.gantt.client.shared.Resolution#Week

The following examples show how to use org.tltv.gantt.client.shared.Resolution#Week . 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: TimelineWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void fillTimelineForResolution(final long startDate, long endDate, final int left) {
    if (resolution == Resolution.Day || resolution == Resolution.Week) {
        fillTimelineForDayResolution(startDate, endDate, left);
    } else if (resolution == Resolution.Hour) {
        fillTimelineForHourResolution(startDate, endDate, left);
    } else {
        GWT.log(getClass().getSimpleName() + " resolution " + (resolution != null ? resolution.name() : "null")
                + " is not supported");
        return;
    }

    GWT.log(getClass().getSimpleName() + " Filled new data and styles to visible timeline elements");
}
 
Example 2
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 3
Source File: TimelineWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Adjust left position for optimal position to detect accurate date with
 * the current resolution.
 */
private double adjustLeftPositionForDateDetection(int left) {
    double datePos;
    if (resolution == Resolution.Week) {
        // detect date from the center of the first day block inside the
        // week block.
        datePos = left + dayOrHourWidthPx / 2;
    } else {
        // detect date from the center of the block (day/hour)
        datePos = left + resBlockWidthPx / 2;
    }
    return datePos;
}
 
Example 4
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 5
Source File: TimelineWidget.java    From gantt with Apache License 2.0 4 votes vote down vote up
/**
 * Re-calculates required widths for this widget.
 * <p>
 * Re-creates and fills the visible part of the resolution element.
 */
public void updateWidths() {
    if (resolutionDiv == null) {
        GWT.log(getClass().getSimpleName() + " is not ready for updateWidths() call. Call update(...) instead.");
        return;
    }

    GWT.log(getClass().getSimpleName() + " Started updating widths.");

    // start by clearing old content in resolution element
    resolutionDiv.removeAllChildren();

    setMinWidth(blocksInRange * minResolutionWidth);

    // update horizontal overflow state here, after min-width is updated.
    updateTimelineOverflowingHorizontally();

    createTimelineElementsOnVisibleArea();
    // fill timeline
    fillVisibleTimeline();

    // remove spacer block if it exist
    removeResolutionSpacerBlock();

    // calculate new block width for day-resolution.
    // Year and month blocks are vertically in-line with days.
    dayWidthPercentage = 100.0 / blocksInRange;
    dayOrHourWidthPx = calculateDayOrHourResolutionBlockWidthPx(blocksInRange);

    // calculate block width for currently selected resolution
    // (day,week,...)
    // resolution div's content may not be vertically in-line with
    // year/month blocks. This is the case for example with Week resolution.
    resBlockMinWidthPx = minResolutionWidth;
    resBlockWidthPx = calculateActualResolutionBlockWidthPx(dayOrHourWidthPx);
    resBlockWidthPercentage = 100.0 / resolutionBlockCount;
    String pct = createCalcCssValue(resolutionBlockCount);
    if (resolution == Resolution.Week) {
        resBlockMinWidthPx = DAYS_IN_WEEK * minResolutionWidth;
        resBlockWidthPercentage = dayWidthPercentage * DAYS_IN_WEEK;
        pct = createCalcCssValue(blocksInRange, DAYS_IN_WEEK);

    }

    // update resolution block widths
    updateResolutionBlockWidths(pct);

    if (isYearRowVisible()) {
        // update year block widths
        updateBlockWidths(yearRowData);
    }

    if (isMonthRowVisible()) {
        // update month block widths
        updateBlockWidths(monthRowData);
    }

    if (isDayRowVisible()) {
        updateBlockWidths(dayRowData);
    }

    if (isAlwaysCalculatePixelWidths()) {
        updateSpacerBlocks(dayOrHourWidthPx);
    }

    GWT.log(getClass().getSimpleName() + " Widths are updated.");
}
 
Example 6
Source File: TimelineWidget.java    From gantt with Apache License 2.0 4 votes vote down vote up
private double calculateActualResolutionBlockWidthPx(double dayOrHourBlockWidthPx) {
    if (resolution == Resolution.Week) {
        return DAYS_IN_WEEK * dayOrHourBlockWidthPx;
    }
    return dayOrHourBlockWidthPx;
}
 
Example 7
Source File: TimelineWidget.java    From gantt with Apache License 2.0 4 votes vote down vote up
private boolean isFirstResBlockShort() {
    return firstResBlockCount > 0 && ((resolution == Resolution.Week && firstResBlockCount < DAYS_IN_WEEK));
}
 
Example 8
Source File: TimelineWidget.java    From gantt with Apache License 2.0 4 votes vote down vote up
private boolean isLastResBlockShort() {
    return lastResBlockCount > 0 && ((resolution == Resolution.Week && lastResBlockCount < DAYS_IN_WEEK));
}
 
Example 9
Source File: TimelineWidget.java    From gantt with Apache License 2.0 4 votes vote down vote up
private int calculateMinimumResolutionBlockWidth() {
    if (resolution == Resolution.Week) {
        return DAYS_IN_WEEK * minResolutionWidth;
    }
    return minResolutionWidth;
}