Example usage for com.vaadin.server WebBrowser WebBrowser

List of usage examples for com.vaadin.server WebBrowser WebBrowser

Introduction

In this page you can find the example usage for com.vaadin.server WebBrowser WebBrowser.

Prototype

WebBrowser

Source Link

Usage

From source file:facs.components.Booking.java

License:Open Source License

private Component myNext24HoursBookings() {
    VerticalLayout devicesLayout = new VerticalLayout();
    // devicesLayout.setCaption("My Bookings");
    // there will now be space around the test component
    // components added to the test component will now not stick together but have space between
    // them// www. j  av a 2s. c om
    devicesLayout.setMargin(true);
    devicesLayout.setSpacing(true);

    Date serverTime = new WebBrowser().getCurrentDate();
    Date nextDayTime = new Date(serverTime.getTime() + (1000 * 60 * 60 * 24));

    BeanItemContainer<BookingBean> users = getMyNext24HoursBookings(bookingModel.getLDAP(), serverTime,
            nextDayTime);
    // System.out.println(bookingModel.getLDAP());

    GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(users);

    next24HoursBookings = new Grid(gpc);
    // Create a grid
    next24HoursBookings.setStyleName("my-style");
    next24HoursBookings.setWidth("100%");
    next24HoursBookings.setSelectionMode(SelectionMode.SINGLE);
    next24HoursBookings.setEditorEnabled(false);

    next24HoursBookings.setColumnOrder("ID", "confirmation", "deviceName", "service", "start", "end",
            "username", "phone", "price");
    next24HoursBookings.getColumn("price").setHeaderCaption("Approx. Price");
    setRenderers(next24HoursBookings);
    devicesLayout.addComponent(next24HoursBookings);

    return devicesLayout;
}

From source file:facs.components.Booking.java

License:Open Source License

private Component myPastBookings() {
    VerticalLayout devicesLayout = new VerticalLayout();
    // devicesLayout.setCaption("My Bookings");
    // there will now be space around the test component
    // components added to the test component will now not stick together but have space between
    // them/*from   w  w w . ja  v  a  2  s. c  o  m*/
    devicesLayout.setMargin(true);
    devicesLayout.setSpacing(true);

    Date serverTime = new WebBrowser().getCurrentDate();

    BeanItemContainer<BookingBean> users = getMyPastBookings(bookingModel.getLDAP(), serverTime);
    // System.out.println(bookingModel.getLDAP());

    GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(users);

    pastBookings = new Grid(gpc);
    // Create a grid
    pastBookings.setStyleName("my-style");
    pastBookings.setWidth("100%");
    pastBookings.setSelectionMode(SelectionMode.SINGLE);
    pastBookings.setEditorEnabled(false);

    pastBookings.setColumnOrder("ID", "confirmation", "deviceName", "service", "start", "end", "username",
            "phone", "price");

    pastBookings.getColumn("price").setHeaderCaption("Approx. Price");

    setRenderers(pastBookings);
    devicesLayout.addComponent(pastBookings);

    return devicesLayout;
}

From source file:facs.components.Booking.java

License:Open Source License

private Component myUpcomingBookingsSQLContainer() {

    VerticalLayout devicesLayout = new VerticalLayout();
    // devicesLayout.setCaption("My Bookings");
    // there will now be space around the test component
    // components added to the test component will now not stick together but have space between
    // them/*w w w .  j  a va2  s. com*/
    devicesLayout.setMargin(true);
    devicesLayout.setSpacing(true);

    Date serverTime = new WebBrowser().getCurrentDate();
    Date nextDayTime = new Date(serverTime.getTime() + (1000 * 60 * 60 * 24));

    try {
        TableQuery tq = new TableQuery("booking", DBManager.getDatabaseInstanceAlternative());
        tq.setVersionColumn("OPTLOCK");
        SQLContainer container = new SQLContainer(tq);

        // System.out.println("Print Container: " + container.size());
        container.setAutoCommit(isEnabled());

        upcomingBookings = new Grid(container);

        FieldGroup fieldGroup = upcomingBookings.getEditorFieldGroup();
        fieldGroup.addCommitHandler(new FieldGroup.CommitHandler() {
            /**
             * 
             */
            private static final long serialVersionUID = 3799806709907688919L;

            @Override
            public void preCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {

            }

            @Override
            public void postCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {

                Notification("Successfully Updated",
                        "Selected values are updated in the database. If it was a mistake, please remind that there is no 'undo' functionality yet.",
                        "success");

                refreshGrid();
            }

            private void refreshGrid() {
                container.refresh();
            }

        });

    } catch (Exception e) {
        // TODO Auto-generated catch block
        Notification("Something went wrong!",
                "Unable to update/connect the database. There may be a connection problem, please check your internet connection settings then try it again.",
                "error");
        e.printStackTrace();
    }

    upcomingBookings.clearSortOrder();

    upcomingBookings.setStyleName("my-style");
    upcomingBookings.setWidth("100%");
    upcomingBookings.setSelectionMode(SelectionMode.SINGLE);
    upcomingBookings.setEditorEnabled(false);

    devicesLayout.addComponent(upcomingBookings);

    // TODO filtering
    // HeaderRow filterRow = devicesGrid.prependHeaderRow();

    return devicesLayout;
}

