package com.onaro.sanscreen.client.view.changes; import com.onaro.sanscreen.server.interfaces.ServerInterfacesUtils; import com.onaro.sanscreen.server.interfaces.data.Context; import com.onaro.sanscreen.types.ObjectType; import javax.swing.event.HyperlinkListener; import javax.swing.event.HyperlinkEvent; import java.text.MessageFormat; import java.text.ParseException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public abstract class ShowPropertiesHyperLink implements HyperlinkListener { public static final String URI_SCHEMA = "local://ShowPropertiesHyperLink"; //$NON-NLS-1$ //should match the pattern in defined in general.link.pattern of the desc.properties file private static final MessageFormat URI_FORMAT = new MessageFormat(URI_SCHEMA + "/?type={0}&id={1}&time={2}"); //$NON-NLS-1$ static Logger logger = LogManager.getLogger(ShowPropertiesHyperLink.class); public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { try { Object[] args = URI_FORMAT.parse(e.getDescription()); ObjectType objectType = ObjectType.getByName((String)args[0]); assert objectType != null : "No such object type '" + args[0] + "' in " + e.getDescription(); //$NON-NLS-1$ //$NON-NLS-2$ if (objectType != null) { long time = Long.parseLong((String)args[2]); Context context = ServerInterfacesUtils.getResponseContext(time); showProperties(args[1], context, objectType); } } catch (ParseException exception) { logger.error("Failed parsing " + e.getDescription() + " - " + exception.getMessage(), exception); //$NON-NLS-1$ //$NON-NLS-2$ } } } public abstract void showProperties(Object objId, Context context, ObjectType objectType); }