407 lines
8.0 KiB
Java
Executable File
407 lines
8.0 KiB
Java
Executable File
package org.eclipse.uml2.diagram.clazz.providers;
|
|
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import org.eclipse.core.runtime.IProgressMonitor;
|
|
import org.eclipse.core.runtime.IStatus;
|
|
import org.eclipse.emf.ecore.EObject;
|
|
import org.eclipse.emf.transaction.TransactionalEditingDomain;
|
|
import org.eclipse.emf.transaction.util.TransactionUtil;
|
|
import org.eclipse.emf.validation.model.IClientSelector;
|
|
import org.eclipse.emf.validation.service.IBatchValidator;
|
|
import org.eclipse.emf.validation.service.ITraversalStrategy;
|
|
import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
|
|
import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
|
|
import org.eclipse.gmf.runtime.notation.View;
|
|
import org.eclipse.jface.action.IAction;
|
|
import org.eclipse.uml2.diagram.clazz.edit.parts.PackageEditPart;
|
|
import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin;
|
|
import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry;
|
|
import org.eclipse.uml2.diagram.clazz.part.ValidateAction;
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public class UMLValidationProvider extends AbstractContributionItemProvider {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
private static boolean constraintsActive = false;
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static boolean shouldConstraintsBePrivate() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
protected IAction createAction(String actionId,
|
|
IWorkbenchPartDescriptor partDescriptor) {
|
|
if (ValidateAction.VALIDATE_ACTION_KEY.equals(actionId)) {
|
|
return new ValidateAction(partDescriptor);
|
|
}
|
|
return super.createAction(actionId, partDescriptor);
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static void runWithConstraints(View view, Runnable op) {
|
|
final Runnable fop = op;
|
|
Runnable task = new Runnable() {
|
|
|
|
public void run() {
|
|
try {
|
|
constraintsActive = true;
|
|
fop.run();
|
|
} finally {
|
|
constraintsActive = false;
|
|
}
|
|
}
|
|
};
|
|
TransactionalEditingDomain txDomain = TransactionUtil
|
|
.getEditingDomain(view);
|
|
if (txDomain != null) {
|
|
try {
|
|
txDomain.runExclusive(task);
|
|
} catch (Exception e) {
|
|
UMLDiagramEditorPlugin.getInstance().logError(
|
|
"Validation action failed", e); //$NON-NLS-1$
|
|
}
|
|
} else {
|
|
task.run();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
static boolean isInDefaultEditorContext(Object object) {
|
|
if (shouldConstraintsBePrivate() && !constraintsActive) {
|
|
return false;
|
|
}
|
|
if (object instanceof View) {
|
|
return constraintsActive
|
|
&& PackageEditPart.MODEL_ID.equals(UMLVisualIDRegistry
|
|
.getModelID((View) object));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
static final Map semanticCtxIdMap = new HashMap();
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx1 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx2 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx3 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx4 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx5 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx6 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx7 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx8 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx9 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx10 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx11 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx12 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx13 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static class DefaultCtx14 implements IClientSelector {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean selects(Object object) {
|
|
return isInDefaultEditorContext(object);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public static ITraversalStrategy getNotationTraversalStrategy(
|
|
IBatchValidator validator) {
|
|
return new CtxSwitchStrategy(validator);
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
private static class CtxSwitchStrategy implements ITraversalStrategy {
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
private ITraversalStrategy defaultStrategy;
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
private String currentSemanticCtxId;
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
private boolean ctxChanged = true;
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
private EObject currentTarget;
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
private EObject preFetchedNextTarget;
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
CtxSwitchStrategy(IBatchValidator validator) {
|
|
this.defaultStrategy = validator.getDefaultTraversalStrategy();
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public void elementValidated(EObject element, IStatus status) {
|
|
defaultStrategy.elementValidated(element, status);
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean hasNext() {
|
|
return defaultStrategy.hasNext();
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public boolean isClientContextChanged() {
|
|
if (preFetchedNextTarget == null) {
|
|
preFetchedNextTarget = next();
|
|
prepareNextClientContext(preFetchedNextTarget);
|
|
}
|
|
return ctxChanged;
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public EObject next() {
|
|
EObject nextTarget = preFetchedNextTarget;
|
|
if (nextTarget == null) {
|
|
nextTarget = defaultStrategy.next();
|
|
}
|
|
this.preFetchedNextTarget = null;
|
|
return this.currentTarget = nextTarget;
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
public void startTraversal(Collection traversalRoots,
|
|
IProgressMonitor monitor) {
|
|
defaultStrategy.startTraversal(traversalRoots, monitor);
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
private void prepareNextClientContext(EObject nextTarget) {
|
|
if (nextTarget != null && currentTarget != null) {
|
|
if (nextTarget instanceof View) {
|
|
String id = ((View) nextTarget).getType();
|
|
String nextSemanticId = id != null
|
|
&& semanticCtxIdMap.containsKey(id) ? id : null;
|
|
if ((currentSemanticCtxId != null && !currentSemanticCtxId
|
|
.equals(nextSemanticId))
|
|
|| (nextSemanticId != null && !nextSemanticId
|
|
.equals(currentSemanticCtxId))) {
|
|
this.ctxChanged = true;
|
|
}
|
|
currentSemanticCtxId = nextSemanticId;
|
|
} else {
|
|
// context of domain model
|
|
this.ctxChanged = currentSemanticCtxId != null;
|
|
currentSemanticCtxId = null;
|
|
}
|
|
} else {
|
|
this.ctxChanged = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @generated
|
|
*/
|
|
static class JavaAudits {
|
|
}
|
|
}
|