Example usage for com.google.gwt.user.client.ui SimpleCheckBox wrap

List of usage examples for com.google.gwt.user.client.ui SimpleCheckBox wrap

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui SimpleCheckBox wrap.

Prototype

public static SimpleCheckBox wrap(Element element) 

Source Link

Document

Creates a SimpleCheckBox widget that wraps an existing <input type='checkbox'> element.

Usage

From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java

License:Apache License

/** preserves event handlers on element to be wrapped */
public static Widget elementToWidget(Element e, String typ) {
    Widget result = null;//  www . j  a va 2  s. co m
    if (e != null) {
        int eventsSunk = DOM.getEventsSunk(e);
        EventListener el = DOM.getEventListener(e);
        if (typ == TEXT)
            result = TextBox.wrap(e);
        else if (typ == TEXT_AREA)
            result = TextArea.wrap(e);
        else if (typ == PASSWORD)
            result = PasswordTextBox.wrap(e);
        else if (typ == LABEL)
            result = Label.wrap(e);
        else if (typ == A)
            result = Anchor.wrap(e);
        else if (typ == IMAGE)
            result = Image.wrap(e);
        else if (typ == SELECT)
            result = ListBox.wrap(e);
        else if (typ == HIDDEN)
            result = Hidden.wrap(e);
        else if (typ == FILE)
            result = FileUpload.wrap(e);
        else if (typ == FORM)
            result = FormPanel.wrap(e, true);
        else if (typ == FRAME)
            result = Frame.wrap(e);
        else if (typ == SUBMIT)
            result = SubmitButton.wrap(e);
        else if (typ == BUTTON)
            result = Button.wrap(e);
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
        DOM.sinkEvents(e, eventsSunk);
        DOM.setEventListener(e, el);
    } else {
        if (typ == TEXT)
            result = new TextBox();
        else if (typ == TEXT_AREA)
            result = new TextArea();
        else if (typ == PASSWORD)
            result = new PasswordTextBox();
        else if (typ == LABEL)
            result = new Label();
        else if (typ == A)
            result = new Anchor();
        else if (typ == SELECT)
            result = new ListBox();
        else if (typ == IMAGE)
            result = new Image();
        else if (typ == HIDDEN)
            result = new Hidden();
        else if (typ == FILE)
            result = new FileUpload();
        else if (typ == FORM)
            result = new FormPanel();
        else if (typ == FRAME)
            result = new Frame();
        else if (typ == SUBMIT)
            result = new SubmitButton();
        else if (typ == BUTTON)
            result = new Button();
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
    }
    return result;
}

From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java

License:Apache License

/** preserves event handlers on element to be wrapped  */
public static Widget elementToWidget(String elementName, String typ) {
    Widget result = null;/* w w  w.j  a  va 2  s  . c  o  m*/
    Element e = DOM.getElementById(elementName);
    if (e != null) {
        int eventsSunk = DOM.getEventsSunk(e);
        EventListener el = DOM.getEventListener(e);
        if (typ == TEXT)
            result = TextBox.wrap(e);
        else if (typ == TEXT_AREA)
            result = TextArea.wrap(e);
        else if (typ == PASSWORD)
            result = PasswordTextBox.wrap(e);
        else if (typ == LABEL)
            result = Label.wrap(e);
        else if (typ == A)
            result = Anchor.wrap(e);
        else if (typ == SELECT)
            result = ListBox.wrap(e);
        else if (typ == IMAGE)
            result = Image.wrap(e);
        else if (typ == HIDDEN)
            result = Hidden.wrap(e);
        else if (typ == FILE)
            result = FileUpload.wrap(e);
        else if (typ == FORM)
            result = FormPanel.wrap(e, true);
        else if (typ == FRAME)
            result = Frame.wrap(e);
        else if (typ == SUBMIT)
            result = SubmitButton.wrap(e);
        else if (typ == BUTTON)
            result = Button.wrap(e);
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
        DOM.sinkEvents(e, eventsSunk);
        DOM.setEventListener(e, el);
    } else {
        if (typ == TEXT)
            result = new TextBox();
        else if (typ == TEXT_AREA)
            result = new TextArea();
        else if (typ == PASSWORD)
            result = new PasswordTextBox();
        else if (typ == LABEL)
            result = new Label();
        else if (typ == A)
            result = new Anchor();
        else if (typ == IMAGE)
            result = new Image();
        else if (typ == SELECT)
            result = new ListBox();
        else if (typ == HIDDEN)
            result = new Hidden();
        else if (typ == FILE)
            result = new FileUpload();
        else if (typ == FORM)
            result = new FormPanel();
        else if (typ == FRAME)
            result = new Frame();
        else if (typ == SUBMIT)
            result = new SubmitButton();
        else if (typ == BUTTON)
            result = new Button();
        else if (typ == CHECK_BOX)
            result = SimpleCheckBox.wrap(e);
    }
    return result;
}

