<commit_before>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 * ################################################################
 */
package org.objectweb.proactive.ic2d.jmxmonitoring.editpart;

import java.util.List;
import java.util.Observable;

import org.eclipse.draw2d.IFigure;
import org.objectweb.proactive.core.util.URIBuilder;
import org.objectweb.proactive.ic2d.jmxmonitoring.data.AbstractData;
import org.objectweb.proactive.ic2d.jmxmonitoring.data.NodeObject;
import org.objectweb.proactive.ic2d.jmxmonitoring.figure.NodeFigure;
import org.objectweb.proactive.ic2d.jmxmonitoring.figure.listener.NodeListener;
import org.objectweb.proactive.ic2d.jmxmonitoring.util.MVCNotification;
import org.objectweb.proactive.ic2d.jmxmonitoring.util.MVCNotificationTag;
import org.objectweb.proactive.ic2d.jmxmonitoring.util.State;


public class NodeEditPart extends AbstractMonitoringEditPart {
    private NodeObject castedModel;
    private NodeFigure castedFigure;

    //
    // -- CONSTRUCTORS -----------------------------------------------
    //
    public NodeEditPart(NodeObject model) {
        super(model);
    }

    //
    // -- PUBLICS METHODS -----------------------------------------------
    //

    /**
     * Convert the result of EditPart.getModel()
     * to NodeObject (the real type of the model).
     * @return the casted model
     */
    @SuppressWarnings("unchecked")
    @Override
    public NodeObject getCastedModel() {
        if (castedModel == null) {
            castedModel = (NodeObject) getModel();
        }
        return castedModel;
    }

    /**
     * Convert the result of EditPart.getFigure()
     * to NodeFigure (the real type of the figure).
     * @return the casted figure
     */
    @SuppressWarnings("unchecked")
    @Override
    public NodeFigure getCastedFigure() {
        if (castedFigure == null) {
            castedFigure = (NodeFigure) getFigure();
        }
        return castedFigure;
    }

