| /* |
| * Copyright (c) 2006, 2007 Borland Software Corporation. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Richard Gronback (Borland) - initial API and implementation |
| */ |
| |
| package org.eclipse.gmf.examples.mindmap.rcp.providers; |
| |
| import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| import org.eclipse.emf.validation.model.IClientSelector; |
| import org.eclipse.gmf.examples.mindmap.rcp.edit.parts.MapEditPart; |
| import org.eclipse.gmf.examples.mindmap.rcp.part.MindmapDiagramEditorPlugin; |
| import org.eclipse.gmf.examples.mindmap.rcp.part.MindmapVisualIDRegistry; |
| import org.eclipse.gmf.runtime.notation.View; |
| |
| /** |
| * @generated |
| */ |
| public class MindmapValidationProvider { |
| /** |
| * @generated |
| */ |
| public static boolean shouldConstraintsBePrivate() { |
| return false; |
| } |
| |
| /** |
| * @generated |
| */ |
| private static boolean constraintsActive = false; |
| |
| /** |
| * @generated |
| */ |
| public static void runWithConstraints( |
| TransactionalEditingDomain editingDomain, Runnable operation) { |
| final Runnable op = operation; |
| Runnable task = new Runnable() { |
| public void run() { |
| try { |
| constraintsActive = true; |
| op.run(); |
| } finally { |
| constraintsActive = false; |
| } |
| } |
| }; |
| if (editingDomain != null) { |
| try { |
| editingDomain.runExclusive(task); |
| } catch (Exception e) { |
| MindmapDiagramEditorPlugin.getInstance().logError( |
| "Validation 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 |
| && MapEditPart.MODEL_ID.equals(MindmapVisualIDRegistry |
| .getModelID((View) object)); |
| } |
| return true; |
| } |
| |
| /** |
| * @generated |
| */ |
| public static class DefaultCtx1 implements IClientSelector { |
| /** |
| * @generated |
| */ |
| public boolean selects(Object object) { |
| return isInDefaultEditorContext(object); |
| } |
| } |
| |
| } //MindmapValidationProvider |