jadex.bpmn.runtime.task.UserInteractionTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-kernel-bpmn Show documentation
Show all versions of jadex-kernel-bpmn Show documentation
The Jadex BPMN kernel provides a workflow kernel for the standardized business process modeling notation. The kernel relies on annotated BPMN diagrams, which include detailed execution information.
package jadex.bpmn.runtime.task;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import jadex.bpmn.model.MActivity;
import jadex.bpmn.model.MBpmnModel;
import jadex.bpmn.model.MIdElement;
import jadex.bpmn.model.MParameter;
import jadex.bpmn.model.task.ITask;
import jadex.bpmn.model.task.ITaskContext;
import jadex.bpmn.model.task.annotation.Task;
import jadex.bridge.IComponentStep;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IMonitoringComponentFeature;
import jadex.bridge.service.types.monitoring.IMonitoringEvent;
import jadex.bridge.service.types.monitoring.IMonitoringService.PublishEventLevel;
import jadex.commons.SReflect;
import jadex.commons.SUtil;
import jadex.commons.collection.IndexMap;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.ISubscriptionIntermediateFuture;
import jadex.commons.future.IntermediateDefaultResultListener;
import jadex.commons.gui.future.SwingIntermediateResultListener;
import jadex.commons.transformation.annotations.Classname;
import jadex.javaparser.IParsedExpression;
import jadex.javaparser.javaccimpl.JavaCCExpressionParser;
/**
* Opens a dialog for the task and lets the user enter
* result parameters.
*/
@Task(description="The user interaction task can be used for fetching in parameter values " +
"via an interactive user interface dialog. The task automatically uses all declared " +
"in parameters.")
public class UserInteractionTask implements ITask
{
//-------- attributes --------
/** The dialog. */
protected JDialog dialog;
//-------- ITask interface --------
/**
* Execute the task.
* @param context The accessible values.
* @param instance The process instance executing the task.
* @listener To be notified, when the task has completed.
*/
public IFuture execute(final ITaskContext context, IInternalAccess instance)
{
final Future ret = new Future();
final ISubscriptionIntermediateFuture sub = instance.getComponentFeature0(IMonitoringComponentFeature.class).subscribeToEvents(IMonitoringEvent.TERMINATION_FILTER, false, PublishEventLevel.FINE);
sub.addResultListener(new SwingIntermediateResultListener(new IntermediateDefaultResultListener()
{
public void intermediateResultAvailable(IMonitoringEvent result)
{
if(dialog!=null)
{
dialog.setVisible(false);
}
}
public void commandAvailable(Object command)
{
// ignore timer updates
}
}));
final IExternalAccess exta = instance.getExternalAccess();
MActivity task = context.getModelElement();
final String taskname = task.getName();
// Simple pseudo struct for parameters.
final int NAME = 0;
final int TYPE = 1;
final int VALUE = 2;
final int DIRECTION = 3;
final int NEWVALUE = 4;
IndexMap parameters = task.getParameters();
MIdElement pa = task;
MBpmnModel model = context.getBpmnModel();
while(pa!=null && (parameters==null || parameters.size()==0))
{
pa = model.getParent(pa);
if(pa instanceof MActivity)
{
parameters = ((MActivity)pa).getParameters();
}
}
final List