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

The following examples show how to use org.tltv.gantt.client.shared.SubStep. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
Source File: StepComponent.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public void onAddSubStep(SubStep subStep) {
    SubStepComponent component = createSubStepComponent(this, subStep);
    getState(true).subSteps.add(component);
    gantt.subStepMap.put(subStep, component);
    gantt.adjustDatesByAbstractStep(subStep.getOwner());
}
 
Example #14
Source File: StepComponent.java    From gantt with Apache License 2.0 5 votes vote down vote up
/** Detach sub-step component from the UI. */
@Override
public void onRemoveSubStep(SubStep subStep) {
    SubStepComponent component = gantt.subStepMap.get(subStep);
    if (component != null) {
        component.setParent(null);
        getState(true).subSteps.remove(component);
    }
    gantt.subStepMap.remove(subStep);
    gantt.adjustDatesByAbstractStep(subStep.getOwner());
}
 
Example #15
Source File: SubStepComponent.java    From gantt with Apache License 2.0 5 votes vote down vote up
public SubStepComponent(StepComponent stepComponent, SubStep data) {
    if (data.getUid() == null) {
        data.setUid(UUID.randomUUID().toString());
    }
    setParent(stepComponent);
    getState().step = data;
}
 
Example #16
Source File: SubStepComponentFactory.java    From gantt with Apache License 2.0 4 votes vote down vote up
public SubStepComponent create(StepComponent stepComponent, SubStep subStep) {
    return new SubStepComponent(stepComponent, subStep);
}
 
Example #17
Source File: StepComponent.java    From gantt with Apache License 2.0 4 votes vote down vote up
public void addSubStep(StepComponent stepComponent, SubStep subStep) {
    SubStepComponent component = createSubStepComponent(stepComponent,
            subStep);
    getState().subSteps.add(component);

}
 
Example #18
Source File: StepComponent.java    From gantt with Apache License 2.0 4 votes vote down vote up
protected SubStepComponent createSubStepComponent(
        StepComponent stepComponent, SubStep subStep) {
    return this.subStepComponentFactory.create(stepComponent, subStep);
}
 
Example #19
Source File: StorageAdminPanel.java    From sensorhub with Mozilla Public License 2.0 4 votes vote down vote up
protected Gantt buildGantt(IRecordStorageModule<?> storage, IRecordStoreInfo recordInfo)
{
    double[] timeRange = storage.getRecordsTimeRange(recordInfo.getName());
    timeRange[0] -= 3600;
    timeRange[1] += 3600;
    
    Gantt gantt = new Gantt();
    gantt.setWidth(100, Unit.PERCENTAGE);
    gantt.setHeight(130, Unit.PIXELS);
    gantt.setResizableSteps(false);
    gantt.setMovableSteps(false);
    gantt.setStartDate(new Date((long)(timeRange[0]*1000)));
    gantt.setEndDate(new Date((long)(timeRange[1]*1000)));        
    gantt.setYearsVisible(false);
    gantt.setTimelineMonthFormat("MMMM yyyy");
    gantt.setResolution(Resolution.Hour);
    
    Step dataTimeRange = new Step(getPrettyName(recordInfo.getRecordDescription()));
    dataTimeRange.setBackgroundColor("FFFFFF");
    dataTimeRange.setStartDate((long)(timeRange[0]*1000));
    dataTimeRange.setEndDate((long)(timeRange[1]*1000));
            
    // add periods when data is actually available
    Iterator<double[]> clusterTimes = storage.getRecordsTimeClusters(recordInfo.getName());
    while (clusterTimes.hasNext())
    {
        timeRange = clusterTimes.next();
        SubStep clusterPeriod = new SubStep();
        clusterPeriod.setStartDate((long)(timeRange[0]*1000));
        clusterPeriod.setEndDate((long)(timeRange[1]*1000));
        dataTimeRange.addSubStep(clusterPeriod);
        
        clusterPeriod.setDescription(
                new DateTimeFormat().formatIso(timeRange[0], 0) + " / " +
                new DateTimeFormat().formatIso(timeRange[1], 0)
        );
    }        
    
    gantt.addStep(dataTimeRange);
    
    gantt.addClickListener(new Gantt.ClickListener() {
        private static final long serialVersionUID = 1L;
        public void onGanttClick(org.tltv.gantt.Gantt.ClickEvent event) {
            System.out.println("click");
        }
    });
    
    return gantt;
}