001/* 002 * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * troger 016 */ 017package org.nuxeo.ecm.platform.annotations.gwt.client.view.menu; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import org.nuxeo.ecm.platform.annotations.gwt.client.view.AbstractAnnotationCommand; 023 024import com.google.gwt.user.client.ui.MenuBar; 025import com.google.gwt.user.client.ui.MenuItem; 026import com.google.gwt.user.client.ui.PopupPanel; 027 028/** 029 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 030 */ 031public class AnnotationPopupMenu extends PopupPanel { 032 033 private List<AbstractAnnotationCommand> commands; 034 035 private boolean initialized = false; 036 037 public AnnotationPopupMenu(List<AbstractAnnotationCommand> commands) { 038 super(true); 039 this.commands = new ArrayList<AbstractAnnotationCommand>(commands); 040 setStyleName("annotationPopupMenu"); 041 // Fix for IE: don't display the context menu on right click 042 getElement().setAttribute("oncontextmenu", "return false;"); 043 } 044 045 @Override 046 public void show() { 047 if (!initialized) { 048 createPopupMenu(); 049 initialized = true; 050 } 051 super.show(); 052 } 053 054 private void createPopupMenu() { 055 MenuBar popupMenuBar = new MenuBar(true); 056 057 for (AbstractAnnotationCommand command : commands) { 058 command.setAnnotationPopupMenu(this); 059 060 MenuItem item = new MenuItem(command.getTitle(), true, command); 061 item.addStyleName("annotationPopupMenuItem"); 062 popupMenuBar.addItem(item); 063 } 064 065 popupMenuBar.setVisible(true); 066 add(popupMenuBar); 067 } 068 069}