// GraphTea Project: http://github.com/graphtheorysoftware/GraphTea
// Copyright (C) 2012 Graph Theory Software Foundation: http://GraphTheorySoftware.com
// Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.plugins.main.select;

import graphtea.graph.atributeset.GraphAttrSet;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.SubGraph;
import graphtea.graph.graph.Vertex;
import graphtea.platform.core.AbstractAction;
import graphtea.platform.core.BlackBoard;
import graphtea.ui.UIUtils;


/**
 * @author Ruzbeh Ebrahimi
 */
public class SelectAll extends AbstractAction {
    public static final String event = UIUtils.getUIEventKey("SelectAll");

    public SelectAll(BlackBoard bb) {
        super(bb);
        listen4Event(event);
        blackboard.setData(Select.EVENT_KEY, new SubGraph());
    }

    public void performAction(String eventName, Object value) {
        GraphModel g = blackboard.getData(GraphAttrSet.name);
        SubGraph sd = getSelection();
        for (Vertex vertex : g) {
//            if (vertex.view.isSelected) {
//                //vertex.view.isSelected = false;
//                sd.vertices.remove(vertex);
//            } else
            sd.vertices.add(vertex);

        }
        for (Edge edge : g.getEdges()) {
//            if (edge.view.isSelected){
//            sd.edges.remove(edge);
//            //edge.view.isSelected=false;
//        }
//        else
            sd.edges.add(edge);

        }
        Select.setSelection(blackboard, sd);
    }

    public SubGraph getSelection() {
        return Select.getSelection(blackboard);
    }
}