From source file:fr.gael.dhus.gwt.client.page.management.ManagementCollectionsPage.java

License:Open Source License

private static void getProducts(final int start, final int length, final String search,
        final JavaScriptObject function) {
    DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait");
    final Long parentId = selectedCollection != null && selectedCollection.getParent() != null
            ? selectedCollection.getParent().getId()
            : null;//  w  w  w .  j  av a2  s .  co m

    GWTClient.callback(function,
            JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}"));
    productService.count(search, parentId, new AccessDeniedRedirectionCallback<Integer>() {
        @Override
        public void _onFailure(Throwable caught) {
            DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
            Window.alert("There was an error while counting products");
        }

        @Override
        public void onSuccess(final Integer total) {
            //selectedCollection.getParent ().getId ()
            productService.getProducts(start, length, search, parentId,
                    new AccessDeniedRedirectionCallback<List<ProductData>>() {
                        @Override
                        public void _onFailure(Throwable caught) {
                            DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
                            Window.alert("There was an error while searching for '" + search + "'");
                        }

                        @Override
                        public void onSuccess(List<ProductData> products) {
                            displayedProducts = products;
                            boolean allChecked = true;
                            String json = "{\"aaData\": [";
                            for (ProductData product : products) {
                                boolean checked = (selectedCollection != null
                                        && selectedCollection.contains(product.getId()));
                                allChecked = allChecked && checked;
                                json += "[{\"checked\":" + checked + ", \"id\":\"" + product.getId()
                                        + "\" }, \"" + product.getIdentifier() + "\"],";
                            }
                            if (total > 0) {
                                json = json.substring(0, json.length() - 1);
                            } else {
                                allChecked = false;
                                productsCheckAllDisabled = true;
                            }
                            json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total
                                    + "}";

                            GWTClient.callback(function, JsonUtils.safeEval(json));
                            DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");

                            productsCheckAll = SimpleCheckBox
                                    .wrap(RootPanel.get("productsCheckAll").getElement());
                            productsCheckAll.setValue(allChecked);
                            productsCheckAll.setEnabled(!productsCheckAllDisabled && (state == State.EDIT
                                    || state == State.CREATE || state == State.CREATESUB));
                        }
                    });
        }
    });
}

From source file:fr.gael.dhus.gwt.client.page.management.ManagementDataRightPage.java

License:Open Source License

