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

The following examples show how to use org.tltv.gantt.client.shared.Step. 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 removeSteps_withTwoStepsOneHasSubStep_sizeIsZeroAndComponetHierarchyCleaned() {
    Gantt gantt = new Gantt();

    SubStep subStep = new SubStep();
    Step stepWithSubStep = new Step();
    stepWithSubStep.addSubStep(subStep);
    gantt.addStep(stepWithSubStep);
    gantt.addStep(new Step());

    AbstractStepComponent stepWithSubStepComponent = gantt
            .getStepComponent(stepWithSubStep);
    AbstractStepComponent subStepComponent = gantt
            .getStepComponent(subStep);
    Assert.assertNotNull(stepWithSubStepComponent.getParent());
    Assert.assertNotNull(subStepComponent.getParent());

    gantt.removeSteps();
    Assert.assertEquals(0, gantt.getSteps().size());
    Assert.assertNull(stepWithSubStepComponent.getParent());
    Assert.assertNull(subStepComponent.getParent());
    Assert.assertNull(gantt.getStepComponent(stepWithSubStep));
    Assert.assertNull(gantt.getStepComponent(subStep));
}
 
Example #2
Source File: AbstractGhantChartManagerImpl.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the view generic role member to step.
 *
 * @param stepName
 *            the step name
 * @param step
 *            the step
 * @param assignments
 *            the assignments
 * @param stepMapping
 *            the step mapping
 */
private void addViewGenericRoleMemberToStep(final String stepName, final Step step, final List<T> assignments,
		final StepMapping<T> stepMapping) {

	for (final T assignmentData : assignments) {

		String subStepName = "";

		if (stepMapping.getRoleCode(assignmentData) != null) {
			subStepName = new StringBuilder().append(stepMapping.getFirstName(assignmentData))
					.append(CONTENT_SEPARATOR).append(stepMapping.getLastName(assignmentData))
					.append(PARTY_START_TAG).append(stepMapping.getParty(assignmentData)).append(PARTY_END_TAG)
					.toString();
		}

		final SubStep sameRoleSubStep = new SubStep(stepName + '.' + subStepName,CaptionMode.HTML);
		sameRoleSubStep.setDescription(stepName + '.' + subStepName);			
		sameRoleSubStep.setBackgroundColor(stepMapping.getBackgroundColor(assignmentData));

		sameRoleSubStep.setStartDate(stepMapping.getFromDate(assignmentData).getTime());
		sameRoleSubStep.setEndDate(stripDatesAfterCurrentDate(stepMapping.getToDate(assignmentData)).getTime());

		step.addSubStep(sameRoleSubStep);
	}
}
 
Example #3
Source File: DemoUI.java    From gantt with Apache License 2.0 6 votes vote down vote up
private void commit(final Window win, final Binder<? extends AbstractStep> binder,
        final NativeSelect<Step> parentStepSelect) {
    AbstractStep step = binder.getBean();
    gantt.markStepDirty(step);
    if (parentStepSelect.isEnabled() && parentStepSelect.getValue() != null) {
        SubStep subStep = addSubStep(parentStepSelect, step);
        step = subStep;
    }
    if (step instanceof Step && !gantt.getSteps().contains(step)) {
        gantt.addStep((Step) step);
    }
    if (ganttListener != null && step instanceof Step) {
        ganttListener.stepModified((Step) step);
    }
    win.close();
}
 
Example #4
Source File: DemoUI.java    From gantt with Apache License 2.0 6 votes vote down vote up
private void fillParentStepCanditatesToSelect(AbstractStep step, final NativeSelect<Step> parentStepSelect) {
    if (!gantt.getSteps().contains(step)) {
        // new step
        parentStepSelect.setEnabled(true);
        List<Step> items = new ArrayList<>();
        for (Step parentStepCanditate : gantt.getSteps()) {
            items.add(parentStepCanditate);
            if (step instanceof SubStep) {
                if (parentStepCanditate.getSubSteps().contains(step)) {
                    parentStepSelect.setValue(parentStepCanditate);
                    parentStepSelect.setEnabled(false);
                    break;
                }
            }
        }
        parentStepSelect.setItems(items);
    }
}
 
