001/**
002 * 
003 */
004package plugins.kernel.roi.descriptor.property;
005
006import icy.roi.ROI;
007import icy.roi.ROI.ROIGroupId;
008import icy.roi.ROIDescriptor;
009import icy.roi.ROIEvent;
010import icy.roi.ROIEvent.ROIEventType;
011import icy.sequence.Sequence;
012import icy.util.StringUtil;
013
014/**
015 * Group Id descriptor class (see {@link ROIDescriptor})
016 * 
017 * @author Stephane
018 */
019public class ROIGroupIdDescriptor extends ROIDescriptor
020{
021    public static final String ID = "Group id";
022
023    public ROIGroupIdDescriptor()
024    {
025        super(ID, "Group", String.class);
026    }
027
028    @Override
029    public String getDescription()
030    {
031        return "Group id (used for group operation)";
032    }
033
034    @Override
035    public boolean needRecompute(ROIEvent change)
036    {
037        return (change.getType() == ROIEventType.PROPERTY_CHANGED)
038                && (StringUtil.equals(change.getPropertyName(), ROI.PROPERTY_GROUPID));
039    }
040
041    @Override
042    public Object compute(ROI roi, Sequence sequence) throws UnsupportedOperationException
043    {
044        return getGroupId(roi);
045    }
046
047    /**
048     * Returns ROI group id
049     */
050    public static ROIGroupId getGroupId(ROI roi)
051    {
052        if (roi == null)
053            return null;
054
055        return roi.getGroupId();
056    }
057}