Bug 398505 - Rap: Context menus should be created only when needed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=398505
Partially reverted the last change because the menus should be available from the beginning and not only if a file gets selected (as in swing ui). This means lazy creation is not possible for the fileupload widget.
Also removed unnecessary code as already done in the other dropdown buttons.
diff --git a/org.eclipse.scout.rt.ui.rap.incubator.filechooser/src/org/eclipse/scout/rt/ui/rap/form/fields/filechooserfield/RwtScoutFileUploadField.java b/org.eclipse.scout.rt.ui.rap.incubator.filechooser/src/org/eclipse/scout/rt/ui/rap/form/fields/filechooserfield/RwtScoutFileUploadField.java
index 3140e01..1ff1c33 100644
--- a/org.eclipse.scout.rt.ui.rap.incubator.filechooser/src/org/eclipse/scout/rt/ui/rap/form/fields/filechooserfield/RwtScoutFileUploadField.java
+++ b/org.eclipse.scout.rt.ui.rap.incubator.filechooser/src/org/eclipse/scout/rt/ui/rap/form/fields/filechooserfield/RwtScoutFileUploadField.java
@@ -69,6 +69,7 @@
private Composite m_fileContainer;
private IDropDownFileUploadForPatch m_browseButton;
private ProgressBar m_progressBar;
+ private Menu m_contextMenu;
private TextFieldEditableSupport m_editableSupport;
private FileUploadHandler m_handler;
@@ -119,12 +120,10 @@
// prevent the button from grabbing focus
m_fileContainer.setTabList(new Control[]{textField});
- // context menu listener
- getUiBrowseButton().addMenuListener(new P_ContextMenuListener());
-
- // listener
-// P_RwtBrowseButtonListener browseButtonListener = new P_RwtBrowseButtonListener();
-// getUiBrowseButton().addSelectionListener(browseButtonListener);
+ // context menu
+ m_contextMenu = new Menu(getUiBrowseButton().getShell(), SWT.POP_UP);
+ m_contextMenu.addMenuListener(new P_ContextMenuListener());
+ getUiBrowseButton().setMenu(m_contextMenu);
// layout
container.setLayout(new LogicalGridLayout(1, 0));
@@ -405,6 +404,14 @@
@Override
public void menuShown(MenuEvent e) {
super.menuShown(e);
+ /*
+ * Since the FileUpload widget does fire a MouseEvent when it is clicked on, we do not know if the right mouse button has been clicked or not.
+ * Therefore, a MenuDetect listener cannot be attached. The creation of the menu is done once after initialization.
+ * While handling the menuShown, the menu (event source) might already contain contributed Scout menus from the previous right mouse click. To
+ * avoid the menus being added several times, the menu items are removed first before the Scout menus are contributed.
+ */
+ Menu contextMenu = (Menu) e.getSource();
+ cleanUpMenuItems(contextMenu);
final AtomicReference<IMenu[]> scoutMenusRef = new AtomicReference<IMenu[]>();
Runnable t = new Runnable() {
@@ -424,16 +431,6 @@
// grab the actions out of the job, when the actions are providden within
// the scheduled time the popup will be handled.
if (scoutMenusRef.get() != null) {
- Menu contextMenu = (Menu) e.getSource();
-
- /*
- * Since the FileUpload widget does fire a MouseEvent when it is clicked on, we do not know if the right mouse button has been clicked or not.
- * Therefore, a MenuDetect listener cannot be attached. The creation of the menu is done once after a file has been selected
- * (@see DropDownFileUpload.handleSelectionInternal()).
- * While handling the menuShown, the menu (event source) might already contain contributed Scout menus from the previous right mouse click. To
- * avoid the menus being added several times, the menu items are removed first before the Scout menus are contributed.
- */
- cleanUpMenuItems(contextMenu);
RwtMenuUtility.fillContextMenu(scoutMenusRef.get(), RwtScoutFileUploadField.this.getUiEnvironment(), contextMenu);
}
}