Example #5
Source File: Gantt.java    From gantt with Apache License 2.0 6 votes vote down vote up
protected void moveDatesByOwnerStep(AbstractStep step, long previousStartDate, long previousEndDate) {
    if (!(step instanceof Step)) {
        return;
    }
    Step s = (Step) step;

    long startDelta = step.getStartDate() - previousStartDate;
    long endDelta = step.getEndDate() - previousEndDate;
    if (!s.getSubSteps().isEmpty()) {
        for (SubStep sub : s.getSubSteps()) {
            if (startDelta != 0) {
                sub.setStartDate(sub.getStartDate() + startDelta);
            }
            if (endDelta != 0) {
                sub.setEndDate(sub.getEndDate() + endDelta);
            }
            subStepMap.get(sub).getState(true);
        }
    }
}
 
Example #6
Source File: Gantt.java    From gantt with Apache License 2.0 6 votes vote down vote up
protected void firePredecessorChangeEvent(String newPredecessorStepUid, String forTargetStepUid,
        String clearPredecessorForStepUid) {
    Step newPredecessorStep = (Step) getStep(newPredecessorStepUid);
    Step forTargetStep = (Step) getStep(forTargetStepUid);
    Step clearPredecessorForStep = (Step) getStep(clearPredecessorForStepUid);
    if (forTargetStep != null) {
        forTargetStep.setPredecessor(newPredecessorStep);
        stepComponents.get(forTargetStep).getState(true);
        fireEvent(new PredecessorChangeEvent(this, forTargetStep));
    }
    if (clearPredecessorForStep != null) {
        clearPredecessorForStep.setPredecessor(null);
        stepComponents.get(clearPredecessorForStep).getState(true);
        fireEvent(new PredecessorChangeEvent(this, clearPredecessorForStep));
    }
}
 
Example #7
Source File: TreeGridGanttLayout.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Override
public void stepMoved(Step step, int newStepIndex, int oldStepIndex) {
    List<Step> path = getParents(step);

    // remove all childrens
    if (dataProvider.hasChildren(step)) {
        removeChildStepRecursively(ganttTreeGrid, step);
        dataProvider.getTreeData().getChildren(step).stream().collect(Collectors.toList())
                .forEach(dataProvider.getTreeData()::removeItem);
    }

    if (path.size() > 1) {
        Step s = path.remove(path.size() - 1);
        dataProvider.getTreeData().removeItem(s);
        dataProvider.getTreeData().addItem(null, s);
    }
    dataProvider.refreshAll();
}
 
Example #8
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Add new {@link Step}.
 *
 * @param step
 *            New Step object
 */
public void addStep(Step step) {
    if (!stepComponents.containsKey(step)) {
        StepComponent sc = createStepComponent(step);
        stepComponents.put(step, sc);
        getState().steps.add(sc);
    }
}
 
Example #9
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Moves sub-step to other step. Does nothing, if either is null, or
 * sub-step's owner is null or owner is same as target step.
 */
public void moveSubStep(SubStep subStep, Step toStep) {
    if (subStep == null || toStep == null || subStep.getOwner() == null || subStep.getOwner().equals(toStep)) {
        return;
    }
    subStep.getOwner().removeSubStep(subStep);
    toStep.addSubStep(subStep);
}
 
Example #10
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Move existing step at a specific index and shifts the current object at
 * that index and any subsequent objects forward.
 *
 * @throws IndexOutOfBoundsException
 *             if the index is out of range (index < 0 || index >=
 *             getState().steps.size())
 */
public void moveStep(int toIndex, Step step) {
    if (!stepComponents.containsKey(step)) {
        return;
    }
    StepComponent targetComponent = stepComponents.get(getStep(toIndex));
    StepComponent moveComponent = stepComponents.get(step);
    if (targetComponent == moveComponent) {
        return;
    }
    getState().steps.remove(moveComponent);
    moveComponent.setParent(null);
    getState().steps.add(indexOf(targetComponent), moveComponent);
    moveComponent.setParent(this);
}
 
Example #11
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Remove {@link Step}.
 *
 * @param step
 *            Target Step
 * @return true when target step exists and was removed successfully.
 */
public boolean removeStep(Step step) {
    StepComponent sc = stepComponents.remove(step);
    if (sc != null) {
        for (SubStep subStep : new HashSet<SubStep>(step.getSubSteps())) {
            sc.onRemoveSubStep(subStep);
        }
        sc.setParent(null);
        return getState().steps.remove(sc);
    }
    return false;
}
 
Example #12
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a unmodifiable List of steps.
 *
 * @return List of steps
 */