    /**
     * This method is called whenever the observed object is changed.
     * It calls the method <code>refresh()</code>.
     * @param o the observable object (instance of AbstractDataObject).
     * @param arg an argument passed to the notifyObservers  method.
     */
    @Override
    //TODO: this method was taken out from a dedicated Thread 
    //which means that the observable (NodeObject) will be blocked
    //on the notifyObservers method.
    public void update(Observable o, Object arg) {
        //final Object param = arg;
        if (!(arg instanceof MVCNotification)) {
            refresh();
            return;
        }

        final MVCNotification notif = (MVCNotification) arg;

        if ((notif.getMVCNotification() == MVCNotificationTag.STATE_CHANGED) &&
            (notif.getData() == State.NOT_MONITORED)) {
            deactivate();
        } else if ((notif.getMVCNotification() == MVCNotificationTag.STATE_CHANGED) &&
            (notif.getData() != State.NOT_MONITORED)) //in this case we know we have changed highlight state
        {
            //method VirtualNodesGroup.getColor(virtualNode vn)
            //returns the color for the virtual node if the virtual node is selected
            //or null if it is not. 
            //if the collor is null, setHighlight(null) colors the figure 
            //node to the default color
            getViewer().getControl().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    getCastedFigure().setHighlight(
                            getMonitoringView().getVirtualNodesGroup().getColor(
                                    getCastedModel().getVirtualNode()));
                    refresh();
                }
            });
        } else {
            getViewer().getControl().getDisplay().syncExec(new Runnable() {
                public void run() {
                    // Refresh only if this editpart is active
                    // remember edit parts are active after activate() is called
                    // and until deactivate() is called.
                    if (NodeEditPart.this.isActive()) {
                        refresh();
                    }
                }
            });
        }
    }

    @Override
    public void refresh() {
        //TODO: this might be costly. Only when we stop monitoring the parent may be null and 
        //we have npe stak in the logs.  
        //                if (this.getParent() == null) {
        //                    return;
        //                }
        // System.out.println("refreshing " + getCastedModel().getName());
        super.refresh();<commit_msg>async refresh<commit_after>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 * ################################################################
 */
package org.objectweb.proactive.ic2d.jmxmonitoring.editpart;

import java.util.List;
import java.util.Observable;

import org.eclipse.draw2d.IFigure;
import org.objectweb.proactive.core.util.URIBuilder;
import org.objectweb.proactive.ic2d.jmxmonitoring.data.AbstractData;
import org.objectweb.proactive.ic2d.jmxmonitoring.data.NodeObject;
import org.objectweb.proactive.ic2d.jmxmonitoring.figure.NodeFigure;
import org.objectweb.proactive.ic2d.jmxmonitoring.figure.listener.NodeListener;
import org.objectweb.proactive.ic2d.jmxmonitoring.util.MVCNotification;
import org.objectweb.proactive.ic2d.jmxmonitoring.util.MVCNotificationTag;
import org.objectweb.proactive.ic2d.jmxmonitoring.util.State;


public class NodeEditPart extends AbstractMonitoringEditPart {
    private NodeObject castedModel;
    private NodeFigure castedFigure;

    //
    // -- CONSTRUCTORS -----------------------------------------------
    //
    public NodeEditPart(NodeObject model) {
        super(model);
    }

    //
    // -- PUBLICS METHODS -----------------------------------------------
    //

    /**
     * Convert the result of EditPart.getModel()
     * to NodeObject (the real type of the model).
     * @return the casted model
     */
    @SuppressWarnings("unchecked")
    @Override
    public NodeObject getCastedModel() {
        if (castedModel == null) {
            castedModel = (NodeObject) getModel();
        }
        return castedModel;
    }

    /**
     * Convert the result of EditPart.getFigure()
     * to NodeFigure (the real type of the figure).
     * @return the casted figure
     */
    @SuppressWarnings("unchecked")
    @Override
    public NodeFigure getCastedFigure() {
        if (castedFigure == null) {
            castedFigure = (NodeFigure) getFigure();
        }
        return castedFigure;
    }

    /**
     * This method is called whenever the observed object is changed.
     * It calls the method <code>refresh()</code>.
     * @param o the observable object (instance of AbstractDataObject).
     * @param arg an argument passed to the notifyObservers  method.
     */
    @Override
    //TODO: this method was taken out from a dedicated Thread 
    //which means that the observable (NodeObject) will be blocked
    //on the notifyObservers method.
    public void update(Observable o, Object arg) {
        //final Object param = arg;
        if (!(arg instanceof MVCNotification)) {
            refresh();
            return;
        }

        final MVCNotification notif = (MVCNotification) arg;

        if ((notif.getMVCNotification() == MVCNotificationTag.STATE_CHANGED) &&
            (notif.getData() == State.NOT_MONITORED)) {
            deactivate();
        } else if ((notif.getMVCNotification() == MVCNotificationTag.STATE_CHANGED) &&
            (notif.getData() != State.NOT_MONITORED)) //in this case we know we have changed highlight state
        {
            //method VirtualNodesGroup.getColor(virtualNode vn)
            //returns the color for the virtual node if the virtual node is selected
            //or null if it is not. 
            //if the collor is null, setHighlight(null) colors the figure 
            //node to the default color
            getViewer().getControl().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    getCastedFigure().setHighlight(
                            getMonitoringView().getVirtualNodesGroup().getColor(
                                    getCastedModel().getVirtualNode()));
                    refresh();
                }
            });
        } else {
            getViewer().getControl().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    // Refresh only if this editpart is active
                    // remember edit parts are active after activate() is called
                    // and until deactivate() is called.
                    if (NodeEditPart.this.isActive()) {
                        refresh();
                    }
                }
            });
        }
    }

    @Override
    public void refresh() {
        //TODO: this might be costly. Only when we stop monitoring the parent may be null and 
        //we have npe stak in the logs.  
        //                if (this.getParent() == null) {
        //                    return;
        //                }
        // System.out.println("refreshing " + getCastedModel().getName());
        super.refresh();
{'fraction_non_alphanumeric': 0.12767070724688237, 'fraction_numerical': 0.005581233103688846, 'mean_word_length': 2.1299126637554586, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5402312', 'n_tokens_mistral': 3040, 'n_tokens_neox': 2903, 'n_words': 900}