de.fu_berlin.inf.dpp.ui.actions.NewContactAction.java Source code

Java tutorial

Introduction

Here is the source code for de.fu_berlin.inf.dpp.ui.actions.NewContactAction.java

Source

/*
 * DPP - Serious Distributed Pair Programming
 * (c) Freie Universitt Berlin - Fachbereich Mathematik und Informatik - 2006
 * (c) Riad Djemili - 2006
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 1, or (at your option)
 * any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package de.fu_berlin.inf.dpp.ui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.ImageData;
import org.jivesoftware.smack.Connection;
import org.picocontainer.annotations.Inject;

import de.fu_berlin.inf.dpp.SarosPluginContext;
import de.fu_berlin.inf.dpp.net.ConnectionState;
import de.fu_berlin.inf.dpp.net.xmpp.IConnectionListener;
import de.fu_berlin.inf.dpp.net.xmpp.XMPPConnectionService;
import de.fu_berlin.inf.dpp.ui.ImageManager;
import de.fu_berlin.inf.dpp.ui.Messages;
import de.fu_berlin.inf.dpp.ui.util.WizardUtils;

public class NewContactAction extends Action implements Disposable {

    public static final String ACTION_ID = NewContactAction.class.getName();

    @Inject
    private XMPPConnectionService sarosNet;

    private final IConnectionListener connectionListener = new IConnectionListener() {
        @Override
        public void connectionStateChanged(Connection connection, ConnectionState state) {
            setEnabled(sarosNet.isConnected());
        }
    };

    public NewContactAction() {
        setId(ACTION_ID);
        setToolTipText(Messages.NewContactAction_tooltip);
        setImageDescriptor(new ImageDescriptor() {
            @Override
            public ImageData getImageData() {
                return ImageManager.ELCL_CONTACT_ADD.getImageData();
            }
        });

        SarosPluginContext.initComponent(this);

        sarosNet.addListener(connectionListener);
        setEnabled(sarosNet.isConnected());
    }

    @Override
    public void dispose() {
        sarosNet.removeListener(connectionListener);
    }

    @Override
    public void run() {
        WizardUtils.openAddContactWizard();
    }
}