X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fprofile%2FProfileActivityBeanRepresentation.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fprofile%2FProfileActivityBeanRepresentation.java;h=bb4402f5bed18f083db1b64ba081cf5cebae2582;hb=957ddea830ceb97eab9f358d99a591cafc518d8a;hp=0000000000000000000000000000000000000000;hpb=fca6027f6beef8081d719b078e80b98fb56f7a8a;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ProfileActivityBeanRepresentation.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ProfileActivityBeanRepresentation.java new file mode 100644 index 000000000..bb4402f5b --- /dev/null +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ProfileActivityBeanRepresentation.java @@ -0,0 +1,51 @@ +package org.simantics.diagram.profile; + +import java.util.Map; + +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.SimanticsClipboard.Representation; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Tuukka Lehtonen + * @since 6.08 + */ +public class ProfileActivityBeanRepresentation implements Representation { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProfileActivityBeanRepresentation.class); + + public static Key KEY = new KeyOf(ProfileActivityBean.class, "PROFILE_ACTIVITY_BEAN"); + + private final Resource source; + private ProfileActivityBean bean; + + public ProfileActivityBeanRepresentation(Resource source) { + this.source = source; + } + + @Override + public Key getKey() { + return KEY; + } + + @SuppressWarnings("unchecked") + @Override + public T getValue(RequestProcessor processor, Map hints) { + if (bean == null) { + try { + bean = Profiles.readProfileActivity(processor, source); + } catch (DatabaseException e) { + LOGGER.error("Failed to read profile activity information from model " + source, e); + // Prevent the code from attempting further reads from this source + bean = new ProfileActivityBean(); + } + } + return (T) bean; + } + +} \ No newline at end of file