Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Instance factory implementation for newly created custom component plugin(Instance factory implementation for newly created custom component plugin)
icon8.gif  Instance factory implementation for newly created custom component plugin [message #817146] Fri, 09 March 2012 17:56 Go to next message
Bijoy Thomas is currently offline Bijoy ThomasFriend
Messages: 4
Registered: March 2012
Location: bangalore
Junior Member
I am trying to add my custom created widgets to the palette using the a new plugin

i succeeded to add my custom widgets to palette using my newly created plugin. Now i am trying to use factory for the new custom widgets and swt-customized widgets by me. I am trying exactly the same way as Formtoolkit can somebody help me to complete this task.

I did the following steps.

Created factory class.

Created wbp-factoy.xml and wbp-component.xml for this factory.

added the entry for the istance-factory component element of plugin.xml

<instance-factory class="com.widgets.custom.WidgetFactory">
<method name="Button"
signature="createButton(org.eclipse.swt.widgets.Composite,
java.lang.String,int)"/>
</instance-factory>

added the class loader entry this namespace

Can somebody help me find the missing steps to achieve this

Re: Instance factory implementation for newly created custom component plugin [message #817700 is a reply to message #817146] Sat, 10 March 2012 13:50 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
1. wbp-factory.xml

2. You did not explain what problem you have, what does not work.


Konstantin Scheglov,
Google, Inc.
Re: Instance factory implementation for newly created custom component plugin [message #818399 is a reply to message #817700] Sun, 11 March 2012 15:08 Go to previous messageGo to next message
Bijoy Thomas is currently offline Bijoy ThomasFriend
Messages: 4
Registered: March 2012
Location: bangalore
Junior Member
1. Custom Widget class

package com.widgets.custom;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Text;

public class CECScale extends Composite {
private final Text text;

/**
* Create the composite.
*
* @param parent
* @param style
*/
public CECScale(final Composite parent, final int style) {
super(parent, style);
setLayout(new GridLayout(1, false));

Group grpCecscale = new Group(this, SWT.NONE);
grpCecscale.setLayout(new GridLayout(2, false));
GridData gd_grpCecscale = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_grpCecscale.widthHint = 236;
grpCecscale.setLayoutData(gd_grpCecscale);
grpCecscale.setText("CECScale");

Scale scale = new Scale(grpCecscale, SWT.NONE);

text = new Text(grpCecscale, SWT.BORDER);
GridData gd_text = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_text.widthHint = 27;
text.setLayoutData(gd_text);

}

@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}

2. Factory class

package com.widgets.custom;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;

public class WidgetFactory {

public WidgetFactory(Display display) {
}


public Button createButton(Composite parent, String text, int style) {
Button button = new Button(parent, style );
if (text != null)
button.setText(text);
return button;
}


public CECScale createCECScale(Composite parent, int style){
return new CECScale(parent, style);
}

}

3. WidgetFactory.wbp-factory.xml

<?xml version='1.0' encoding='UTF-8'?>
<factory>
<!-- createButton() -->
<method name="createButton">
<parameter type="org.eclipse.swt.widgets.Composite" parent="true" />
<parameter type="java.lang.String" defaultSource="&quot;New Button&quot;" />
<parameter type="int" defaultSource="org.eclipse.swt.SWT.NONE">
<editor id="style">
<parameter name="class">org.eclipse.swt.SWT</parameter>
<parameter name="set">BORDER</parameter>
<parameter name="select0">type PUSH PUSH CHECK RADIO TOGGLE ARROW
</parameter>
<parameter name="select1">align LEFT LEFT CENTER RIGHT</parameter>
</editor>
</parameter>
<description>Creates a button as a part of the form.</description>
<name>Some name for palette entry.</name>
</method>
<method name="createCECScale" factory = "true">
<parameter type="org.eclipse.swt.widgets.Composite" parent="true" />
<parameter type="int" defaultSource="org.eclipse.swt.SWT.NONE">
</parameter>
<description>Creates a label as a part of the form.</description>
<name>Some name for palette entry.</name>
</method>
</factory>

4. Plugin.xml
<!-- ======================================================== -->
<!-- Toolkit -->
<!-- ======================================================== -->
<extension point="org.eclipse.wb.core.toolkits">
<toolkit id="org.eclipse.wb.rcp">
<resourcePrefixes>
<resourcePrefix>com.widgets.custom.</resourcePrefix>
</resourcePrefixes>

<palette>
<category description="Custom widgets" id="com.widgets.custom" name="MyWidgets">
<component class="com.widgets.custom.CECScale"/>
<instance-factory class="com.widgets.custom.WidgetFactory">
<method
name="CECScale"
signature="createCECScale(org.eclipse.swt.widgets.Composite,int)"/>
<method
name="Button"
signature="createButton(org.eclipse.swt.widgets.Composite,java.lang.String,int)">
</method>
</instance-factory>
</category>
</palette>

<classLoader-bundle
bundle="com.widgets.custom.designer"
namespaces="com.widgets.custom.">
</classLoader-bundle>

</toolkit>

-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
Finaly the factory methods are not getting added to the Palette

I am getting the error message : Factory class com.widgets.custom.WidgetFactory contains no factory methods.
Re: Instance factory implementation for newly created custom component plugin [message #820792 is a reply to message #818399] Wed, 14 March 2012 15:13 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
Hm...
Works for me.

See attached plugin which contribute palette entries, and screen shot which shows result.
index.php/fa/7538/0/

But actually you don't need plugin.
You can contribute palette entries using just XML file in project itself.
See attached test project.
index.php/fa/7539/0/


Konstantin Scheglov,
Google, Inc.

[Updated on: Wed, 14 March 2012 15:13]

Report message to a moderator

Re: Instance factory implementation for newly created custom component plugin [message #820923 is a reply to message #820792] Wed, 14 March 2012 18:47 Go to previous messageGo to next message
Bijoy Thomas is currently offline Bijoy ThomasFriend
Messages: 4
Registered: March 2012
Location: bangalore
Junior Member
Thanks for the reply.
But i dont think it will solve my problem .What i am trying to do is we have customized Eclipse ide and also platform which developed on eclipse, all our application use this platform, our platform consist of lot customized widgets, also we are using a factory for creating the widgets. So i want to bundle the new plugin as part of my customized eclipse ide. so that my application developors will be able to use window builder.

So i am looking for a solution which is similar to Form toolkit implementation in window builder, using a separate plugin may be using *.wbp-factory.xml
Re: Instance factory implementation for newly created custom component plugin [message #825971 is a reply to message #820923] Wed, 21 March 2012 13:43 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
Do you want to put *.wbp-factory.xml file into plugin?
In this case put it into wbp-meta folder, into sub-folder with the same name as name of package of factory class.
Well, you can see how this is done with Forms.

See attached example of such plugin.


Konstantin Scheglov,
Google, Inc.
Re: Instance factory implementation for newly created custom component plugin [message #842835 is a reply to message #825971] Thu, 12 April 2012 16:53 Go to previous message
Bijoy Thomas is currently offline Bijoy ThomasFriend
Messages: 4
Registered: March 2012
Location: bangalore
Junior Member
Thanks its working for me.
Previous Topic:Errors while installing under Ubuntu 11.10
Next Topic:Wrong class resolution during bind with elementName
Goto Forum:
  


Current Time: Thu Mar 28 12:40:37 GMT 2024

Powered by FUDForum. Page generated in 0.03650 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top