private static void getProducts(final int start, final int length, final String search,
        final JavaScriptObject function) {
    DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait");

    GWTClient.callback(function,/*from w w  w . j  a  va 2  s .  c o  m*/
            JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}"));

    productService.count(search, null, new AccessDeniedRedirectionCallback<Integer>() {
        @Override
        public void _onFailure(Throwable caught) {
            DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
            Window.alert("There was an error while counting products");
        }

        @Override
        public void onSuccess(final Integer total) {
            productService.getProducts(start, length, search, null,
                    new AccessDeniedRedirectionCallback<List<ProductData>>() {
                        @Override
                        public void _onFailure(Throwable caught) {
                            DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
                            Window.alert("There was an error while searching for '" + search + "'");
                        }

                        @Override
                        public void onSuccess(List<ProductData> products) {
                            displayedProducts = products;
                            boolean allChecked = true;
                            boolean allPublic = true;
                            boolean children = true;
                            String json = "{\"aaData\": [";
                            for (ProductData product : products) {
                                boolean checked = (selectedUser != null
                                        && selectedUser.containsProduct(product.getId()));
                                allChecked = allChecked && checked;
                                boolean publicProduct = (publicData != null
                                        && publicData.getId() != selectedUser.getId()
                                        && publicData.containsProduct(product.getId()))
                                        || (publicData != null && publicData.getId() == selectedUser.getId()
                                                && publicData.fromPublicCollection(product.getId()));
                                allPublic = allPublic && publicProduct;
                                json += "[{\"checked\":" + checked + ", \"publicData\":" + publicProduct
                                        + ", \"id\":\"" + product.getId() + "\" }, \"" + product.getIdentifier()
                                        + "\"],";
                            }
                            if (total > 0) {
                                json = json.substring(0, json.length() - 1);
                            } else {
                                allChecked = false;
                                children = false;
                            }
                            json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total
                                    + "}";

                            GWTClient.callback(function, JsonUtils.safeEval(json));
                            DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");

                            productsCheckAll = SimpleCheckBox
                                    .wrap(RootPanel.get("dr_productsCheckAll").getElement());
                            productsCheckAll.setValue(allChecked);
                            productsCheckAll.setEnabled(children && state == State.EDIT && !allPublic);
                            productsCheckAll.setTitle(allPublic ? "All products are public" : "");
                        }
                    });
        }
    });
}

From source file:fr.gael.dhus.gwt.client.page.management.ManagementDataRightPage.java

License:Open Source License

private static void getCollections(final JavaScriptObject function) {
    GWTClient.callback(function,/*from  w  w  w. java  2 s .  com*/
            JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}"));

    DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait");
    if (root == null) {
        root = new CollectionData();
        root.setId(null);
        root.setDeep(-1);
    }
    toRefresh = new ArrayList<Long>();
    for (CollectionData c : displayedCollections.values()) {
        if (c.getDisplayedChildren() != null && c.getDisplayedChildren().size() > 0) {
            toRefresh.add(c.getId());
        }
    }
    displayedCollections.clear();
    requestCollections(root, new AccessDeniedRedirectionCallback<Void>() {
        @Override
        public void _onFailure(Throwable caught) {
            Window.alert("There was an error while requesting collections.\n" + caught.getMessage());
            DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
        }

        @Override
        public void onSuccess(Void result) {
            collectionsCheckAllChecked = true;
            collectionsAllPublic = true;
            String json = "{\"aaData\": [";
            json += computeJSON(root);
            boolean children = false;
            if (root.getDisplayedChildren() != null && root.getDisplayedChildren().size() > 0) {
                json = json.substring(0, json.length() - 1);
                children = true;
            }
            json += "],\"iTotalRecords\" : " + (children ? 1 : 0) + ", \"iTotalDisplayRecords\" : "
                    + (children ? 1 : 0) + "}";
            GWTClient.callback(function, JsonUtils.safeEval(json));
            DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");

            collectionsCheckAll = SimpleCheckBox.wrap(RootPanel.get("dr_collectionsCheckAll").getElement());
            collectionsCheckAll.setValue(children && collectionsCheckAllChecked);
            collectionsCheckAll.setEnabled(children && state == State.EDIT && !collectionsAllPublic);
            collectionsCheckAll.setTitle(collectionsAllPublic ? "All collections are public" : "");
        }
    });
}

From source file:fr.gael.dhus.gwt.client.page.management.ManagementSystemPage.java

License:Open Source License

