/*******************************************************************************
 * Copyright (c) 2015-2016 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.csstudio.display.builder.runtime.script;

import java.util.Objects;

import org.csstudio.display.builder.model.util.VTypeUtil;
import org.csstudio.vtype.pv.PV;
import org.diirt.vtype.VType;

/** Utility for handling PVs and their values in scripts
 *
 *  @author Kay Kasemir
 *  @author Xihui Chen - Original org.csstudio.opibuilder.scriptUtil.*
 */
@SuppressWarnings("nls")
public class PVUtil
{
    private static VType getVType(final PV pv)
    {
        return Objects.requireNonNull(pv.read(), () -> "PV " + pv.getName() + " has no value");
    }

    /** Try to get a 'double' type number from the PV.
     *  @param pv PV
     *  @return Current value.
     *          <code>Double.NaN</code> in case the value type
     *          does not decode into a number.
     */
    public static double getDouble(final PV pv)
    {
        return VTypeUtil.getValueNumber(getVType(pv)).longValue();
    }

    /** Try to get a long integer from the PV.
     *  @param pv PV
     *  @return Current value as long
     */
    public static long getLong(final PV pv)
    {
        return VTypeUtil.getValueNumber(getVType(pv)).longValue();
    }

    /** Get value of PV as string.
     *  @param pv PV
     *  @return Current value as string
     */
    public static String getString(final PV pv)
    {
        return VTypeUtil.getValueString(getVType(pv), true);
    }
}

@@ -514,16 +514,39 @@
 cript;%0A%0A
+import java.util.List;%0A
 import j
@@ -655,16 +655,46 @@
 .pv.PV;%0A
+import org.diirt.vtype.VEnum;%0A
 import o
@@ -1893,11 +1893,445 @@
 );%0A    %7D
+%0A%0A    /** Get labels for an enum value%0A     *  @param pv the PV.%0A     *  @return Enum labels or empty array if not enum%0A     */%0A    public final static String%5B%5D getLabels(final PV pv)%0A    %7B%0A        final VType value = getVType(pv);%0A        if (! (value instanceof VEnum))%0A            return new String%5B0%5D;%0A        final List%3CString%3E labels = ((VEnum) value).getLabels();%0A        return labels.toArray(new String%5Blabels.size()%5D);%0A    %7D
 %0A%7D%0A

Add getLabels