From source file:facs.components.Booking.java

License:Open Source License

private Component myUpcomingBookings() {
    VerticalLayout devicesLayout = new VerticalLayout();
    // devicesLayout.setCaption("My Bookings");
    // there will now be space around the test component
    // components added to the test component will now not stick together but have space between
    // them//  w w  w  .  j a v  a2s. co m
    devicesLayout.setMargin(true);
    devicesLayout.setSpacing(true);

    Date serverTime = new WebBrowser().getCurrentDate();
    Date nextDayTime = new Date(serverTime.getTime() + (1000 * 60 * 60 * 24));

    BeanItemContainer<BookingBean> users = getMyUpcomingBookings(bookingModel.getLDAP(), nextDayTime);
    // System.out.println(bookingModel.getLDAP());

    GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(users);
    gpc.addGeneratedProperty("delete", new PropertyValueGenerator<String>() {
        /**
         * 
         */
        private static final long serialVersionUID = 1263377339178640406L;

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            // return FontAwesome.TRASH_O.getHtml(); // The caption
            return "Trash"; // The caption

        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });

    /*
     * 
     * try {
     * 
     * FreeformQuery query = new FreeformQuery(
     * "SELECT * FROM booking INNER JOIN user ON booking.user_ldap = user.user_ldap WHERE deleted IS NULL AND booking.user_ldap ='"
     * + bookingModel.getLDAP() + "';", DBManager.getDatabaseInstanceAlternative(), "booking_id");
     * SQLContainer container = new SQLContainer(query);
     * 
     * // System.out.println("Print Container: " + container.size());
     * container.setAutoCommit(isEnabled());
     * 
     * myBookings = new Grid(container);
     * 
     * } catch (Exception e) { e.printStackTrace(); }
     * 
     * myBookings.setColumnOrder("booking_id", "confirmation", "device_name", "service", "start",
     * "end", "kostenstelle", "price", "project");
     * 
     * myBookings.removeColumn("user_ldap"); myBookings.removeColumn("timestamp");
     * myBookings.removeColumn("deleted"); myBookings.removeColumn("user_name");
     * myBookings.removeColumn("group_id"); myBookings.removeColumn("workgroup_id");
     * myBookings.removeColumn("email"); myBookings.removeColumn("phone");
     * myBookings.removeColumn("admin_panel"); myBookings.removeColumn("user_id");
     * 
     * myBookings.getColumn("booking_id").setHeaderCaption("Booking ID");
     */

    upcomingBookings = new Grid(gpc);
    // Create a grid
    upcomingBookings.setStyleName("my-style");
    upcomingBookings.setWidth("100%");
    upcomingBookings.setSelectionMode(SelectionMode.SINGLE);
    upcomingBookings.setEditorEnabled(false);

    upcomingBookings.setColumnOrder("ID", "confirmation", "deviceName", "service", "start", "end", "username",
            "phone", "price");
    upcomingBookings.getColumn("price").setHeaderCaption("Approx. Price");

    // System.out.println(myBookings.getColumns());
    setRenderers(upcomingBookings);
    devicesLayout.addComponent(upcomingBookings);

    upcomingBookings.getColumn("delete")
            .setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {
                /**
                 * 
                 */
                private static final long serialVersionUID = 302628105070456680L;

                @Override
                public void click(RendererClickEvent event) {

                    try {

                        Window cd = new Window("Delete Booking");

                        cd.setHeight("200px");
                        cd.setWidth("400px");
                        cd.setResizable(false);

                        GridLayout dialogLayout = new GridLayout(3, 3);

                        Button okButton = new Button("Yes");
                        okButton.addStyleName(ValoTheme.BUTTON_DANGER);
                        Button cancelButton = new Button("No, I'm actually not sure!");
                        cancelButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
                        Label information = new Label("Are you sure you want to trash this item?");
                        information.addStyleName(ValoTheme.LABEL_NO_MARGIN);

                        okButton.addClickListener(new Button.ClickListener() {
                            /**
                             * 
                             */
                            private static final long serialVersionUID = 1778157399909757369L;

                            @Override
                            public void buttonClick(ClickEvent okEvent) {

                                purgeBooking((BookingBean) event.getItemId());

                                booking.setSelectedTab(myUpcomingBookings());

                                cd.close();

                                showNotification("The booking was deleted!",
                                        "You wanted to delete an upcoming booking and it wasn't within the next 24 hours. All good, item purged.");
                            }
                        });

                        cancelButton.addClickListener(new Button.ClickListener() {
                            /**
                             * 
                             */
                            private static final long serialVersionUID = -8957620319158438769L;

                            @Override
                            public void buttonClick(ClickEvent okEvent) {
                                cd.close();
                            }
                        });

                        dialogLayout.addComponent(information, 0, 0, 2, 0);
                        dialogLayout.addComponent(okButton, 0, 1);
                        dialogLayout.addComponent(cancelButton, 1, 1);
                        dialogLayout.setMargin(true);
                        dialogLayout.setSpacing(true);
                        cd.setContent(dialogLayout);
                        cd.center();
                        UI.getCurrent().addWindow(cd);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }

            }));

    // TODO filtering
    // HeaderRow filterRow = devicesGrid.prependHeaderRow();

    return devicesLayout;
}