| /*=============================================================================# |
| # Copyright (c) 2009, 2021 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.ecommons.ui.actions; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.core.commands.IHandler2; |
| |
| |
| /** |
| * Utility to manage the command handler of a service layer (view, dialog, etc.). |
| */ |
| public class HandlerCollection { |
| |
| |
| private final Map<String, IHandler2> handlers= new HashMap<>(); |
| |
| |
| public HandlerCollection() { |
| } |
| |
| |
| public void add(final String commandId, final IHandler2 handler) { |
| if (commandId == null || handler == null) { |
| throw new NullPointerException(); |
| } |
| this.handlers.put(commandId, handler); |
| } |
| |
| public IHandler2 get(final String commandId) { |
| return this.handlers.get(commandId); |
| } |
| |
| public void update(final Object evaluationContext) { |
| for (final IHandler2 handler : this.handlers.values()) { |
| handler.setEnabled(evaluationContext); |
| } |
| } |
| |
| |
| public void dispose() { |
| for (final IHandler2 handler : this.handlers.values()) { |
| handler.dispose(); |
| } |
| this.handlers.clear(); |
| } |
| |
| } |