001package de.deepamehta.plugins.boxrenderer.canvas; 002 003import de.deepamehta.plugins.topicmaps.ViewmodelCustomizer; 004import de.deepamehta.plugins.topicmaps.service.TopicmapsService; 005 006import de.deepamehta.core.Topic; 007import de.deepamehta.core.model.CompositeValueModel; 008import de.deepamehta.core.osgi.PluginActivator; 009import de.deepamehta.core.service.PluginService; 010import de.deepamehta.core.service.annotation.ConsumesService; 011 012import java.util.logging.Logger; 013 014 015 016public class BoxRendererPlugin extends PluginActivator implements ViewmodelCustomizer { 017 018 // ------------------------------------------------------------------------------------------------------- Constants 019 020 private static final String PROP_COLOR = "dm4.boxrenderer.color"; 021 022 // ---------------------------------------------------------------------------------------------- Instance Variables 023 024 private Logger logger = Logger.getLogger(getClass().getName()); 025 026 // -------------------------------------------------------------------------------------------------- Public Methods 027 028 // *** Hook Implementations *** 029 030 @Override 031 @ConsumesService("de.deepamehta.plugins.topicmaps.service.TopicmapsService") 032 public void serviceArrived(PluginService service) { 033 ((TopicmapsService) service).registerViewmodelCustomizer(this); 034 } 035 036 @Override 037 public void serviceGone(PluginService service) { 038 // Note: unregistering is important. Otherwise the Topicmaps plugin would hold a viewmodel 039 // customizer with a stale dms instance as soon as the Box Renderer is redeployed. 040 // A subsequent storeViewProperties() call (see below) would fail. 041 ((TopicmapsService) service).unregisterViewmodelCustomizer(this); 042 } 043 044 // *** ViewmodelCustomizer Implementation *** 045 046 @Override 047 public void enrichViewProperties(Topic topic, CompositeValueModel viewProps) { 048 if (topic.hasProperty(PROP_COLOR)) { 049 String color = (String) topic.getProperty(PROP_COLOR); 050 viewProps.put(PROP_COLOR, color); 051 } 052 } 053 054 @Override 055 public void storeViewProperties(Topic topic, CompositeValueModel viewProps) { 056 if (viewProps.has(PROP_COLOR)) { 057 String color = viewProps.getString(PROP_COLOR); 058 topic.setProperty(PROP_COLOR, color, false); // addToIndex = false 059 } 060 } 061}