View Javadoc
1   /*
2    * Copyright 2000-2018 Vaadin Ltd.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  
17  package com.vaadin.v7.contextmenu;
18  
19  import java.io.Serializable;
20  import java.util.EventListener;
21  
22  import com.vaadin.contextmenu.ContextMenu;
23  import com.vaadin.contextmenu.ContextMenu.ContextMenuOpenListener.ContextMenuOpenEvent;
24  import com.vaadin.v7.contextmenu.GridContextMenu.GridContextMenuOpenListener.GridContextMenuOpenEvent;
25  import com.vaadin.v7.shared.ui.grid.GridConstants.Section;
26  import com.vaadin.v7.ui.Grid;
27  import com.vaadin.v7.ui.Grid.GridContextClickEvent;
28  
29  @SuppressWarnings("serial")
30  /**
31   * Compatibility version of ContextMenu to use with v7.Grid in the Framework 8.0
32   * compatibility packages.
33   *
34   * @deprecated To use only for compatibility v7.Grid
35   */
36  @Deprecated
37  public class GridContextMenu extends ContextMenu {
38  
39      public GridContextMenu(Grid parentComponent) {
40          super(parentComponent, true);
41      }
42  
43      private void addGridSectionContextMenuListener(final Section section,
44              final GridContextMenuOpenListener listener) {
45          addContextMenuOpenListener(new ContextMenuOpenListener() {
46              @Override
47              public void onContextMenuOpen(ContextMenuOpenEvent event) {
48                  if (event
49                          .getContextClickEvent() instanceof GridContextClickEvent) {
50                      GridContextClickEvent gridEvent = (GridContextClickEvent) event
51                              .getContextClickEvent();
52                      if (gridEvent.getSection() == section) {
53                          listener.onContextMenuOpen(new GridContextMenuOpenEvent(
54                                  GridContextMenu.this, gridEvent));
55                      }
56                  }
57              }
58          });
59      }
60  
61      public void addGridHeaderContextMenuListener(
62              GridContextMenuOpenListener listener) {
63          addGridSectionContextMenuListener(Section.HEADER, listener);
64      }
65  
66      public void addGridFooterContextMenuListener(
67              GridContextMenuOpenListener listener) {
68          addGridSectionContextMenuListener(Section.FOOTER, listener);
69      }
70  
71      public void addGridBodyContextMenuListener(
72              GridContextMenuOpenListener listener) {
73          addGridSectionContextMenuListener(Section.BODY, listener);
74      }
75  
76      public interface GridContextMenuOpenListener
77              extends EventListener, Serializable {
78  
79          public void onContextMenuOpen(GridContextMenuOpenEvent event);
80  
81          public static class GridContextMenuOpenEvent
82                  extends ContextMenuOpenEvent {
83              private final Object itemId;
84              private final int rowIndex;
85              private final Object propertyId;
86              private final Section section;
87  
88              public GridContextMenuOpenEvent(ContextMenu contextMenu,
89                      GridContextClickEvent contextClickEvent) {
90                  super(contextMenu, contextClickEvent);
91                  itemId = contextClickEvent.getItemId();
92                  rowIndex = contextClickEvent.getRowIndex();
93                  propertyId = contextClickEvent.getPropertyId();
94                  section = contextClickEvent.getSection();
95              }
96  
97              public Object getItemId() {
98                  return itemId;
99              }
100 
101             public int getRowIndex() {
102                 return rowIndex;
103             }
104 
105             public Object getPropertyId() {
106                 return propertyId;
107             }
108 
109             public Section getSection() {
110                 return section;
111             }
112         }
113     }
114 }