PreviewOptions#

Options for Project#preview. They set which part of the project is scheduled, which extra data the ScheduleResult carries, and which baseline the preview expects. Create one with new PreviewOptions() and set fields with the fluent withX setters. The defaults schedule the whole project and return only the changed tasks.

Declaration#

public class PreviewOptions extends ValueRecord implements DeepCloneable<PreviewOptions>

Constructors#

PreviewOptions()#

public PreviewOptions()

Creates options with every field at its default.

Fields#

Field Type Default Description
subtree Subtree null Limits scheduling to one task's branch. null schedules the whole project.
analytics AnalyticsOptions new AnalyticsOptions() (none requested) Requests slack and the critical path. Fills ScheduleResult.analytics.
reasons boolean false Fills Mutation.reason on each update.
baselineId String null The baseline the preview expects. null skips the check.
profile ProfileQuery null Requests a load profile of the previewed dates. Fills ScheduleResult.profile.

subtree#

public Subtree subtree = null;

Limits scheduling to the scope that the Subtree value describes. Build the value with new Subtree(id).

analytics#

public AnalyticsOptions analytics = new AnalyticsOptions();

Turns on AnalyticsOptions.slack and AnalyticsOptions.criticalPath for the previewed dates. With both flags false (the default), ScheduleResult.analytics is null. With either flag set, it holds an Analytics value. Check its status before reading the data.

reasons#

public boolean reasons = false;

When true, each Mutation in ScheduleResult.updates carries a Reason in its reason field. When false, reason is always null.

baselineId#

public String baselineId = null;

A baseline token taken from the latest ScheduleResult.baselineId. When it isn't null and doesn't name the project's current baseline, Project#preview throws a ProjectException with code STALE_BASELINE. It stops a preview from running over a baseline that changed underneath the UI.

SchedulingChanges.baselineId is checked the same way, independently of this field.

profile#

public ProfileQuery profile = null;

When set, ScheduleResult.profile holds the LoadProfile of the previewed dates over the range and resources that the ProfileQuery describes. When null, ScheduleResult.profile is null. An invalid query makes Project#preview throw an InputException.

Methods#

withSubtree, withAnalytics, withReasons, withBaselineId, withProfile#

public PreviewOptions withSubtree(Subtree value)
public PreviewOptions withAnalytics(AnalyticsOptions value)
public PreviewOptions withReasons(boolean value)
public PreviewOptions withBaselineId(String value)
public PreviewOptions withProfile(ProfileQuery value)

Each setter assigns its field and returns this instance for chaining.

Returns - this PreviewOptions.

deepClone#

public PreviewOptions deepClone()

Returns a copy that shares no nested object (subtree, analytics, profile) with this instance.

Returns - a new PreviewOptions with the same values.

copy#

public PreviewOptions copy()

Returns a shallow copy. The copy shares the subtree, analytics and profile objects with this instance.

Returns - a new PreviewOptions with the same field values.

equals, hashCode, toString#

public boolean equals(Object other)
public int hashCode()
public String toString()

Inherited from ValueRecord. Two PreviewOptions are equal when their public fields are equal. toString() lists the fields in the form PreviewOptions{field=value, …}.

Example#

import java.util.List;
import org.dhtmlx.plen.*;

public class PreviewWithOptions {
  public static void main(String[] args) throws Exception {
    Moment monday = Moment.fromYmdHm(2026, 1, 5, 8, 0);
    Moment wednesday = Moment.fromYmdHm(2026, 1, 7, 8, 0);
    Moment nextMonday = Moment.fromYmdHm(2026, 1, 12, 8, 0);

    ProjectData data = new ProjectData()
        .withTasks(List.of(
            new TaskData(Id.str("design")).withStartDate(monday).withDuration(2.0),
            new TaskData(Id.str("build")).withStartDate(monday).withDuration(3.0)))
        .withLinks(List.of(
            new LinkData().withId(Id.str("l1")).withSource(Id.str("design")).withTarget(Id.str("build"))));

    Project project = new Project();
    ScheduleResult solved = project.solve(data, new SolveOptions());

    // The user drags "design" to Wednesday.
    SchedulingChanges changes = new SchedulingChanges();
    changes.tasks.update.add(new TaskUpdate(Id.str("design")).withStartDate(Patch.of(wednesday)));

    PreviewOptions options = new PreviewOptions()
        .withReasons(true)
        .withBaselineId(solved.baselineId)
        .withProfile(new ProfileQuery(monday, nextMonday));

    ScheduleResult preview = project.preview(changes, options);
    for (Mutation update : preview.updates) {
      // design: 2026-01-07 08:00 - 2026-01-09 08:00 (Preferred{})
      // build: 2026-01-09 08:00 - 2026-01-14 08:00 (Asap{linkId=l1, sourceId=design})
      System.out.println(update.id + ": " + update.startDate + " - " + update.endDate + " (" + update.reason + ")");
    }
  }
}