use of org.jbpm.examples.checklist.ChecklistItem in project jbpm by kiegroup.
the class ChecklistItemFactory method getLoggedChecklistItems.
public static Collection<ChecklistItem> getLoggedChecklistItems(WorkflowProcess process, List<NodeInstanceLog> nodeInstances) {
Map<String, ChecklistItem> result = new HashMap<String, ChecklistItem>();
Map<String, String> relevantNodes = new HashMap<String, String>();
getRelevantNodes(process, relevantNodes);
for (NodeInstanceLog log : nodeInstances) {
String orderingNb = relevantNodes.get(log.getNodeId());
if (orderingNb != null) {
if (log.getType() == NodeInstanceLog.TYPE_EXIT) {
result.put(orderingNb, createChecklistItem(log.getNodeName(), log.getNodeType(), "", orderingNb, 0, log.getProcessId(), Status.Completed));
} else {
if (result.get(orderingNb) == null) {
result.put(orderingNb, createChecklistItem(log.getNodeName(), log.getNodeType(), "", orderingNb, 0, log.getProcessId(), Status.InProgress));
}
}
}
}
return result.values();
}
use of org.jbpm.examples.checklist.ChecklistItem in project jbpm by kiegroup.
the class ChecklistUI method refresh.
private void refresh() {
Long processInstanceId = getSelectedProcessInstance();
if (processInstanceId != null) {
List<ChecklistContextConstraint> contexts = null;
items = checklistManager.getTasks(processInstanceId, contexts);
} else {
items = new ArrayList<ChecklistItem>();
}
DefaultTableModel tableModel = new DefaultTableModel(items.size(), 5);
for (int i = 0; i < items.size(); i++) {
ChecklistItem item = items.get(i);
String orderingNb = item.getOrderingNb();
if (orderingNb == null) {
orderingNb = "";
} else if (orderingNb.endsWith("+")) {
orderingNb = "*";
}
tableModel.setValueAt(item.getStatus(), i, 0);
tableModel.setValueAt("(" + orderingNb + ")", i, 1);
tableModel.setValueAt(item.getName(), i, 2);
tableModel.setValueAt(item.getType(), i, 3);
tableModel.setValueAt(item.getActors(), i, 4);
// tableModel.setValueAt(item.getPriority(), i, 4);
}
itemTable.setModel(tableModel);
itemTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
private static final long serialVersionUID = 6L;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
JLabel label = new JLabel();
if (value != null) {
label.setHorizontalAlignment(JLabel.CENTER);
switch((Status) value) {
case Completed:
label.setIcon(ICONS[0]);
break;
case Aborted:
label.setIcon(ICONS[2]);
break;
case InProgress:
label.setIcon(ICONS[1]);
break;
case Created:
label.setIcon(ICONS[1]);
break;
case Reserved:
label.setIcon(ICONS[1]);
break;
case Ready:
label.setIcon(ICONS[1]);
break;
case Optional:
label.setIcon(ICONS[3]);
break;
case Pending:
break;
default:
break;
}
}
return label;
}
});
itemTable.getColumnModel().getColumn(3).setCellRenderer(new DefaultTableCellRenderer() {
private static final long serialVersionUID = 6L;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
JLabel label = new JLabel();
label.setHorizontalAlignment(JLabel.CENTER);
if (value != null) {
String s = (String) value;
if ("HumanTaskNode".equals(s)) {
label.setIcon(TYPE_ICONS[0]);
} else if ("ActionNode".equals(s)) {
label.setIcon(TYPE_ICONS[1]);
} else if ("SubProcessNode".equals(s)) {
label.setIcon(TYPE_ICONS[2]);
} else if ("WorkItemNode".equals(s)) {
label.setIcon(TYPE_ICONS[3]);
}
}
return label;
}
});
itemTable.getColumnModel().getColumn(0).setPreferredWidth(32);
itemTable.getColumnModel().getColumn(0).setMaxWidth(32);
itemTable.getColumnModel().getColumn(1).setPreferredWidth(40);
itemTable.getColumnModel().getColumn(2).setPreferredWidth(230);
itemTable.getColumnModel().getColumn(3).setPreferredWidth(32);
itemTable.getColumnModel().getColumn(3).setMaxWidth(32);
itemTable.getColumnModel().getColumn(4).setPreferredWidth(120);
}
use of org.jbpm.examples.checklist.ChecklistItem in project jbpm by kiegroup.
the class DefaultChecklistManager method getTasks.
@SuppressWarnings("unchecked")
public List<ChecklistItem> getTasks(long processInstanceId) {
RuntimeEngine runtime = getRuntime();
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
Map<String, ChecklistItem> orderingIds = new HashMap<String, ChecklistItem>();
if (processInstance != null) {
WorkflowProcess process = (WorkflowProcess) ksession.getKieBase().getProcess(processInstance.getProcessId());
Collection<ChecklistItem> result = ChecklistItemFactory.getPendingChecklistItems(process);
result.addAll(ChecklistItemFactory.getLoggedChecklistItems(process, (List<NodeInstanceLog>) runtime.getAuditService().findNodeInstances(processInstance.getId())));
for (ChecklistItem item : result) {
if (item.getOrderingNb() != null && item.getOrderingNb().trim().length() > 0) {
orderingIds.put(item.getOrderingNb(), item);
}
}
}
TaskService taskService = runtime.getTaskService();
List<Long> taskIds = taskService.getTasksByProcessInstanceId(processInstanceId);
List<ChecklistItem> result = new ArrayList<ChecklistItem>();
for (Long taskId : taskIds) {
Task task = taskService.getTaskById(taskId);
if (task != null) {
ChecklistItem item = ChecklistItemFactory.createChecklistItem(task);
if (item.getOrderingNb() != null) {
orderingIds.put(item.getOrderingNb(), item);
} else {
result.add(item);
}
}
}
for (ChecklistItem item : orderingIds.values()) {
result.add(item);
}
Collections.sort(result, new Comparator<ChecklistItem>() {
public int compare(ChecklistItem o1, ChecklistItem o2) {
if (o1.getOrderingNb() != null && o2.getOrderingNb() != null) {
return o1.getOrderingNb().compareTo(o2.getOrderingNb());
} else if (o1.getTaskId() != null && o2.getTaskId() != null) {
return o1.getTaskId().compareTo(o2.getTaskId());
} else {
throw new IllegalArgumentException();
}
}
});
manager.disposeRuntimeEngine(runtime);
return result;
}
Aggregations