Search in sources :

Example 1 with ChecklistItem

use of org.jbpm.examples.checklist.ChecklistItem in project jbpm by kiegroup.

the class DefaultChecklistManager method getTasks.

public List<ChecklistItem> getTasks(long processInstanceId, List<ChecklistContextConstraint> contexts) {
    List<ChecklistItem> items = getTasks(processInstanceId);
    List<ChecklistItem> results = new ArrayList<ChecklistItem>();
    for (ChecklistItem item : items) {
        if (contexts != null) {
            for (ChecklistContextConstraint context : contexts) {
                if (!context.acceptsTask(item)) {
                    break;
                }
            }
        }
        results.add(item);
    }
    return results;
}
Also used : ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) ArrayList(java.util.ArrayList) ChecklistContextConstraint(org.jbpm.examples.checklist.ChecklistContextConstraint)

Example 2 with ChecklistItem

use of org.jbpm.examples.checklist.ChecklistItem in project jbpm by kiegroup.

the class ChecklistExample method printChecklistItems.

private static void printChecklistItems(List<ChecklistItem> items, long processInstanceId) {
    System.out.println("Checklist " + processInstanceId);
    for (ChecklistItem item : items) {
        String orderingNb = item.getOrderingNb();
        if (orderingNb == null) {
            orderingNb = "";
        } else if (orderingNb.endsWith("+")) {
            orderingNb = "*";
        }
        System.out.println(fixedLength(orderingNb, 4) + " " + fixedLength(item.getName(), 20) + " " + fixedLength(item.getStatus().toString(), 10) + " " + fixedLength(item.getActors(), 25) + fixedLength(item.getTaskId() == null ? "" : item.getTaskId() + "", 3));
    }
}
Also used : ChecklistItem(org.jbpm.examples.checklist.ChecklistItem)

Example 3 with ChecklistItem

use of org.jbpm.examples.checklist.ChecklistItem in project jbpm by kiegroup.

the class ChecklistUI method initializeComponent.

private void initializeComponent() {
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    getRootPane().setLayout(new BorderLayout());
    getRootPane().add(panel, BorderLayout.CENTER);
    JButton createButton = new JButton("New...");
    createButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            create();
        }
    });
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(5, 5, 5, 5);
    c.anchor = GridBagConstraints.WEST;
    panel.add(createButton, c);
    contexts = new JComboBox(new DefaultComboBoxModel());
    contexts.setPreferredSize(new Dimension(80, 24));
    contexts.setSize(new Dimension(80, 24));
    c = new GridBagConstraints();
    c.weightx = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(5, 5, 5, 5);
    panel.add(contexts, c);
    contexts.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            refresh();
        }
    });
    JButton refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            refresh();
        }
    });
    c = new GridBagConstraints();
    c.insets = new Insets(5, 5, 5, 5);
    panel.add(refreshButton, c);
    itemTable = new JTable(1, 6);
    itemTable.setRowHeight(35);
    itemTable.setShowHorizontalLines(false);
    itemTable.setShowVerticalLines(false);
    itemTable.addKeyListener(new KeyListener() {

        public void keyTyped(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            ctrl = false;
        }

        public void keyPressed(KeyEvent e) {
            if (e.isControlDown()) {
                ctrl = true;
            }
        }
    });
    itemTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            int index = e.getFirstIndex();
            if (index >= 0 && index < items.size()) {
                ChecklistItem item = items.get(index);
                if (item.getStatus() == Status.Created) {
                    String actorId = getActorId();
                    try {
                        checklistManager.claimTask(actorId, item.getTaskId());
                        if (ctrl) {
                            checklistManager.abortTask(actorId, item.getTaskId());
                        } else {
                            checklistManager.completeTask(actorId, item.getTaskId());
                        }
                    } catch (Throwable t) {
                    // Do nothing
                    }
                    refresh();
                } else if (item.getStatus() == Status.Reserved) {
                    String actorId = getActorId();
                    if (item.getActors().equals(actorId)) {
                        try {
                            if (ctrl) {
                                checklistManager.abortTask(actorId, item.getTaskId());
                            } else {
                                checklistManager.completeTask(actorId, item.getTaskId());
                            }
                        } catch (Throwable t) {
                        // Do nothing
                        }
                        refresh();
                    }
                } else if (item.getStatus() == Status.Optional) {
                    try {
                        checklistManager.selectOptionalTask(item.getName(), Long.valueOf((String) contexts.getSelectedItem()));
                    } catch (Throwable t) {
                        // Do nothing
                        t.printStackTrace();
                    }
                    refresh();
                }
            }
        }
    });
    // TODO:
    // default width of columns
    // icons for state
    // not-editable
    // no selection
    // (scratch for aborted?)
    // replace refresh, create, etc. by icon
    c = new GridBagConstraints();
    c.gridy = 1;
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(5, 5, 5, 5);
    panel.add(itemTable, c);
    JLabel nameLabel = new JLabel("Logged in as:");
    c = new GridBagConstraints();
    c.gridy = 2;
    c.insets = new Insets(5, 5, 5, 5);
    c.anchor = GridBagConstraints.WEST;
    panel.add(nameLabel, c);
    userNameTextField = new JTextField("krisv");
    userNameTextField.setPreferredSize(new Dimension(80, 20));
    userNameTextField.setSize(new Dimension(80, 20));
    c = new GridBagConstraints();
    c.gridy = 2;
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1;
    c.insets = new Insets(5, 5, 5, 5);
    c.anchor = GridBagConstraints.WEST;
    panel.add(userNameTextField, c);
    JButton createItemButton = new JButton("+");
    createItemButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            createNewItem();
        }
    });
    c = new GridBagConstraints();
    c.gridy = 2;
    c.insets = new Insets(5, 5, 5, 5);
    c.anchor = GridBagConstraints.EAST;
    panel.add(createItemButton, c);
    panel.doLayout();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) ListSelectionListener(javax.swing.event.ListSelectionListener) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) KeyListener(java.awt.event.KeyListener)

