I get this code from tutorialspoint.com/gwt as I was learning UiBinder.
Actually I am confused about what does the second line actually does? Why are we using interface name as a ".class" argument in create() function.And what the parameters "widget" and "login" resembles in UiBinder.
The code is:
public class Login extends Composite
{
private static LoginUiBinder uiBinder = GWT.create(LoginUiBinder.class);
#UiTemplate("Login.ui.xml")
interface LoginUiBinder extends UiBinder<Widget, Login>
{
}
}
Every widget that is declared in a template is created by a call to GWT.create().
The UiBinder interface declares two parameter types:
U is the type of root element declared in the ui.xml file, returned by the createAndBindUi call
O is the owner type whose #UiFields are to be filled in.
(In your example U is Widget and O is Login.)
Refer this link
Related
I try to extend my MyDSLProposalProvider from an external Eclipse RCP Project. I created an extension point schema which requires a class property which extends my ProposalProvider. In the new project I extend the class an overrode some methods justs to give me some output so I can see that the external method is called. But this is currently not happening. Is there anything I have to consider?
Currently the hirachy looks like:
MyDSLProposalProvider extends AbstractMyDSLProposalProvider
ExternalProposalProvider extends MyDSLProposalProvider
I rewrote a Method generated in the AbstractMyDSLProposalProvider but when its triggered the predefined Method in the AbstractMyDSLProposalProvider is called and not my new implementation.
public class ExternalMyDSLProposalPovider extends MyDSLProposalProvider
{
#Override
public void completeComponent_Name(EObject model, Assignment
assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
System.err.println("extern");
if(model instanceof Component)
{
createProposal("foo", "foo", context, acceptor);
}
super.completeComponent_Name(model, assignment, context, acceptor);
}
}
This is the class in the external Eclipse Project.
Thanks for the help.
When you declare an extension point using a schema that you have defined Eclipse puts that declaration in the extension point registry. That is all that is does, you must then write code to make uses of those declarations.
You read the extension point registry using something like:
IExtensionRegistry extRegistry = Platform.getExtensionRegistry();
IExtensionPoint extPoint = extRegistry.getExtensionPoint("your extension point id");
IConfigurationElement [] elements = extPoint.getConfigurationElements();
elements is now an array of the declarations in the various plugins using the extension point.
IConfigurationElement has various methods to get the values of the attributes of the declaration.
If you have defined a class in one of the attributes you can create an instance of the class using:
IConfigurationElement element = .... a config element
Object obj = element.createExecutableExtension("attribute name");
In your case the result should be your ExternalMyDSLProposalPovider.
You will then need to hook this object up with whatever is doing to proposals.
I am migrating from org.apache.felix.scr annotations to org.osgi.service.component annotations. I have a set of Components that inherit from a common abstract class. In the felix case, I can use a #Component annotation with the option componentAbstract=true on the super class, and then use #Reference annotation in the super class. I cannot find how to migrate this to osgi annotations.
Is it possible to use Component annotations in a super class of a Component? And if so, what is then the appropriate way to handle the properties and metatype generation?
So, what I am looking for, is something like this
/* No component definition should be generated for the parent, as it is
abstract and cannot be instantiated */
#Component(property="parent.property=parentValue")
public abstract class Parent {
#Reference
protected Service aService;
protected activate(Map<String,Object> props) {
System.out.println("I have my parent property: "+props.get("parent.property"));
#Override
public abstract void doSomething();
}
/* For this class, the proper Component definition should be generated, also
including the information coming from the annotations in the parent */
#Component(property="child.property=childValue")
public class Child extends Parent {
#Activate
public activate(Map<String,Object> props) {
super.activate(props);
System.out.println("I have my child property: "+props.get("child.property"));
}
public void doSomething() {
aService.doSomething();
}
}
By default BND will not process DS annotations in parent classes. You can change that with -dsannotations-options: inherit but please see http://enroute.osgi.org/faq/ds-inheritance.html why you shouldn't!
2021-02-23 UPDATE: It seems like the page mentioned above is no longer available. I don't know if it was moved elsewhere or simply removed but its content (in Markdown format) is still available on GitHub: https://github.com/osgi/osgi.enroute.site/blob/pre-R7/_faq/ds-inheritance.md
How do I create a template that each time when I create a class that extends MyClass, it will automatically add 3 functions.
EDIT:
In other words I am trying to implement Abstract functionality in AS3. Assume that MyClass have both private and protected methods.
I see the only way to write own code template and call it every time you need, in Flash Builder: window->preference->flash builder->editors->code template->action script->new and give the name to the template, for instance myclass.
You can use existed templates as an example for template syntax.
Template code for MyClass child class with three methods:
import my.package.MyClass
/**
* #author ${user}
*/
public class ${enclosing_type} extends MyClass
{
public function ${enclosing_type}()
{
}
override public function publicMethod():void
{
}
override protected function protectedMethod():void
{
}
override private function privateMethod():void
{
}
${cursor}
}
Usage:
Create new "action script file" or "new class",
remove all file content
type myclass and choose from auto-complete options template myclass
If you are actually extending MyClass, all of MyClass's functions are already available to your descendants. You can also override either of them with old header and desired new body, and still be able to call older versions of those functions via super qualifier. So, you add those functions to MyClass and let them be.
Another way is to make an interface - it's a set of declarations without any function bodies, which you have to implement in any class that wants this interface in its content. A short introduction to interfaces. Then your MyClass will be an interface, with 3 function declarations in it, and whichever class will be declared as implements MyClass will have to provide bodies for these functions.
Check other keywords on that page, including extends and implements.
Hope this helps.
EDIT: There are no abstract classes in AS3, however you can emulate abstract functions in a normal class via exception throwing:
protected function abstractFunction(...params):void {
throw new Error("Abstract!");
}
I'm trying to create my custom TabLayoutPanel extension, my code is following:
public class ExpandableTabLayoutPanel extends TabLayoutPanel {
#UiConstructor
public ExpandableTabLayoutPanel(double barHeight, Unit barUnit) {
super(barHeight, barUnit);
addExpandableBehaviour();
}
private addExpandableBehaviour(){
//...
}
}
And here I invoke it from UIBinder:
<a:ExpandableTabLayoutPanel barHeight="20" barUnit="PX">
<a:tab>
<a:header>header</a:header>
<a:AdvancedRichTextArea styleName="{style.area}" ui:field="area"/>
</a:tab>
</a:ExpandableTabLayoutPanel>
(I was forced by error messages to use a:tab/a:header instead of g:tab/g:header even if I don't have tab and header defined in my a: package/workspace, but that's probably not the issue)
If #UiConstructor annotation is present over ExpandableTabLayoutPanel like in the listing, I'm getting strange error:
[ERROR] [gwtreproduce] - <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> missing required attribute(s): arg1 barHeight Element <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> (:13)
When I disable #UiConstructor, I'm getting even stranger error:
[ERROR] [gwtreproduce] - Errors in 'generated://E6338B946DFB2D28988DA492134093C7/reproduce/client/TestView_TestViewUiBinderImpl.java' : [ERROR] [gwtreproduce] - Line 33: Type mismatch: cannot convert from TabLayoutPanel to ExpandableTabLayoutPanel
What am I doing wrong with extending TabLayoutPanel?
And side question: how it is possible that TabLayoutPanel constructor isn't annotated with #UiConstructor and can be used in UiBinder (how UiBinder knows which constructor to invoke)?
for you side question : you have to add (provided=true) to the UiField annotation of your widget. Then in the code, set the instance yourself, before createAndBindUi() call like this :
class Whaoo extends Composite{
/* with 'provided', UiBinder don't call any constructor */
#UiField(provided = true)
final Great foo;
interface WhaooUiBinder extends
UiBinder<Widget, Whaoo> {}
private static WhaooUiBinder uiBinder =
GWT.create(WhaooUiBinder.class);
public Whaoo() {
// initialize "provided" before createAndBindUi call
foo = new Great(String bar, int pouet);
initWidget(uiBinder.createAndBindUi(this));
}
}
I am working on a ExtGWT 3.0 (beta) application.
I have a simple Java bean containing one property:
public class MyBean {
private String content;
// getter and setter here...
}
I want to bind the property to a TextField.
I have created an interface:
interface MyBeanProperties extends PropertyAccess<MyBean> {
ValueProvider<MyBean, String> content();
}
But what's next? How do I tell the TextField to bind to that particular property of a particular MyBean object?
PropertyAccess is used to generically refer to an objects properties, often for data widgets that use a Store like the grid or charts. For binding a form to a bean, check out GWT's editor framework at http://code.google.com/webtoolkit/doc/latest/DevGuideUiEditors.html. There are some examples for this with GXT at http://www.sencha.com/examples/#ExamplePlace:basicbinding%28uibinder%29
Roughly, you'll build a form widget that wraps all the properties you need, and make an editor driver for that editor and its bean:
public class MyBeanEditor implements Editor<MyBean> {
// do any kind of widget setup you like, just make sure to have methods/fields
// package protected or higher that extends Editor (Field extends Editor)
TextField content;
}
//... declare the driver
interface Driver extends SimpleBeanEditorDriver<MyBean, MyBeanEditor> {}
//... use the driver to bind a form to a bean
Driver driver = GWT.create(Driver.class);
driver.initialize(myBeanEditorInstance);
driver.edit(myBean);
//... when save is clicked (or a timer, or whatever), get the value and do
// something with it
MyBean model = driver.flush();