Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

eclipse - How to provide a custom component in the existing Web page Editor Palette

I want to add a new custom component in the Web page Editor Palete named "myHTMLComponent". So, as soon as user opens any html page with WPE, myHTMLComponentM should be present there. How can I do the needful, moreover this component will as well need to generate the code changes accordingly. How to achieve the desired result.

Is there any input I can get for this. I already created standardmetadata tag, but what next!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally, I found the solution of the problem.

For adding new categories in the palette, we need to use pagedesignerextension in plugin.xml as following -

<extension
point="org.eclipse.jst.pagedesigner.pageDesignerExtension">
<paletteFactory
class="com.comp.myeditor.palette.CustomEditorPaletteFactory">
</paletteFactory>
</extension>

Where CustomEditorPaletteFactory will be extending AbstractPaletteFactory. Here in createPaletteRoot(), we can add our category.

public PaletteRoot createPaletteRoot(IEditorInput editorInput){
PaletteRoot paletteRoot = new PaletteRoot();
paletteRoot.add(createStandardComponents());
return paletteRoot;
//return null;
}


private static PaletteContainer createStandardComponents() {
PaletteDrawer componentsDrawer = new PaletteDrawer("CustomHTMLComponent");

TagToolPaletteEntry paletteEntry = new TagToolPaletteEntry(
new FormPaletteComponent(".....);
componentsDrawer.add(paletteEntry);

return componentsDrawer;
}

This will create the component category in the palette and we can add as many components as needed using the componentsdrawer.

For adding a new category in the existing one - Add this in the constructor -

super();
        this._paletteContext = PaletteItemManager.createPaletteContext(file);
        this._manager = PaletteItemManager.getInstance(_paletteContext);

Then use Palette Grouping like this -

PaletteGroup controls = new PaletteGroup("CUST HTML");
        super.add(controls);

        ToolEntry tool = new SelectionToolEntry("CUST Cursor",
                "Cursor DESCRIPTION");

        controls.add(tool);
        setDefaultEntry(tool);
//Custom Marquee
        controls.add(new MarqueeToolEntry("Marquee", "Marquee Desc"));

        controls.add(new PaletteSeparator());
//This class maintins or load all categories features
        controls.add(new CustomComponentToolEntry("Custom Component", "Custom Component Descrition", 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...