All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
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.
org.ikasan.dashboard.ui.scheduler.component.SchedulerJobSelectGridWidget Maven / Gradle / Ivy
package org.ikasan.dashboard.ui.scheduler.component;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.grid.HeaderRow;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.data.renderer.TemplateRenderer;
import org.ikasan.dashboard.ui.scheduler.listener.SchedulerJobSelectedListener;
import org.ikasan.dashboard.ui.util.DateFormatter;
import org.ikasan.scheduled.job.model.SolrSchedulerJobRecordImpl;
import org.ikasan.scheduled.job.model.SolrSchedulerJobSearchFilterImpl;
import org.ikasan.spec.scheduled.context.model.ContextTemplate;
import org.ikasan.spec.scheduled.job.model.JobConstants;
import org.ikasan.spec.scheduled.job.model.SchedulerJobRecord;
import org.ikasan.spec.scheduled.job.model.SchedulerJobSearchFilter;
import org.ikasan.spec.scheduled.job.service.SchedulerJobService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class SchedulerJobSelectGridWidget extends Div {
private SchedulerJobFilteringGrid schedulerJobFilteringGrid;
private List schedulerJobSelectedListeners = new ArrayList<>();
private Dialog parent;
private String jobType = null;
private SchedulerJobSearchFilter schedulerJobSearchFilter;
private String jobSelectLabel;
private SchedulerJobService schedulerJobService;
private ContextTemplate contextTemplate;
public SchedulerJobSelectGridWidget(SchedulerJobService schedulerJobService, ContextTemplate contextTemplate, Dialog parent
, SchedulerJobSearchFilter schedulerJobSearchFilter, String jobSelectLabel) {
this.schedulerJobSearchFilter = schedulerJobSearchFilter;
this.schedulerJobService = schedulerJobService;
this.contextTemplate = contextTemplate;
this.parent = parent;
this.jobSelectLabel = jobSelectLabel;
init(schedulerJobService, contextTemplate);
}
/**
* Constructor
*/
public SchedulerJobSelectGridWidget(SchedulerJobService schedulerJobService, ContextTemplate contextTemplate, Dialog parent
, String jobSelectLabel) {
this.parent = parent;
this.schedulerJobService = schedulerJobService;
this.contextTemplate = contextTemplate;
this.schedulerJobSearchFilter = new SolrSchedulerJobSearchFilterImpl();
this.jobSelectLabel = jobSelectLabel;
init(schedulerJobService, contextTemplate);
}
private void init(SchedulerJobService schedulerJobService, ContextTemplate contextTemplate) {
this.createGrid(schedulerJobService, contextTemplate);
this.schedulerJobFilteringGrid.init();
H3 label = new H3(this.jobSelectLabel);
label.getElement().getStyle().set("margin-top", "10px");
VerticalLayout layout = new VerticalLayout();
layout.setSizeFull();
layout.setMargin(false);
layout.setSpacing(false);
layout.setPadding(false);
layout.add(label, this.createButtonLayout(), this.schedulerJobFilteringGrid);
this.add(layout);
this.setSizeFull();
}
private void createGrid(SchedulerJobService schedulerJobService, ContextTemplate contextTemplate) {
schedulerJobFilteringGrid = new SchedulerJobFilteringGrid(schedulerJobService, schedulerJobSearchFilter);
schedulerJobFilteringGrid.getElement().getStyle().set("margin-top", "40px");
schedulerJobFilteringGrid.removeAllColumns();
schedulerJobFilteringGrid.setVisible(true);
schedulerJobFilteringGrid.setWidthFull();
schedulerJobFilteringGrid.setHeight("75vh");
schedulerJobFilteringGrid.setContextName(contextTemplate.getName());
schedulerJobFilteringGrid.addColumn(new ComponentRenderer<>(schedulerJobRecord -> {
HorizontalLayout horizontalLayout = new HorizontalLayout();
Text text = new Text(schedulerJobRecord.getJobName());
horizontalLayout.add(text);
return horizontalLayout;
})).setHeader(getTranslation("table-header.job-name", UI.getCurrent().getLocale()))
.setResizable(true)
.setSortable(true)
.setKey("flowName")
.setFlexGrow(3);
schedulerJobFilteringGrid.addColumn(new ComponentRenderer<>(schedulerJobRecord -> {
HorizontalLayout horizontalLayout = new HorizontalLayout();
Text text = new Text(SolrSchedulerJobSearchFilterImpl.JOB_TYPE_MAPPINGS_INVERTED.get(schedulerJobRecord.getType()));
horizontalLayout.add(text);
return horizontalLayout;
})).setHeader(getTranslation("table-header.job-type", UI.getCurrent().getLocale()))
.setResizable(true)
.setSortable(true)
.setKey("type")
.setFlexGrow(2);
this.schedulerJobFilteringGrid.addColumn(TemplateRenderer.of(
"[[item.date]]
")
.withProperty("date",
ikasanSolrDocument -> DateFormatter.instance().getFormattedDate(ikasanSolrDocument.getTimestamp())))
.setHeader(getTranslation("table-header.created-date-time", UI.getCurrent().getLocale()))
.setKey("timestamp")
.setResizable(true)
.setSortable(true)
.setFlexGrow(2);
this.schedulerJobFilteringGrid.addColumn(TemplateRenderer.of(
"[[item.modified]]
")
.withProperty("modified",
ikasanSolrDocument -> DateFormatter.instance().getFormattedDate(ikasanSolrDocument.getModifiedTimestamp())))
.setHeader(getTranslation("table-header.modified-date-time", UI.getCurrent().getLocale()))
.setKey("modifiedTimestamp")
.setResizable(true)
.setSortable(true)
.setFlexGrow(2);
this.schedulerJobFilteringGrid.addColumn(new ComponentRenderer<>(schedulerJobRecord -> {
HorizontalLayout horizontalLayout = new HorizontalLayout();
Text text = new Text(schedulerJobRecord.getModifiedBy());
horizontalLayout.add(text);
return horizontalLayout;
}))
.setResizable(true)
.setHeader(getTranslation("table-header.modified-by", UI.getCurrent().getLocale()))
.setSortable(true)
.setFlexGrow(1);
this.schedulerJobFilteringGrid.addItemDoubleClickListener(event -> {
this.schedulerJobSelectedListeners.forEach(listener -> listener.jobSelected(event.getItem().getJob()));
if(parent != null) {
parent.close();
}
});
HeaderRow hr = schedulerJobFilteringGrid.appendHeaderRow();
Map jobNamesMap = (Map) this.schedulerJobService.findByContext(this.contextTemplate.getName(), -1, -1).getResultList().stream()
.filter(job -> !((SolrSchedulerJobRecordImpl)job).getType().equals(JobConstants.CONTEXT_START_JOB)
&& !((SolrSchedulerJobRecordImpl)job).getType().equals(JobConstants.CONTEXT_TERMINAL_JOB))
.collect(Collectors.toMap(SolrSchedulerJobRecordImpl::getJobName, SolrSchedulerJobRecordImpl::getJobName, (o1, o2) -> o1));
this.schedulerJobFilteringGrid.addComboBoxGridFiltering(hr, schedulerJobSearchFilter::setJobNameFilter
, jobNamesMap.entrySet(), "flowName");
if(this.jobType == null) {
this.schedulerJobFilteringGrid.addSelectGridFiltering(hr, schedulerJobSearchFilter::setJobTypeFilter
, SolrSchedulerJobSearchFilterImpl.JOB_TYPE_MAPPINGS.entrySet(), "type");
}
}
private HorizontalLayout createButtonLayout() {
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.setMargin(false);
buttonLayout.setPadding(false);
buttonLayout.getElement().getStyle().set("position", "absolute");
buttonLayout.getElement().getStyle().set("right", "30px");
buttonLayout.getElement().getStyle().set("margin-top", "0px");
Button refreshButton = this.createRefreshButton();
buttonLayout.add(refreshButton);
return buttonLayout;
}
private Button createRefreshButton() {
Button refreshJobsButton = new Button(getTranslation("button.refresh", UI.getCurrent().getLocale()), VaadinIcon.REFRESH.create());
refreshJobsButton.setIconAfterText(true);
refreshJobsButton.addClickListener(event -> this.schedulerJobFilteringGrid.init());
return refreshJobsButton;
}
public void addSchedulerJobSelectedListener(SchedulerJobSelectedListener listener) {
this.schedulerJobSelectedListeners.add(listener);
}
public void removeSchedulerJobSelectedListener(SchedulerJobSelectedListener listener) {
this.schedulerJobSelectedListeners.remove(listener);
}
}