Steps Involved in adding designtime for a new component.
Step
1. Adding designtime classes
- DesignInfo class
-
Bean Info class
- DesignTime rendeder class
- entry
in faces faces-config file for DesignTime renderer class
Step
2. Modifying resource and layer.xml files to add the component
in palette
An entry needs to be added in layer.xml to view
the component on palette.
layer.xml file is located
at:
woodstock/ide-plugins/netbeans/woodstock-suite/components/src/org/netbeans/modules/visualweb/woodstock/webui/jsf/designtime
Example:
Masthead component entry in layer.xml:
<attr
name="WoodstockMasthead.comp_palette_item/WoodstockVersionPage.comp_palette_item"
boolvalue="true"/>
and
<file
name="WoodstockMasthead.comp_palette_item"
url="resources/WoodstockMasthead.comp_palette_item"/>
Create
a file "Woodstock+component name+.comp_palette_item" and
add it to
woodstock/ide-plugins/netbeans/woodstock-suite/components/src/org/netbeans/modules/visualweb/
woodstock/webui/jsf/designtime/resources
"Woodstock+component
name+.comp_palette_item.xml" should have following
entries:
<?xml version="1.0"
encoding="UTF-8"?>
<palette_item
version="1.0">
<component
classname="com.sun.webui.jsf.component.+component name+"
type="visual" />
<!--<icon16
urlvalue="nbres:/com/sun/webui/jsf/component/+component
name+_C16.png" />
<icon32
urlvalue="nbres:/com/sun/webui/jsf/component/+component
name+_C32.png" />-->
<description
localizing-bundle="org.netbeans.modules.visualweb.woodstock.webui.jsf.designtime.resources.Bundle"
display-name-key="NAME_com-sun-webui-jsf-component-+component
name+"
tooltip-key="HINT_com-sun-webui-jsf-component-+component name+"
help-key="projrave_ui_elements_palette_wdstk-jsf1.2_alarm"/>//
this can be modified once the help text is ready
</palette_item>
All
the resorce keys needs to be added in Bundle.properties file.
If
you do not have icon images for the component then you can comment
out that section.
Step 3: Update Project Woodstock
Component in NetBeans Visual Web Pack
Install Procedure
(Taken from
http://wiki.java.net/bin/view/Javatools/InstallingWoodstockComponentsInNetBeans)
1. Set JAVA_HOME to jdk5's installed path
2. Install the Netbeans6.0 development build http://bits.netbeans.org/netbeans/6.0/.
3. Check out a version of the Project Woodstock tree(cvs->woodstock). Currently, only the main trunk of the Woodstock tree has been tested so other branches may not work. There should not be any space in between the checked out path like C:\Program Files\ or C:\Documents and Settings. Sometimes it creates problem while building the project.So Checkout project woodstock in a path where spaces can be avoided.
4. In NetBeans6?, Goto File-> Open Project Now goto the path where you have checked out woodstock and open "woodstock/ide-plugins/netbeans/woodstock-suite" project.
5. Set woodstock-suite as the main project(File-> Set as main project). Now build the project(build->Build Main project). Here you will get some annotation error's, but this will not affect the build.
6. After building the project woodstock suite. Go to the Projects Window and execute "Create NBMs" (Rightclick on "woodstock suite"-> click "create NBMs")from the context menu.
7. Now a directory called updates will be created(woodstock/ide-plugins/netbeans/woodstock-suite/build/updates) This has two generated NBMs files in the woodstock suite build directory.("woodstock/ide-plugins/netbeans/woodstock-suite/build/updates/*.nbms". )
8. Execute the project : Run->Run Main Project which will run another instance of the IDE using a different userdir
9. Goto Tools->Plugins->Downloaded Tab->Add Plugins in the new netbeans IDE. NetBeans6? has a new Plugin installation dialog.
10. Browse to location of built NBMs(woodstock/ide-plugins/netbeans/woodstock-suite/build/updates/*.nbms) and use multi-select to add both of them. Two selected modules should appear in the left pane.
11. Then Press "Install" and follow the instructions
12. Click on finish and now restart the IDE(two options will be there 1.restart now,2. Restart later, select option1 it will restart the ide automatically)
13. Now in the new IDE goto Tools->Plugins to check that the new modules were installed. On the "Settings" tab, select "View->NetBeans Modules". Switch to "Installed" tab and search for "project woodstock". Check that the installed version is correct.
14. Create a webapplication in the new IDE. The palette in the new ide contains the updated components.
==============================================================
DesignTime
Implementation:
Adding BeanInfo class:
BeanInfo
class needs to be placed under
webui/src/designtime/com/sun/webui/jsf/component folder.
This
class extends BeanInfoBase class of component.
This class can be
used to achieve some specific design-time behavior.
For example to
add inline editable functionality to label component.
public
class LabelBeanInfo extends LabelBeanInfoBase {
public LabelBeanInfo() {
super();
this.getBeanDescriptor().setValue(
Constants.BeanDescriptor.INLINE_EDITABLE_PROPERTIES,
new String[] { "*text://span://label" }); // NOI18N
}
}
Adding DesignInfo class:
DesignInfo
class needs to be placed under
webui/src/designtime/com/sun/webui/jsf/component folder.
This
class extends AbstractDesignInfo class. Which finally implements
designInfo interface.
Here, one can specify the components
designtime behavior. For example If vesrsionPage component can not
accept
child then accept child method of DesignInfo class will
return false.
public boolean acceptChild(DesignBean
parentBean, DesignBean childBean, Class childClass) {
return false;
}
Adding DesignTimeRenderer Class:
It
is also possible to overlay a special design-time renderer on top of
the normal runtime renderer.
For some components its needed to
define DesigntimeRendere to achieve design-time specific behavior.
For example,
when a component is dropped for first time in visual
designer you may want to put some shadow text and also some
style
attribute. This can be achieved using design time renderer
class.
Steps to create a design-time renderer class:
1.Create
a DesignTimeRenderer, which delegates to the normal runtime
Renderer.
2. Add an entry to DesignTimeRenderer to reference the
design-time faces-config file.
Design-time renderer will be
executed during desing time only; it will not be executed at
runtime.
faces-config file:
<renderer>
<component-family>com.sun.webui.jsf.ContentPageTitle</component-family>
<renderer-type>com.sun.webui.jsf.ContentPageTitleDesignTime</renderer-type>
<renderer-class>com.sun.webui.jsf.renderkit.html.ContentPageTitleDesignTimeRenderer</renderer-class>
</renderer>
Code to
achieve shadow-text and style for contentPage component:
protected
String getShadowText(UIComponent component) {
return
DesignMessageUtil.getMessage(PanelLayoutDesignTimeRenderer.class,
"contentPage.label");
}
public void encodeBegin(FacesContext
context, UIComponent component) throws IOException {
if (component.getChildCount() == 0) {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("div", component);
String id = component.getId();
writer.writeAttribute("id", id, "id");
//NOI18N
// Calculate CSS height and width style settings
StringBuffer sb = new StringBuffer();
String style = (String)
component.getAttributes().get("style");
if ((style != null) && (style.length() > 0))
{
sb.append(style);
}
if (style == null || style.indexOf("width:") == -1)
{
sb.append("width: 128px; "); // NOI18N
}
if (style == null || style.indexOf("height:") == -1)
{
sb.append("height: 128px; "); // NOI18N
}
sb.append(style);
sb.append("; -rave-layout: grid"); // NOI18N
writer.writeAttribute("style", sb.toString(), null);
//NOI18N
sb.setLength(0);
// Calculate CSS style classes
String styleClass = (String)
component.getAttributes().get("styleClass");
if ((styleClass != null) && (styleClass.length() > 0))
{
sb.append(styleClass);
sb.append(" ");
}
sb.append(UNINITITIALIZED_STYLE_CLASS);
sb.append(" ");
sb.append(BORDER_STYLE_CLASS);
writer.writeAttribute("class", sb.toString(), null); //
NOI18
writer.writeText(getShadowText(component), null);
writer.endElement("div");
return;
}
super.encodeBegin(context, component);
}