Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The MIT License
*
* Copyright (c) 2009-2023 PrimeTek Informatics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.primefaces.component.timeline;
import java.io.IOException;
import java.io.Serializable;
import java.time.ZoneId;
import java.util.*;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import org.primefaces.PrimeFaces;
import org.primefaces.model.timeline.TimelineEvent;
import org.primefaces.model.timeline.TimelineGroup;
import org.primefaces.model.timeline.TimelineModel;
import org.primefaces.util.CalendarUtils;
import org.primefaces.util.ComponentUtils;
import org.primefaces.util.EscapeUtils;
import org.primefaces.util.FastStringWriter;
public class DefaultTimelineUpdater extends TimelineUpdater implements PhaseListener {
private static final long serialVersionUID = 20130317L;
private static final Logger LOGGER = Logger.getLogger(DefaultTimelineUpdater.class.getName());
private String widgetVar;
private List crudOperationDatas;
enum CrudOperation {
ADD,
UPDATE,
DELETE,
SELECT,
CLEAR
}
@Override
public void add(TimelineEvent event) {
if (event == null) {
return;
}
checkCrudOperationDataList();
crudOperationDatas.add(new CrudOperationData(CrudOperation.ADD, event));
}
@Override
public void update(TimelineEvent event) {
if (event == null) {
return;
}
checkCrudOperationDataList();
crudOperationDatas.add(new CrudOperationData(CrudOperation.UPDATE, event));
}
@Override
public void delete(String id) {
checkCrudOperationDataList();
crudOperationDatas.add(new CrudOperationData(CrudOperation.DELETE, id));
}
@Override
public void select(String id) {
checkCrudOperationDataList();
crudOperationDatas.add(new CrudOperationData(CrudOperation.SELECT, id));
}
@Override
public void clear() {
checkCrudOperationDataList();
crudOperationDatas.add(new CrudOperationData(CrudOperation.CLEAR));
}
@Override
public PhaseId getPhaseId() {
return PhaseId.ANY_PHASE;
}
@Override
public void beforePhase(PhaseEvent event) {
if (PhaseId.APPLY_REQUEST_VALUES.equals(event.getPhaseId())) {
populateTimelineUpdater(event.getFacesContext());
}
else if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId())) {
processCrudOperations(event.getFacesContext());
}
}
private void populateTimelineUpdater(FacesContext context) {
Map map = (Map) context.getAttributes().get(TimelineUpdater.class.getName());
if (map == null) {
map = new HashMap<>();
context.getAttributes().put(TimelineUpdater.class.getName(), map);
}
if (!map.containsKey(widgetVar)) {
map.put(widgetVar, this);
}
}
private void processCrudOperations(FacesContext context) {
if (crudOperationDatas == null) {
return;
}
StringBuilder sb = new StringBuilder();
Timeline timeline = (Timeline) context.getViewRoot().findComponent(id);
TimelineRenderer timelineRenderer = ComponentUtils.getUnwrappedRenderer(
context,
Timeline.COMPONENT_FAMILY,
Timeline.DEFAULT_RENDERER);
TimelineModel