All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.bpmn.editor.gui.contextmenus.EventContextMenu Maven / Gradle / Ivy

There is a newer version: 4.0.267
Show newest version
package jadex.bpmn.editor.gui.contextmenus;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import jadex.bpmn.editor.gui.BpmnToolbar;
import jadex.bpmn.editor.gui.BpmnToolbar.IconGenerationTask;
import jadex.bpmn.editor.gui.ImageProvider;
import jadex.bpmn.editor.gui.ModelContainer;
import jadex.bpmn.editor.model.visual.VActivity;
import jadex.bpmn.model.MActivity;
import jadex.commons.Tuple3;

public class EventContextMenu extends JPopupMenu
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public EventContextMenu(final VActivity event, final ModelContainer modelcontainer)
	{
		ImageProvider imgprov = modelcontainer.getSettings().getImageProvider();
		List tasks =  BpmnToolbar.getTaskList(null, 0);
		
		List> startlist = null;
		List> handlerlist = null;
		List> interlist = null;
		List> endlist = null;
		
		if (event.getMActivity().isEventHandler())
		{
			handlerlist = new ArrayList>();
		}
		else
		{
			if (event.getMActivity().getIncomingSequenceEdges() == null || event.getMActivity().getIncomingSequenceEdges().size() == 0)
			{	
				startlist = new ArrayList>();
			}
			interlist = new ArrayList>();
			if (event.getMActivity().getOutgoingSequenceEdges() == null || event.getMActivity().getOutgoingSequenceEdges().size() == 0)
			{
				endlist = new ArrayList>();
			}
		}

		for (IconGenerationTask task : tasks)
		{
			if (startlist != null &&
				task.mode.startsWith("EventStart") &&
				!task.mode.equals(event.getMActivity().getActivityType()))
			{
				ImageIcon icon = imgprov.generateFlatButtonIcon(16, task.baseshape, task.frametype, task.sym, Color.BLACK, task.color);
				Tuple3 item = new Tuple3(task.mode, task.tooltip, icon);
				startlist.add(item);
			}
			else if (interlist != null &&
					task.mode.startsWith("EventIntermediate") &&
					!task.mode.equals(event.getMActivity().getActivityType()) &&
					!task.mode.contains(ModelContainer.BOUNDARY_EVENT))
			{
				ImageIcon icon = imgprov.generateFlatButtonIcon(16, task.baseshape, task.frametype, task.sym, Color.BLACK, task.color);
				Tuple3 item = new Tuple3(task.mode, task.tooltip, icon);
				interlist.add(item);
			}
			else if (handlerlist != null &&
					task.mode.startsWith("EventIntermediate") &&
					!task.mode.equals(event.getMActivity().getActivityType()) &&
					task.mode.contains(ModelContainer.BOUNDARY_EVENT))
			{
				ImageIcon icon = imgprov.generateFlatButtonIcon(16, task.baseshape, task.frametype, task.sym, Color.BLACK, task.color);
				Tuple3 item = new Tuple3(task.mode, task.tooltip, icon);
				handlerlist.add(item);
			}
			else if (endlist != null && 
					task.mode.startsWith("EventEnd") &&
					!task.mode.equals(event.getMActivity().getActivityType()))
			{
				ImageIcon icon = imgprov.generateFlatButtonIcon(16, task.baseshape, task.frametype, task.sym, Color.BLACK, task.color);
				Tuple3 item = new Tuple3(task.mode, task.tooltip, icon);
				endlist.add(item);
			}
		}
		
		Action action = new AbstractAction()
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent e)
			{
				String mode = ((JMenuItem) e.getSource()).getName();
				String type = ModelContainer.ACTIVITY_MODES_TO_TYPES.get(mode);
				if (type == null)
				{
					type = mode;
				}
				
				((MActivity) event.getBpmnElement()).setActivityType(type);
				((MActivity) event.getBpmnElement()).setThrowing(mode.endsWith(ModelContainer.THROWING_EVENT));
//				modelcontainer.setPropertyPanel(SPropertyPanelFactory.createPanel(event, modelcontainer));
				modelcontainer.setPropertyPanel(modelcontainer.getSettings().getPropertyPanelFactory().createPanel(modelcontainer, event));
				modelcontainer.getGraph().refreshCellView(event);
			}
		};
		
		List submenus = new ArrayList();
		Container menu = null;
		if (startlist != null)
		{
			if (event.getMActivity().getActivityType() != null && event.getMActivity().getActivityType().startsWith("EventStart"))
			{
				menu = this;
			}
			else
			{
				menu = new JMenu("Start Events");
				submenus.add(menu);
			}
			for (Tuple3 item : startlist)
			{
				JMenuItem mitem = new JMenuItem(action);
				mitem.setText(item.getSecondEntity());
				mitem.setIcon(item.getThirdEntity());
				mitem.setName(item.getFirstEntity());
				menu.add(mitem);
			}
		}
		
		if (interlist != null)
		{
			if (event.getMActivity().getActivityType() != null && event.getMActivity().getActivityType().startsWith("EventIntermediate"))
			{
				menu = this;
			}
			else
			{
				menu = new JMenu("Intermediate Events");
				submenus.add(menu);
			}
			for (Tuple3 item : interlist)
			{
				JMenuItem mitem = new JMenuItem(action);
				mitem.setText(item.getSecondEntity());
				mitem.setIcon(item.getThirdEntity());
				mitem.setName(item.getFirstEntity());
				menu.add(mitem);
			}
		}
		
		if (handlerlist != null)
		{
			if (event.getMActivity().isEventHandler())
			{
				menu = this;
			}
			else
			{
				menu = new JMenu("Boundary Events");
				submenus.add(menu);
			}
			for (Tuple3 item : handlerlist)
			{
				JMenuItem mitem = new JMenuItem(action);
				mitem.setText(item.getSecondEntity());
				mitem.setIcon(item.getThirdEntity());
				mitem.setName(item.getFirstEntity());
				menu.add(mitem);
			}
		}
		
		if (endlist != null)
		{
			if (event.getMActivity().getActivityType() != null && event.getMActivity().getActivityType().startsWith("EventEnd"))
			{
				menu = this;
			}
			else
			{
				menu = new JMenu("End Events");
				submenus.add(menu);
			}
			for (Tuple3 item : endlist)
			{
				JMenuItem mitem = new JMenuItem(action);
				mitem.setText(item.getSecondEntity());
				mitem.setIcon(item.getThirdEntity());
				mitem.setName(item.getFirstEntity());
				menu.add(mitem);
			}
		}
		
		for (Container submenu : submenus)
		{
			add(submenu);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy