@Override public void buttonClick(ClickEvent event) { try { if (userSvc.markUserActive(this.activationId)) { String baseUrl = AccountsApplication.getInstance().getURL().toString().split("\\?")[0]; AccountsApplication.getInstance() .getMainWindow() .open(new ExternalResource(baseUrl + "?restartApplication")); } else { AccountsApplication.getInstance().nav.loadNewView(new AccountsLoginView()); Messenger.genericMessage( MessageSeverity.WARNING, STRINGS.getString(AccountsMessages.ACTIVATE_USER_FAILED), "Warning thrown while trying to activate with [" + this.activationId + "]", null); } } catch (AccountsBaseException e) { Messenger.genericMessage( MessageSeverity.ERROR, STRINGS.getString(AccountsMessages.MSGR_UNRECOVERABLE_ERROR), "Wrapped Exception thrown while trying to activate user", e); } }
@Override public void buildStringsFromLocale() { STRINGS = AccountsApplication.getResourceBundle(); addNewBalanceSheet.setCaption(STRINGS.getString(AccountsMessages.BAL_SHEET_TOOLBAR_ADD)); addNewBalanceSheet.setDescription(STRINGS.getString(AccountsMessages.BAL_SHEET_TOOLBAR_ADD)); closeBalanceSheet.setCaption(STRINGS.getString(AccountsMessages.BAL_SHEET_TOOLBAR_REMOVE)); closeBalanceSheet.setDescription(STRINGS.getString(AccountsMessages.BAL_SHEET_TOOLBAR_REMOVE)); mainContent.setCaption(STRINGS.getString(AccountsMessages.BAL_SHEET_WIN_HEADER)); int numBalSheets = 0; if (myBalSheetDetails.getData() != null) numBalSheets = ((Integer) myBalSheetDetails.getData()).intValue(); myBalSheetDetails.setCaption( STRINGS .getString(AccountsMessages.BAL_SHEET_COUNT) .replace("{0}", String.valueOf(numBalSheets))); }
private Panel generateMyBalanceSheetContent() { mainContent = new Panel(); mainContent.setSizeFull(); VerticalLayout mainPanelVl = new VerticalLayout(); List<BalanceSheet> myBalSheets = null; try { myBalSheets = accSvc.getMyBalanceSheets((AccountsUser) AccountsApplication.getInstance().getUser()); Collections.sort( myBalSheets, new Comparator<BalanceSheet>() { @Override public int compare(BalanceSheet o1, BalanceSheet o2) { if (o1.isActive() == o2.isActive()) return 0; else if (o1.isActive() && !o2.isActive()) return -1; else return 1; } }); } catch (AccountsSheetException e) { log.log(Level.SEVERE, "Error trying to query number of balance sheets", e); mainContent.addComponent( new Label(STRINGS.getString(AccountsMessages.MSGR_UNRECOVERABLE_ERROR))); return mainContent; } myBalSheetDetails = new Label(); myBalSheetDetails.setData(myBalSheets.size()); mainPanelVl.addComponent(myBalSheetDetails); mainPanelVl.addComponent(displayMyBalSheetsInRows(myBalSheets)); mainContent.addComponent(mainPanelVl); return mainContent; }
public class PaymentTypeMgmt extends BaseSubwindow implements Button.ClickListener, ValueChangeListener { private static final long serialVersionUID = 1L; @BusinessProcess private IPaymentTypeMgmt accSvc; private ResourceBundle STRINGS = AccountsApplication.getResourceBundle(); private BalanceSheet balSheet; private ListSelect paymentCategories, paymentTypes; private LinkedHashMap<String, CategoryType> categories; private LinkedHashMap<String, PaymentType> types; private Accordion accordion; private Tab current, addNewCategory, addNewType; private Form catFrm, typeFrm; private final int NUM_ROWS = 6; private final int ADD_NEW_CATEGORY = 0; private final int ADD_NEW_TYPE = 1; private final int ADD_CATG_FLD_NAME = 0; private final int ADD_CATG_CREDIT_BOOL = 1; private final int ADD_TYPE_FLD_NAME = 0; private final int ADD_TYPE_FLD_CAT = 1; public PaymentTypeMgmt(BalanceSheet sheet) { super(AccountsMessages.BAL_SHEET_NEW_PAY_TYPE); this.balSheet = sheet; setWidth("320px"); setIcon(IconManager.getIcon(IconManager.CATG_MGMT_SM)); accordion = new Accordion(); accordion.setSizeFull(); HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); VerticalLayout vl1 = new VerticalLayout(); vl1.setSpacing(true); paymentCategories = new ListSelect(STRINGS.getString(AccountsMessages.BAL_SHEET_PAYMENT_CATEGORY)); populatePaymentCategories(); paymentCategories.setNullSelectionAllowed(false); paymentCategories.setImmediate(true); paymentCategories.setRows(NUM_ROWS); paymentCategories.addListener(this); Set<String> keys = categories.keySet(); if (keys.size() > 0) paymentCategories.select(keys.iterator().next()); vl1.addComponent(paymentCategories); hl.addComponent(vl1); VerticalLayout vl2 = new VerticalLayout(); vl2.setSpacing(true); paymentTypes = new ListSelect(STRINGS.getString(AccountsMessages.BAL_SHEET_PAYMENT_TYPE)); populatePaymentTypes(categories.get(paymentCategories.getValue())); paymentTypes.setNullSelectionAllowed(false); paymentTypes.setImmediate(true); paymentTypes.setRows(NUM_ROWS); vl2.addComponent(paymentTypes); hl.addComponent(vl2); current = accordion.addTab(hl); current.setCaption(STRINGS.getString(AccountsMessages.CURRENT)); addNewCategory = accordion.addTab(generateCreateNewCategoryForm()); addNewCategory.setCaption( STRINGS.getString(AccountsMessages.ADD_NEW) + " " + STRINGS.getString(AccountsMessages.BAL_SHEET_PAYMENT_CATEGORY)); addNewType = accordion.addTab(generateCreateNewTypeForm()); addNewType.setCaption( STRINGS.getString(AccountsMessages.ADD_NEW) + " " + STRINGS.getString(AccountsMessages.BAL_SHEET_PAYMENT_TYPE)); addComponent(accordion); } private void populatePaymentCategories() { try { List<CategoryType> svcCategories = accSvc.getCategoriesForSheet(balSheet); categories = new LinkedHashMap<>(svcCategories.size()); paymentCategories.removeAllItems(); if (typeFrm != null) ((Select) typeFrm.getField(ADD_TYPE_FLD_CAT)).removeAllItems(); for (CategoryType cat : svcCategories) { categories.put(cat.getName(), cat); paymentCategories.addItem(cat.getName()); if (typeFrm != null) ((Select) typeFrm.getField(ADD_TYPE_FLD_CAT)).addItem(cat.getName()); } Set<String> keys = categories.keySet(); if (keys.size() > 0) paymentCategories.select(keys.iterator().next()); } catch (AccountsSheetException e) { close(); Messenger.genericMessage( MessageSeverity.ERROR, STRINGS.getString(AccountsMessages.MSGR_UNRECOVERABLE_ERROR), "Failed trying to query Payment Categories for Balance Sheet", e); } } private void populatePaymentTypes(CategoryType selectedCategory) { try { List<PaymentType> svcTypes = accSvc.getTypesForCategory(selectedCategory); types = new LinkedHashMap<>(); paymentTypes.removeAllItems(); for (PaymentType type : svcTypes) { types.put(type.getName(), type); paymentTypes.addItem(type.getName()); } } catch (AccountsSheetException e) { close(); Messenger.genericMessage( MessageSeverity.ERROR, STRINGS.getString(AccountsMessages.MSGR_UNRECOVERABLE_ERROR), "Failed trying to query Payment Types for Balance Sheet", e); } } private VerticalLayout generateCreateNewCategoryForm() { catFrm = new Form(); TextField categoryName = new TextField( STRINGS.getString(AccountsMessages.BAL_SHEET_PAYMENT_CATEGORY) + " " + STRINGS.getString(AccountsMessages.NAME)); categoryName.addValidator(new ConfirmUniqueCategoryNameFieldValidator(balSheet)); catFrm.addField(ADD_CATG_FLD_NAME, categoryName); catFrm.addField( ADD_CATG_CREDIT_BOOL, new CheckBox(STRINGS.getString(AccountsMessages.BAL_SHEET_CREDIT) + "?")); return generateGenericTabSheet(catFrm, ADD_NEW_CATEGORY); } private VerticalLayout generateCreateNewTypeForm() { typeFrm = new Form(); Select selCatg = new Select( STRINGS.getString(AccountsMessages.BAL_SHEET_PAYMENT_CATEGORY), categories.keySet()); selCatg.setNullSelectionAllowed(false); selCatg.setImmediate(true); TextField typeName = new TextField( STRINGS.getString(AccountsMessages.BAL_SHEET_PAYMENT_CATEGORY) + " " + STRINGS.getString(AccountsMessages.NAME)); typeName.addValidator(new ConfirmUniqueTypeNameFieldValidator(selCatg, categories)); typeFrm.addField(ADD_TYPE_FLD_NAME, typeName); typeFrm.addField(ADD_TYPE_FLD_CAT, selCatg); return generateGenericTabSheet(typeFrm, ADD_NEW_TYPE); } private VerticalLayout generateGenericTabSheet(Form frm, int CREATION_TYPE) { VerticalLayout vl = new VerticalLayout(); vl.setSpacing(true); vl.addComponent(frm); HorizontalLayout hl = new HorizontalLayout(); Button btn = new Button(STRINGS.getString(AccountsMessages.CREATE)); btn.addListener((Button.ClickListener) this); btn.setData(CREATION_TYPE); hl.addComponent(btn); hl.setComponentAlignment(btn, Alignment.MIDDLE_RIGHT); vl.addComponent(hl); return vl; } @Override public void buttonClick(ClickEvent event) { switch ((Integer) event.getButton().getData()) { case ADD_NEW_CATEGORY: try { catFrm.commit(); if (catFrm.isValid()) { accSvc.addNewPaymentCategory( (String) catFrm.getField(ADD_CATG_FLD_NAME).getValue(), ((CheckBox) catFrm.getField(ADD_CATG_CREDIT_BOOL)).booleanValue(), balSheet); } } catch (InvalidValueException e) { // Ignoring InvalidValueException as // an appropriate msg is displayed in UI } catch (AccountsSheetException e) { close(); Messenger.genericMessage( MessageSeverity.ERROR, STRINGS.getString(AccountsMessages.MSGR_UNRECOVERABLE_ERROR), "Failed trying to add Payment Categories for Balance Sheet", e); } break; case ADD_NEW_TYPE: try { typeFrm.commit(); if (typeFrm.isValid()) { accSvc.addNewPaymentType( (String) typeFrm.getField(ADD_TYPE_FLD_NAME).getValue(), categories.get(typeFrm.getField(ADD_TYPE_FLD_CAT).getValue())); } } catch (InvalidValueException e) { // Ignoring InvalidValueException as // an appropriate msg is displayed in UI } catch (AccountsSheetException e) { close(); Messenger.genericMessage( MessageSeverity.ERROR, STRINGS.getString(AccountsMessages.MSGR_UNRECOVERABLE_ERROR), "Failed trying to add Payment Types for Balance Sheet", e); } break; } populatePaymentCategories(); populatePaymentTypes(categories.get(paymentCategories.getValue())); accordion.setSelectedTab(current); } @Override public void valueChange(ValueChangeEvent event) { populatePaymentTypes(categories.get(paymentCategories.getValue())); } }
@Override public void buildStringsFromLocale() { STRINGS = AccountsApplication.getResourceBundle(); activateMyUserButton.setCaption(STRINGS.getString(AccountsMessages.ACTIVATE_USER)); }
@Override public void buildStringsFromLocale() { ResourceBundle STRINGS = AccountsApplication.getResourceBundle(); upButton.setDescription(STRINGS.getString(AccountsMessages.NEXT_LANGUAGE_UP)); downButton.setDescription(STRINGS.getString(AccountsMessages.NEXT_LANGUAGE_DOWN)); }