public List<Step> getSteps() {
    List<Step> steps = new ArrayList<Step>();
    for (Connector sc : getState(false).steps) {
        steps.add(((StepComponent) sc).getState(false).step);
    }
    return Collections.unmodifiableList(steps);
}
 
Example #13
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all the steps in this Gantt chart.
 */
public void removeSteps() {
    Set<Step> allSteps = new HashSet<Step>(stepComponents.keySet());
    for (Step step : allSteps) {
        removeStep(step);
    }
}
 
Example #14
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected void fireMoveEvent(String stepUid, String newStepUid, long startDate, long endDate,
        MouseEventDetails details) {
    AbstractStep step = getStep(stepUid);
    AbstractStep newStep = getStep(newStepUid);
    int previousStepIndex = (step instanceof Step) ? getStepIndex((Step) step)
            : getStepIndex(((SubStep) step).getOwner());
    long previousStartDate = step.getStartDate();
    long previousEndDate = step.getEndDate();
    step.setStartDate(startDate);
    step.setEndDate(endDate);
    int newStepIndex;
    if (isMovableStepsBetweenRows() && newStep instanceof Step) {
        newStepIndex = getStepIndex((Step) newStep);
        if (step instanceof Step) {
            // move to new row
            moveStep(newStepIndex, (Step) step);
        } else {
            // move sub-step to new owner
            moveSubStep((SubStep) step, (Step) newStep);
        }
    } else {
        newStepIndex = previousStepIndex;
    }
    moveDatesByOwnerStep(step, previousStartDate, previousEndDate);
    adjustDatesByAbstractStep(step);
    fireEvent(new MoveEvent(this, step, step.getStartDate(), step.getEndDate(), newStepIndex, previousStartDate,
            previousEndDate, previousStepIndex, details));
}
 
Example #15
Source File: Gantt.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected Step ajustDatesBySubStep(AbstractStep step) {
    // adjust parent step start/end date:
    SubStep subStep = ((SubStep) step);
    Step owner = subStep.getOwner();
    // Cut owner step's start/end date to fit sub-steps in.
    if (owner.isStartDateUndefined() || subStep.getStartDate() < owner.getStartDate()) {
        owner.setStartDate(subStep.getStartDate());
    }
    if (owner.isEndDateUndefined() || subStep.getEndDate() > owner.getEndDate()) {
        owner.setEndDate(subStep.getEndDate());
    }
    return owner;
}
 
Example #16
Source File: StepConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void updatePredecessorWidgetReference() {

        // check predecessor change and update widget reference if
        // needed.
        Step predecessor = getState().step.getPredecessor();
        Step oldPredecessor = null;
        if (getWidget().getPredecessorStepWidget() != null) {
            oldPredecessor = getWidget().getPredecessorStepWidget().getStep();
        }

        if ((predecessor == null && oldPredecessor != null)
                || (predecessor != null && !predecessor.equals(oldPredecessor))) {
            getWidget().setPredecessorStepWidget(((GanttConnector) getParent()).getStepWidget(predecessor));
        }
    }
 
Example #17
Source File: AbstractStepWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected void updateCaption() {
    if (step.getCaptionMode() == Step.CaptionMode.HTML) {
        caption.setInnerHTML(step.getCaption());
    } else {
        caption.setInnerText(step.getCaption());
    }
}
 
Example #18
Source File: GanttConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected Map<Step, StepWidget> getStepsMap() {
    Map<Step, StepWidget> steps = new HashMap<Step, StepWidget>();
    StepWidget stepWidget;
    for (Connector sc : getState().steps) {
        stepWidget = ((StepConnector) sc).getWidget();
        steps.put(((StepConnector) sc).getState().step, stepWidget);
    }
    return steps;
}
 
