<commit_before>package org.splevo.ui.views.vpmgraph;

import org.eclipse.jface.action.Action;
import org.eclipse.wb.swt.ResourceManager;
import org.graphstream.graph.Node;
import org.splevo.ui.Activator;

/**
 * Action to filter the single nodes without any relationships from a graph.
 * 
 * This action only manipulates the visible graph by setting or removing the ui.hide attribute from
 * those nodes without any edges.
 * 
 * @author <NAME>
 * 
 */
class FilterSingleNodeAction extends Action {

    private static final String ICON_INACTIVE = "icons/inactive/filter-empty-nodes.png";

    private static final String ICON_ACTIVE = "icons/active/filter-empty-nodes.png";

    /**
     * The vpm graph to manipulate. It is necessary to work with the view and always request the
     * current instance of the graph because this might change during runtime. Otherwise, the action
     * might not manipulate the right graph instance.
     */
    private VPMGraphView vpmGraphView;

    /** The attribute id to hide a node in the view. */
    private static final String NODE_ATTRIBUTE_HIDE = "ui.hide";

    /**
     * Constructor to set the necessary references.
     * 
     * @param vpmGraphView
     *            The graph to manipulate
     */
    public FilterSingleNodeAction(VPMGraphView vpmGraphView) {
        super("Filter Single Nodes Action");
        this.vpmGraphView = vpmGraphView;
        setToolTipText("Show single nodes without relationships");
        setImageDescriptor(ResourceManager.getPluginImageDescriptor(Activator.PLUGIN_ID, ICON_ACTIVE));
    }

    @Override
    public void run() {
        toggleIcon();
        toggleNodes(isChecked());
    }

    /**
     * Toggle the nodes ui.hide attribute. Add or remove the attribute depending on the provided
     * parameter.
     * 
     * @param checked
     *            The parameter to decide about the attribute add/remove.
     */
    private void toggleNodes(boolean checked) {

        if (checked) {
            for (Node currentNode : this.vpmGraphView.getVpmGraph().getNodeSet()) {
                if (currentNode.getDegree() == 0) {
                    currentNode.addAttribute(NODE_ATTRIBUTE_HIDE);
                }
            }
        } else {
            for (Node currentNode : this.vpmGraphView.getVpmGraph().getNodeSet()) {
                if (currentNode.getDegree() == 0) {
                    currentNode.removeAttribute(NODE_ATTRIBUTE_HIDE);
                }
            }
        }
    }

    /**
     * Toggle the action icon depending on it's checked status.
     */
    private void toggleIcon() {
        if (isChecked()) {
            setChecked(false);
            setImageDescriptor(ResourceManager.getPluginImageDescriptor(Activator.PLUGIN_ID, ICON_ACTIVE));
        } else {
            setChecked(true);
            setImageDescriptor(ResourceManager.getPluginImageDescriptor(Activator.PLUGIN_ID, ICON_INACTIVE));
        }
    }
}<commit_msg>SPLEVO-40 VPM Graph Viewer: Add action to filter single nodes Improved code and icon usabilty<commit_after>package org.splevo.ui.views.vpmgraph;

import org.apache.log4j.Logger;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.wb.swt.ResourceManager;
import org.graphstream.graph.Node;
import org.splevo.ui.Activator;

/**
 * Action to filter the single nodes without any relationships from a graph.
 * 
 * This action only manipulates the visible graph by setting or removing the ui.hide attribute from
 * those nodes without any edges.
 * 
 * @author <NAME>
 * 
 */
class FilterSingleNodeAction extends Action {

    /** Path to icon to use for the action. */
    private static final String ICON_ACTIVE = "icons/active/filter-empty-nodes.png";

    /** The logger for this class. */
    private Logger logger = Logger.getLogger(FilterSingleNodeAction.class);

    /**
     * The vpm graph to manipulate. It is necessary to work with the view and always request the
     * current instance of the graph because this might change during runtime. Otherwise, the action
     * might not manipulate the right graph instance.
     */
    private VPMGraphView vpmGraphView;

    /** The attribute id to hide a node in the view. */
    private static final String NODE_ATTRIBUTE_HIDE = "ui.hide";

    /**
     * Constructor to set the necessary references.
     * 
     * @param vpmGraphView
     *            The graph to manipulate
     */
    public FilterSingleNodeAction(VPMGraphView vpmGraphView) {
        super("Filter Single Nodes Action", IAction.AS_CHECK_BOX);
        this.vpmGraphView = vpmGraphView;
        setToolTipText("Show single nodes without relationships");
        setImageDescriptor(ResourceManager.getPluginImageDescriptor(Activator.PLUGIN_ID, ICON_ACTIVE));
        setChecked(false);
    }

    @Override
    public void run() {

        if (this.vpmGraphView.getVpmGraph() == null) {
            logger.warn("No VPMGraph present in VPMGraph view.");
            return;
        }
        toggleNodes();
    }

    /**
     * Toggle the nodes ui.hide attribute. Add or remove the attribute depending on the provided
     * parameter.
     */
    private void toggleNodes() {

        if (isChecked()) {
            for (Node currentNode : this.vpmGraphView.getVpmGraph().getNodeSet()) {
                if (currentNode.getDegree() == 0) {
                    currentNode.addAttribute(NODE_ATTRIBUTE_HIDE);
                }
            }
        } else {
            for (Node currentNode : this.vpmGraphView.getVpmGraph().getNodeSet()) {
                if (currentNode.getDegree() == 0) {
                    currentNode.removeAttribute(NODE_ATTRIBUTE_HIDE);
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08739554317548746, 'fraction_numerical': 0.0012186629526462396, 'mean_word_length': 2.481818181818182, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1697140', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1544, 'n_words': 448}