Search in sources :

Example 1 with GwtXSRFToken

use of org.eclipse.kapua.app.console.shared.model.GwtXSRFToken in project kapua by eclipse.

the class GwtSecurityTokenServiceImpl method generateSecurityToken.

@Override
public GwtXSRFToken generateSecurityToken() {
    GwtXSRFToken token = null;
    // Before to generate a token we must to check if the user is correctly authenticated
    HttpSession session = getHttpSession();
    if (session != null) {
        token = new GwtXSRFToken(UUID.randomUUID().toString());
        session.setAttribute(XSRF_TOKEN_KEY, token);
        s_logger.debug("Generated XSRF token: {} for HTTP session: {}", token.getToken(), session.getId());
    }
    return token;
}
Also used : HttpSession(javax.servlet.http.HttpSession) GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken)

Example 2 with GwtXSRFToken

use of org.eclipse.kapua.app.console.shared.model.GwtXSRFToken in project kapua by eclipse.

the class KapuaRemoteServiceServlet method isValidXSRFToken.

/**
 * Verify if the given userToken is valid on the given session.
 * This method tests if the server xsrf token is equals on the user token.
 * If yes, the method returns true, otherwise returns false.
 * This method controls the xsrf token date validity based on the expire date field.
 *
 * @param session
 * @param userToken
 * @return boolean
 */
public static boolean isValidXSRFToken(HttpSession session, GwtXSRFToken userToken) {
    s_logger.debug("Starting XSRF Token validation...'");
    if (userToken == null) {
        s_logger.debug("XSRF Token is NOT VALID -> NULL TOKEN");
        return false;
    }
    // Retrieve the server side token
    GwtXSRFToken serverXSRFToken = (GwtXSRFToken) session.getAttribute(GwtSecurityTokenServiceImpl.XSRF_TOKEN_KEY);
    if (serverXSRFToken != null) {
        String serverToken = serverXSRFToken.getToken();
        // Checking the XSRF validity on the serverToken
        if (isValidStringToken(serverToken)) {
            if (isValidStringToken(userToken.getToken())) {
                if (serverToken.equals(userToken.getToken())) {
                    // Checking expire date
                    if (new Date().before(userToken.getExpiresOn())) {
                        s_logger.debug("XSRF Token is VALID - {}", userToken.getToken());
                        // Reset used token
                        session.setAttribute(GwtSecurityTokenServiceImpl.XSRF_TOKEN_KEY, null);
                        return true;
                    } else {
                        session.setAttribute(GwtSecurityTokenServiceImpl.XSRF_TOKEN_KEY, null);
                        s_logger.error("XSRF Token is EXPIRED - {}", userToken.getToken());
                    }
                }
            }
        }
    }
    s_logger.debug("XSRF Token is NOT VALID - {}", userToken.getToken());
    return false;
}
Also used : GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken) Date(java.util.Date)

Example 3 with GwtXSRFToken

use of org.eclipse.kapua.app.console.shared.model.GwtXSRFToken in project kapua by eclipse.

the class AccountForm method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    FormData formData = new FormData("-30");
    m_formPanel = new FormPanel();
    m_formPanel.setFrame(false);
    m_formPanel.setBodyBorder(true);
    m_formPanel.setHeaderVisible(false);
    m_formPanel.setScrollMode(Scroll.AUTOY);
    m_formPanel.setLayout(new FlowLayout());
    // //////////////////////////////////////////
    // Account Information field set
    // //////////////////////////////////////////
    FieldSet fieldSet = new FieldSet();
    fieldSet.setHeading(MSGS.accountFormInformation());
    FormLayout layoutAccount = new FormLayout();
    layoutAccount.setLabelWidth(LABEL_WIDTH_FORM);
    fieldSet.setLayout(layoutAccount);
    // 
    // Show parent account name
    // 
    final LabelField parentAccountName = new LabelField();
    parentAccountName.setName("parentAccountName");
    parentAccountName.setFieldLabel(MSGS.accountFormParentAccount());
    parentAccountName.setLabelSeparator(":");
    fieldSet.add(parentAccountName, formData);
    // 
    // Account name field
    // 
    final LabelField accountNameLabel = new LabelField();
    accountNameLabel.setName("accountNameLabel");
    accountNameLabel.setFieldLabel(MSGS.accountFormName());
    accountNameLabel.setLabelSeparator(":");
    fieldSet.add(accountNameLabel, formData);
    final TextField<String> accountNameField = new TextField<String>();
    accountNameField.setAllowBlank(false);
    accountNameField.setName("accountName");
    accountNameField.setFieldLabel("* " + MSGS.accountFormName());
    accountNameField.setValidator(new TextFieldValidator(accountNameField, FieldType.SIMPLE_NAME));
    fieldSet.add(accountNameField, formData);
    // 
    // passwords
    // 
    final TextField<String> accountPassword = new TextField<String>();
    accountPassword.setAllowBlank(false);
    accountPassword.setName("accountPassword");
    accountPassword.setFieldLabel("* " + MSGS.accountFormPassword());
    accountPassword.setValidator(new TextFieldValidator(accountPassword, FieldType.PASSWORD));
    accountPassword.setPassword(true);
    fieldSet.add(accountPassword, formData);
    // 
    // Confirm password
    // 
    final TextField<String> confirmPassword = new TextField<String>();
    confirmPassword.setAllowBlank(false);
    confirmPassword.setName("confirmPassword");
    confirmPassword.setFieldLabel("* " + MSGS.accountFormConfirmPassword());
    confirmPassword.setValidator(new ConfirmPasswordFieldValidator(confirmPassword, accountPassword));
    confirmPassword.setPassword(true);
    fieldSet.add(confirmPassword, formData);
    m_formPanel.add(fieldSet);
    // //////////////////////////////////////////
    // Deployment Information field set
    // //////////////////////////////////////////
    FieldSet fieldSetDeployment = new FieldSet();
    fieldSetDeployment.setHeading(MSGS.accountFormDeploymentInformation());
    FormLayout layoutDeployment = new FormLayout();
    layoutDeployment.setLabelWidth(LABEL_WIDTH_FORM);
    fieldSetDeployment.setLayout(layoutDeployment);
    // 
    // broker cluster
    // 
    final LabelField accountClusterLabel = new LabelField();
    accountClusterLabel.setName("accountBrokerLabel");
    accountClusterLabel.setFieldLabel(MSGS.accountFormBrokerCluster());
    accountClusterLabel.setLabelSeparator(":");
    fieldSetDeployment.add(accountClusterLabel, formData);
    final NumberField optlock = new NumberField();
    optlock.setName("optlock");
    optlock.setEditable(false);
    optlock.setVisible(false);
    fieldSetDeployment.add(optlock, formData);
    // add the field set and reset
    m_formPanel.add(fieldSetDeployment);
    // //////////////////////////////////////////
    // Organization Information field set
    // //////////////////////////////////////////
    FieldSet fieldSetOrg = new FieldSet();
    fieldSetOrg.setHeading(MSGS.accountFormOrgInformation());
    FormLayout layoutOrg = new FormLayout();
    layoutOrg.setLabelWidth(LABEL_WIDTH_FORM);
    fieldSetOrg.setLayout(layoutOrg);
    // 
    // Organization name
    // 
    final TextField<String> organizationName = new TextField<String>();
    organizationName.setAllowBlank(false);
    organizationName.setName("organizationName");
    organizationName.setFieldLabel("* " + MSGS.accountFormOrgName());
    fieldSetOrg.add(organizationName, formData);
    // 
    // Organization email
    // 
    final TextField<String> organizationEmail = new TextField<String>();
    organizationEmail.setAllowBlank(false);
    organizationEmail.setName("organizationEmail");
    organizationEmail.setFieldLabel("* " + MSGS.accountFormOrgEmail());
    organizationEmail.setValidator(new TextFieldValidator(organizationEmail, FieldType.EMAIL));
    fieldSetOrg.add(organizationEmail, formData);
    // //////////////////////////////////////////
    // Organization Information sub field set
    // //////////////////////////////////////////
    FieldSet organizationSubFieldSet = new FieldSet();
    organizationSubFieldSet.setHeading(MSGS.accountFormOrgMoreInformation());
    organizationSubFieldSet.setBorders(false);
    organizationSubFieldSet.setCollapsible(true);
    organizationSubFieldSet.setWidth(515);
    FormLayout organizationSubLayout = new FormLayout();
    organizationSubLayout.setLabelWidth(LABEL_WIDTH_FORM - 11);
    organizationSubFieldSet.setLayout(organizationSubLayout);
    // 
    // Other organization data
    // 
    FormData subFieldsetFormData = new FormData("-7");
    final TextField<String> organizationPersonName = new TextField<String>();
    organizationPersonName.setName("organizationPersonName");
    organizationPersonName.setFieldLabel(MSGS.accountFormOrgPersonName());
    organizationSubFieldSet.add(organizationPersonName, subFieldsetFormData);
    final TextField<String> organizationPhoneNumber = new TextField<String>();
    organizationPhoneNumber.setName("organizationPhoneNumber");
    organizationPhoneNumber.setFieldLabel(MSGS.accountFormOrgPhoneNumber());
    organizationSubFieldSet.add(organizationPhoneNumber, subFieldsetFormData);
    final TextField<String> organizationAddressLine1 = new TextField<String>();
    organizationAddressLine1.setName("organizationAddressLine1");
    organizationAddressLine1.setFieldLabel(MSGS.accountFormOrgAddress1());
    organizationSubFieldSet.add(organizationAddressLine1, subFieldsetFormData);
    final TextField<String> organizationAddressLine2 = new TextField<String>();
    organizationAddressLine2.setName("organizationAddressLine2");
    organizationAddressLine2.setFieldLabel(MSGS.accountFormOrgAddress2());
    organizationSubFieldSet.add(organizationAddressLine2, subFieldsetFormData);
    final TextField<String> organizationZipPostCode = new TextField<String>();
    organizationZipPostCode.setName("organizationZipPostCode");
    organizationZipPostCode.setFieldLabel(MSGS.accountFormOrgZipPostCode());
    organizationSubFieldSet.add(organizationZipPostCode, subFieldsetFormData);
    final TextField<String> organizationCity = new TextField<String>();
    organizationCity.setName("organizationCity");
    organizationCity.setFieldLabel(MSGS.accountFormOrgCity());
    organizationSubFieldSet.add(organizationCity, subFieldsetFormData);
    final TextField<String> organizationStateProvinceCounty = new TextField<String>();
    organizationStateProvinceCounty.setName("organizationStateProvinceCounty");
    organizationStateProvinceCounty.setFieldLabel(MSGS.accountFormOrgState());
    organizationSubFieldSet.add(organizationStateProvinceCounty, subFieldsetFormData);
    final TextField<String> organizationCountry = new TextField<String>();
    organizationCountry.setName("organizationCountry");
    organizationCountry.setFieldLabel(MSGS.accountFormOrgCountry());
    organizationSubFieldSet.add(organizationCountry, subFieldsetFormData);
    // add the field set and reset
    fieldSetOrg.add(organizationSubFieldSet);
    m_formPanel.add(fieldSetOrg);
    // 
    if (m_existingAccount == null) {
        // Show editable name, password, confirm password
        accountNameLabel.setVisible(false);
        accountClusterLabel.setVisible(false);
    } else // 
    // If is an update of an existing account
    // 
    {
        // Show parent account name and account name
        accountNameField.setVisible(false);
        accountPassword.setVisible(false);
        confirmPassword.setVisible(false);
    }
    m_status = new Status();
    m_status.setBusy(MSGS.waitMsg());
    m_status.hide();
    m_status.setAutoWidth(true);
    m_formPanel.setButtonAlign(HorizontalAlignment.LEFT);
    m_formPanel.getButtonBar().add(m_status);
    m_formPanel.getButtonBar().add(new FillToolItem());
    // 
    // Behave of Submit Button
    // 
    m_formPanel.addButton(new Button(MSGS.submitButton(), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            // make sure all visible fields are valid before performing the action
            for (Field<?> field : m_formPanel.getFields()) {
                if (field.isVisible() && !field.isValid()) {
                    MessageBox.alert(MSGS.error(), MSGS.formErrors(), null);
                    return;
                }
            }
            // 
            // Hold the dialog until the action comes back
            m_status.show();
            m_formPanel.getButtonBar().disable();
            // 
            if (m_existingAccount == null) {
                final GwtAccountCreator gwtAccountCreator = new GwtAccountCreator();
                gwtAccountCreator.setParentAccountId(m_currentSession.getSelectedAccount().getId());
                gwtAccountCreator.setAccountName(accountNameField.getValue());
                gwtAccountCreator.setAccountPassword(accountPassword.getValue());
                // Organization data
                gwtAccountCreator.setOrganizationName(organizationName.getValue());
                gwtAccountCreator.setOrganizationPersonName(organizationPersonName.getValue());
                gwtAccountCreator.setOrganizationEmail(organizationEmail.getValue());
                gwtAccountCreator.setOrganizationPhoneNumber(organizationPhoneNumber.getValue());
                gwtAccountCreator.setOrganizationAddressLine1(organizationAddressLine1.getValue());
                gwtAccountCreator.setOrganizationAddressLine2(organizationAddressLine2.getValue());
                gwtAccountCreator.setOrganizationCity(organizationCity.getValue());
                gwtAccountCreator.setOrganizationZipPostCode(organizationZipPostCode.getValue());
                gwtAccountCreator.setOrganizationStateProvinceCounty(organizationStateProvinceCounty.getValue());
                gwtAccountCreator.setOrganizationCountry(organizationCountry.getValue());
                // 
                // Call to create an account
                // Getting XSRF token
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtAccountService.create(token, gwtAccountCreator, new AsyncCallback<GwtAccount>() {

                            public void onFailure(Throwable caught) {
                                FailureHandler.handleFormException(m_formPanel, caught);
                                m_status.hide();
                                m_formPanel.getButtonBar().enable();
                            }

                            public void onSuccess(GwtAccount account) {
                                ConsoleInfo.display(MSGS.info(), MSGS.accountCreatedConfirmation(account.getUnescapedName()));
                                m_newAccount = account;
                                // gwtAccountUtils.loadChildAccounts();
                                hide();
                            }
                        });
                    }
                });
            } else // 
            // Update the account
            // 
            {
                // Organization data
                GwtOrganization gwtOrganization = new GwtOrganization();
                gwtOrganization.setName(organizationName.getValue());
                gwtOrganization.setPersonName(organizationPersonName.getValue());
                gwtOrganization.setEmailAddress(organizationEmail.getValue());
                gwtOrganization.setPhoneNumber(organizationPhoneNumber.getValue());
                gwtOrganization.setAddressLine1(organizationAddressLine1.getValue());
                gwtOrganization.setAddressLine2(organizationAddressLine2.getValue());
                gwtOrganization.setZipPostCode(organizationZipPostCode.getValue());
                gwtOrganization.setCity(organizationCity.getValue());
                gwtOrganization.setStateProvinceCounty(organizationStateProvinceCounty.getValue());
                gwtOrganization.setCountry(organizationCountry.getValue());
                m_existingAccount.setGwtOrganization(gwtOrganization);
                // 
                // Call to update the account
                // Getting XSRF token
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtAccountService.update(token, m_existingAccount, new AsyncCallback<GwtAccount>() {

                            public void onFailure(Throwable caught) {
                                FailureHandler.handleFormException(m_formPanel, caught);
                                m_status.hide();
                                m_formPanel.getButtonBar().enable();
                            }

                            public void onSuccess(GwtAccount account) {
                                ConsoleInfo.display(MSGS.info(), MSGS.accountUpdatedConfirmation(account.getUnescapedName()));
                                m_existingAccount = account;
                                hide();
                            }
                        });
                    }
                });
            }
        }
    }));
    // 
    // Cancel Button
    // 
    m_formPanel.addButton(new Button(MSGS.cancelButton(), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            hide();
        }
    }));
    m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
    // 
    // Populate field if necessary
    // 
    parentAccountName.setValue(m_currentSession.getSelectedAccount().getName());
    if (m_existingAccount != null) {
        gwtAccountService.find(m_existingAccount.getId(), new AsyncCallback<GwtAccount>() {

            public void onFailure(Throwable caught) {
                FailureHandler.handle(caught);
            }

            public void onSuccess(GwtAccount account) {
                // set value and original value as we want to track the Dirty state
                accountNameLabel.setValue(account.getName());
                accountNameField.setValue(account.getName());
                accountNameField.setOriginalValue(account.getName());
                accountClusterLabel.setValue(account.getBrokerURL());
                organizationName.setValue(account.getGwtOrganization().getName());
                organizationName.setOriginalValue(account.getGwtOrganization().getName());
                organizationPersonName.setValue(account.getGwtOrganization().getPersonName());
                organizationPersonName.setOriginalValue(account.getGwtOrganization().getPersonName());
                organizationEmail.setValue(account.getGwtOrganization().getEmailAddress());
                organizationEmail.setOriginalValue(account.getGwtOrganization().getEmailAddress());
                organizationPhoneNumber.setValue(account.getGwtOrganization().getPhoneNumber());
                organizationPhoneNumber.setOriginalValue(account.getGwtOrganization().getPhoneNumber());
                organizationAddressLine1.setValue(account.getGwtOrganization().getAddressLine1());
                organizationAddressLine1.setOriginalValue(account.getGwtOrganization().getAddressLine1());
                organizationAddressLine2.setValue(account.getGwtOrganization().getAddressLine2());
                organizationAddressLine2.setOriginalValue(account.getGwtOrganization().getAddressLine2());
                organizationZipPostCode.setValue(account.getGwtOrganization().getZipPostCode());
                organizationZipPostCode.setOriginalValue(account.getGwtOrganization().getZipPostCode());
                organizationCity.setValue(account.getGwtOrganization().getCity());
                organizationCity.setOriginalValue(account.getGwtOrganization().getCity());
                organizationStateProvinceCounty.setValue(account.getGwtOrganization().getStateProvinceCounty());
                organizationStateProvinceCounty.setOriginalValue(account.getGwtOrganization().getStateProvinceCounty());
                organizationCountry.setValue(account.getGwtOrganization().getCountry());
                organizationCountry.setOriginalValue(account.getGwtOrganization().getCountry());
                optlock.setValue(account.getOptlock());
            }
        });
    }
    add(m_formPanel);
}
Also used : FlowLayout(com.extjs.gxt.ui.client.widget.layout.FlowLayout) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) Button(com.extjs.gxt.ui.client.widget.button.Button) GwtOrganization(org.eclipse.kapua.app.console.shared.model.GwtOrganization) ConfirmPasswordFieldValidator(org.eclipse.kapua.app.console.client.util.ConfirmPasswordFieldValidator) TextField(com.extjs.gxt.ui.client.widget.form.TextField) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) FormData(com.extjs.gxt.ui.client.widget.layout.FormData) FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) Status(com.extjs.gxt.ui.client.widget.Status) GwtAccount(org.eclipse.kapua.app.console.shared.model.GwtAccount) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) GwtAccountCreator(org.eclipse.kapua.app.console.shared.model.GwtAccountCreator) TextFieldValidator(org.eclipse.kapua.app.console.client.util.TextFieldValidator) FillToolItem(com.extjs.gxt.ui.client.widget.toolbar.FillToolItem) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Example 4 with GwtXSRFToken

use of org.eclipse.kapua.app.console.shared.model.GwtXSRFToken in project kapua by eclipse.

the class DeviceConfigComponents method apply.

public void apply() {
    if (!m_devConfPanel.isValid()) {
        MessageBox mb = new MessageBox();
        mb.setIcon(MessageBox.ERROR);
        mb.setMessage(MSGS.deviceConfigError());
        mb.show();
        return;
    }
    // ask for confirmation
    String componentName = m_devConfPanel.getConfiguration().getComponentName();
    String message = MSGS.deviceConfigConfirmation(componentName);
    final boolean isCloudUpdate = "CloudService".equals(componentName);
    if (isCloudUpdate) {
        message = MSGS.deviceCloudConfigConfirmation(componentName);
    }
    MessageBox.confirm(MSGS.confirm(), message, new Listener<MessageBoxEvent>() {

        public void handleEvent(MessageBoxEvent ce) {
            // if confirmed, push the update
            // if confirmed, delete
            Dialog dialog = ce.getDialog();
            if (dialog.yesText.equals(ce.getButtonClicked().getText())) {
                // mark the whole config panel dirty and for reload
                m_tabConfig.setDevice(m_selectedDevice);
                m_devConfPanel.mask(MSGS.applying());
                m_tree.mask();
                m_apply.setEnabled(false);
                m_reset.setEnabled(false);
                m_refreshButton.setEnabled(false);
                // 
                // Getting XSRF token
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        final GwtConfigComponent configComponent = m_devConfPanel.getUpdatedConfiguration();
                        gwtDeviceManagementService.updateComponentConfiguration(token, m_selectedDevice, configComponent, new AsyncCallback<Void>() {

                            public void onFailure(Throwable caught) {
                                FailureHandler.handle(caught);
                                m_dirty = true;
                            }

                            public void onSuccess(Void arg0) {
                                m_dirty = true;
                                if (isCloudUpdate) {
                                    refreshWhenOnline();
                                } else {
                                    refresh();
                                }
                            }
                        });
                    }
                });
            // start the configuration update
            }
        }
    });
}
Also used : MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) Dialog(com.extjs.gxt.ui.client.widget.Dialog) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GwtConfigComponent(org.eclipse.kapua.app.console.shared.model.GwtConfigComponent) GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken) MessageBox(com.extjs.gxt.ui.client.widget.MessageBox)

