X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.model%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fmodel%2Fdnd%2FDndBrowseContext.java;h=3f36e61f78bbeea819e4d93750318d3d12cb8225;hp=afd3773e717491dcfa176418954e501dd076b140;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/dnd/DndBrowseContext.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/dnd/DndBrowseContext.java index afd3773e7..3f36e61f7 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/dnd/DndBrowseContext.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/dnd/DndBrowseContext.java @@ -1,96 +1,96 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 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.browsing.ui.model.dnd; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; - -import org.eclipse.swt.dnd.DND; -import org.simantics.browsing.ui.BuiltinKeys; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.model.InvalidContribution; -import org.simantics.browsing.ui.model.nodetypes.EntityNodeType; -import org.simantics.browsing.ui.model.nodetypes.NodeType; -import org.simantics.browsing.ui.model.nodetypes.OrderedNodeTypeMultiMap; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.viewpoint.ontology.ViewpointResource; - -public class DndBrowseContext { - OrderedNodeTypeMultiMap dropActionContributions = new OrderedNodeTypeMultiMap(); - - private DndBrowseContext() { - } - - public static DndBrowseContext create(ReadGraph g, Collection browseContextResources) throws DatabaseException, InvalidContribution { - ViewpointResource vr = ViewpointResource.getInstance(g); - DndBrowseContext browseContext = new DndBrowseContext(); - for(Resource browseContextResource : findSubcontexts(g, browseContextResources)) { - for(Resource actionContributionResource : - g.getObjects(browseContextResource, vr.BrowseContext_HasDropActionContribution)) { - DropActionContribution.load(g, actionContributionResource, - browseContext.dropActionContributions - ); - } - } - return browseContext; - } - - private static Collection findSubcontexts(ReadGraph g, - Collection browseContexts) throws DatabaseException { - ViewpointResource vr = ViewpointResource.getInstance(g); - HashSet result = new HashSet(browseContexts); - ArrayList stack = new ArrayList(browseContexts); - while(!stack.isEmpty()) { - Resource cur = stack.remove(stack.size()-1); - for(Resource sc : g.getObjects(cur, vr.BrowseContext_Includes)) - if(result.add(sc)) - stack.add(sc); - } - return result; - } - - private static NodeType getNodeType(ReadGraph graph, NodeContext parent) throws DatabaseException { - NodeType nodeType = parent.getConstant(NodeType.TYPE); - if(nodeType == null) { - // TODO remove this code when root of model browser is fixed - Object input = parent.getConstant(BuiltinKeys.INPUT); - if(input instanceof Resource) - nodeType = EntityNodeType.getNodeTypeFor(graph, (Resource)input); - } - return nodeType; - } - - /** - * Returns drop copy action. - */ - public Runnable getAction(ReadGraph graph, NodeContext target, Object source) throws DatabaseException { - return getAction(graph, target, source, DND.DROP_COPY); - } - - /** - * Return drop operation for given operation. @See org.eclipse.swt.dnd.DND - */ - public Runnable getAction(ReadGraph graph, NodeContext target, Object source, int operation) throws DatabaseException { - NodeType nodeType = getNodeType(graph, target); - if(nodeType == null) - return null; - for(DropActionContribution contribution : dropActionContributions.get(graph, nodeType)) { - Runnable action = contribution.getAction(graph, target, source, operation); - if(action != null) - return action; - } - return null; - } -} +/******************************************************************************* + * Copyright (c) 2010, 2011 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.browsing.ui.model.dnd; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; + +import org.eclipse.swt.dnd.DND; +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.model.InvalidContribution; +import org.simantics.browsing.ui.model.nodetypes.EntityNodeType; +import org.simantics.browsing.ui.model.nodetypes.NodeType; +import org.simantics.browsing.ui.model.nodetypes.OrderedNodeTypeMultiMap; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.viewpoint.ontology.ViewpointResource; + +public class DndBrowseContext { + OrderedNodeTypeMultiMap dropActionContributions = new OrderedNodeTypeMultiMap(); + + private DndBrowseContext() { + } + + public static DndBrowseContext create(ReadGraph g, Collection browseContextResources) throws DatabaseException, InvalidContribution { + ViewpointResource vr = ViewpointResource.getInstance(g); + DndBrowseContext browseContext = new DndBrowseContext(); + for(Resource browseContextResource : findSubcontexts(g, browseContextResources)) { + for(Resource actionContributionResource : + g.getObjects(browseContextResource, vr.BrowseContext_HasDropActionContribution)) { + DropActionContribution.load(g, actionContributionResource, + browseContext.dropActionContributions + ); + } + } + return browseContext; + } + + private static Collection findSubcontexts(ReadGraph g, + Collection browseContexts) throws DatabaseException { + ViewpointResource vr = ViewpointResource.getInstance(g); + HashSet result = new HashSet(browseContexts); + ArrayList stack = new ArrayList(browseContexts); + while(!stack.isEmpty()) { + Resource cur = stack.remove(stack.size()-1); + for(Resource sc : g.getObjects(cur, vr.BrowseContext_Includes)) + if(result.add(sc)) + stack.add(sc); + } + return result; + } + + private static NodeType getNodeType(ReadGraph graph, NodeContext parent) throws DatabaseException { + NodeType nodeType = parent.getConstant(NodeType.TYPE); + if(nodeType == null) { + // TODO remove this code when root of model browser is fixed + Object input = parent.getConstant(BuiltinKeys.INPUT); + if(input instanceof Resource) + nodeType = EntityNodeType.getNodeTypeFor(graph, (Resource)input); + } + return nodeType; + } + + /** + * Returns drop copy action. + */ + public Runnable getAction(ReadGraph graph, NodeContext target, Object source) throws DatabaseException { + return getAction(graph, target, source, DND.DROP_COPY); + } + + /** + * Return drop operation for given operation. @See org.eclipse.swt.dnd.DND + */ + public Runnable getAction(ReadGraph graph, NodeContext target, Object source, int operation) throws DatabaseException { + NodeType nodeType = getNodeType(graph, target); + if(nodeType == null) + return null; + for(DropActionContribution contribution : dropActionContributions.get(graph, nodeType)) { + Runnable action = contribution.getAction(graph, target, source, operation); + if(action != null) + return action; + } + return null; + } +}