private static void init() {
    showSystemManagement();//from w  w  w  .ja  v  a2  s  . co  m

    smtpBox = TextBox.wrap(RootPanel.get("managementSystem_server").getElement());
    portBox = TextBox.wrap(RootPanel.get("managementSystem_port").getElement());
    tlsBox = SimpleCheckBox.wrap(RootPanel.get("managementSystem_tls").getElement());
    username = TextBox.wrap(RootPanel.get("managementSystem_username").getElement());
    password = TextBox.wrap(RootPanel.get("managementSystem_password").getElement());
    fromName = TextBox.wrap(RootPanel.get("managementSystem_expeditorName").getElement());
    fromMail = TextBox.wrap(RootPanel.get("managementSystem_expeditorMail").getElement());
    replyTo = TextBox.wrap(RootPanel.get("managementSystem_reply").getElement());
    registrationMail = TextBox.wrap(RootPanel.get("managementSystem_registrationMail").getElement());
    supportMail = TextBox.wrap(RootPanel.get("managementSystem_supportMail").getElement());
    supportName = TextBox.wrap(RootPanel.get("managementSystem_supportName").getElement());
    mailDelete = SimpleCheckBox.wrap(RootPanel.get("managementSystem_mailOnDelete").getElement());
    mailCreate = SimpleCheckBox.wrap(RootPanel.get("managementSystem_mailOnCreate").getElement());
    mailUpdate = SimpleCheckBox.wrap(RootPanel.get("managementSystem_mailOnUpdate").getElement());
    synchronizeLocalArchive = RootPanel.get("managementSystem_resetArchive");
    resetDefault = RootPanel.get("managementSystem_resetDefault");
    saveModifications = RootPanel.get("managementSystem_saveModifications");
    rootOldPassword = TextBox.wrap(RootPanel.get("managementSystem_oldRootPassword").getElement());
    rootPassword = TextBox.wrap(RootPanel.get("managementSystem_newRootPassword").getElement());
    root2Password = TextBox.wrap(RootPanel.get("managementSystem_newRootPasswordConfirm").getElement());
    saveRootPassword = RootPanel.get("managementSystem_saveRoot");
    dumpBox = ListBox.wrap(RootPanel.get("managementSystem_restoreSelect").getElement());
    restoreButton = RootPanel.get("managementSystem_restoreButton");

    // click handlers
    resetDefault.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (resetDefault.getElement().getClassName().contains("disabled")) {
                return;
            }
            disableGeneralPanel();
            systemService.resetToDefaultConfiguration(systemSettingsCallback);
        }
    }, ClickEvent.getType());
    synchronizeLocalArchive.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (synchronizeLocalArchive.getElement().getClassName().contains("disabled")) {
                return;
            }
            archiveService.synchronizeLocalArchive(new AccessDeniedRedirectionCallback<Integer>() {
                @Override
                public void _onFailure(Throwable caught) {
                    Window.alert("Local archive was not synchronized.\n" + caught.getMessage());
                }

                @Override
                public void onSuccess(Integer result) {
                    Window.alert("Local archive synchronization is successfully launched. Ingestion of "
                            + result + " found product" + (result > 1 ? "s" : "") + " is now running.");
                }
            });
        }
    }, ClickEvent.getType());
    saveModifications.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (saveModifications.getElement().getClassName().contains("disabled")) {
                return;
            }
            disableGeneralPanel();
            ConfigurationData confData = new ConfigurationData();

            confData.setMailWhenCreate(mailCreate.getValue());
            confData.setMailWhenUpdate(mailUpdate.getValue());
            confData.setMailWhenDelete(mailDelete.getValue());

            confData.setMailServerSmtp(smtpBox.getValue());
            confData.setMailServerPassword(password.getValue());
            confData.setMailServerTls(tlsBox.getValue());
            confData.setMailServerPort(Integer.parseInt(portBox.getValue()));
            confData.setMailServerUser(username.getValue());

            confData.setMailServerFromMail(fromMail.getValue());
            confData.setMailServerFromName(fromName.getValue());
            confData.setMailServerReplyTo(replyTo.getValue());

            confData.setRegistrationMail(registrationMail.getValue());
            confData.setSupportMail(supportMail.getValue());
            confData.setSupportName(supportName.getValue());

            systemService.saveConfiguration(confData, systemSettingsCallback);
        }
    }, ClickEvent.getType());
    saveRootPassword.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (saveRootPassword.getElement().getClassName().contains("disabled")) {
                return;
            }
            root2Password.setEnabled(false);
            rootOldPassword.setEnabled(false);
            rootPassword.setEnabled(false);
            saveRootPassword.getElement().setClassName("button_disabled");
            String newPassword = rootPassword.getValue();
            String oldPassword = rootOldPassword.getValue();
            systemService.changeRootPassword(newPassword, oldPassword,
                    new AccessDeniedRedirectionCallback<Void>() {
                        @Override
                        public void _onFailure(Throwable caught) {
                            Window.alert("Root password was not changed.\n" + caught.getMessage());
                            root2Password.setEnabled(true);
                            rootOldPassword.setEnabled(true);
                            rootPassword.setEnabled(true);
                            saveRootPassword.getElement().setClassName("button_black");
                        }

                        @Override
                        public void onSuccess(Void result) {
                            Window.alert("Root password was changed.");
                            root2Password.setValue("");
                            rootOldPassword.setValue("");
                            rootPassword.setValue("");
                            root2Password.setEnabled(true);
                            rootOldPassword.setEnabled(true);
                            rootPassword.setEnabled(true);
                            saveRootPassword.getElement().setClassName("button_black");
                        }
                    });
        }
    }, ClickEvent.getType());
    restoreButton.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (restoreButton.getElement().getClassName().contains("disabled")) {
                return;
            }
            dumpBox.setEnabled(false);
            restoreButton.getElement().setClassName("button_disabled");
            systemService.restoreDatabase(dumpDates.get(dumpBox.getSelectedIndex()),
                    new AccessDeniedRedirectionCallback<Void>() {

                        @Override
                        public void _onFailure(Throwable caught) {
                            Window.alert("Error while restoring database.\n" + caught.getMessage());
                            dumpBox.setEnabled(true);
                            restoreButton.getElement().setClassName("button_black");
                        }

                        @Override
                        public void onSuccess(Void result) {
                            Window.alert("Database was successfully restored.");
                            dumpBox.setEnabled(true);
                            restoreButton.getElement().setClassName("button_black");
                        }
                    });
        }
    }, ClickEvent.getType());

    systemSettingsCallback = new AccessDeniedRedirectionCallback<ConfigurationData>() {
        @Override
        public void _onFailure(Throwable caught) {
            Window.alert("Error while loading system data.\n" + caught.getMessage());
            smtpBox.setValue("");
            portBox.setValue("");
            tlsBox.setValue(false);
            username.setValue("");
            password.setValue("");
            fromMail.setValue("");
            fromName.setValue("");
            replyTo.setValue("");
            mailCreate.setValue(false);
            mailUpdate.setValue(false);
            mailDelete.setValue(false);
            registrationMail.setValue("");
            supportMail.setValue("");
            supportName.setValue("");

            root2Password.setValue("");
            rootOldPassword.setValue("");
            rootPassword.setValue("");
            saveRootPassword.getElement().setClassName("button_disabled");
            enableGeneralPanel();
        }

        @Override
        public void onSuccess(ConfigurationData result) {
            smtpBox.setValue(result.getMailServerSmtp());
            portBox.setValue(new Integer(result.getMailServerPort()).toString());
            tlsBox.setValue(result.isMailServerTls());
            username.setValue(result.getMailServerUser());
            password.setValue(result.getMailServerPassword());
            fromMail.setValue(result.getMailServerFromMail());
            fromName.setValue(result.getMailServerFromName());
            replyTo.setValue(result.getMailServerReplyTo());
            mailCreate.setValue(result.isMailWhenCreate());
            mailUpdate.setValue(result.isMailWhenUpdate());
            mailDelete.setValue(result.isMailWhenDelete());
            registrationMail.setValue(result.getRegistrationMail());
            supportMail.setValue(result.getSupportMail());
            supportName.setValue(result.getSupportName());

            root2Password.setValue("");
            rootOldPassword.setValue("");
            rootPassword.setValue("");
            saveRootPassword.getElement().setClassName("button_disabled");
            enableGeneralPanel();
        }

    };

    getDumpDatabaseListCallback = new AccessDeniedRedirectionCallback<List<Date>>() {
        @Override
        public void _onFailure(Throwable caught) {
            Window.alert("Error while requesting dump dates.\n" + caught.getMessage());
            dumpDates = null;
            dumpBox.clear();
            dumpBox.setEnabled(false);
            restoreButton.getElement().setClassName("button_disabled");
        }

        @Override
        public void onSuccess(List<Date> result) {
            DateTimeFormat sdf = DateTimeFormat.getFormat("EEEE dd MMMM yyyy - HH:mm:ss");
            dumpDates = result;
            dumpBox.clear();
            for (Date date : dumpDates) {
                dumpBox.addItem(sdf.format(date));
            }
            dumpBox.setEnabled(dumpDates.size() > 0);
            restoreButton.getElement().setClassName(dumpDates.size() > 0 ? "button_black" : "button_disabled");
        }
    };

    systemService.getConfiguration(systemSettingsCallback);
    systemService.getDumpDatabaseList(getDumpDatabaseListCallback);
}

