Created
July 9, 2019 14:44
-
-
Save mkgl/9f5e1f14ac22549856d60ec2389c5010 to your computer and use it in GitHub Desktop.
A sample hello world Vaadin app wrapped for Magnolia 6, featuring the `AlertBuilder`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# goes into ${magnolia.resources.dir} (light module) or src/main/resources (java module), under /samples/apps/hello.yaml | |
appClass: info.magnolia.dev.HelloMagnoliaApp | |
label: Hello Magnolia | |
icon: icon-forums-app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package info.magnolia.dev; | |
import static com.vaadin.ui.Notification.Type.HUMANIZED_MESSAGE; | |
import info.magnolia.icons.MagnoliaIcons; | |
import info.magnolia.ui.AlertBuilder; | |
import info.magnolia.ui.api.app.AppContext; | |
import info.magnolia.ui.api.app.AppView; | |
import info.magnolia.ui.api.location.Location; | |
import info.magnolia.ui.framework.app.BaseApp; | |
import java.text.MessageFormat; | |
import com.vaadin.ui.Button; | |
import com.vaadin.ui.FormLayout; | |
import com.vaadin.ui.Notification; | |
import com.vaadin.ui.TextField; | |
/** | |
* A sample hello world Vaadin app wrapped for Magnolia, featuring the {@link AlertBuilder}. | |
*/ | |
public class HelloMagnoliaApp extends BaseApp { | |
public HelloMagnoliaApp(AppContext appContext, AppView view) { | |
super(appContext, view); | |
} | |
@Override | |
public void start(Location location) { | |
// say hi | |
TextField nameField = new TextField("Enter your name"); | |
Button sayHi = new Button("Say Hello", event -> sayHello(nameField.getValue())); | |
sayHi.addStyleName("primary"); | |
Button notSureSayHi = new Button("Say Hello (not sure)", event -> { | |
String name = nameField.getValue(); | |
AlertBuilder.confirmDialog("Say hi?") | |
.withLevel(Notification.Type.HUMANIZED_MESSAGE) | |
.withBody("Are you sure you want to say hello?") | |
.withOkButtonCaption("You bet!") | |
.withDeclineButtonCaption("No way!") | |
.withConfirmationHandler(() -> sayHello(name)) | |
.buildAndOpen(); | |
}); | |
notSureSayHi.addStyleName("secondary"); | |
FormLayout form = new FormLayout(nameField, sayHi, notSureSayHi); | |
form.setSizeFull(); | |
getView().addSubAppView(() -> form, "Hello Resurface", MagnoliaIcons.MESSAGE_APP.getCssClass(), false); | |
} | |
private static void sayHello(String name) { | |
MessageFormat messageFormat = new MessageFormat("Hello {0}!"); | |
Notification.show(messageFormat.format(new Object[] { name }), HUMANIZED_MESSAGE); | |
} | |
@Override | |
public void locationChanged(Location location) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment