package org.yakindu.sct.statechart.diagram.validation.provider.impl;

import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.xtext.EcoreUtil2;
import org.yakindu.model.sct.statechart.FinalState;
import org.yakindu.model.sct.statechart.InitialState;
import org.yakindu.model.sct.statechart.NamedElement;
import org.yakindu.model.sct.statechart.Region;
import org.yakindu.model.sct.statechart.State;
import org.yakindu.model.sct.statechart.StatechartFactory;
import org.yakindu.model.sct.statechart.StatechartPackage;
import org.yakindu.model.sct.statechart.Vertex;
import org.yakindu.sct.statechart.diagram.extensions.IValidationProvider;
import org.yakindu.sct.statechart.diagram.validation.provider.AbstractJavaValidationProvider;

/**
 * Implementation of {@link IValidationProvider} that contains common
 * {@link ValidationRule}s for Statechart.
 * 
 * @author muelder
 * 
 */
public class StatechartDefaultValidationProvider extends
		AbstractJavaValidationProvider {

	@ValidationRule
	public IStatus validateExactlyOneInitialState(Region region) {
		List<InitialState> initialStates = EcoreUtil2.typeSelect(region.getVertices(), InitialState.class);
		if (initialStates.size() != 1) {
			return createErrorStatus("A region must contain exactly one initial state!");
		}
		return createOKStatus();
	}

	@ValidationRule
	public IStatus validateIncomingTransitions(Vertex vertex) {
		if (vertex.getIncomingTransitions().size() == 0
				&& !(vertex instanceof InitialState)) {
			return createErrorStatus("A state must have at least one incoming transition!");
		}
		return createOKStatus();
	}

	@ValidationRule
	public IStatus validateOutgoingTransitions(State vertex) {
		if (!(vertex instanceof FinalState)) {
			if (vertex.getOutgoingTransitions().size() == 0) {
				return createWarningStatus("A state should have at least one outgoing transition.");
			}
		}
		return createOKStatus();
	}

	@ValidationRule
	public IStatus validateNameIsNotEmpty(State state) {
		if ( !(state instanceof FinalState) && (state.getName() == null || "".equals(state.getName())))
			return createErrorStatus("A state must have a name!");
		return createOKStatus();
	}

}

@@ -323,236 +323,61 @@
 art.
-NamedElement;%0D%0Aimport org.yakindu.model.sct.statechart.Region;%0D%0Aimport org.yakindu.model.sct.statechart.State;%0D%0Aimport org.yakindu.model.sct.statechart.StatechartFactory;%0D%0Aimport org.yakindu.model.sct.statechart.StatechartPackag
+Region;%0D%0Aimport org.yakindu.model.sct.statechart.Stat
 e;%0D%0A
@@ -1229,35 +1229,8 @@
 tus 
-validateIncomingTransitions
 (Ver

Complete - # 210: Basisvalidierung für grafische Modellelemente fertigstellen