Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
答复: [gef-dev] GEF editor inside Eclipse RCP

It is my solution, perhaps it can help youJ

 

                            IEditorInput input = new IEditorInput(){

                                     public boolean exists() {

                                               return true;

                                     }

 

                                     public ImageDescriptor getImageDescriptor() {

                                               return null;

                                     }

 

                                     public String getName() {

                                               return "SpringConfig";

                                     }

 

                                     public IPersistableElement getPersistable() {

                                               return null;

                                     }

 

                                     public String getToolTipText() {

                                               return "SpringConfig";

                                     }

 

                                     public Object getAdapter(Class adapter) {

                                               if (adapter.equals(ISpringConfig.class)) {

                                                        return config;

                                               }

                                               return null;

                                     }

                                    

                            };

                            try {

                                     IDE.openEditor(getActivePage(), input, springEditorId, true);

                            } catch (PartInitException e) {

                                     e.printStackTrace();

                            }

 

Here  I create a EditorInput for my rutime class – SpringConfig

 


发件人: gef-dev-bounces@xxxxxxxxxxx [mailto:gef-dev-bounces@xxxxxxxxxxx] 代表 ved.gunjan
发送时间: 2006年7月1 18:02
收件人: gef-dev@xxxxxxxxxxx
主题: [gef-dev] GEF editor inside Eclipse RCP

 

Hi Experts,

Im new to the world of RCP and also GEF.
Presently im trying to open a GEF editor inside Eclipse RCP application.
I have written an action which tries to open the gef editor in its run method.
I have also created my own editor input which implemnts IEditorInput interface via IPathEditorInput interface, as it was mentioned in the RCP tutorilas.

But the problem is that i want to open the gef editor without this input, as i dont have a input path to open the editor.

My question are
1)Is it mandatory to have an editor input.
2)Cant I open the gef editor without the input path? i just want to open an editor with pallete from the run method of the action class.

If yes then how ????


Below are the snap shot of the classes used.
-------------------------------------------------------------------
run method of the action class which open the editor.

 public void run() {
 IEditorInput input = new MyRCPEditorInput();          try {
            window.getActivePage().openEditor(input, MyRCPEditor.ID);
        } catch (PartInitException e) {
        }
   }
------------------------------------------------

Editor Class.
--------------------------------------------------------------
public class MyRCPEditor extends GraphicalEditorWithPalette {
    public static String ID = "com.rcp.core.actions.test.MyRCPEditor";
    private ContentsModel contentModel;

    public MyRCPEditor() {
        setEditDomain(new DefaultEditDomain(this));
    }

    protected void initializeGraphicalViewer() {
        GraphicalViewer viewer = getGraphicalViewer();
        ContentsModel parent = new ContentsModel();

        HelloModel child1 = new HelloModel();
        child1.setConstraint(new Rectangle(0, 0, -1, -1));
        parent.addChild(child1);

        HelloModel child2 = new HelloModel();
        child2.setConstraint(new Rectangle(30, 30, -1, -1));
        parent.addChild(child2);

        HelloModel child3 = new HelloModel();
        child3.setConstraint(new Rectangle(10, 80, 80, 50));
        parent.addChild(child3);

        viewer.setContents(parent);
    }

    public void doSave(IProgressMonitor monitor) {
    }

    public void doSaveAs() {
    }

    public void gotoMarker(IMarker marker) {
    }

    public boolean isDirty() {
        return false;
    }

    public boolean isSaveAsAllowed() {
        return false;
    }

    protected void configureGraphicalViewer() {
        super.configureGraphicalViewer();

        GraphicalViewer viewer = getGraphicalViewer();
        viewer.setEditPartFactory(new MyEditPartFactory());
    }

    protected PaletteRoot getPaletteRoot() {
        PaletteRoot root = new PaletteRoot();
        PaletteGroup toolGroup = new PaletteGroup("");

        ToolEntry tool = new SelectionToolEntry();
        toolGroup.add(tool);
        root.setDefaultEntry(tool);

        tool = new MarqueeToolEntry();
        toolGroup.add(tool);

        PaletteDrawer drawer = new PaletteDrawer("Products");

        ImageDescriptor descriptor = ImageDescriptor.createFromFile(MyRCPEditor.class,
                "/icons/newModel.gif");

        CreationToolEntry creationEntry = new CreationToolEntry("TestEditor",
                "Adding Products", new SimpleFactory(HelloModel.class),
                descriptor, descriptor);
        drawer.add(creationEntry);

        root.add(toolGroup);
        root.add(drawer);

        return root;
    }

    @Override
    protected void setInput(IEditorInput input) {
        // TODO Auto-generated method stub
        super.setInput(input);

        MyRCPEditorInput rcpInput = ((MyRCPEditorInput) input);
        contentModel = rcpInput.getContentModel();
        setPartName(rcpInput.getName());
    }
}
------------------------------------------------------------------

Any help/suggestion will be great.
Thanks and Regards.
Ved

 


Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.



Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and may be confidential and/or privileged of Neusoft Group Ltd., its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful. If you have received this communication in error, please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you.

Back to the top