Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified

ContextMenu : unable to achieve on JDE 4.1 and below : some items are displayed twice

Hi all, I am working on the Menu and Context Menu currently.For an edit field,I want to add a menu item "Search" on its context menu.I created a custom edit field, and over-rided the makeContextMenu() to add the "Search" item. In my Screen class, i over-rided the makeMenu() and handled it as below : protected void makeMenu(Menu menu, int instance) { super.makeMenu(menu, instance); if (instance == Menu.INSTANCE_DEFAULT) { menu.add(new MenuItem("Login", 20, 10) { public void run() { login(); } }); } else if (instance == Menu.INSTANCE_CONTEXT) { // context menu handling : Field focussedField = UiApplication.getUiApplication() .getActiveScreen().getLeafFieldWithFocus(); if (focussedField != null) { ContextMenu cm = focussedField.getContextMenu(); if (!cm.isEmpty()) { menu.add(cm); } } } } CustomEditField : protected void makeContextMenu(ContextMenu contextMenu) { super.makeContextMenu(contextMenu); contextMenu.addItem(new MenuItem("MyeditField 1", 10, 2) { public void run() { } }); } I got this solution from the following thread, and it works fine for JDE 4.2 and above : http://supportforums.blackberry.com/t5/Java-Development/Need-help-with-ContextMenu-of- CustomEditField/m-p/456946 However, I am trying to achieve the same on JDE 4.1 and below also.I tried a simple workaround, by replacing the Menu.INSTANCE_CONTEXT and Menu.INSTANCE_DEFAULT with thier actual values since these constants have been included only since JDE 4.2 I was able to achieve the context menu properly, but when i try to paste some selected and copied text, I get the "Paste" item twice in my context menu, although it is displayed only once in the main menu. I suppose I have to include handling for Menu.INSTANCE_CONTEXT_SELECTION also, but am clueless about how to handle it.. Also, if anyone can suggest a cleaner way of achieving it in JDE 4.1 or below, it would be really great.. Thanks..
Developer
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified

Re: ContextMenu : unable to achieve on JDE 4.1 and below : some items are displayed twice

Sorry for the extremely bad formatting. Here I go again :

 

Hi all, I am working on the Menu and Context Menu currently.For an edit field,I want to add a menu item "Search" on its context menu.I created a custom edit field, and over-rided the makeContextMenu() to add the "Search" item. In my Screen class, i over-rided the makeMenu() and handled it as below :

 

 

protected void makeMenu(Menu menu, int instance) {
		super.makeMenu(menu, instance);

		if (instance == Menu.INSTANCE_DEFAULT) {

			menu.add(new MenuItem("Login", 20, 10) {
				public void run() {
					login();
				}
			});

		} else if (instance == Menu.INSTANCE_CONTEXT) {
			// context menu handling :

			Field focussedField = UiApplication.getUiApplication()
					.getActiveScreen().getLeafFieldWithFocus();
			if (focussedField != null) {
				ContextMenu cm = focussedField.getContextMenu();
				if (!cm.isEmpty()) {
					menu.add(cm);
				}
			}
		}
	}

 

 

My customEditField looks like :

 

 

protected void makeContextMenu(ContextMenu contextMenu) {
		super.makeContextMenu(contextMenu);
		contextMenu.addItem(new MenuItem("MyeditField 1", 10, 2) {

			public void run() {
			}

		});
		
		
	}

 

 

I got this solution from the following thread, and it works fine for JDE 4.2 and above : http://supportforums.blackberry.com/t5/Java-Develo pment/Need-help-with-ContextMenu-of- CustomEditField/m-p/456946

 

However, I am trying to achieve the same on JDE 4.1 and below also.

 

I tried a simple workaround, by replacing the Menu.INSTANCE_CONTEXT and Menu.INSTANCE_DEFAULT with thier actual values since these constants have been included only since JDE 4.2

 

I was able to achieve the context menu properly, but when i try to paste some selected and copied text, I get the "Paste" item twice in my context menu, although it is displayed only once in the main menu.

 

I suppose I have to include handling for Menu.INSTANCE_CONTEXT_SELECTION also, but am clueless about how to handle it..

 

Also, if anyone can suggest a cleaner way of achieving it in JDE 4.1 or below, it would be really great.. Thanks..