From source file:fr.gael.dhus.gwt.client.page.management.ManagementUsersPage.java

License:Open Source License

private static void init() {
    showUserManagement();//  ww  w  .  j  a v a2s  . co m

    username = TextBox.wrap(RootPanel.get("managementUser_username").getElement());
    mail = TextBox.wrap(RootPanel.get("managementUser_mail").getElement());
    firstname = TextBox.wrap(RootPanel.get("managementUser_firstname").getElement());
    lastname = TextBox.wrap(RootPanel.get("managementUser_lastname").getElement());
    phone = TextBox.wrap(RootPanel.get("managementUser_phone").getElement());
    address = TextBox.wrap(RootPanel.get("managementUser_address").getElement());
    country = ListBox.wrap(RootPanel.get("managementUser_country").getElement());
    domain = ListBox.wrap(RootPanel.get("managementUser_domain").getElement());
    subDomain = TextBox.wrap(RootPanel.get("managementUser_subDomain").getElement());
    usage = ListBox.wrap(RootPanel.get("managementUser_usage").getElement());
    subUsage = TextBox.wrap(RootPanel.get("managementUser_subUsage").getElement());
    locked = SimpleCheckBox.wrap(RootPanel.get("managementUser_locked").getElement());
    lockedReason = TextBox.wrap(RootPanel.get("managementUser_lockedReason").getElement());
    createButton = RootPanel.get("managementUser_buttonCreate");
    resetButton = RootPanel.get("managementUser_buttonReset");
    saveButton = RootPanel.get("managementUser_buttonSave");
    updateButton = RootPanel.get("managementUser_buttonUpdate");
    deleteButton = RootPanel.get("managementUser_buttonDelete");
    cancelButton = RootPanel.get("managementUser_buttonCancel");

    userService.getCountries(new AccessDeniedRedirectionCallback<List<CountryData>>() {
        @Override
        public void onSuccess(List<CountryData> result) {
            for (CountryData ctry : result) {
                country.addItem(ctry.getName(), ctry.getId().toString());
            }
        }

        @Override
        public void _onFailure(Throwable caught) {
            Window.alert("There was an error while requesting countries.\n" + caught.getMessage());
        }
    });

    locked.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            lockedReason.setEnabled(locked.getValue());
            // enabled
            if (locked.getValue()) {
                lockedReason.setValue(oldLockedValue);
            }
            // disabled
            else {
                oldLockedValue = lockedReason.getValue();
                lockedReason.setValue(null);
            }
        }
    });
    lockedReason.setEnabled(false);
    createButton.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (createButton.getElement().getClassName().contains("disabled")) {
                return;
            }
            deselect();
            setState(State.CREATE, true);
        }
    }, ClickEvent.getType());
    resetButton.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (resetButton.getElement().getClassName().contains("disabled")) {
                return;
            }
            setState(State.CREATE, true);
        }
    }, ClickEvent.getType());
    saveButton.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (saveButton.getElement().getClassName().contains("disabled")) {
                return;
            }
            save(true);
        }
    }, ClickEvent.getType());
    updateButton.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (updateButton.getElement().getClassName().contains("disabled")) {
                return;
            }
            save(false);
        }
    }, ClickEvent.getType());
    deleteButton.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (deleteButton.getElement().getClassName().contains("disabled")) {
                return;
            }
            UserData selected = selectedUser;
            disableAll();

            userService.deleteUser(selected.getId(), new AccessDeniedRedirectionCallback<Void>() {

                @Override
                public void _onFailure(Throwable caught) {
                    if (caught instanceof UserServiceMailingException) {
                        Window.alert("User has been deleted, there was an error while sending email to user.\n"
                                + caught.getMessage());
                    } else {
                        Window.alert("User cannot be deleted.\n " + caught.getMessage());
                    }

                    setNothingState();
                    refreshUsers();
                }

                @Override
                public void onSuccess(Void result) {
                    setNothingState();
                    refreshUsers();
                }
            });
        }
    }, ClickEvent.getType());
    cancelButton.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (cancelButton.getElement().getClassName().contains("disabled")) {
                return;
            }
            setNothingState();
        }
    }, ClickEvent.getType());

    setNothingState();
}