Example #19
Source File: GanttConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Return {@link StepWidget} objects that are related to the given
 * StepWidget. Via {@link Step#getPredecessor()} for example.
 */
public Set<StepWidget> findRelatedSteps(Step targetStep, List<ComponentConnector> stepConnectors) {
    Set<StepWidget> widgets = new HashSet<StepWidget>();
    for (ComponentConnector con : stepConnectors) {
        StepWidget stepWidget = ((StepConnector) con).getWidget();
        if (targetStep.equals(stepWidget.getStep().getPredecessor())) {
            widgets.add(stepWidget);
        }
    }
    return widgets;
}
 
Example #20
Source File: StepComponent.java    From gantt with Apache License 2.0 5 votes vote down vote up
public StepComponent(Gantt gantt, Step data) {
    this.gantt = gantt;
    if (data.getUid() == null) {
        data.setUid(UUID.randomUUID().toString());
    }
    setParent(gantt);
    getState().step = data;
    for (SubStep subStep : data.getSubSteps()) {
        onAddSubStep(subStep);
    }
    data.addSubStepObserver(new SubStepObserverProxy(this));
}
 
Example #21
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 #22
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 #23
Source File: GridGanttLayout.java    From gantt with Apache License 2.0 5 votes vote down vote up
private Grid<Step> createGridForGantt() {

        dataProvider = new ListDataProvider<>(new ArrayList<>(gantt.getSteps()));
        Grid<Step> grid = new Grid<>(dataProvider);
        grid.setWidth(400, Unit.PIXELS);
        grid.setHeight(100, Unit.PERCENTAGE);

        Column<Step, ?> c = grid.addColumn(Step::getCaption);
        c.setSortable(false);
        c.setResizable(false);

        gantt.setVerticalScrollDelegateTarget(grid);

        return grid;
    }
 
Example #24
Source File: GridGanttLayout.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public void stepModified(Step step) {
    if (!dataProvider.getItems().contains(step)) {
        dataProvider.getItems().add(step);
    }
    dataProvider.refreshItem(step);
}
 
Example #25
Source File: DemoUI.java    From gantt with Apache License 2.0 5 votes vote down vote up
private SubStep addSubStep(final NativeSelect parentStepSelect, AbstractStep dataSource) {
    SubStep subStep = new SubStep();
    subStep.setCaption(dataSource.getCaption());
    subStep.setCaptionMode(dataSource.getCaptionMode());
    subStep.setStartDate(dataSource.getStartDate());
    subStep.setEndDate(dataSource.getEndDate());
    subStep.setBackgroundColor(dataSource.getBackgroundColor());
    subStep.setDescription(dataSource.getDescription());
    subStep.setProgress(dataSource.getProgress());
    subStep.setShowProgress(dataSource.isShowProgress());
    subStep.setStyleName(dataSource.getStyleName());
    ((Step) parentStepSelect.getValue()).addSubStep(subStep);
    return subStep;
}
 
Example #26
Source File: DemoUI.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void delete(final Window win, final Binder<? extends AbstractStep> binder) {
    AbstractStep step = binder.getBean();
    if (step instanceof SubStep) {
        SubStep substep = (SubStep) step;
        substep.getOwner().removeSubStep(substep);
    } else {
        gantt.removeStep((Step) step);
        if (ganttListener != null) {
            ganttListener.stepDeleted((Step) step);
        }
    }
    win.close();
}
 
Example #27
Source File: GridGanttLayout.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public void stepMoved(Step step, int newStepIndex, int oldStepIndex) {
    if (oldStepIndex < newStepIndex) {
        newStepIndex--;
    }
    dataProvider.getItems().remove(step);
    ((List<Step>) dataProvider.getItems()).add(newStepIndex, step);
    dataProvider.refreshAll();
}
 
Example #28
Source File: DemoUI.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void fillPredecessorCanditatesToSelect(AbstractStep step,
        final NativeSelect<AbstractStep> predecessorSelect) {
    List<AbstractStep> items = new ArrayList<>();
    for (Step stepCanditate : gantt.getSteps()) {
        if (!stepCanditate.equals(step) && stepCanditate instanceof Step) {
            items.add(stepCanditate);
        }
    }
    predecessorSelect.setItems(items);
}
 
Example #29
Source File: DemoUI.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public void buttonClick(ClickEvent event) {
    Step newStep = new Step();
    Date now = new Date();
    newStep.setStartDate(now.getTime());
    newStep.setEndDate(now.getTime() + (7 * 24 * 3600000));
    openStepEditor(newStep);
}
 
Example #30
Source File: TreeGridGanttLayout.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Remove all child steps directed by the TreeGrid's hierarchical data
 * source.
 */
private void removeChildStepRecursively(TreeGrid<Step> grid, Step itemId) {
    if (dataProvider.hasChildren(itemId)) {
        for (Step child : dataProvider.getTreeData().getChildren(itemId)) {
            gantt.removeStep(child);
            removeChildStepRecursively(grid, child);
        }
    }
}