Example usage for org.apache.wicket.extensions.markup.html.form.palette Palette Palette

List of usage examples for org.apache.wicket.extensions.markup.html.form.palette Palette Palette

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.markup.html.form.palette Palette Palette.

Prototype

public Palette(final String id, final IModel<? extends Collection<T>> model,
        final IModel<? extends Collection<? extends T>> choicesModel,
        final IChoiceRenderer<? super T> choiceRenderer, final int rows, final boolean allowOrder,
        boolean allowMoveAll) 

Source Link

Document

Constructor.

Usage

From source file:nl.verheulconsultants.monitorisp.ui.HomePage.java

License:Open Source License

/**
 * Wicket initializes this page multiple times. Be aware not to execute code multiple times if not allowed.
 */// w ww  .  j a v  a2 s . c  o  m
public HomePage() {
    // Prevent spurious reloads by checking if the contoller is allready running
    // Only start automatically when the previous session data could be read
    if (CONTROLLER.isRunning()) {
        startAutomatically = false;
    } else {
        startAutomatically = CONTROLLER.initWithPreviousSessionData();
    }
    address = new InputRouterAddress(CONTROLLER.getRouterAddress());
    routerAddress = new TextField<>("routerAddress", new PropertyModel(address, "address"));
    newUrl = new TextField<>("newHost", Model.of(""));

    formSelectHosts = new Form<Void>("paletteForm") {
        @Override
        protected void onSubmit() {
            if (CONTROLLER.getSessionData().saveData()) {
                LOGGER.info("All data are saved.");
            }
        }
    };

    formRouter = new Form<Void>("routerForm") {
        @Override
        protected void onSubmit() {
            final String addressValue = routerAddress.getModelObject();
            if ("unknown".equals(addressValue) || isValidHostAddress(addressValue)) {
                CONTROLLER.setRouterAddress(addressValue);
                LOGGER.info("The router address is set to {}", addressValue);
            } else {
                error("Wrong router address. Please try again or type unknown");
            }
        }
    };

    stopButton = new Button("stopButton") {
        @Override
        public void onSubmit() {
            if (CONTROLLER != null && CONTROLLER.isBusyCheckingConnections()) {
                CONTROLLER.stopTemporarily();
                LOGGER.info("The service is stopped temporarely.");
            } else {
                LOGGER.info("Can not stop, the controller is not running.");
            }
        }
    };

    formNewHost = new Form<Void>("addHostForm") {
        @Override
        protected void onSubmit() {
            final String urlValue = newUrl.getModelObject();
            if (isValidHostAddress(urlValue)) {
                Collection<Host> hostsLocal = CONTROLLER.getPaletteModel().getObject();
                hostsLocal.add(new Host(Integer.toString(hostsLocal.size()), urlValue));
                LOGGER.info("The URL {} is added", urlValue);
                LOGGER.info("The host list is changed to {}", CONTROLLER.getPaletteModel());
            } else {
                error("Wrong host address. Please try again.");
            }
        }
    };

    startButton = new Button("startButton") {
        @Override
        public void onSubmit() {
            startRunning();
        }
    };

    removeButton = new Button("removeButton") {
        @Override
        public void onSubmit() {
            Collection<Host> hostsLocal = CONTROLLER.getPaletteModel().getObject();
            LOGGER.info("These URL's will be removed {}", CONTROLLER.getSelected());
            hostsLocal.removeAll(CONTROLLER.getSelected());
            LOGGER.info("The model is changed to {}", CONTROLLER.getPaletteModel());
        }
    };

    // To show a message.
    add(new FeedbackPanel("feedback"));

    IChoiceRenderer<Host> renderer = new ChoiceRenderer<>("hostAddress", "id");
    palette = new Palette<>("palette1", CONTROLLER.getSelectedModel(), CONTROLLER.getPaletteModel(), renderer,
            10, true, false);
    LOGGER.info("The palette is initiated with choices {}.", CONTROLLER.getPaletteModel());
    LOGGER.info("The palette is initiated with selection {}.", CONTROLLER.getSelected());

    // version 7.x.x
    palette.add(new DefaultTheme());

    add(formSelectHosts);
    formSelectHosts.add(palette);
    formSelectHosts.add(removeButton);
    formSelectHosts.add(startButton);
    formSelectHosts.add(stopButton);

    newUrl.setRequired(false);

    add(formNewHost);
    formNewHost.add(newUrl);

    add(formRouter);

    routerAddress.setRequired(false);
    formRouter.add(routerAddress);

    //get the list of items to display from provider (database, etc)
    //in the form of a LoadableDetachableModel
    IModel listStatusViewModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            return CONTROLLER.getStatusData();
        }
    };

    ListView statusListView = new ListView("statusListView", listStatusViewModel) {
        @Override
        protected void populateItem(final ListItem item) {
            StatusListItem sli = (StatusListItem) item.getModelObject();
            item.add(new Label("Name", sli.getName()));
            item.add(new Label("Value", sli.getValue()));
            item.add(new Label("Index", sli.getIndex()));
        }
    };

    //encapsulate the ListView in a WebMarkupContainer in order for it to update
    WebMarkupContainer statusListContainer = new WebMarkupContainer("statusContainer");
    //generate a markup-id so the contents can be updated through an AJAX call
    statusListContainer.setOutputMarkupId(true);
    statusListContainer.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(AJAX_UPDATE_INTERVAL)));
    // add the list view to the container
    statusListContainer.add(statusListView);
    // finally add the container to the page
    add(statusListContainer);

    //get the list of items to display from provider (database, etc)
    //in the form of a LoadableDetachableModel
    IModel listOutageViewModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            return CONTROLLER.getOutageDataReversedOrder();
        }
    };

    ListView outageListView = new ListView("outageListView", listOutageViewModel) {
        @Override
        protected void populateItem(final ListItem item) {
            OutageListItem olu = (OutageListItem) item.getModelObject();
            item.add(new Label("Index", olu.getIndex()));
            item.add(new Label("Start", olu.getStart()));
            item.add(new Label("End", olu.getEnd()));
            item.add(new Label("Duration", millisToTime(olu.getDuration())));
            item.add(new Label("OutageCausedInternal", olu.getOutageCauseAsString()));
        }
    };

    //encapsulate the ListView in a WebMarkupContainer in order for it to update
    WebMarkupContainer outageListContainer = new WebMarkupContainer("outageContainer");
    //generate a markup-id so the contents can be updated through an AJAX call
    outageListContainer.setOutputMarkupId(true);
    outageListContainer.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(AJAX_UPDATE_INTERVAL)));
    // add the list view to the container
    outageListContainer.add(outageListView);
    // finally add the container to the page
    add(outageListContainer);

    if (startAutomatically) {
        LOGGER.info("The controller will be started automatically.");
        startRunning();
    }
}