Skip to content

patternfly-java/patternfly-java

Repository files navigation

Verify Codebase Maven Central GWT3/J2CL compatible Chat on Gitter

PatternFly Java is a Java implementation of PatternFly 5 based on GWT/J2CL and Elemento. Its goal is to provide an easy-to-use, elegant, and efficient API to build complex web applications with PatternFly in Java. The following code snippet gives a taste of what PatternFly Java looks like:

body().add(page()
        .addSkipToContent(skipToContent("main-id"))
        .addMasthead(masthead()
                .addToggle(mastheadToggle())
                .addBrand(brand("/assets/your-logo.svg"), "#home"))
        .addSidebar(sidebar()
                .addBody(sidebarBody()
                        .addNavigation(navigation(flat)
                                .addItem(navigationItem("get-started", "Get started", "#get-started"))
                                .addItem(navigationItem("contribute", "Contribute", "#contribute"))
                                .addItem(navigationItem("get-in-touch", "Get in touch", "#get-in-touch")))))
        .addMain(pageMain("main-id")
                .addSection(pageMainSection()
                        .light()
                        .add(textContent()
                                .add(title(1, "PatternFly - Java"))
                                .add(p()
                                        .add(a("https://github.com/patternfly-java/patternfly-java", "_blank")
                                                .textContent("PatternFly Java"))
                                        .add(" is a Java implementation of ")
                                        .add(a("https://www.patternfly.org/", "_blank")
                                                .textContent("PatternFly"))
                                        .add(" based on GWT and ")
                                        .add(a("https://github.com/hal/elemento", "_blank")
                                                .textContent("Elemento"))
                                        .add("."))))));

To see more components in action, head over to the PatternFly Java showcase. It demonstrates the usage of all currently supported components. To get all details about how to use PatternFly Java take a look at the API documentation.

Getting Started

PatternFly Java is available in Maven Central. To use it, add the following dependency to your POM:

<dependency>
    <groupId>org.patternfly</groupId>
    <artifactId>patternfly-java</artifactId>
    <version>0.1.1</version>
</dependency>

If you're using GWT, inherit from org.patternfly.PatternFly:

<module>
    <inherits name="org.patternfly.PatternFly"/>
</module>

API Design

PatternFly Java integrates with and builds upon Elemento's builder API. Static factory methods are used to create the components, and public instances methods modify and add child elements.

expandableSection()
        .indented()
        .addToggle(expandableSectionToggle("Show more", "Show less"))
        .addContent(expandableSectionContent()
                .textContent("This content is visible only when the component is expanded."))
dropdown()
        .addToggle(menuToggle("Dropdown"))
        .addMenu(menu()
                .addContent(menuContent()
                        .addList(menuList()
                                .addItem(actionMenuItem("item-0", "Action"))
                                .addItem(linkMenuItem("item-1", "Link", "#home"))
                                .addItem(actionMenuItem("item-2", "Disabled action")
                                        .disabled())
                                .addItem(linkMenuItem("item-3", "Disabled link", "#")
                                        .disabled())
                                .addDivider()
                                .addItem(actionMenuItem("item-4", "Separated action"))
                                .addItem(linkMenuItem("item-5", "Separated link", "#home")))))

PatternFly Assets

PatternFly Java does not come with stylesheets, fonts, or other static PatternFly assets. We don't want to dictate how to embed these assets. One way is to download or get PatternFly using a CDN provider like jsDelivr and include the stylesheets in your HTML page. See the getting started section on the PatternFly website for more details.

Third Party

Some PatternFly components rely on 3rd party dependencies. If you want to use these components, you must add a call to ThirdParty.injectXyz() in your application.

Components Dependency Version Code
Dropdown
SingleSelect
MultiSelect
Popover
Tooltip
Popper 2.11.8 ThirdParty.injectPopper()
CodeEditor Monaco 0.44.0 ThirdParty.injectMonaco()

If you want to inject all dependencies, please use ThirdPrty.injectAll()

PatternFly Support

PatternFly Java aims to provide almost complete support for all components, charts, extensions, and layouts. The following issues show how many components, charts, extensions, and layouts have already been implemented.

Get Involved

PatternFly Java is still under development. The API might change, and things might not work as expected. Please give it a try and share your feedback. Join the chat, enter the discussions or use the GitHub issues to report bugs or request new features.

Of course, you're welcome to contribute to PatternFly Java. If you like what you're seeing, leave us a star!