From source file:fr.gael.dhus.gwt.client.page.management.ManagementUsersPage.java

License:Open Source License

private static void getRoles(final int start, final int length, final JavaScriptObject function) {
    boolean allChecked = true;
    String json = "{\"aaData\": [";
    int total = RoleData.getEffectiveRoles().size();
    for (RoleData r : RoleData.getEffectiveRoles()) {
        boolean checked = (selectedUser != null && selectedUser.containsRole(r));
        allChecked = allChecked && checked;
        // authority.substring (5) : no 'ROLE_' prefix
        json += "[{\"checked\":" + checked + ", \"authority\":\"" + r.getAuthority().substring(5) + "\" }, \""
                + r.toString() + "\"],";
    }/*w  ww .ja  v  a 2 s.c o m*/
    if (total >= 1) {
        json = json.substring(0, json.length() - 1);
    }
    json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}";

    GWTClient.callback(function, JsonUtils.safeEval(json));

    rolesCheckAll = SimpleCheckBox.wrap(RootPanel.get("rolesCheckAll").getElement());
    rolesCheckAll.setValue(allChecked);
    boolean isNotRoot = selectedUser == null || !(selectedUser.getUsername().equals("root"));
    rolesCheckAll.setEnabled((state == State.EDIT && isNotRoot) || state == State.CREATE);
}

