001/*
002 * GWTEventService
003 * Copyright (c) 2011 and beyond, strawbill UG (haftungsbeschr?nkt)
004 *
005 * This is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU Lesser General Public License as
007 * published by the Free Software Foundation; either version 3 of
008 * the License, or (at your option) any later version.
009 * Other licensing for GWTEventService may also be possible on request.
010 * Please view the license.txt of the project for more information.
011 *
012 * This software is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this software; if not, write to the Free
019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021 */
022package de.novanic.eventservice.client.event.command;
023
024import de.novanic.eventservice.client.connection.strategy.connector.RemoteEventConnector;
025import de.novanic.eventservice.client.event.domain.Domain;
026import com.google.gwt.user.client.rpc.AsyncCallback;
027
028import java.util.Set;
029
030/**
031 * Deactivates the event listening of the client completely or for a specified domain/context.
032 *
033 * @author sstrohschein
034 *         <br>Date: 27.03.2009
035 *         <br>Time: 23:33:35
036 */
037public class DeactivationCommand extends ServerCallCommand<Void>
038{
039    private Domain myDomain;
040    private Set<Domain> myDomains;
041
042    /**
043     * Creates a DeactivationCommand to deactivate the event listening of the client for a specified domain.
044     * @param aRemoteEventConnector {@link de.novanic.eventservice.client.connection.strategy.connector.RemoteEventConnector}
045     * @param aDomain domain which should be deactivated for event listening
046     * @param aAsyncCallback callback for the command
047     */
048    public DeactivationCommand(RemoteEventConnector aRemoteEventConnector, Domain aDomain, AsyncCallback<Void> aAsyncCallback) {
049        super(aRemoteEventConnector, aAsyncCallback);
050        myDomain = aDomain;
051    }
052
053    /**
054     * Creates a DeactivationCommand to deactivate the event listening of the client for a set of domains. That should be
055     * used instead of {@link de.novanic.eventservice.client.event.command.DeactivationCommand#DeactivationCommand(de.novanic.eventservice.client.connection.strategy.connector.RemoteEventConnector , de.novanic.eventservice.client.event.domain.Domain, com.google.gwt.user.client.rpc.AsyncCallback)}
056     * when more than one domain should be deactivated, to reduce server calls.
057     * @param aRemoteEventConnector {@link de.novanic.eventservice.client.connection.strategy.connector.RemoteEventConnector}
058     * @param aDomains domains which should be deactivated for event listening
059     * @param aAsyncCallback callback for the command
060     */
061    public DeactivationCommand(RemoteEventConnector aRemoteEventConnector, Set<Domain> aDomains, AsyncCallback<Void> aAsyncCallback) {
062        super(aRemoteEventConnector, aAsyncCallback);
063        myDomains = aDomains;
064    }
065
066    /**
067     * Deactivates the event listening of the client completely or for a specified domain/context.
068     * @see de.novanic.eventservice.client.event.command.DeactivationCommand#DeactivationCommand(de.novanic.eventservice.client.connection.strategy.connector.RemoteEventConnector , de.novanic.eventservice.client.event.domain.Domain, com.google.gwt.user.client.rpc.AsyncCallback)
069     * @see de.novanic.eventservice.client.event.command.DeactivationCommand#DeactivationCommand(de.novanic.eventservice.client.connection.strategy.connector.RemoteEventConnector , java.util.Set, com.google.gwt.user.client.rpc.AsyncCallback)
070     */
071    public void execute() {
072        if(myDomains != null) {
073            getRemoteEventConnector().deactivate(myDomains, getCommandCallback());
074        } else {
075            getRemoteEventConnector().deactivate(myDomain, getCommandCallback());
076        }
077    }
078}