Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:53:35+00:00 2026-06-11T10:53:35+00:00

I wrote some code for disabling the popup menu actions when we choose the

  • 0

I wrote some code for disabling the popup menu actions when we choose the particulation action.Those actions are coming dynamically. But what happens it is disabling the actions when we click the particular action
on the popumenu. But also it keep increasing the actions. For example I have 3 actions in the popup menu. First time when I right click and choose any actions it is disabling. Next time when I right click it comes 6 actions. Third time it comes 9 actions and so on..
This is the problem I am facing. Following is my code.

package rcppopumenu;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

public class View extends ViewPart {
    public static final String ID = "RCPPOPUMENU.view";

    private Action action1;
    private Action action2;
    private TableViewer viewer = null;
    private Composite composite = null;
    private Button button = null;

    /**
     * This is a callback that will allow us to create the viewer and initialize
     * it.
     */
    public void createPartControl(Composite parent) {

        composite = parent;
        composite.setLayout(new RowLayout());
        button = new Button(composite, SWT.NONE);
        button.setText("Hello");

        // viewer = new TableViewer(composite);

        // createActions();
        createHookContextMenu();
    }

    private void createHookContextMenu() {

        MenuManager menuMgr = new MenuManager("#PopupMenu");
        menuMgr.setRemoveAllWhenShown(true);
        menuMgr.addMenuListener(new IMenuListener() {
            public void menuAboutToShow(IMenuManager manager) {
                View.this.fillContextMenu(manager);
            }
        });
        Menu menu = menuMgr.createContextMenu(button);
        button.setMenu(menu);
        getSite()
                .registerContextMenu(menuMgr, getSite().getSelectionProvider());

    }

    private void fillContextMenu(IMenuManager manager) {

        List<Action> createActions = createActions();

        for (Action action : createActions) {

            manager.add(action);

        }

        // Other plug-ins can contribute there actions here
        manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    }

    List<Action> list = new ArrayList<Action>();

    private List<Action> createActions() {

    //  list.clear();

        String[] array = { "a", "b", "c" };

        for (final String str : array) {

            Action action1 = new Action() {

                public void run() {
                    System.out.println(str);
                    setEnabled(false);
                }
            };
            action1.setText(str);
            action1.setToolTipText("Action 1 tooltip");
            action1.setImageDescriptor(PlatformUI.getWorkbench()
                    .getSharedImages()
                    .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));




            if (!list.contains(action1)) {
                list.add(action1);
            }

        }

        return list;

    }

    /**
     * Passing the focus request to the viewer's control.
     */
    public void setFocus() {

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:53:36+00:00Added an answer on June 11, 2026 at 10:53 am

    Your createActions() method should be called only once, and your actions list stored in your object as a member attribute – Called in the createPartControl() method for example – .

    private List<Action> actionsList;
    
    
    /**
     * This is a callback that will allow us to create the viewer and initialize
     * it.
     */
    public void createPartControl(Composite parent) {
    
        composite = parent;
        composite.setLayout(new RowLayout());
        button = new Button(composite, SWT.NONE);
        button.setText("Hello");
    
        // viewer = new TableViewer(composite);
    
        actionsList = createActions();
        createHookContextMenu();
    }
    
    private void fillContextMenu(IMenuManager manager) {
    
        for (Action action : actionsList) {
    
            manager.add(action);
    
        }
    
        // Other plug-ins can contribute there actions here
        manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote some code but I am unable to compile it: #include <cstdio> #include
i wrote some code to get the html source code but it is working
Well I wrote some code and all I was doing was for loops, but
I just wrote some code that works very well. But I feel that it
I wrote some code using ZipInputStream but there is something wrong with it. ZipInputStream
I wrote some code in VHDL that is expected to look at a rotory
I wrote some code that activity starts a service to get some text from
I wrote some code to read a file in my Java Servlet class. (I'm
I wrote some code which monitors the output of Stopwatch using a tight loop.
I wrote some code (Java and LDAP) to create a user in the Active

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.