Example 5 with GwtXSRFToken

use of org.eclipse.kapua.app.console.shared.model.GwtXSRFToken in project kapua by eclipse.

the class DeviceTabBundles method initToolBar.

private void initToolBar() {
    m_toolBar = new ToolBar();
    // 
    // Refresh Button
    m_refreshButton = new Button(MSGS.refreshButton(), AbstractImagePrototype.create(Resources.INSTANCE.refresh()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (!refreshProcess) {
                refreshProcess = true;
                if (m_selectedDevice.isOnline()) {
                    m_toolBar.disable();
                    m_dirty = true;
                    refresh();
                    refreshProcess = false;
                } else {
                    MessageBox.alert(MSGS.alerts(), MSGS.deviceOffline(), new Listener<MessageBoxEvent>() {

                        @Override
                        public void handleEvent(MessageBoxEvent be) {
                            m_grid.unmask();
                            refreshProcess = false;
                        }
                    });
                }
            }
        }
    });
    m_refreshButton.setEnabled(true);
    m_toolBar.add(m_refreshButton);
    m_toolBar.add(new SeparatorToolItem());
    final AsyncCallback<Void> callback = new AsyncCallback<Void>() {

        public void onFailure(Throwable caught) {
            FailureHandler.handle(caught);
            m_dirty = true;
        }

        public void onSuccess(Void arg0) {
            // mark this panel dirty and also all the other pier panels
            m_deviceTabs.setDevice(m_selectedDevice);
            m_dirty = true;
            refresh();
        }
    };
    // 
    // Start Button
    m_startButton = new Button(MSGS.deviceBndStart(), AbstractImagePrototype.create(Resources.INSTANCE.bundleStart()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (m_selectedDevice.isOnline()) {
                m_toolBar.disable();
                m_grid.mask(MSGS.loading());
                // 
                // Getting XSRF token
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtDeviceManagementService.startBundle(token, m_selectedDevice, m_grid.getSelectionModel().getSelectedItem(), callback);
                    }
                });
            } else {
                MessageBox.alert(MSGS.alerts(), MSGS.deviceOffline(), new Listener<MessageBoxEvent>() {

                    @Override
                    public void handleEvent(MessageBoxEvent be) {
                        m_grid.unmask();
                    }
                });
            }
        }
    });
    m_startButton.setEnabled(true);
    m_toolBar.add(m_startButton);
    m_toolBar.add(new SeparatorToolItem());
    // 
    // Stop Button
    m_stopButton = new Button(MSGS.deviceBndStop(), AbstractImagePrototype.create(Resources.INSTANCE.bundleStop()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (m_selectedDevice.isOnline()) {
                final GwtGroupedNVPair pair = m_grid.getSelectionModel().getSelectedItem();
                String bundleName = pair.getName();
                MessageBox.confirm(MSGS.confirm(), MSGS.deviceStopBundle(bundleName), new Listener<MessageBoxEvent>() {

                    public void handleEvent(MessageBoxEvent ce) {
                        // if confirmed, stop
                        Dialog dialog = ce.getDialog();
                        if (dialog.yesText.equals(ce.getButtonClicked().getText())) {
                            m_toolBar.disable();
                            m_grid.mask(MSGS.loading());
                            // 
                            // Getting XSRF token
                            gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                                @Override
                                public void onFailure(Throwable ex) {
                                    FailureHandler.handle(ex);
                                }

                                @Override
                                public void onSuccess(GwtXSRFToken token) {
                                    gwtDeviceManagementService.stopBundle(token, m_selectedDevice, pair, callback);
                                }
                            });
                        }
                    }
                });
            } else {
                MessageBox.alert(MSGS.alerts(), MSGS.deviceOffline(), new Listener<MessageBoxEvent>() {

                    @Override
                    public void handleEvent(MessageBoxEvent be) {
                        m_grid.unmask();
                    }
                });
            }
        }
    });
    m_stopButton.setEnabled(true);
    m_toolBar.add(m_stopButton);
    m_toolBar.add(new SeparatorToolItem());
    m_toolBar.disable();
}
Also used : SeparatorToolItem(com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GwtGroupedNVPair(org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair) GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken) MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) Button(com.extjs.gxt.ui.client.widget.button.Button) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) Dialog(com.extjs.gxt.ui.client.widget.Dialog) ToolBar(com.extjs.gxt.ui.client.widget.toolbar.ToolBar) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Aggregations

