/*
 * Copyright 2013 Marcus Behrendt & Robert Friedrichs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */

package de.behrfried.wikianalyzer.wawebapp.client.engine;

import java.util.HashSet;
import java.util.Set;
import com.smartgwt.client.widgets.Canvas;
import de.behrfried.wikianalyzer.util.command.Command;

/**
 * Default implementation for {@link CommandManager}.
 * 
 * @author marcus
 * 
 */
public class CommandManager {

	private final static CommandManager INSTANCE = new CommandManager();

	public static CommandManager get() {
		return INSTANCE;
	}

	/**
	 * Stores {@link Canvas}es with their registered {@link Command}s
	 */
	private final Set<Command> commands = new HashSet<Command>();

	private CommandManager() {}

	/**
	 * {@inheritDoc}
	 */
	public boolean addCommand(final Command command) throws IllegalArgumentException {
		if(command == null) {
			throw new IllegalArgumentException("command == null");
		}
		return this.commands.add(command);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean removeCommand(final Command command) throws IllegalArgumentException {
		if(command == null) {
			throw new IllegalArgumentException("command == null");
		}
		return this.commands.remove(command);
	}

	/**
	 * {@inheritDoc}
	 */
	public void invalidateRequerySuggested() {
		for(final Command command : this.commands) {
			command.raiseCanExecuteChanged();
		}
	}
}

@@ -725,51 +725,8 @@
 et;%0A
-import com.smartgwt.client.widgets.Canvas;%0A
 impo
@@ -788,56 +788,100 @@
 %0A * 
-Default implementation for %7B@link CommandManager
+Singleton class for holding %7B@link Command%7Ds and invoking their %7B@code raiseExecuteChanged()
 %7D.%0A 
@@ -940,16 +940,68 @@
 ager %7B%0A%0A
+%09/**%0A%09 * the Singleton CommandManager instance%0A%09 */%0A
 %09private
@@ -1063,16 +1063,89 @@
 ger();%0A%0A
+%09/**%0A%09 * Returns the Singleton CommandManager instance.%0A%09 * @return%0A%09 */%0A
 %09public 
@@ -1206,17 +1206,17 @@
 /**%0A%09 * 
-S
+s
 tores %7B@
@@ -1224,47 +1224,8 @@
 ink 
-Canvas%7Des with their registered %7B@link 
 Comm
@@ -1299,16 +1299,76 @@
 nd%3E();%0A%0A
+%09/**%0A%09 * Private constructor to prevent instantiation.%0A%09 */%0A
 %09private
@@ -1393,38 +1393,300 @@
 %7B%7D%0A%0A%09/**%0A%09 *
+ Adds the passed
  %7B@
+l
 in
-heritDoc%7D
+k Command%7D to the CommandManager.%0A%09 * @param command the Command to be added to the CommandManager%0A%09 * @return %3Ccode%3Etrue%3C/code%3E if passed Command didn't exist the CommandManager before%0A%09 * @throws IllegalArgumentException if command == %3Ccode%3Enull%3C/code%3E
 %0A%09 */%0A%09publi
@@ -1894,38 +1894,357 @@
 %09%7D%0A%0A%09/**%0A%09 *
+ Removes the passed
  %7B@
+l
 in
-heritDoc%7D
+k Command%7D from the CommandManager.%0A%09 * @param command the Command to be removed from the CommandManager%0A%09 * @return %3Ccode%3Etrue%3C/code%3E if the CommandManager has contained the passed Command and could remove it, otherwise %3Ccode%3Efalse%3C/code%3E%0A%09 * @throws IllegalArgumentException if command == %3Ccode%3Enull%3C/code%3E
 %0A%09 */%0A%09publi
@@ -2467,21 +2467,77 @@
 %09 * 
-%7B@inheritDoc%7D
+Invokes the %7B@code raiseCanExecuteChanged()%7D of each %7B@link Command%7D.
 %0A%09 *

enhance CommandManager