Search in sources :

Example 16 with RuntimePV

use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.

the class ArrayPVDispatcherTest method testStringArray.

/**
 * Test double-typed array PV
 */
@Test
public void testStringArray() throws Exception {
    final RuntimePV array_pv = PVFactory.getPV("loc://an_array(\"One\", \"Two\", \"Three\")");
    final AtomicReference<List<RuntimePV>> element_pvs = new AtomicReference<>();
    final CountDownLatch got_element_pvs = new CountDownLatch(1);
    // Listener to the ArrayPVDispatcher
    final Listener dispatch_listener = new Listener() {

        @Override
        public void arrayChanged(final List<RuntimePV> pvs) {
            element_pvs.set(pvs);
            got_element_pvs.countDown();
        }
    };
    final ArrayPVDispatcher dispatcher = new ArrayPVDispatcher(array_pv, "elementA247FE_", dispatch_listener);
    // Await initial set of per-element PVs
    got_element_pvs.await();
    assertThat(VTypeUtil.getValueString(element_pvs.get().get(0).read(), false), equalTo("One"));
    assertThat(VTypeUtil.getValueString(element_pvs.get().get(1).read(), false), equalTo("Two"));
    assertThat(VTypeUtil.getValueString(element_pvs.get().get(2).read(), false), equalTo("Three"));
    // Change array -> Observe update of per-element PV
    System.out.println("Updating array");
    array_pv.write(new String[] { "Uno", "Due", "Another", "Vier" });
    dump(element_pvs.get());
    assertThat(VTypeUtil.getValueString(element_pvs.get().get(0).read(), false), equalTo("Uno"));
    assertThat(VTypeUtil.getValueString(element_pvs.get().get(3).read(), false), equalTo("Vier"));
    // Change per-element PV -> Observe update of array
    System.out.println("Updating per-element PV for element [2]");
    element_pvs.get().get(2).write("Hello");
    final List<String> array_value = ((VStringArray) array_pv.read()).getData();
    System.out.println("Array: " + array_value);
    assertThat(array_value.get(2), equalTo("Hello"));
    // Close dispatcher
    dispatcher.close();
    // Close the array PV
    PVFactory.releasePV(array_pv);
}
Also used : ArrayPVDispatcher(org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) Listener(org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher.Listener) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) VStringArray(org.diirt.vtype.VStringArray) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 17 with RuntimePV

use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.

the class PVNameToValueBinding method disconnect.

private void disconnect() {
    final RuntimePV pv = pv_ref.getAndSet(null);
    if (pv == null)
        return;
    pv.removeListener(listener);
    PVFactory.releasePV(pv);
    runtime.removePV(pv);
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV)

Example 18 with RuntimePV

use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.

the class TableWidgetRuntime method start.

@Override
public void start() throws Exception {
    super.start();
    // Connect selection info PV
    final String selection_pv_name = widget.propSelectionPV().getValue();
    if (!selection_pv_name.isEmpty()) {
        logger.log(Level.FINER, "Connecting {0} to {1}", new Object[] { widget, selection_pv_name });
        try {
            final RuntimePV pv = PVFactory.getPV(selection_pv_name);
            addPV(pv);
            widget.runtimePropSelection().addPropertyListener(selection_listener);
            selection_pv = pv;
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Error connecting PV " + selection_pv_name, ex);
        }
    }
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV)

Example 19 with RuntimePV

use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.

the class TableWidgetRuntime method stop.

@Override
public void stop() {
    // Disconnect selection info PV
    final RuntimePV pv = selection_pv;
    selection_pv = null;
    if (pv != null) {
        widget.runtimePropSelection().removePropertyListener(selection_listener);
        removePV(pv);
        PVFactory.releasePV(pv);
    }
    super.stop();
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV)

Example 20 with RuntimePV

use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.

the class DataBrowserWidgetRuntime method start.

@Override
public void start() throws Exception {
    super.start();
    String pv_name = widget.propSelectionValuePVName().getValue();
    if (!pv_name.isEmpty())
        pv_name = MacroHandler.replace(widget.getEffectiveMacros(), pv_name);
    if (!pv_name.isEmpty()) {
        final RuntimePV pv = PVFactory.getPV(pv_name);
        addPV(pv);
        selection_pv = pv;
        db_model_listener = new ModelSampleSelectionListener();
        widget.getDataBrowserModel().addListener(db_model_listener);
    }
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV)

Aggregations

RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)21 CountDownLatch (java.util.concurrent.CountDownLatch)6 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)6 List (java.util.List)5 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 WidgetPropertyListener (org.csstudio.display.builder.model.WidgetPropertyListener)4 ArrayPVDispatcher (org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher)4 VType (org.diirt.vtype.VType)4 Test (org.junit.Test)4 Listener (org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher.Listener)3 Collection (java.util.Collection)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Level (java.util.logging.Level)2 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)2 VTypeUtil (org.csstudio.display.builder.model.util.VTypeUtil)2 ROIWidgetProperty (org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty)2