Skip to content

Commit

Permalink
Add overload of create method that receives a click listener
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-godoy committed Jul 2, 2019
1 parent fdb7742 commit 3ac04c2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ To see the demo, navigate to http://localhost:8080/
## Release notes

- **Version 1.0.0** Initial Version (based on FontAwesome 5.9.0)
- **Version 1.0.1** Add overload of `create` method that receives a click listener.

## Issue tracking

Expand Down
14 changes: 14 additions & 0 deletions src/codegen/IconsetEnumGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ private static CompilationUnit createCompilationUnit() throws FileNotFoundExcept
cu.setPackageDeclaration(PACKAGE_NAME);
cu.addImport("com.vaadin.flow.component.icon.IronIcon");
cu.addImport("com.vaadin.flow.component.dependency.HtmlImport");
cu.addImport("com.vaadin.flow.component.ClickEvent");
cu.addImport("com.vaadin.flow.component.ClickNotifier");
cu.addImport("com.vaadin.flow.component.ComponentEventListener");

ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration();
type.setName("FontAwesome");
Expand Down Expand Up @@ -301,11 +304,22 @@ private static EnumDeclaration createEnumDeclaration(String enumName, String ico
create.setType("Icon");
create.getBody().get().addStatement(new ReturnStmt("new Icon(this.getIconPart())"));

create = decl.addMethod("create", PUBLIC);
create.setJavadocComment(new JavadocComment("Create a new {@link IronIcon} instance with the icon determined by the name and a listener for click events.\n"
+ "@param listener the event listener for click events\n"
+ "@return a new instance of {@link IronIcon} component"));
create.setType("Icon");
create.addParameter("ComponentEventListener<ClickEvent<IronIcon>>", "listener");
create.getBody().get().addStatement(parseStatement("Icon icon = create();"));
create.getBody().get().addStatement(parseStatement("icon.addClickListener(listener);"));
create.getBody().get().addStatement(new ReturnStmt("icon"));

//create a server side component for the iconset
ClassOrInterfaceDeclaration icon = new ClassOrInterfaceDeclaration();
icon.setName("Icon");
icon.addModifier(PUBLIC, STATIC, FINAL);
icon.addExtendedType("IronIcon");
icon.addImplementedType("ClickNotifier<IronIcon>");
icon.setJavadocComment(new JavadocComment(String.format("Server side component for {@code %s}", decl.getName())));
icon.addSingleMemberAnnotation("HtmlImport", new NameExpr(decl.getName()+".URL"));
icon.addSingleMemberAnnotation("SuppressWarnings", new StringLiteralExpr("serial"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import com.vaadin.flow.component.icon.IronIcon;
import com.vaadin.flow.component.dependency.HtmlImport;
import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.ComponentEventListener;

/**
* FontAwesome 5.9.0 icons.
Expand Down Expand Up @@ -679,12 +682,23 @@ public Icon create() {
return new Icon(this.getIconPart());
}

/**
* Create a new {@link IronIcon} instance with the icon determined by the name and a listener for click events.
* @param listener the event listener for click events
* @return a new instance of {@link IronIcon} component
*/
public Icon create(ComponentEventListener<ClickEvent<IronIcon>> listener) {
Icon icon = create();
icon.addClickListener(listener);
return icon;
}

/**
* Server side component for {@code Regular}
*/
@HtmlImport(Regular.URL)
@SuppressWarnings("serial")
public static final class Icon extends IronIcon {
public static final class Icon extends IronIcon implements ClickNotifier<IronIcon> {

Icon(String icon) {
super(ICONSET, icon);
Expand Down Expand Up @@ -4561,12 +4575,23 @@ public Icon create() {
return new Icon(this.getIconPart());
}

/**
* Create a new {@link IronIcon} instance with the icon determined by the name and a listener for click events.
* @param listener the event listener for click events
* @return a new instance of {@link IronIcon} component
*/
public Icon create(ComponentEventListener<ClickEvent<IronIcon>> listener) {
Icon icon = create();
icon.addClickListener(listener);
return icon;
}

/**
* Server side component for {@code Solid}
*/
@HtmlImport(Solid.URL)
@SuppressWarnings("serial")
public static final class Icon extends IronIcon {
public static final class Icon extends IronIcon implements ClickNotifier<IronIcon> {

Icon(String icon) {
super(ICONSET, icon);
Expand Down Expand Up @@ -6327,12 +6352,23 @@ public Icon create() {
return new Icon(this.getIconPart());
}

/**
* Create a new {@link IronIcon} instance with the icon determined by the name and a listener for click events.
* @param listener the event listener for click events
* @return a new instance of {@link IronIcon} component
*/
public Icon create(ComponentEventListener<ClickEvent<IronIcon>> listener) {
Icon icon = create();
icon.addClickListener(listener);
return icon;
}

/**
* Server side component for {@code Brands}
*/
@HtmlImport(Brands.URL)
@SuppressWarnings("serial")
public static final class Icon extends IronIcon {
public static final class Icon extends IronIcon implements ClickNotifier<IronIcon> {

Icon(String icon) {
super(ICONSET, icon);
Expand Down

0 comments on commit 3ac04c2

Please sign in to comment.