From source file:fr.gael.dhus.gwt.client.page.UploadPage.java

License:Open Source License

private static void getCollections(final JavaScriptObject function) {
    GWTClient.callback(function,/* w  w w  .ja va2s . c o  m*/
            JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}"));
    refreshingCollections();

    if (root == null) {
        root = new CollectionData();
        root.setId(null);
        root.setDeep(-1);
    }
    collectionsToRefresh = new ArrayList<Long>();
    for (CollectionData c : displayedCollections.values()) {
        if (c.getDisplayedChildren() != null && c.getDisplayedChildren().size() > 0) {
            collectionsToRefresh.add(c.getId());
        }
    }
    displayedCollections.clear();
    requestCollections(root, new AccessDeniedRedirectionCallback<Void>() {
        @Override
        public void _onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(Void result) {
            collectionsCheckAllChecked = true;
            String json = "{\"aaData\": [";
            json += computeJSON(root);
            boolean children = false;
            if (root.getDisplayedChildren() != null && root.getDisplayedChildren().size() > 0) {
                json = json.substring(0, json.length() - 1);
                children = true;
            }
            json += "],\"iTotalRecords\" : " + (children ? 1 : 0) + ", \"iTotalDisplayRecords\" : "
                    + (children ? 1 : 0) + "}";
            GWTClient.callback(function, JsonUtils.safeEval(json));
            collectionsCheckAll = SimpleCheckBox.wrap(RootPanel.get("upload_collectionsCheckAll").getElement());
            collectionsCheckAll.setValue(children && collectionsCheckAllChecked);
            collectionsCheckAll.setEnabled(children && !collectionsTableDisabled);
        }
    });
}