X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsymbolcontribution%2FElementSymbolItem.java;h=8a8a796f527234072b7f88db60f65143d8b72b54;hb=refs%2Fchanges%2F38%2F238%2F2;hp=50ad79612b2fabed9d454427327e68d72e9e686e;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/ElementSymbolItem.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/ElementSymbolItem.java index 50ad79612..8a8a796f5 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/ElementSymbolItem.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/ElementSymbolItem.java @@ -1,96 +1,96 @@ -/******************************************************************************* - * 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.diagram.symbolcontribution; - -import org.simantics.db.ReadGraph; -import org.simantics.db.RequestProcessor; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ResourceRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.procedure.Listener; -import org.simantics.db.request.Read; -import org.simantics.diagram.query.DiagramRequests; -import org.simantics.diagram.symbollibrary.ISymbolGroup; -import org.simantics.diagram.symbollibrary.ISymbolItem; -import org.simantics.diagram.synchronization.graph.BasicResources; -import org.simantics.g2d.element.ElementClass; -import org.simantics.g2d.element.handler.StaticSymbol; -import org.simantics.ui.SimanticsUI; -import org.simantics.utils.datastructures.cache.ProvisionException; -import org.simantics.utils.datastructures.hints.IHintObservable; - -/** - * @author Tuukka Lehtonen - */ -public class ElementSymbolItem extends SymbolItem { - - public ElementSymbolItem(Resource item, String name, ISymbolGroup group) { - super( - AdaptableTriple.make( - item, - // Prevents infinite recursion which will happen - // if SymbolGroup is used as group ID. - group instanceof IIdentifiedObject ? ((IIdentifiedObject) group).getId() : group, - // Name is in the identification so that name - // changes refresh the symbol library - name), - name, - group); - } - - public ElementSymbolItem(Resource item, String name, String description, ISymbolGroup group) { - super( - AdaptableTriple.make( - item, - // Prevents infinite recursion which will happen - // if SymbolGroup is used as group ID. - group instanceof IIdentifiedObject ? ((IIdentifiedObject) group).getId() : group, - // Name is in the identification so that name - // changes refresh the symbol library - name), - name, - description, - group); - } - - @Override - public ElementClass getElementClass(IHintObservable hints) { - Resource item = adapt(Resource.class); - RequestProcessor sgrp = SimanticsUI.peekSession(); - if (sgrp == null) - throw new ProvisionException("No RequestProcessor available for querying an ElementClass for resource " + item); - try { - Listener listener = hints.getHint(ISymbolItem.KEY_ELEMENT_CLASS_LISTENER); - ElementClass ec = listener == null - ? sgrp.syncRequest(createRequest(item, hints)) - : sgrp.syncRequest(createRequest(item, hints), listener); - if (ec == null) - throw new ProvisionException("ElementClass query failed, returned null"); - if (!ec.containsClass(StaticSymbol.class)) - throw new ProvisionException("ElementClass " + ec + " does not provide a StaticSymbol handler"); - return ec; - } catch (DatabaseException e) { - throw new ProvisionException(e); - } - } - - private Read createRequest(Resource item, final IHintObservable hints) { - return new ResourceRead(item) { - @Override - public ElementClass perform(ReadGraph graph) throws DatabaseException { - BasicResources.getInstance(graph); - return graph.syncRequest( DiagramRequests.getElementClass(resource, hints) ); - } - }; - } - -} +/******************************************************************************* + * 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.diagram.symbolcontribution; + +import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.diagram.query.DiagramRequests; +import org.simantics.diagram.symbollibrary.ISymbolGroup; +import org.simantics.diagram.symbollibrary.ISymbolItem; +import org.simantics.diagram.synchronization.graph.BasicResources; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.handler.StaticSymbol; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.cache.ProvisionException; +import org.simantics.utils.datastructures.hints.IHintObservable; + +/** + * @author Tuukka Lehtonen + */ +public class ElementSymbolItem extends SymbolItem { + + public ElementSymbolItem(Resource item, String name, ISymbolGroup group) { + super( + AdaptableTriple.make( + item, + // Prevents infinite recursion which will happen + // if SymbolGroup is used as group ID. + group instanceof IIdentifiedObject ? ((IIdentifiedObject) group).getId() : group, + // Name is in the identification so that name + // changes refresh the symbol library + name), + name, + group); + } + + public ElementSymbolItem(Resource item, String name, String description, ISymbolGroup group) { + super( + AdaptableTriple.make( + item, + // Prevents infinite recursion which will happen + // if SymbolGroup is used as group ID. + group instanceof IIdentifiedObject ? ((IIdentifiedObject) group).getId() : group, + // Name is in the identification so that name + // changes refresh the symbol library + name), + name, + description, + group); + } + + @Override + public ElementClass getElementClass(IHintObservable hints) { + Resource item = adapt(Resource.class); + RequestProcessor sgrp = SimanticsUI.peekSession(); + if (sgrp == null) + throw new ProvisionException("No RequestProcessor available for querying an ElementClass for resource " + item); + try { + Listener listener = hints.getHint(ISymbolItem.KEY_ELEMENT_CLASS_LISTENER); + ElementClass ec = listener == null + ? sgrp.syncRequest(createRequest(item, hints)) + : sgrp.syncRequest(createRequest(item, hints), listener); + if (ec == null) + throw new ProvisionException("ElementClass query failed, returned null"); + if (!ec.containsClass(StaticSymbol.class)) + throw new ProvisionException("ElementClass " + ec + " does not provide a StaticSymbol handler"); + return ec; + } catch (DatabaseException e) { + throw new ProvisionException(e); + } + } + + private Read createRequest(Resource item, final IHintObservable hints) { + return new ResourceRead(item) { + @Override + public ElementClass perform(ReadGraph graph) throws DatabaseException { + BasicResources.getInstance(graph); + return graph.syncRequest( DiagramRequests.getElementClass(resource, hints) ); + } + }; + } + +}