Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.licket.core.optional;

/**
* @author lukaszgrabski
*/
@FunctionalInterface
public interface ElseConsumer {

void doElse() throws Throwable;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.licket.core.optional;

import java.util.Optional;
import java.util.function.Consumer;

/**
* @author lukaszgrabski
*/
public class OptionalExt<T> {

private Consumer<Void> elseConsumer;

public static <T> OptionalExt<T> forOptional(Optional<T> optional) {
return new OptionalExt<T>(optional);
}

private final Optional<T> optional;

public OptionalExt(Optional<T> optional) {
this.optional = optional;
}

public OptionalExt<T> ifPresent(Consumer<T> valueConsumer) {
optional.ifPresent(valueConsumer);
return this;
}

public void orElse(ElseConsumer elseConsumer) throws Throwable {
if (optional.isPresent()) {
return;
}
elseConsumer.doElse();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.licket.demo.licket;

import org.licket.core.model.LicketComponentModel;
import org.licket.core.resource.Resource;
import org.licket.demo.resource.ApplicationCssResource;
import org.licket.demo.view.AddContactForm;
Expand All @@ -19,53 +18,54 @@
import org.springframework.util.IdGenerator;
import org.springframework.util.JdkIdGenerator;

import static org.licket.core.view.hippo.ComponentModelProperty.fromComponentModelProperty;
import static org.licket.semantic.component.modal.ModalSettingsBuilder.builder;

@Configuration
@Import(SemanticUIPluginConfiguration.class)
public class LicketConfiguration {

@LicketRootContainer
public ContactsAppRoot root() {
return new ContactsAppRoot("contacts-page");
}
@LicketRootContainer
public ContactsAppRoot root() {
return new ContactsAppRoot("contacts-page");
}

@LicketComponent
public ContactsPanel contactsPanel() {
return new ContactsPanel("contacts-panel");
}
@LicketComponent
public ContactsPanel contactsPanel() {
return new ContactsPanel("contacts-panel");
}

@LicketComponent
public ContactsList contactsList() {
return new ContactsList("contact", new LicketComponentModel("contacts"));
}
@LicketComponent
public ContactsList contactsList() {
return new ContactsList("contact", fromComponentModelProperty("contacts"));
}

@LicketComponent
public AddContactForm addContactForm() {
return new AddContactForm("new-contact-form");
}
@LicketComponent
public AddContactForm addContactForm() {
return new AddContactForm("new-contact-form");
}

@LicketComponent
public ViewContactPanel viewContactPanel() {
return new ViewContactPanel("view-contact-panel");
}
@LicketComponent
public ViewContactPanel viewContactPanel() {
return new ViewContactPanel("view-contact-panel");
}

private ModalSettings modalDialogSettings() {
return builder().showActions().build();
}
private ModalSettings modalDialogSettings() {
return builder().showActions().build();
}

@LicketComponent
public AddContactPanel addContactPanel() {
return new AddContactPanel("add-contact-panel", modalDialogSettings());
}
@LicketComponent
public AddContactPanel addContactPanel() {
return new AddContactPanel("add-contact-panel", modalDialogSettings());
}

@Bean
public IdGenerator idGenerator() {
return new JdkIdGenerator();
}
@Bean
public IdGenerator idGenerator() {
return new JdkIdGenerator();
}

@Bean
public Resource applicationCssResource() {
return new ApplicationCssResource();
}
@Bean
public Resource applicationCssResource() {
return new ApplicationCssResource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import java.util.function.BiConsumer;

import static org.licket.core.model.LicketComponentModel.emptyComponentModel;
import static org.licket.core.model.LicketComponentModel.ofString;
import static org.licket.core.view.LicketComponentView.internalTemplateView;
import static org.licket.core.view.hippo.ComponentModelProperty.fromComponentModelProperty;

/**
* @author activey
Expand Down Expand Up @@ -50,7 +50,7 @@ public final void onContactAdded(BiConsumer<Contact, ComponentActionCallback> ca
protected void onInitializeContainer() {
add(new LicketInput("name"));
add(new LicketInput("description"));
add(new AbstractLicketList("email", ofString("emails")) {
add(new AbstractLicketList("email", fromComponentModelProperty("emails")) {

@Override
protected void onInitializeContainer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ protected void onInitializeContainer() {
@Override
protected void onBeforeClick(ComponentFunctionCallback componentFunctionCallback) {
dimmer.api(componentFunctionCallback).show(this);

}

protected void onClick(Void modelObject) {
Expand All @@ -56,7 +55,6 @@ protected void onClick(Void modelObject) {
protected void onAfterClick(ComponentActionCallback componentActionCallback) {
componentActionCallback.reload(contactsPanel);
dimmer.api(componentActionCallback).hide(this);

}
});
add(new AbstractLicketLink("add-contact") {
Expand Down
42 changes: 21 additions & 21 deletions licket-demo/src/main/java/org/licket/demo/view/ContactsList.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.licket.demo.view;

import org.licket.core.model.LicketComponentModel;
import org.licket.core.view.LicketLabel;
import org.licket.core.view.hippo.ComponentModelProperty;
import org.licket.core.view.list.AbstractLicketList;
import org.licket.core.view.media.LicketImage;
import org.licket.core.view.mount.MountedComponentLink;
Expand All @@ -11,29 +11,29 @@
import java.util.Optional;

import static java.util.Optional.of;
import static org.licket.core.view.mount.params.MountingParamValueDecorator.fromParentModel;
import static org.licket.core.view.mount.params.MountingParamValueDecorator.fromParentModelProperty;

public class ContactsList extends AbstractLicketList {

public ContactsList(String id, LicketComponentModel<String> enclosingComponentPropertyModel) {
super(id, enclosingComponentPropertyModel);
}
public ContactsList(String id, ComponentModelProperty componentModelProperty) {
super(id, componentModelProperty);
}

@Override
protected void onInitializeContainer() {
add(new LicketImage("pictureUrl"));
add(new LicketLabel("name"));
add(new LicketLabel("description"));
add(new MountedComponentLink<Contact>("view-contact", ViewContactPanel.class) {
@Override
protected void aggregateParams(MountingParamsAggregator paramsAggregator) {
paramsAggregator.name("id").value(fromParentModel("id"));
}
});
}
@Override
protected void onInitializeContainer() {
add(new LicketImage("pictureUrl"));
add(new LicketLabel("name"));
add(new LicketLabel("description"));
add(new MountedComponentLink<Contact>("view-contact", ViewContactPanel.class) {
@Override
protected void aggregateParams(MountingParamsAggregator paramsAggregator) {
paramsAggregator.name("id").value(fromParentModelProperty("id"));
}
});
}

@Override
protected Optional<String> keyPropertyName() {
return of("id");
}
@Override
protected Optional<String> keyPropertyName() {
return of("id");
}
}
37 changes: 18 additions & 19 deletions licket-demo/src/main/java/org/licket/demo/view/ContactsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@
*/
public class ContactsPanel extends AbstractLicketMultiContainer<Contacts> {

@Autowired
private ContactsList contactsList;
@Autowired
private ContactsList contactsList;

@Autowired
private ContactsService contactsService;
@Autowired
private ContactsService contactsService;

public ContactsPanel(String id) {
super(id, Contacts.class, emptyComponentModel(), internalTemplateView());
}
public ContactsPanel(String id) {
super(id, Contacts.class, emptyComponentModel(), internalTemplateView());
}

@Override
protected void onInitializeContainer() {
add(contactsList);
@Override
protected void onInitializeContainer() {
add(contactsList);
readContacts();
}

readContacts();
}
private void readContacts() {
setComponentModelObject(fromIterable(contactsService.getAllContacts()));
}

private void readContacts() {
setComponentModelObject(fromIterable(contactsService.getAllContacts()));
}

public void reloadList() {
readContacts();
}
public void reloadList() {
readContacts();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import java.util.Optional;

import static org.licket.core.model.LicketComponentModel.ofModelObject;
import static org.licket.core.model.LicketComponentModel.ofString;
import static org.licket.core.view.LicketComponentView.fromComponentClass;
import static org.licket.core.view.LicketComponentView.internalTemplateView;
import static org.licket.core.view.hippo.ComponentModelProperty.fromComponentModelProperty;

/**
* @author lukaszgrabski
Expand All @@ -46,7 +46,7 @@ protected void onInitializeContainer() {
protected void onInitializeContainer() {
add(new LicketLabel("name"));
add(new LicketLabel("description"));
add(new AbstractLicketList("email", ofString("emails")) {
add(new AbstractLicketList("email", fromComponentModelProperty("emails")) {

@Override
protected void onInitializeContainer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
public class AddContactFormModalSection extends AbstractLicketMonoContainer<Void> {

public AddContactFormModalSection(String id) {
super(id, Void.class, emptyComponentModel(),
fromComponentClass(AddContactFormModalSection.class));
super(id, Void.class, emptyComponentModel(), fromComponentClass(AddContactFormModalSection.class));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*/
public abstract class AbstractAstNodeBuilder<T extends AstNode> {

public abstract T build();
public abstract T build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,41 @@
*/
public class ArrayElementGetBuilder extends AbstractAstNodeBuilder<ElementGet> {

private AbstractAstNodeBuilder<?> element;
private AbstractAstNodeBuilder<?> target;

private ArrayElementGetBuilder() {}

public static ArrayElementGetBuilder arrayElementGet() {
return new ArrayElementGetBuilder();
}

public ArrayElementGetBuilder element(StringLiteralBuilder stringLiteral) {
this.element = stringLiteral;
return this;
}

public ArrayElementGetBuilder element(String element) {
this.element = stringLiteral(element);
return this;
}

public ArrayElementGetBuilder target(PropertyNameBuilder propertyName) {
this.target = propertyName;
return this;
}

public ArrayElementGetBuilder target(AbstractAstNodeBuilder<?> propertyName) {
this.target = propertyName;
return this;
}

@Override
public ElementGet build() {
ElementGet elementGet = new ElementGet();
elementGet.setElement(element.build());
elementGet.setTarget(target.build());
return elementGet;
}
private AbstractAstNodeBuilder<?> element;
private AbstractAstNodeBuilder<?> target;

private ArrayElementGetBuilder() {
}

public static ArrayElementGetBuilder arrayElementGet() {
return new ArrayElementGetBuilder();
}

public ArrayElementGetBuilder element(StringLiteralBuilder stringLiteral) {
this.element = stringLiteral;
return this;
}

public ArrayElementGetBuilder element(String element) {
this.element = stringLiteral(element);
return this;
}

public ArrayElementGetBuilder target(PropertyNameBuilder propertyName) {
this.target = propertyName;
return this;
}

public ArrayElementGetBuilder target(AbstractAstNodeBuilder<?> propertyName) {
this.target = propertyName;
return this;
}

@Override
public ElementGet build() {
ElementGet elementGet = new ElementGet();
elementGet.setElement(element.build());
elementGet.setTarget(target.build());
return elementGet;
}
}
Loading