package transformation.wizards;

import com.nomagic.magicdraw.core.Application;
import com.nomagic.magicdraw.core.Project;
import com.nomagic.magicdraw.ui.actions.DefaultDiagramAction;
import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Diagram;


import java.awt.event.ActionEvent;

public class UMLsec_WizardDiagramAction  extends DefaultDiagramAction {
	
	public UMLsec_WizardDiagramAction()
	{
	super("", "UMLsec model completion check",  null, null);
	}
	
	/**
	 * Overrides the DefaultDiagramAction method. 
	 * Is called when the respective menu element is clicked.
	 * Validates the model and calls the UMLsec diagram completion check.
	 */
	public void actionPerformed(ActionEvent ae) {
		
		Project project = Application.getInstance().getProject();
		Diagram activityDiagram = project.getActiveDiagram().getDiagram();
		
		if (project.getActiveDiagram().getDiagramType().getType().equals("Activity Diagram") == false) {
			javax.swing.JOptionPane.showMessageDialog( null, "Diagram must be an Activity Diagram");
		}
		
		else if (StereotypesHelper.getAppliedStereotypeByString(activityDiagram, "rbac") == null) {
			javax.swing.JOptionPane.showMessageDialog( null, "Diagram must be of sterotype <<rbac>>");
		}
		
		else {
		    new UMLsec_Wizard();
		}
		
	}

}
