org.tltv.gantt.client.shared.Resolution Java Examples

The following examples show how to use org.tltv.gantt.client.shared.Resolution. 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: GanttTest.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Test
public void setDateRangeForHourResolutionAndGMTp10TimezoneTest() {
    Gantt gantt = new Gantt();
    gantt.setResolution(Resolution.Hour);
    gantt.setTimeZone(TimeZone.getTimeZone("Australia/Melbourne"));

    DateTime expectedStart = new DateTime(2014, 1, 1, 10, 0, 0, 000,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Australia/Melbourne")));
    DateTime expectedEnd = new DateTime(2015, 1, 1, 10, 59, 59, 999,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Australia/Melbourne")));

    DateTime start = new DateTime(2014, 1, 1, 10, 30, 30, 123,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Australia/Melbourne")));
    DateTime end = new DateTime(2015, 1, 1, 10, 30, 30, 123,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Australia/Melbourne")));

    gantt.setStartDate(start.toDate());
    gantt.setEndDate(end.toDate());

    Assert.assertEquals(gantt.getStartDate(), expectedStart.toDate());
    Assert.assertEquals(gantt.getEndDate(), expectedEnd.toDate());
}
 
Example #2
Source File: TimelineWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
private void prepareTimelineForDayResolution(long startDate, long endDate) {
    prepareTimelineForResolution(DAY_INTERVAL, startDate, endDate, new ResolutionBlockRegisterer() {

        int dayCounter = firstDayOfRange;
        Weekday weekday;
        boolean firstWeek = true;

        @Override
        public void registerResolutionBlock(int index, Date date, String currentYear, boolean lastTimelineBlock) {

            weekday = getWeekday(dayCounter);

            if (resolution == Resolution.Week) {
                registerWeekResolutionBlock(index, weekday, lastTimelineBlock, firstWeek);
                if (firstWeek && (weekday == Weekday.Last || lastTimelineBlock)) {
                    firstWeek = false;
                }
            } else {
                registerDayResolutionBlock();
            }

            dayCounter = Math.max((dayCounter + 1) % 8, 1);
        }
    });
}
 
Example #3
Source File: TimelineWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
private boolean isChanged(Resolution resolution, long startDate, long endDate, int firstDayOfWeek,
        int firstDayOfRange, int firstHourOfRange, String locale) {
    boolean resolutionChanged = this.resolution != resolution;
    if (resolutionChanged) {
        minResolutionWidth = -1;
    }

    if (forceUpdateFlag) {
        forceUpdateFlag = false;
        return true;
    }
    return resolutionChanged || this.startDate != startDate || this.endDate != endDate
            || this.firstDayOfWeek != firstDayOfWeek || this.firstDayOfRange != firstDayOfRange
            || this.firstHourOfRange != firstHourOfRange
            || (this.locale == null && locale != null || (this.locale != null && !this.locale.equals(locale)));
}
 
Example #4
Source File: GanttTest.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Test
public void setDateRangeForDayResolutionAndDefaultTimezoneTest_TimeZoneAustraliaMelbourne() {
    Gantt gantt = new Gantt();
    gantt.setResolution(Resolution.Day);
    gantt.setTimeZone(TimeZone.getTimeZone("Australia/Melbourne"));

    DateTimeZone tz = DateTimeZone.forTimeZone(TimeZone
            .getTimeZone("Australia/Melbourne"));

    DateTime expectedStart = new DateTime(2014, 1, 1, 0, 0, 0, 000, tz);
    DateTime expectedEnd = new DateTime(2014, 9, 1, 23, 59, 59, 999, tz);

    DateTime start = new DateTime(2014, 1, 1, 10, 30, 30, 123, tz);
    DateTime end = new DateTime(2014, 9, 1, 10, 30, 30, 123, tz);

    gantt.setStartDate(start.toDate());
    gantt.setEndDate(end.toDate());

    Assert.assertEquals(expectedStart.toDate(), gantt.getStartDate());
    Assert.assertEquals(expectedEnd.toDate(), gantt.getEndDate());
}
 
Example #5
Source File: GanttTest.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Test
public void setDateRangeForDayResolutionAndDefaultTimezoneTest_TimeZonePacificHonolulu() {
    Gantt gantt = new Gantt();
    gantt.setResolution(Resolution.Day);
    gantt.setTimeZone(TimeZone.getTimeZone("Pacific/Honolulu"));

    DateTimeZone tz = DateTimeZone.forTimeZone(TimeZone
            .getTimeZone("Pacific/Honolulu"));

    DateTime expectedStart = new DateTime(2014, 1, 1, 0, 0, 0, 000, tz);
    DateTime expectedEnd = new DateTime(2015, 1, 1, 23, 59, 59, 999, tz);

    DateTime start = new DateTime(2014, 1, 1, 10, 30, 30, 123, tz);
    DateTime end = new DateTime(2015, 1, 1, 10, 30, 30, 123, tz);

    gantt.setStartDate(start.toDate());
    gantt.setEndDate(end.toDate());

    Assert.assertEquals(expectedStart.toDate(), gantt.getStartDate());
    Assert.assertEquals(expectedEnd.toDate(), gantt.getEndDate());
}
 
Example #6
Source File: GanttTest.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Test
public void setDateRangeForDayResolutionAndGMTm10TimezoneTest() {
    Gantt gantt = new Gantt();
    gantt.setResolution(Resolution.Day);
    gantt.setTimeZone(TimeZone.getTimeZone("Pacific/Honolulu"));

    DateTime expectedStart = new DateTime(2014, 1, 1, 0, 0, 0, 000,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Pacific/Honolulu")));
    DateTime expectedEnd = new DateTime(2015, 1, 1, 23, 59, 59, 999,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Pacific/Honolulu")));

    DateTime start = new DateTime(2014, 1, 1, 10, 30, 30, 123,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Pacific/Honolulu")));
    DateTime end = new DateTime(2015, 1, 1, 10, 30, 30, 123,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Pacific/Honolulu")));

    gantt.setStartDate(start.toDate());
    gantt.setEndDate(end.toDate());

    Assert.assertEquals(gantt.getStartDate(), expectedStart.toDate());
    Assert.assertEquals(gantt.getEndDate(), expectedEnd.toDate());
}
 
Example #7
Source File: DemoUI.java    From gantt with Apache License 2.0 6 votes vote down vote up
private boolean validateResolutionChange(final org.tltv.gantt.client.shared.Resolution res) {
    long max = 5 * 12 * 4 * 7 * 24 * 3600000L;
    if (res == org.tltv.gantt.client.shared.Resolution.Hour
            && (gantt.getEndDate().getTime() - gantt.getStartDate().getTime()) > max) {

        // revert to previous resolution
        setResolution(gantt.getResolution());

        // make user to confirm hour resolution, if the timeline range is
        // very long.
        Util.showConfirmationPopup(
                "Timeline range is a quite long for hour resolution. Rendering may be slow. Continue anyway?",
                new Runnable() {

                    @Override
                    public void run() {
                        setResolution(res);
                        gantt.setResolution(res);
                    }
                });
        return false;
    }
    return true;
}
 
Example #8
Source File: GanttTest.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Test
public void setDateRange_withDayResolutionAndTZEuropeAmsterdam() {
    Gantt gantt = new Gantt();
    gantt.setResolution(Resolution.Day);
    gantt.setTimeZone(TimeZone.getTimeZone("Europe/Amsterdam"));

    DateTime expectedStart = new DateTime(2015, 4, 1, 0, 0, 0, 000,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Europe/Amsterdam")));
    DateTime expectedEnd = new DateTime(2015, 4, 30, 23, 59, 59, 999,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Europe/Amsterdam")));

    DateTime start = new DateTime(2015, 4, 1, 10, 30, 30, 123,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Europe/Amsterdam")));
    DateTime end = new DateTime(2015, 4, 30, 10, 30, 30, 123,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Europe/Amsterdam")));

    gantt.setStartDate(start.toDate());
    gantt.setEndDate(end.toDate());

    Assert.assertEquals(gantt.getStartDate(), expectedStart.toDate());
    Assert.assertEquals(gantt.getEndDate(), expectedEnd.toDate());
}
 
Example #9
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Set new timeline resolution. Allowed resolutions are
 * {@link Resolution#Hour}, {@link Resolution#Day} and
 * {@link Resolution#Week}.
 *
 * @param resolution
 */
public void setResolution(Resolution resolution) {
    if (resolution == null) {
        resolution = Resolution.Day;
    }
    boolean changed = !resolution.equals(getResolution());
    getState().resolution = resolution;
    if (changed) {
        // adjust timeline range for the new resolution.
        setInternalStartDate(getStartDate());
        setInternalEndDate(getEndDate());
        updateTimelineStartTimeDetails();
    }
}
 
Example #10
Source File: DemoUI.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void setResolution(org.tltv.gantt.client.shared.Resolution resolution) {
    resolutionValueChangeRegistration.ifPresent(Registration::remove);
    try {
        reso.setValue(resolution);
    } finally {
        resolutionValueChangeRegistration = Optional.of(reso.addValueChangeListener(resolutionValueChangeListener));
    }
}
 
Example #11
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
private Date resetTimeToMin(Date date) {
    Calendar cal = getCalendar();
    cal.setTimeInMillis(date.getTime());
    if (!getResolution().equals(Resolution.Hour)) {
        // reset hour only if the resolution is set to DAY, WEEK or MONTH
        cal.set(Calendar.HOUR, cal.getMinimum(Calendar.HOUR));
        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.AM_PM, cal.getMinimum(Calendar.AM_PM));
    }
    cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
    return cal.getTime();
}
 
Example #12
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
private Date resetTimeToMax(Date date) {
    Calendar cal = getCalendar();
    cal.setTimeInMillis(date.getTime());
    if (!getResolution().equals(Resolution.Hour)) {
        // reset hour only if the resolution is set to DAY, WEEK or MONTH
        cal.set(Calendar.HOUR, cal.getMaximum(Calendar.HOUR));
        cal.set(Calendar.AM_PM, cal.getMaximum(Calendar.AM_PM));
    }
    cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
    return cal.getTime();
}
 
Example #13
Source File: GanttTest.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Test
public void addStepWithDatesAndGetByUid_addAndGetSuccessfully() {
    Gantt gantt = new Gantt();
    gantt.setResolution(Resolution.Day);

    DateTime start = new DateTime(2014, 1, 1, 10, 30, 30, 123);
    DateTime end = new DateTime(2014, 9, 1, 10, 30, 30, 123);

    gantt.setStartDate(start.toDate());
    gantt.setEndDate(end.toDate());

    List<Step> steps = new ArrayList<Step>();

    DateTime expectedStart = new DateTime(2014, 1, 1, 10, 30, 30, 123);
    DateTime expectedEnd = new DateTime(2014, 1, 8, 10, 30, 30, 123);

    DateTime stepStart = new DateTime(2014, 1, 1, 10, 30, 30, 123);
    DateTime stepEnd = new DateTime(2014, 1, 8, 10, 30, 30, 123);

    Step step = new Step();
    step.setStartDate(stepStart.toDate());
    step.setEndDate(stepEnd.toDate());
    gantt.addStep(step);

    steps.add(step);

    Assert.assertNotNull(step.getUid());

    Step foundStep = (Step) gantt.getStep(step.getUid());

    Assert.assertNotNull(foundStep);
    Assert.assertEquals(step, foundStep);
    Assert.assertEquals(step.getUid(), foundStep.getUid());
    Assert.assertTrue(steps.contains(foundStep));
    Assert.assertEquals(expectedStart.toDate().getTime(),
            foundStep.getStartDate());
    Assert.assertEquals(expectedEnd.toDate().getTime(),
            foundStep.getEndDate());
}
 
Example #14
Source File: GanttTest.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Test
public void addEmptyStepAndGetByUid_addAndGetSuccessfully() {
    Gantt gantt = new Gantt();
    gantt.setResolution(Resolution.Day);

    DateTime start = new DateTime(2014, 1, 1, 10, 30, 30, 123);
    DateTime end = new DateTime(2014, 9, 1, 10, 30, 30, 123);

    gantt.setStartDate(start.toDate());
    gantt.setEndDate(end.toDate());

    List<Step> steps = new ArrayList<Step>();

    Step step = new Step();
    gantt.addStep(step);

    steps.add(step);

    Assert.assertNotNull(step.getUid());

    Step foundStep = (Step) gantt.getStep(step.getUid());

    Assert.assertNotNull(foundStep);
    Assert.assertEquals(step, foundStep);
    Assert.assertEquals(step.getUid(), foundStep.getUid());
    Assert.assertTrue(steps.contains(foundStep));
}
 
Example #15
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 #16
Source File: TimelineWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void showResolutionBlocksOnView() {
    double positionLeftSnapshot = positionLeft;
    double datePos = positionLeftSnapshot;
    firstWeekBlockHidden = false;

    int left = (int) positionLeftSnapshot;
    if (positionLeftSnapshot > 0 && resBlockWidthPx > 0) {
        double overflow = 0.0;
        boolean firstResBlockShort = isFirstResBlockShort();
        overflow = getScrollOverflowForResolutionBlock(positionLeftSnapshot, left, firstResBlockShort);
        left = (int) (positionLeftSnapshot - overflow);
        datePos = adjustLeftPositionForDateDetection(left);
    }
    if (datePos < 0.0) {
        datePos = positionLeftSnapshot;
    }
    long leftDate;
    boolean noticeDst = resolution == Resolution.Hour;
    leftDate = getDateForLeftPosition(datePos, noticeDst);

    double containerWidth = GanttUtil.getBoundingClientRectWidth(getElement().getParentElement());
    fillTimelineForResolution(leftDate,
            Math.min(endDate, getDateForLeftPosition(datePos + containerWidth, noticeDst)), left);

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

    GWT.log(getClass().getSimpleName() + " Updated visible timeline elements for horizontal scroll position "
            + left);
}
 
Example #17
Source File: AbstractGhantChartManagerImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the gantt.
 *
 * @return the gantt
 */
private static final Gantt createGantt() {
	final Gantt gantt = new Gantt();
	gantt.setSizeFull();
	gantt.setWidth(100, Unit.PERCENTAGE);
	gantt.setHeight(100, Unit.PERCENTAGE);
	gantt.setResizableSteps(false);
	gantt.setMovableSteps(false);
	gantt.setResolution(Resolution.Week);
	return gantt;
}
 
Example #18
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 #19
Source File: GanttTest.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Test
public void setDateRange_withDayResolutionAndTZEuropeAmsterdamAndCustomTimezoneOffsetDate() {
    Gantt gantt = new Gantt() {
        @Override
        protected Date getTimezoneOffsetDate() {
            return new DateTime(2015, 4, 1, 0, 0, 0, 000,
                    DateTimeZone.forTimeZone(TimeZone
                            .getTimeZone("Europe/Amsterdam"))).toDate();
        }
    };
    gantt.setResolution(Resolution.Day);
    gantt.setTimeZone(TimeZone.getTimeZone("Europe/Amsterdam"));

    DateTime expectedEnd = new DateTime(2015, 4, 30, 23, 59, 59, 999,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Europe/Amsterdam")));

    DateTime start = new DateTime(2015, 4, 1, 10, 30, 30, 123,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Europe/Amsterdam")));
    DateTime end = new DateTime(2015, 4, 30, 10, 30, 30, 123,
            DateTimeZone.forTimeZone(TimeZone
                    .getTimeZone("Europe/Amsterdam")));

    gantt.setStartDate(start.toDate());
    gantt.setEndDate(end.toDate());

    Assert.assertEquals(gantt.getEndDate(), expectedEnd.toDate());
}
 
Example #20
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 #21
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;
}
 
Example #22
Source File: TimelineWidget.java    From gantt with Apache License 2.0 4 votes vote down vote up
public boolean isDayRowVisible() {
    return resolution == Resolution.Hour;
}
 
Example #23
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 #24
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 #25
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 #26
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 #27
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 #28
Source File: Gantt.java    From gantt with Apache License 2.0 4 votes vote down vote up
/**
 * Set component's active {@link TimeZone}.
 *
 * @param zone
 *            Timezone
 */
public void setTimeZone(TimeZone zone) {
    if (!getTimeZone().equals(zone)) {
        int startdate = 0;
        int startmonth = 0;
        int startyear = 0;
        int starthour = 0;
        int enddate = 0;
        int endmonth = 0;
        int endyear = 0;
        int endhour = 0;
        // keep previous date/month/year
        if (getStartDate() != null) {
            getCalendar().setTime(getStartDate());
            startdate = getCalendar().get(Calendar.DATE);
            startmonth = getCalendar().get(Calendar.MONTH);
            startyear = getCalendar().get(Calendar.YEAR);
            starthour = getCalendar().get(Calendar.HOUR_OF_DAY);
        }
        if (getEndDate() != null) {
            getCalendar().setTime(getEndDate());
            enddate = getCalendar().get(Calendar.DATE);
            endmonth = getCalendar().get(Calendar.MONTH);
            endyear = getCalendar().get(Calendar.YEAR);
            endhour = getCalendar().get(Calendar.HOUR_OF_DAY);
        }

        timezone = zone; // internal timezone may be null
        if (zone == null) {
            zone = TimeZone.getDefault();
        }

        // refresh timeline range. Depending on the resolution, it might
        // need some adjusting.

        getCalendar().setTimeZone(zone);
        if (getStartDate() != null) {
            getCalendar().setTime(getStartDate());
            getCalendar().set(Calendar.DATE, startdate);
            getCalendar().set(Calendar.MONTH, startmonth);
            getCalendar().set(Calendar.YEAR, startyear);
            if (getResolution() == Resolution.Hour) {
                getCalendar().set(Calendar.HOUR_OF_DAY, starthour);
            }
            setInternalStartDate(getCalendar().getTime());
        }

        if (getEndDate() != null) {
            getCalendar().setTime(getEndDate());
            getCalendar().set(Calendar.DATE, enddate);
            getCalendar().set(Calendar.MONTH, endmonth);
            getCalendar().set(Calendar.YEAR, endyear);
            if (getResolution() == Resolution.Hour) {
                getCalendar().set(Calendar.HOUR_OF_DAY, endhour);
            }
            setInternalEndDate(getCalendar().getTime());
        }

        updateTimelineStartTimeDetails();
        updateCurrentDateAndTime();
        markAsDirty();
    }
}
 
Example #29
Source File: DemoUI.java    From gantt with Apache License 2.0 4 votes vote down vote up
private Panel createControls() {
    Panel panel = new Panel();
    panel.setWidth(100, Unit.PERCENTAGE);

    controls = new HorizontalLayout();
    controls.setSpacing(true);
    controls.setMargin(true);
    panel.setContent(controls);

    subControls = new HorizontalLayout();
    subControls.setSpacing(true);
    subControls.setVisible(false);

    start = createStartDateField();
    end = createEndDateField();

    Button createStep = new Button("Create New Step...", createStepClickListener);

    HorizontalLayout heightAndUnit = new HorizontalLayout(Util.createHeightEditor(gantt),
            Util.createHeightUnitEditor(gantt));

    HorizontalLayout widthAndUnit = new HorizontalLayout(Util.createWidthEditor(gantt),
            Util.createWidthUnitEditor(gantt));

    reso = new NativeSelect<Resolution>("Resolution");
    reso.setEmptySelectionAllowed(false);
    reso.setItems(org.tltv.gantt.client.shared.Resolution.Hour, org.tltv.gantt.client.shared.Resolution.Day,
            org.tltv.gantt.client.shared.Resolution.Week);
    reso.setValue(gantt.getResolution());
    resolutionValueChangeRegistration = Optional.of(reso.addValueChangeListener(resolutionValueChangeListener));

    localeSelect = new NativeSelect<Locale>("Locale") {
        @Override
        public void attach() {
            super.attach();

            if (getValue() == null) {
                // use default locale
                setValue(gantt.getLocale());
                addValueChangeListener(localeValueChangeListener);
            }
        }
    };
    localeSelect.setEmptySelectionAllowed(false);
    localeSelect.setItems(Locale.getAvailableLocales());
    localeSelect.setItemCaptionGenerator((l) -> l.getDisplayName(getLocale()));

    ComboBox<String> timezoneSelect = new ComboBox<String>("Timezone");
    timezoneSelect.setWidth(300, Unit.PIXELS);
    timezoneSelect.setEmptySelectionAllowed(false);
    timezoneSelect.setItemCaptionGenerator(new ItemCaptionGenerator<String>() {

        @Override
        public String apply(String item) {
            if ("Default".equals(item)) {
                return "Default (" + getDefaultTimeZone().getDisplayName() + ")";
            }
            TimeZone tz = TimeZone.getTimeZone(item);
            return tz.getID() + " (raw offset " + (tz.getRawOffset() / 60000) + "m)";
        }
    });
    List<String> items = new ArrayList<>();
    items.add("Default");
    items.addAll(Gantt.getSupportedTimeZoneIDs());
    timezoneSelect.setItems((caption, fltr) -> caption.contains(fltr), items);
    timezoneSelect.setValue("Default");
    timezoneSelect.addValueChangeListener(timezoneValueChangeListener);

    final Button toggleSubControlsBtn = new Button("Show More Settings...");
    toggleSubControlsBtn.addStyleName("link");
    toggleSubControlsBtn.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            subControls.setVisible(!subControls.isVisible());
            toggleSubControlsBtn.setCaption(subControls.isVisible() ? "Less Settings..." : "More Settings...");
        }
    });

    controls.addComponent(start);
    controls.addComponent(end);
    controls.addComponent(reso);
    controls.addComponent(subControls);
    controls.addComponent(toggleSubControlsBtn);
    controls.setComponentAlignment(toggleSubControlsBtn, Alignment.BOTTOM_CENTER);

    subControls.addComponent(localeSelect);
    subControls.addComponent(timezoneSelect);
    subControls.addComponent(heightAndUnit);
    subControls.addComponent(widthAndUnit);
    subControls.addComponent(createStep);
    subControls.setComponentAlignment(createStep, Alignment.MIDDLE_LEFT);

    return panel;
}
 
Example #30
Source File: DemoUI.java    From gantt with Apache License 2.0 4 votes vote down vote up
@Override
public void valueChange(ValueChangeEvent<org.tltv.gantt.client.shared.Resolution> event) {
    if (validateResolutionChange(event.getValue())) {
        gantt.setResolution(event.getValue());
    }
}