Search in sources :

Example 6 with ChecklistItem

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();
}
Also used : NodeInstanceLog(org.kie.api.runtime.manager.audit.NodeInstanceLog) HashMap(java.util.HashMap) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem)

Example 7 with ChecklistItem

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);
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) JLabel(javax.swing.JLabel) ChecklistContextConstraint(org.jbpm.examples.checklist.ChecklistContextConstraint) ChecklistContextConstraint(org.jbpm.examples.checklist.ChecklistContextConstraint) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) Component(java.awt.Component)

Example 8 with ChecklistItem

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;
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess)

Aggregations

ChecklistItem (org.jbpm.examples.checklist.ChecklistItem)8 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 List (java.util.List)2 JLabel (javax.swing.JLabel)2 JTable (javax.swing.JTable)2 ChecklistContextConstraint (org.jbpm.examples.checklist.ChecklistContextConstraint)2 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JButton (javax.swing.JButton)1 JComboBox (javax.swing.JComboBox)1