]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ProfileActivityBeanRepresentation.java
Support diagram profile activity store/restore in model export/import
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / profile / ProfileActivityBeanRepresentation.java
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 (file)
index 0000000..bb4402f
--- /dev/null
@@ -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> T getValue(RequestProcessor processor, Map<String,Object> 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