Example 4 with ChecklistItem

use of org.jbpm.examples.checklist.ChecklistItem in project jbpm by kiegroup.

the class ChecklistUI method createNewItem.

private void createNewItem() {
    if (getSelectedProcessInstance() != null) {
        CreateItemDialog dialog = new CreateItemDialog(this, getActorId());
        dialog.setVisible(true);
        String name = dialog.getItemName();
        if (name != null) {
            ChecklistItem item = getSelectedItem();
            String orderingNb = null;
            if (item != null) {
                orderingNb = item.getOrderingNb() + "+";
            } else {
                if (items.size() == 0) {
                    orderingNb = "1+";
                } else {
                    orderingNb = items.get(items.size() - 1).getOrderingNb() + "+";
                }
            }
            String[] actors = null;
            String actorIds = dialog.getActors();
            if (actorIds.trim().length() == 0) {
                actors = new String[0];
            } else {
                actors = actorIds.split(",");
            }
            String[] groups = null;
            String groupIds = dialog.getGroups();
            if (groupIds.trim().length() == 0) {
                groups = new String[0];
            } else {
                groups = groupIds.split(",");
            }
            checklistManager.addTask(dialog.getActors(), actors, groups, name, orderingNb, getSelectedProcessInstance());
            refresh();
        }
    }
}
Also used : ChecklistItem(org.jbpm.examples.checklist.ChecklistItem)

Example 5 with ChecklistItem

use of org.jbpm.examples.checklist.ChecklistItem in project jbpm by kiegroup.

the class ChecklistExample method main.

public static void main(String[] args) {
    try {
        JBPMHelper.startH2Server();
        JBPMHelper.setupDataSource();
        RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(new UserGroupCallback() {

            public List<String> getGroupsForUser(String userId) {
                List<String> result = new ArrayList<String>();
                if ("actor4".equals(userId)) {
                    result.add("group1");
                }
                return result;
            }

            public boolean existsUser(String arg0) {
                return true;
            }

            public boolean existsGroup(String arg0) {
                return true;
            }
        }).addAsset(KieServices.Factory.get().getResources().newClassPathResource("checklist/SampleChecklistProcess.bpmn"), ResourceType.BPMN2).get();
        ChecklistManager checklistManager = new DefaultChecklistManager(environment);
        long c1 = checklistManager.createContext("org.jbpm.examples.checklist.sample1", "actor1");
        List<ChecklistItem> items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task1");
        ChecklistItem item1 = findChecklistItem(items, "Task1");
        checklistManager.completeTask("actor1", item1.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Adding Extra Task");
        String[] actorIds = new String[] { "actor5" };
        ChecklistItem itemExtra = checklistManager.addTask("actor5", actorIds, new String[0], "TaskExtra", "2+", c1);
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task2");
        ChecklistItem item2 = findChecklistItem(items, "Task2");
        checklistManager.claimTask("actor4", item2.getTaskId());
        checklistManager.completeTask("actor4", item2.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task3b");
        ChecklistItem item3b = findChecklistItem(items, "Task3b");
        checklistManager.claimTask("actor3", item3b.getTaskId());
        checklistManager.completeTask("actor3", item3b.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task3a");
        ChecklistItem item3a = findChecklistItem(items, "Task3a");
        checklistManager.completeTask("actor1", item3a.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Extra Task");
        itemExtra = findChecklistItem(items, "TaskExtra");
        checklistManager.completeTask("actor5", itemExtra.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task4");
        ChecklistItem item4 = findChecklistItem(items, "Task4");
        checklistManager.completeTask("actor1", item4.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(0);
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ChecklistManager(org.jbpm.examples.checklist.ChecklistManager) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) List(java.util.List) ArrayList(java.util.ArrayList) UserGroupCallback(org.kie.api.task.UserGroupCallback)

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