<commit_before>/*******************************************************************************
 * Copyright (c) 2010 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.opibuilder.editparts;

import org.csstudio.simplepv.IPV;
import org.csstudio.ui.util.thread.UIBundlingThread;

/**
 * The connection handler for PV widget. It will set the enable state of the widget
 * based on control PV's connectivity.
 * @author <NAME>
 *
 */
public class PVWidgetConnectionHandler extends ConnectionHandler{


    /**
     * @param editpart the editpart must implemented {@link IPVWidgetEditpart}
     */
    public PVWidgetConnectionHandler(AbstractBaseEditPart editpart) {
        super(editpart);
    }

    @Override
    protected void markWidgetAsDisconnected(IPV pv) {
        super.markWidgetAsDisconnected(pv);
        IPVWidgetEditpart pvWidgetEditpart = (IPVWidgetEditpart) editPart;
        final IPV controlPV = pvWidgetEditpart.getControlPV();
        if(controlPV != null && controlPV == pv){
        UIBundlingThread.getInstance().addRunnable(
                editPart.getRoot().getViewer().getControl().getDisplay(),
                new Runnable() {
                    @Override
                    public void run() {
                        pvWidgetEditpart.setControlEnabled(false);
                    }
                });
        }
    }

//    @Override
//    protected void widgetConnectionRecovered(PV pv) {
//        if(isConnected())
//            return;
//        super.widgetConnectionRecovered(pv);
//        final PV controlPV = ((IPVWidgetEditpart)editPart).getControlPV();
//        if(controlPV != null && controlPV == pv){
//        UIBundlingThread.getInstance().addRunnable(
//                editPart.getRoot().getViewer().getControl().getDisplay(),
//                new Runnable() {
//            public void run() {
//                editPart.getFigure().setEnabled(
//                        editPart.getWidgetModel().isEnabled()
//                        && controlPV.isWriteAllowed());
//            }
//        });
//        }
//<commit_msg>The PVWidget should be disabled by default, and be enabled after, if the PV is not read-only.<commit_after>/*******************************************************************************
 * Copyright (c) 2010 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.opibuilder.editparts;

import org.csstudio.simplepv.IPV;
import org.csstudio.ui.util.thread.UIBundlingThread;

/**
 * The connection handler for PV widget. It will set the enable state of the widget
 * based on control PV's connectivity.
 * @author <NAME>
 *
 */
public class PVWidgetConnectionHandler extends ConnectionHandler{


    /**
     * @param editpart the editpart must implemented {@link IPVWidgetEditpart}
     */
    public PVWidgetConnectionHandler(AbstractBaseEditPart editpart) {
        super(editpart);
    }

    @Override
    protected void markWidgetAsDisconnected(IPV pv) {
        super.markWidgetAsDisconnected(pv);
        disablePVWidget(pv);
    }

    @Override
    protected void markWidgetAsDisconnectedFirstTime(IPV pv) {
        super.markWidgetAsDisconnectedFirstTime(pv);
        disablePVWidget(pv);
    }

    private void disablePVWidget(IPV pv) {
        IPVWidgetEditpart pvWidgetEditpart = (IPVWidgetEditpart) editPart;
        final IPV controlPV = pvWidgetEditpart.getControlPV();
        if(controlPV != null && controlPV == pv){
        UIBundlingThread.getInstance().addRunnable(
                editPart.getRoot().getViewer().getControl().getDisplay(),
                new Runnable() {
                    @Override
                    public void run() {
                        pvWidgetEditpart.setControlEnabled(false);
                    }
                });
        }

    }

//    @Override
//    protected void widgetConnectionRecovered(PV pv) {
//        if(isConnected())
//            return;
//        super.widgetConnectionRecovered(pv);
//        final PV controlPV = ((IPVWidgetEditpart)editPart).getControlPV();
//        if(controlPV != null && controlPV == pv){
//        UIBundlingThread.getInstance().addRunnable(
//                editPart.getRoot().getViewer().getControl().getDisplay(),
//                new Runnable() {
//            public void run() {
//                editPart.getFigure().setEnabled(
//                        editPart.getWidgetModel().isEnabled()
//                        && controlPV.isWriteAllowed());
//            }
//        });
//        }
//
{'fraction_non_alphanumeric': 0.16173608407940834, 'fraction_numerical': 0.003114052160373686, 'mean_word_length': 2.4699527346387575, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2377419', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1261, 'n_words': 300}