<commit_before>package com.vaadin.addon.contextmenu;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.EventObject;
import java.util.List;
import java.util.logging.Logger;

import com.vaadin.addon.contextmenu.ContextMenu.ContextMenuOpenListener.ContextMenuOpenEvent;
import com.vaadin.addon.contextmenu.client.ContextMenuClientRpc;
import com.vaadin.addon.contextmenu.client.ContextMenuServerRpc;
import com.vaadin.addon.contextmenu.client.MenuSharedState;
import com.vaadin.addon.contextmenu.client.MenuSharedState.MenuItemState;
import com.vaadin.event.ContextClickEvent;
import com.vaadin.event.ContextClickEvent.ContextClickListener;
import com.vaadin.event.ContextClickEvent.ContextClickNotifier;
import com.vaadin.server.AbstractExtension;
import com.vaadin.server.Resource;
import com.vaadin.server.ResourceReference;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Component;
import com.vaadin.util.ReflectTools;

@SuppressWarnings("serial")
public class ContextMenu extends AbstractExtension implements Menu {

	private Logger logger = Logger.getLogger("ContextMenu");

	private AbstractMenu menu = new AbstractMenu();

	private ContextClickListener contextClickListener = new ContextClickListener() {
		@Override
		public void contextClick(ContextClickEvent event) {
			logger.info("Context click listener");

			fireEvent(new ContextMenuOpenEvent(ContextMenu.this, event));

			open(event.getClientX(), event.getClientY());
		}
	};

	/**
	 * @param parentComponent
	 *            The component to whose lifecycle the context menu is tied to.
	 * @param setAsMenuForParentComponent
	 *            Determines if this menu will be shown for the parent
	 *            component.
	 */
	public ContextMenu(AbstractComponent parentComponent,
			boolean setAsMenuForParentComponent) {
		extend(parentComponent);

		registerRpc(new ContextMenuServerRpc() {
			@Override
			public void itemClicked(int itemId, boolean menuClosed) {
				menu.itemClicked(itemId);
			}
		});

		if (setAsMenuForParentComponent)
			setAsContextMenuOf(parentComponent);
	}

	/**
	 * Sets this as a context menu of the component. You can set one menu to as
	 * many components as you wish.
	 * 
	 * @param component
	 */
	public void setAsContextMenuOf(ContextClickNotifier component) {
		component.addContextClickListener(contextClickListener);
	}

	public void addContextMenuOpenListener(
			ContextMenuOpenListener contextMenuComponentListener) {
		addListener(ContextMenuOpenEvent.class, contextMenuComponentListener,
				ContextMenuOpenListener.MENU_OPENED);
	}

	@Override
	public void beforeClientResponse(boolean initial) {
		logger.info("beforeClientResponse");

		super.beforeClientResponse(initial);

		// FIXME: think about where this is supposed to be

		/*
		 * This should also be used by MenuBar, upgrading it from Vaadin 6 to
		 * Vaadin 7 communication mechanism. Thus to be moved e.g. to the
		 * AbstractMenu.
		 */
		MenuSharedState menuSharedState = getState();
		menuSharedState.htmlContentAllowed = isHtmlContentAllowed();
		menuSharedState.menuItems = convertItemsToState(getItems());
	}

	public void open(int x, int y) {
		getRpcProxy(ContextMenuClientRpc.class).showContextMenu(x, y);
	}

	private List<MenuItemState> convertItemsToState(List<MenuItem> items) {
		if (items == null || items.size() == 0)
			return null;

		List<MenuItemState> state = new ArrayList<MenuItemState>();

		for (MenuItem item : items) {
			MenuItemState menuItemState = new MenuItemState();

			if (!item.isVisible())<commit_msg>Fix #6, fix #15: Removed logger and log statements<commit_after>package com.vaadin.addon.contextmenu;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.EventObject;
import java.util.List;

import com.vaadin.addon.contextmenu.ContextMenu.ContextMenuOpenListener.ContextMenuOpenEvent;
import com.vaadin.addon.contextmenu.client.ContextMenuClientRpc;
import com.vaadin.addon.contextmenu.client.ContextMenuServerRpc;
import com.vaadin.addon.contextmenu.client.MenuSharedState;
import com.vaadin.addon.contextmenu.client.MenuSharedState.MenuItemState;
import com.vaadin.event.ContextClickEvent;
import com.vaadin.event.ContextClickEvent.ContextClickListener;
import com.vaadin.event.ContextClickEvent.ContextClickNotifier;
import com.vaadin.server.AbstractExtension;
import com.vaadin.server.Resource;
import com.vaadin.server.ResourceReference;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Component;
import com.vaadin.util.ReflectTools;

@SuppressWarnings("serial")
public class ContextMenu extends AbstractExtension implements Menu {

	private AbstractMenu menu = new AbstractMenu();

	private ContextClickListener contextClickListener = new ContextClickListener() {
		@Override
		public void contextClick(ContextClickEvent event) {
			fireEvent(new ContextMenuOpenEvent(ContextMenu.this, event));

			open(event.getClientX(), event.getClientY());
		}
	};

	/**
	 * @param parentComponent
	 *            The component to whose lifecycle the context menu is tied to.
	 * @param setAsMenuForParentComponent
	 *            Determines if this menu will be shown for the parent
	 *            component.
	 */
	public ContextMenu(AbstractComponent parentComponent,
			boolean setAsMenuForParentComponent) {
		extend(parentComponent);

		registerRpc(new ContextMenuServerRpc() {
			@Override
			public void itemClicked(int itemId, boolean menuClosed) {
				menu.itemClicked(itemId);
			}
		});

		if (setAsMenuForParentComponent)
			setAsContextMenuOf(parentComponent);
	}

	/**
	 * Sets this as a context menu of the component. You can set one menu to as
	 * many components as you wish.
	 * 
	 * @param component
	 */
	public void setAsContextMenuOf(ContextClickNotifier component) {
		component.addContextClickListener(contextClickListener);
	}

	public void addContextMenuOpenListener(
			ContextMenuOpenListener contextMenuComponentListener) {
		addListener(ContextMenuOpenEvent.class, contextMenuComponentListener,
				ContextMenuOpenListener.MENU_OPENED);
	}

	@Override
	public void beforeClientResponse(boolean initial) {
		super.beforeClientResponse(initial);

		// FIXME: think about where this is supposed to be

		/*
		 * This should also be used by MenuBar, upgrading it from Vaadin 6 to
		 * Vaadin 7 communication mechanism. Thus to be moved e.g. to the
		 * AbstractMenu.
		 */
		MenuSharedState menuSharedState = getState();
		menuSharedState.htmlContentAllowed = isHtmlContentAllowed();
		menuSharedState.menuItems = convertItemsToState(getItems());
	}

	public void open(int x, int y) {
		getRpcProxy(ContextMenuClientRpc.class).showContextMenu(x, y);
	}

	private List<MenuItemState> convertItemsToState(List<MenuItem> items) {
		if (items == null || items.size() == 0)
			return null;

		List<MenuItemState> state = new ArrayList<MenuItemState>();

		for (MenuItem item : items) {
			MenuItemState menuItemState = new MenuItemState();

			if (!item.isVisible())
{'fraction_non_alphanumeric': 0.0890625, 'fraction_numerical': 0.001278409090909091, 'mean_word_length': 5.075064710957722, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4906794', 'n_tokens_mistral': 2155, 'n_tokens_neox': 1941, 'n_words': 475}