/*******************************************************************************
 * This file is part of OpenNMS(R).
 *
 * Copyright (C) 2012-2014 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <license@opennms.org>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

package org.opennms.features.topology.app.internal.operations;

import java.util.List;

import org.opennms.features.topology.api.Constants;
import org.opennms.features.topology.api.GraphContainer;
import org.opennms.features.topology.api.Operation;
import org.opennms.features.topology.api.OperationContext;
import org.opennms.features.topology.api.support.VertexHopGraphProvider;
import org.opennms.features.topology.api.support.VertexHopGraphProvider.FocusNodeHopCriteria;
import org.opennms.features.topology.api.topo.VertexRef;

public class AddFocusVerticesOperation implements Constants, Operation {

	@Override
	public Undoer execute(List<VertexRef> targets, final OperationContext operationContext) {
		if (targets == null || targets.isEmpty()) return null;

		final GraphContainer graphContainer = operationContext.getGraphContainer();

		FocusNodeHopCriteria criteria = VertexHopGraphProvider.getFocusNodeHopCriteriaForContainer(graphContainer);
		for (VertexRef target : targets) {
			criteria.add(target);
		}
		graphContainer.redoLayout();
		return null;
	}

	@Override
	public boolean display(List<VertexRef> targets, OperationContext operationContext) {
		return enabled(targets, operationContext);
	}

	@Override
	public boolean enabled(List<VertexRef> targets, OperationContext operationContext) {
		if (targets == null || targets.isEmpty()) return false;

		final GraphContainer graphContainer = operationContext.getGraphContainer();

		FocusNodeHopCriteria criteria = VertexHopGraphProvider.getFocusNodeHopCriteriaForContainer(graphContainer, false);
		if (criteria == null) {
			return true;
		} else {
			for (VertexRef target : targets) {
				// If any of the vertices are not currently in the criteria, return true
				if (!criteria.contains(target)) {
					return true;
				}
			}
		}

		return false;
	}

	@Override
	public String getId() {
		return "AddFocusVertices";
	}
}

@@ -1675,16 +1675,72 @@
 iteria;%0A
+import org.opennms.features.topology.api.topo.Criteria;%0A
 import o
@@ -2701,32 +2701,352 @@
 phContainer();%0A%0A
+        for (Criteria crit : graphContainer.getCriteria())%7B%0A            if(crit instanceof VertexHopGraphProvider.VertexHopCriteria) %7B%0A                if (((VertexHopGraphProvider.VertexHopCriteria) crit).getVertices().containsAll(targets))%7B%0A                    return false;%0A                %7D%0A            %7D%0A        %7D%0A%0A%0A
 %09%09FocusNodeHopCr
@@ -3326,9 +3326,8 @@
 if (
-!
 crit
@@ -3359,27 +3359,28 @@
 %09%09%09%09%09return 
-tru
+fals
 e;%0A%09%09%09%09%7D%0A%09%09%09
@@ -3391,28 +3391,27 @@
 %7D%0A%0A%09%09return 
-fals
+tru
 e;%0A%09%7D%0A%0A%09@Ove

disable 'Add to Focus' context menu it for nodes in focus