X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Factions%2FValidateMappingHandler.java;h=8ed33bf59570423948f443067ff487150e8e2897;hb=HEAD;hp=2bc74652d58c0e121c75f826374cb88605cd9eaf;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ValidateMappingHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ValidateMappingHandler.java index 2bc74652d..8ed33bf59 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ValidateMappingHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ValidateMappingHandler.java @@ -1,82 +1,82 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.ui.actions; - -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.PlatformUI; -import org.simantics.Simantics; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.validation.ValidateMapping; -import org.simantics.structural.stubs.StructuralResource2; -import org.simantics.structural.ui.modelBrowser.nodes.CompositeNode; - -public class ValidateMappingHandler extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection(); - - if (!selection.isEmpty() && selection instanceof StructuredSelection) { - final Set compositesToTest = new HashSet(); - - final List elements = ((StructuredSelection) selection).toList(); - for (Object element : elements) { - if (element instanceof IAdaptable) { - Resource node = (Resource) ((IAdaptable) element).getAdapter(Resource.class); - if (node != null) { - compositesToTest.add(node); - } - } - } - - Simantics.getSession().asyncRequest(new ReadRequest() { - @Override - public void run(ReadGraph graph) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - StructuralResource2 STR = StructuralResource2.getInstance(graph); - - // Try to test all child composites also. - Deque toBeChecked = new ArrayDeque(compositesToTest); - while (!toBeChecked.isEmpty()) { - Resource check = toBeChecked.poll(); - - for (Resource child : graph.syncRequest(new ObjectsWithType(check, L0.ConsistsOf, STR.Composite))) { - if (compositesToTest.add(child)) - toBeChecked.offer(child); - } - } - - for (Resource composite : compositesToTest) - graph.syncRequest(new ValidateMapping(composite)); - } - }); - } - return null; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.actions; + +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.PlatformUI; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.validation.ValidateMapping; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural.ui.modelBrowser.nodes.CompositeNode; + +public class ValidateMappingHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection(); + + if (!selection.isEmpty() && selection instanceof StructuredSelection) { + final Set compositesToTest = new HashSet(); + + final List elements = ((StructuredSelection) selection).toList(); + for (Object element : elements) { + if (element instanceof IAdaptable) { + Resource node = (Resource) ((IAdaptable) element).getAdapter(Resource.class); + if (node != null) { + compositesToTest.add(node); + } + } + } + + Simantics.getSession().asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + + // Try to test all child composites also. + Deque toBeChecked = new ArrayDeque(compositesToTest); + while (!toBeChecked.isEmpty()) { + Resource check = toBeChecked.poll(); + + for (Resource child : graph.syncRequest(new ObjectsWithType(check, L0.ConsistsOf, STR.Composite))) { + if (compositesToTest.add(child)) + toBeChecked.offer(child); + } + } + + for (Resource composite : compositesToTest) + graph.syncRequest(new ValidateMapping(composite)); + } + }); + } + return null; + } + +}