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

  • Home
  • SEARCH
  • 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 3696182
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:42:28+00:00 2026-05-19T04:42:28+00:00

All, I am creating a palette less eclipse plugin where am adding figures to

  • 0

All,

I am creating a palette less eclipse plugin where am adding figures to the custom editor through the contextual menu, but am not finding a way to do it. Can anyone please guide me as to how to go about adding figures to editor dynamically through context menu i.e. adding actions/commands.


Since Eclipse GEF plugin development finds so less examples to look at, I am adding my solution so others find it useful. This code helps to render a node to the editor.

Source code for Action class to render figures to the editor:

public class AddNodeAction extends EditorPartAction
{
 public static final String ADD_NODE = "ADDNODE";

 public AddNodeAction(IEditorPart editor) {
  super(editor);
            setText("Add a Node");
            setId(ADD_NODE);     // Important to set ID
 }

 public void run()
 {
  <ParentModelClass> parent=  (<ParentModelClass>)getEditorPart().getAdapter(<ParentModelClass>.class);

  if (parent== null)
   return;
  CommandStack command = (CommandStack)getEditorPart().getAdapter(CommandStack.class);

  if (command != null)
  {
   CompoundCommand totalCmd = new CompoundCommand();
   <ChildModelToRenderFigureCommand>cmd = new <ChildModelToRenderFigureCommand>(parent);
   cmd.setParent(parent);
   <ChildModelClass> newNode = new <ChildModelClass>();
   cmd.setNode(newNode);
   cmd.setLocation(getLocation()); // Any location you wish to set to
   totalCmd.add(cmd);
   command.execute(totalCmd);
  }
 }

 @Override
 protected boolean calculateEnabled() 
 {
  return true;
 }
}
  • 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-05-19T04:42:29+00:00Added an answer on May 19, 2026 at 4:42 am

    I think you need multiple different things here. Please remember that GEF would like you to have proper MVC pattern, where you have your own model, Figures as View and EditParts as controllers.

    From the top of my head I would say that you need at least these things:

    • CreateCommand
      • contains all model level modifications that you need to
        perform to add your new data to your
        data model (undoable and transactional)
    • CreateAction
      • makes that CreateCommand instance, initializes it with current selection and executes that command in editdomain
    • ContextMenuProvider
      • Provides that CreateAction to context menu

    If you happen to be using GMF the canonical mechanism will generate the editparts for you automatically when you make the model modifications inside a command, but if you are not using GMF, you must make sure that your own models and editparts are handling and refreshing the new item adding properly.

    EDIT:
    Ok, here is some code suggestion with playing around with requests.

    public void run() {
       // Fetch viewer from editor part (might not work, if not, try some other way)
       EditPartViewer viewer = (EditPartViewer) part.getAdapter(EditPartViewer.class);
       // get Target EditPart that is under the mouse
       EditPart targetEditPart = viewer.findObjectAt(getLocation());
       // If nothing under mouse, set root item as target (just playing safe)
       if(targetEditPart == null)
           targetEditPart = viewer.getContents();
    
       // Make and initialize create request with proper information
       CreateRequest createReq = new CreateRequest();
       createReq.setLocation(getLocation());
       createReq.setFactory(new OwnFactoryImplementation());
    
       // Ask from target editpart command for this request
       Command command = targetEditPart.getCommand(createReq);
    
       // If command is ok, and it can be executed, go and execute it on commandstack
      if(command != null && command.canExecute()) {
          viewer.getEditDomain().getCommandStack().execute(command);
      }
    }
    

    Now what happens is that editpart will be requested for creation, so the action itself doesn’t know how the command works, what makes it objective agaist the command.

    So to make things work, you need to install new EditPolicy to your EditPart. EditPolicies can be installed on EditParts createDefaultEditPolicies() function. This EditPolicy must react and return command when there is CreateRequest. This way any child can provide own kind of command for creating children for itself.

    Here is a good image how it works (controller is EditPart):
    Diagram

    Please ask if I can help you some more. I know that this looks bit more complex, but this makes your own life much more easier, and after you have done that, you actually understand Command-Request Pattern quite well, and it can be reused in many different places.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running through an XML document, selecting all the elements, and creating links based
It's gotta be free. It's hobby, after all, not a business!. Creating for-profit software
As you all know creating a web service with generic methods is not possible.
Initialization would include creating all the required tables, constraints and populating the tables. edit:
When creating a criteria for NHibernate all criteria are added as AND . For
I have a C# Application I am creating that stores all data in SQL
I'm having issues creating an ActionLink using Preview 5. All the docs I can
I'm trying to choose a tool for creating UML diagrams of all flavours. Usability
I am working on creating an immutable class. I have marked all the properties
In my application, I use log4net, with all types creating their own logger based

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.