<commit_before>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.plugin.whiteboard;

import java.awt.event.*;

import java.util.*;
import javax.swing.*;

import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;

/**
 * WhiteboardMenuItem
 * 
 * @author <NAME>
 */
public class WhiteboardMenuItem
    implements  PluginComponent,
                ActionListener
{
    private JMenu whiteboardMenu
        = new JMenu(Resources.getString("whiteboardMenuItemText"));

    /**
     * The current meta contact
     */
    private MetaContact metaContact;

    /**
     * The Whiteboard session manager
     */
    private WhiteboardSessionManager session;

    /**
     * WhiteboardMenuItem constructor.
     *
     * @param session the whiteboard session manager
     */
    public WhiteboardMenuItem (WhiteboardSessionManager session)
    {
        this.session = session;
        this.whiteboardMenu.setIcon (Resources.getImage ("mpenIcon"));
    }

    /**
     * Sets the current meta contact.
     *
     * @param metaContact the current meta contact
     */
    public void setCurrentContact (MetaContact metaContact)
    {
        this.metaContact = metaContact;
        
        this.whiteboardMenu.removeAll();
        
        Iterator iter = metaContact.getContacts();
        while (iter.hasNext())
        {
            Contact contact = (Contact)iter.next();
            ProtocolProviderService pps = contact.getProtocolProvider();
            
            OperationSetWhiteboarding opSetWb = (OperationSetWhiteboarding)
                pps.getOperationSet(OperationSetWhiteboarding.class);

            String contactDisplayName = contact.getDisplayName();
            
            JMenuItem contactItem = new JMenuItem(contactDisplayName);
            contactItem.setName(contact.getDisplayName() + pps.getProtocolName());

            if (opSetWb != null)
            {
                contactItem.addActionListener(this);
            }
            else
            {
                contactItem.setEnabled(false);
                contactItem.setToolTipText(
                        Resources.getString("whiteboardMenuItemNotSupportedTooltip"));
            }
            
            this.whiteboardMenu.add(contactItem);
        }
    }

    /**
     * Sets the current meta group.
     *
     * @param metaGroup the current meta contact group
     */
    public void setCurrentContactGroup (MetaContactGroup metaGroup)
    {
    }

    /**
     * Invoked when an action occurs: user start a whiteboard session.
     * 
     * @param e event
     */
    public void actionPerformed (ActionEvent e)
    {
        String itemID = ((JMenuItem)e.getSource()).getName();
        Iterator i = this.metaContact.getContacts();

        while(i.hasNext()) 
        {
            Contact contact = (Contact)i.next();

            String id = contact.getAddress()
                + contact.getProtocolProvider().getProtocolName();

            if(itemID.equals(id)) 
                session.initWhiteboard (contact);
        }
    }

    public String getConstraints()
    {
        return null;
    }

    public Container getContainer()
    {
        return Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU;
    }

    public Object getComponent()
    {
        return whiteboardMenu;
    }

    public String getName()
    {
        return whiteboardMenu.getText();
    }
}<commit_msg>Show whiteboard menu only if the meta contact has conrtact supporting it.<commit_after>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.plugin.whiteboard;

import java.awt.event.*;

import java.util.*;
import javax.swing.*;

import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;

/**
 * WhiteboardMenuItem
 * 
 * @author <NAME>
 */
public class WhiteboardMenuItem
    implements  PluginComponent,
                ActionListener
{
    private JMenu whiteboardMenu
        = new JMenu(Resources.getString("whiteboardMenuItemText"));

    /**
     * The current meta contact
     */
    private MetaContact metaContact;

    /**
     * The Whiteboard session manager
     */
    private WhiteboardSessionManager session;

    /**
     * WhiteboardMenuItem constructor.
     *
     * @param session the whiteboard session manager
     */
    public WhiteboardMenuItem (WhiteboardSessionManager session)
    {
        this.session = session;
        this.whiteboardMenu.setIcon (Resources.getImage ("mpenIcon"));
    }

    /**
     * Sets the current meta contact.
     *
     * @param metaContact the current meta contact
     */
    public void setCurrentContact (MetaContact metaContact)
    {
        this.metaContact = metaContact;
        
        this.whiteboardMenu.removeAll();
        
        Iterator iter = metaContact.getContacts();
        while (iter.hasNext())
        {
            Contact contact = (Contact)iter.next();
            ProtocolProviderService pps = contact.getProtocolProvider();
            
            OperationSetWhiteboarding opSetWb = (OperationSetWhiteboarding)
                pps.getOperationSet(OperationSetWhiteboarding.class);

            String contactDisplayName = contact.getDisplayName();
            
            JMenuItem contactItem = new JMenuItem(contactDisplayName);
            contactItem.setName(contact.getDisplayName() + pps.getProtocolName());

            if (opSetWb != null)
            {
                contactItem.addActionListener(this);
            }
            else
            {
                contactItem.setEnabled(false);
                contactItem.setToolTipText(
                        Resources.getString("whiteboardMenuItemNotSupportedTooltip"));
            }
            
            this.whiteboardMenu.add(contactItem);
        }
    }

    /**
     * Sets the current meta group.
     *
     * @param metaGroup the current meta contact group
     */
    public void setCurrentContactGroup (MetaContactGroup metaGroup)
    {
    }

    /**
     * Invoked when an action occurs: user start a whiteboard session.
     * 
     * @param e event
     */
    public void actionPerformed (ActionEvent e)
    {
        String itemID = ((JMenuItem)e.getSource()).getName();
        Iterator i = this.metaContact.getContacts();

        while(i.hasNext()) 
        {
            Contact contact = (Contact)i.next();

            String id = contact.getAddress()
                + contact.getProtocolProvider().getProtocolName();

            if(itemID.equals(id)) 
                session.initWhiteboard (contact);
        }
    }

    public String getConstraints()
    {
        return null;
    }

    public Container getContainer()
    {
        return Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU;
    }

    public Object getComponent()
    {
        Iterator iter = metaContact.getContacts();
        while (iter.hasNext())
        {
            Contact contact = (Contact)iter.next();
            ProtocolProviderService pps = contact.getProtocolProvider();
            
            OperationSetWhiteboarding opSetWb = (OperationSetWhiteboarding)
                pps.getOperationSet(OperationSetWhiteboarding.class);
           
            if (opSetWb != null)
            {
                return whiteboardMenu; 
            }
        }
        
        return null;
    }

    public String getName()
    {
        return whiteboardMenu.getText();
    }
}
{'fraction_non_alphanumeric': 0.09028132992327366, 'fraction_numerical': 0.0, 'mean_word_length': 2.056271981242673, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2406152', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1972, 'n_words': 439}