GwtXSRFToken (org.eclipse.kapua.app.console.shared.model.GwtXSRFToken)14 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)9 Button (com.extjs.gxt.ui.client.widget.button.Button)6 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)5 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)4 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)4 Dialog (com.extjs.gxt.ui.client.widget.Dialog)4 FormPanel (com.extjs.gxt.ui.client.widget.form.FormPanel)4 FormLayout (com.extjs.gxt.ui.client.widget.layout.FormLayout)4 SeparatorToolItem (com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem)3 ToolBar (com.extjs.gxt.ui.client.widget.toolbar.ToolBar)3 GwtUser (org.eclipse.kapua.app.console.shared.model.GwtUser)3 ComponentEvent (com.extjs.gxt.ui.client.event.ComponentEvent)2 FormEvent (com.extjs.gxt.ui.client.event.FormEvent)2 FieldSet (com.extjs.gxt.ui.client.widget.form.FieldSet)2 FileUploadField (com.extjs.gxt.ui.client.widget.form.FileUploadField)2 LabelField (com.extjs.gxt.ui.client.widget.form.LabelField)2 NumberField (com.extjs.gxt.ui.client.widget.form.NumberField)2 TextField (com.extjs.gxt.ui.client.widget.form.TextField)2 FlowLayout (com.extjs.gxt.ui.client.widget.layout.FlowLayout)2