Example usage for com.vaadin.ui Button setEnabled

List of usage examples for com.vaadin.ui Button setEnabled

Introduction

In this page you can find the example usage for com.vaadin.ui Button setEnabled.

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:com.openhris.payroll.PayrollAdvancesLedgerUI.java

public PayrollAdvancesLedgerUI(int branchId) {
    this.branchId = branchId;

    setSpacing(false);//w  ww  .  ja  v a  2  s . c om
    setMargin(false);
    setWidth("100%");
    setHeight("100%");
    setImmediate(true);

    final VerticalSplitPanel vsplit = new VerticalSplitPanel();

    vsplit.setImmediate(true);
    vsplit.setMargin(false);
    vsplit.setSizeFull();
    vsplit.setLocked(true);

    vsplit.setSplitPosition(90, Sizeable.UNITS_PIXELS);

    GridLayout glayout = new GridLayout(2, 1);
    glayout.setWidth("60%");
    glayout.setMargin(true);
    glayout.setSpacing(true);

    employeeComboBox(getBranchId());
    glayout.addComponent(employee, 0, 0);

    Button button = new Button();
    button.setWidth("100%");
    button.setCaption("Generate Ledger");
    button.setEnabled(UserAccessControl.isPayroll());
    button.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            System.out.println("employeeId: " + employee.getValue());
        }
    });

    glayout.addComponent(button, 1, 0);
    glayout.setComponentAlignment(button, Alignment.BOTTOM_LEFT);

    vsplit.setFirstComponent(glayout);
    addComponent(vsplit);

    setExpandRatio(vsplit, 1.0f);
}

From source file:com.openhris.timekeeping.EditAttendanceTableContainerWindow.java

VerticalLayout generateAttendanceTable() {
    VerticalLayout vlayout = new VerticalLayout();
    vlayout.setSizeFull();//from w w w. j  a va  2 s  . c o m
    vlayout.setSpacing(true);

    if (getEmploymentWageEntry().equals("monthly")) {
        employmentWage = utilities.roundOffToTwoDecimalPlaces((employmentWage * 12) / 314);
    }

    final Table table = new Table();
    table.removeAllItems();
    table.setEnabled(true);
    table.setWidth("100%");
    table.setImmediate(true);
    table.setColumnCollapsingAllowed(true);

    table.addContainerProperty("edit", CheckBox.class, null);
    table.addContainerProperty("date", String.class, null);
    table.addContainerProperty("policy", String.class, null);
    table.addContainerProperty("holidays", String.class, null);
    table.addContainerProperty("premium", CheckBox.class, null);
    table.addContainerProperty("lates", TextField.class, null);
    table.addContainerProperty("undertime", TextField.class, null);
    table.addContainerProperty("overtime", TextField.class, null);
    table.addContainerProperty("night differential", TextField.class, null);
    table.addContainerProperty("l/min", Double.class, null);
    table.addContainerProperty("u/min", Double.class, null);
    table.addContainerProperty("o/min", Double.class, null);
    table.addContainerProperty("nd/min", Double.class, null);
    table.addContainerProperty("lholiday", Double.class, null);
    table.addContainerProperty("sholiday", Double.class, null);
    table.addContainerProperty("wdo", Double.class, null);
    table.addContainerProperty("psday", Double.class, null); //paid non-working holiday
    table.addContainerProperty("latesLH", Double.class, null);
    table.addContainerProperty("latesSH", Double.class, null);
    table.addContainerProperty("latesWO", Double.class, null);
    table.addContainerProperty("undertimeLH", Double.class, null);
    table.addContainerProperty("undertimeSH", Double.class, null);
    table.addContainerProperty("undertimeWO", Double.class, null);

    table.setColumnAlignment("edit", Table.ALIGN_CENTER);
    table.setColumnAlignment("date", Table.ALIGN_CENTER);
    table.setColumnAlignment("policy", Table.ALIGN_CENTER);
    table.setColumnAlignment("premium", Table.ALIGN_CENTER);
    table.setColumnAlignment("lates", Table.ALIGN_CENTER);
    table.setColumnAlignment("undertime", Table.ALIGN_CENTER);
    table.setColumnAlignment("overtime", Table.ALIGN_CENTER);
    table.setColumnAlignment("night differential", Table.ALIGN_CENTER);
    table.setColumnAlignment("l/min", Table.ALIGN_RIGHT);
    table.setColumnAlignment("u/min", Table.ALIGN_RIGHT);
    table.setColumnAlignment("o/min", Table.ALIGN_RIGHT);
    table.setColumnAlignment("nd/min", Table.ALIGN_RIGHT);
    table.setColumnAlignment("lholiday", Table.ALIGN_RIGHT);
    table.setColumnAlignment("sholiday", Table.ALIGN_RIGHT);
    table.setColumnAlignment("wdo", Table.ALIGN_RIGHT);
    table.setColumnAlignment("psday", Table.ALIGN_RIGHT);
    table.setColumnAlignment("latesLH", Table.ALIGN_RIGHT);
    table.setColumnAlignment("latesSH", Table.ALIGN_RIGHT);
    table.setColumnAlignment("latesWO", Table.ALIGN_RIGHT);
    table.setColumnAlignment("undertimeLH", Table.ALIGN_RIGHT);
    table.setColumnAlignment("undertimeSH", Table.ALIGN_RIGHT);
    table.setColumnAlignment("undertimeWO", Table.ALIGN_RIGHT);

    table.setColumnCollapsed("latesLH", true);
    table.setColumnCollapsed("latesSH", true);
    table.setColumnCollapsed("latesWO", true);
    table.setColumnCollapsed("undertimeLH", true);
    table.setColumnCollapsed("undertimeSH", true);
    table.setColumnCollapsed("undertimeWO", true);

    final String[] holidayList = { "legal-holiday", "special-holiday" };
    for (int i = 0; i < getDateList().size(); i++) {
        Object itemId = new Integer(i);

        final CheckBox edit = new CheckBox();
        edit.setData(i);
        edit.setEnabled(UserAccessControl.isEditAttendance());
        edit.setImmediate(true);

        final CheckBox premium = new CheckBox();
        premium.setData(itemId);
        premium.setEnabled(false);
        premium.setImmediate(true);

        final TextField lates = new TextField();
        lates.setWidth("50px");
        lates.setValue("0");
        lates.setEnabled(true);
        lates.setData(itemId);
        lates.setEnabled(false);
        lates.setImmediate(true);

        final TextField undertime = new TextField();
        undertime.setWidth("50px");
        undertime.setValue("0");
        undertime.setEnabled(true);
        undertime.setData(itemId);
        undertime.setEnabled(false);
        undertime.setImmediate(true);

        final TextField overtime = new TextField();
        overtime.setWidth("50px");
        overtime.setValue("0");
        overtime.setEnabled(true);
        overtime.setData(itemId);
        overtime.setEnabled(false);
        overtime.setImmediate(true);

        final TextField nightDifferential = new TextField();
        nightDifferential.setWidth("50px");
        nightDifferential.setValue("0");
        nightDifferential.setEnabled(true);
        nightDifferential.setData(itemId);
        nightDifferential.setEnabled(false);
        nightDifferential.setImmediate(true);

        edit.addListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                premium.setEnabled(event.getButton().booleanValue());
                lates.setEnabled(event.getButton().booleanValue());
                undertime.setEnabled(event.getButton().booleanValue());
                overtime.setEnabled(event.getButton().booleanValue());
                nightDifferential.setEnabled(event.getButton().booleanValue());
            }
        });

        premium.addListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                Object itemId = lates.getData();
                Item item = table.getItem(itemId);

                lates.setValue("0");
                undertime.setValue("0");
                overtime.setValue("0");
                nightDifferential.setValue("0");

                item.getItemProperty("l/min").setValue(0.0);
                item.getItemProperty("u/min").setValue(0.0);
                item.getItemProperty("o/min").setValue(0.0);
                item.getItemProperty("nd/min").setValue(0.0);

                if (event.getButton().booleanValue() == true) {
                    premiumRate = 0.1;
                } else {
                    premiumRate = 0.0;
                }

                item.getItemProperty("wdo")
                        .setValue(utilities.roundOffToTwoDecimalPlaces(
                                Double.parseDouble(item.getItemProperty("wdo").getValue().toString())
                                        + (Double.parseDouble(item.getItemProperty("wdo").getValue().toString())
                                                * premiumRate)));

                item.getItemProperty("lholiday")
                        .setValue(utilities.roundOffToTwoDecimalPlaces(Double
                                .parseDouble(item.getItemProperty("lholiday").getValue().toString())
                                + (Double.parseDouble(item.getItemProperty("lholiday").getValue().toString())
                                        * premiumRate)));

                item.getItemProperty("sholiday")
                        .setValue(utilities.roundOffToTwoDecimalPlaces(Double
                                .parseDouble(item.getItemProperty("sholiday").getValue().toString())
                                + (Double.parseDouble(item.getItemProperty("sholiday").getValue().toString())
                                        * premiumRate)));
            }
        });

        lates.addListener(new FieldEvents.TextChangeListener() {

            @Override
            public void textChange(FieldEvents.TextChangeEvent event) {
                Object itemId = lates.getData();
                Item item = table.getItem(itemId);
                String policyStr = item.getItemProperty("policy").toString();
                String holidayStr = item.getItemProperty("holidays").toString();
                double lateDeduction;

                boolean checkIfInputIsInteger = utilities.checkInputIfInteger(event.getText().trim());
                if (!checkIfInputIsInteger) {
                    getWindow().showNotification("Enter numeric format for lates!",
                            Window.Notification.TYPE_WARNING_MESSAGE);
                    return;
                }

                if (!event.getText().isEmpty()) {
                    if (utilities.convertStringToInteger(event.getText().trim()) > 5) {
                        lateDeduction = computation.processEmployeesLates(policyStr, holidayStr,
                                utilities.convertStringToInteger(event.getText().trim()), getEmploymentWage());
                        if (policyStr == null || policyStr.isEmpty()) {
                            item.getItemProperty("l/min")
                                    .setValue(utilities.roundOffToTwoDecimalPlaces(lateDeduction));
                        } else if (policyStr.equals("working-holiday") && holidayStr.equals("legal-holiday")) {
                            item.getItemProperty("latesLH")
                                    .setValue(utilities.roundOffToTwoDecimalPlaces(lateDeduction));
                            item.getItemProperty("latesSH").setValue(0.0);
                            item.getItemProperty("latesWO").setValue(0.0);
                            item.getItemProperty("l/min").setValue(0.0);
                        } else if (policyStr.equals("working-holiday")
                                && holidayStr.equals("special-holiday")) {
                            item.getItemProperty("latesLH").setValue(0.0);
                            item.getItemProperty("latesSH")
                                    .setValue(utilities.roundOffToTwoDecimalPlaces(lateDeduction));
                            item.getItemProperty("latesWO").setValue(0.0);
                            item.getItemProperty("l/min").setValue(0.0);
                        } else if (policyStr.equals("working-day-off")) {
                            item.getItemProperty("latesLH").setValue(0.0);
                            item.getItemProperty("latesSH").setValue(0.0);
                            item.getItemProperty("latesWO")
                                    .setValue(utilities.roundOffToTwoDecimalPlaces(lateDeduction));
                            item.getItemProperty("l/min").setValue(0.0);
                        }
                    } else {
                        item.getItemProperty("l/min").setValue(0.0);
                    }
                } else {
                    item.getItemProperty("l/min").setValue(0.0);
                }

            }
        });

        undertime.addListener(new FieldEvents.TextChangeListener() {

            @Override
            public void textChange(FieldEvents.TextChangeEvent event) {
                Object itemId = lates.getData();
                Item item = table.getItem(itemId);
                String policyStr = item.getItemProperty("policy").toString();
                String holidayStr = item.getItemProperty("holidays").toString();
                double undertimeDeduction;

                boolean checkIfInputIsInteger = utilities.checkInputIfInteger(event.getText().trim());
                if (!checkIfInputIsInteger) {
                    getWindow().showNotification("Enter numeric format for undertime!",
                            Window.Notification.TYPE_WARNING_MESSAGE);
                    return;
                }

                if (!event.getText().isEmpty()) {
                    undertimeDeduction = computation.processEmployeesUndertime(policyStr, holidayStr,
                            utilities.convertStringToInteger(event.getText().trim()), getEmploymentWage());
                    if (policyStr == null || policyStr.isEmpty()) {
                        item.getItemProperty("u/min")
                                .setValue(utilities.roundOffToTwoDecimalPlaces(undertimeDeduction));
                    } else if (policyStr.equals("working-holiday") && holidayStr.equals("legal-holiday")) {
                        item.getItemProperty("undertimeLH")
                                .setValue(utilities.roundOffToTwoDecimalPlaces(undertimeDeduction));
                        item.getItemProperty("undertimeSH").setValue(0.0);
                        item.getItemProperty("undertimeWO").setValue(0.0);
                        item.getItemProperty("u/min").setValue(0.0);
                    } else if (policyStr.equals("working-holiday") && holidayStr.equals("special-holiday")) {
                        item.getItemProperty("undertimeLH").setValue(0.0);
                        item.getItemProperty("undertimeSH")
                                .setValue(utilities.roundOffToTwoDecimalPlaces(undertimeDeduction));
                        item.getItemProperty("undertimeWO").setValue(0.0);
                        item.getItemProperty("u/min").setValue(0.0);
                    } else if (policyStr.equals("working-day-off")) {
                        item.getItemProperty("undertimeLH").setValue(0.0);
                        item.getItemProperty("undertimeSH").setValue(0.0);
                        item.getItemProperty("undertimeWO")
                                .setValue(utilities.roundOffToTwoDecimalPlaces(undertimeDeduction));
                        item.getItemProperty("u/min").setValue(0.0);
                    }
                } else {
                    item.getItemProperty("u/min").setValue(0.0);
                }
            }
        });

        overtime.addListener(new FieldEvents.TextChangeListener() {

            @Override
            public void textChange(FieldEvents.TextChangeEvent event) {
                Object itemId = lates.getData();
                Item item = table.getItem(itemId);
                String policyStr = item.getItemProperty("policy").toString();
                String holidayStr = item.getItemProperty("holidays").toString();
                double overtimeAddition;

                boolean checkIfInputIsInteger = utilities.checkInputIfInteger(event.getText().trim());
                if (!checkIfInputIsInteger) {
                    getWindow().showNotification("Enter numeric format for undertime!",
                            Window.Notification.TYPE_WARNING_MESSAGE);
                    return;
                }

                if (!event.getText().isEmpty()) {
                    overtimeAddition = computation.processEmployeesOvertime(policyStr, holidayStr,
                            Integer.parseInt(event.getText().trim()), getEmploymentWage());
                    item.getItemProperty("o/min").setValue(utilities
                            .roundOffToTwoDecimalPlaces(overtimeAddition + (overtimeAddition * premiumRate)));
                } else {
                    item.getItemProperty("o/min").setValue(0.0);
                }
            }
        });

        nightDifferential.addListener(new FieldEvents.TextChangeListener() {

            @Override
            public void textChange(FieldEvents.TextChangeEvent event) {
                Object itemId = lates.getData();
                Item item = table.getItem(itemId);
                String policyStr = item.getItemProperty("policy").toString();
                String holidayStr = item.getItemProperty("holidays").toString();
                double nightDifferentialAddition;

                boolean checkIfInputIsInteger = utilities.checkInputIfInteger(event.getText().trim());
                if (!checkIfInputIsInteger) {
                    getWindow().showNotification("Enter numeric format for undertime!",
                            Window.Notification.TYPE_WARNING_MESSAGE);
                    return;
                }

                if (!event.getText().isEmpty()) {
                    nightDifferentialAddition = computation.processEmployeesNightDifferential(policyStr,
                            holidayStr, Integer.parseInt(event.getText().trim()), getEmploymentWage());
                    item.getItemProperty("nd/min").setValue(utilities.roundOffToTwoDecimalPlaces(
                            nightDifferentialAddition + (nightDifferentialAddition * premiumRate)));
                } else {
                    item.getItemProperty("nd/min").setValue(0.0);
                }
            }
        });

        List<Timekeeping> timekeepingListByRowData = timekeepingService.getTimekeepingRowData(
                utilities.convertDateFormat(getDateList().get(i).toString()), getPayrollId());

        for (Timekeeping t : timekeepingListByRowData) {
            String policy;
            String holiday;
            if (!t.getPolicy().equals("null")) {
                policy = t.getPolicy();
            } else {
                policy = "";
            }

            if (!t.getHoliday().equals("null")) {
                holiday = t.getHoliday();
            } else {
                holiday = "";
            }

            premium.setValue(t.isPremium());

            lates.setValue(t.getLates());
            undertime.setValue(t.getUndertime());
            overtime.setValue(t.getOvertime());
            nightDifferential.setValue(t.getNightDifferential());
            table.addItem(
                    new Object[] { edit, utilities.convertDateFormat(getDateList().get(i).toString()), policy,
                            holiday, premium, lates, undertime, overtime, nightDifferential,
                            t.getLateDeduction(), t.getUndertimeDeduction(), t.getOvertimePaid(),
                            t.getNightDifferentialPaid(), t.getLegalHolidayPaid(), t.getSpecialHolidayPaid(),
                            t.getWorkingDayOffPaid(), t.getNonWorkingHolidayPaid(),
                            t.getLatesLegalHolidayDeduction(), t.getLatesSpecialHolidayDeduction(),
                            t.getLatesWorkingDayOffDeduction(), t.getUndertimeLegalHolidayDeduction(),
                            t.getUndertimeSpecialHolidayDeduction(), t.getUndertimeWorkingDayOffDeduction() },
                    new Integer(i));
        }
    }
    table.setPageLength(table.size());

    for (Object listener : table.getListeners(ItemClickEvent.class)) {
        table.removeListener(ItemClickEvent.class, listener);
    }

    table.addListener(new ItemClickEvent.ItemClickListener() {

        @Override
        public void itemClick(ItemClickEvent event) {
            final Object itemId = event.getItemId();
            final Item item = table.getItem(itemId);

            Boolean editRow = Boolean.valueOf(item.getItemProperty("edit").getValue().toString());

            if (event.getPropertyId().equals("policy")) {
                if (editRow) {
                    Window sub = new AttendancePolicyWindow(holidayList, item, getEmploymentWageEntry(),
                            getEmploymentWage());
                    if (sub.getParent() == null) {
                        getApplication().getMainWindow().addWindow(sub);
                    }
                } else {
                    getWindow().showNotification("Click Edit!", Window.Notification.TYPE_WARNING_MESSAGE);
                }
            }
        }
    });

    vlayout.addComponent(table);

    final Button saveButton = new Button();
    saveButton.setWidth("200px");
    saveButton.setCaption("UPDATE ATTENDANCE DATA");
    saveButton.setEnabled(UserAccessControl.isEditAttendance());

    for (Object listener : saveButton.getListeners(Button.ClickListener.class)) {
        saveButton.removeListener(Button.ClickListener.class, listener);
    }

    GridLayout glayout = new GridLayout(2, 1);
    glayout.setSizeFull();
    glayout.setSpacing(true);

    saveButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                Collection attendanceTableCollection = table.getContainerDataSource().getItemIds();
                List<Timekeeping> attendanceList = new ArrayList<>();
                Iterator iterator = attendanceTableCollection.iterator();
                while (iterator.hasNext()) {
                    String str = table.getItem(iterator.next()).toString();
                    String[] attStr = str.split(" ");
                    List<String> tkeepList = new ArrayList<>(Arrays.asList(attStr));

                    Timekeeping t = new Timekeeping();
                    t.setAttendanceDate(utilities.parsingDate(tkeepList.get(1)));
                    t.setPolicy(tkeepList.get(2));
                    t.setHoliday(tkeepList.get(3));
                    t.setPremium(utilities.convertStringToBoolean(tkeepList.get(4)));
                    t.setLates(utilities.convertStringToDouble(tkeepList.get(5)));
                    t.setUndertime(utilities.convertStringToDouble(tkeepList.get(6)));
                    t.setOvertime(utilities.convertStringToDouble(tkeepList.get(7)));
                    t.setNightDifferential(utilities.convertStringToDouble(tkeepList.get(8)));
                    t.setLateDeduction(utilities.convertStringToDouble(tkeepList.get(9)));
                    t.setUndertimeDeduction(utilities.convertStringToDouble(tkeepList.get(10)));
                    t.setOvertimePaid(utilities.convertStringToDouble(tkeepList.get(11)));
                    t.setNightDifferentialPaid(utilities.convertStringToDouble(tkeepList.get(12)));
                    t.setLegalHolidayPaid(utilities.convertStringToDouble(tkeepList.get(13)));
                    t.setSpecialHolidayPaid(utilities.convertStringToDouble(tkeepList.get(14)));
                    t.setWorkingDayOffPaid(utilities.convertStringToDouble(tkeepList.get(15)));
                    t.setNonWorkingHolidayPaid(utilities.convertStringToDouble(tkeepList.get(16)));
                    t.setLatesLegalHolidayDeduction(utilities.convertStringToDouble(tkeepList.get(17)));
                    t.setLatesSpecialHolidayDeduction(utilities.convertStringToDouble(tkeepList.get(18)));
                    t.setLatesWorkingDayOffDeduction(utilities.convertStringToDouble(tkeepList.get(19)));
                    t.setUndertimeLegalHolidayDeduction(utilities.convertStringToDouble(tkeepList.get(20)));
                    t.setUndertimeSpecialHolidayDeduction(utilities.convertStringToDouble(tkeepList.get(21)));
                    t.setUndertimeWorkingDayOffDeduction(utilities.convertStringToDouble(tkeepList.get(22)));
                    attendanceList.add(t);
                }

                ProcessPayrollComputation processPayroll = new ProcessPayrollComputation(getEmployeeId(),
                        getBranchId());
                processPayroll.initVariables();
                processPayroll.initVariablesForComputation(attendanceList);
                boolean result = processPayroll.processPayrollComputation(payrollDate, payrollPeriod,
                        attendancePeriodFrom, attendancePeriodTo, getPayrollId());
                if (result) {
                    close();
                } else {
                    getWindow().showNotification("SQL ERROR");
                }
            } catch (Exception e) {
                e.getMessage();
            }
        }

    });
    glayout.addComponent(saveButton, 0, 0);
    glayout.setComponentAlignment(saveButton, Alignment.MIDDLE_LEFT);
    //        vlayout.addComponent(saveButton);

    Button printButton = new Button("PRINT ATTENDANCE");
    printButton.setWidth("200px");
    printButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            OpenHrisReports reports = new OpenHrisReports(0, null);
            String fileName = "IndividualAttendanceReport_";
            reports.deleteFile(fileName);
            Window reportWindow = new IndividualAttendanceReport(getPayrollId(), getApplication());
        }
    });
    glayout.addComponent(printButton, 1, 0);
    glayout.setComponentAlignment(printButton, Alignment.MIDDLE_RIGHT);

    vlayout.addComponent(glayout);

    return vlayout;
}

From source file:com.rdonasco.common.vaadin.view.ButtonUtil.java

License:Apache License

public static void enableButtons(Button... buttons) {
    for (Button button : buttons) {
        button.setEnabled(true);
    }/* w w  w. ja v  a 2 s  .c  o  m*/
}

From source file:com.rdonasco.common.vaadin.view.ButtonUtil.java

License:Apache License

public static void disableButtons(Button... buttons) {
    for (Button button : buttons) {
        button.setEnabled(false);
    }/* ww  w .  j  a  v  a  2  s  .  c o  m*/
}

From source file:com.save.employee.request.RequestFormWindow.java

Component buildRequestForm() {
    GridLayout glayout = new GridLayout(4, 7);
    glayout.setSizeFull();/*from   ww  w  .j av a2 s . c  o m*/
    glayout.setSpacing(true);
    glayout.setMargin(true);

    controlNo = new TextField("Control No.");
    controlNo.setWidth("100%");
    controlNo.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    glayout.addComponent(controlNo, 0, 0);

    dateOfActivity = new DateField("Date of Activity: ");
    dateOfActivity.setWidth("100%");
    dateOfActivity.addStyleName(ValoTheme.DATEFIELD_SMALL);
    glayout.addComponent(dateOfActivity, 1, 0);

    area = CommonComboBox.areas();
    area.setWidth("100%");
    glayout.addComponent(area, 2, 0);

    activity = new TextField("Activity: ");
    activity.setWidth("100%");
    activity.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    glayout.addComponent(activity, 0, 1, 1, 1);

    venue = new TextField("Venue: ");
    venue.setWidth("100%");
    venue.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    glayout.addComponent(venue, 0, 2, 1, 2);

    requirements = new TextArea("Requirements: ");
    requirements.setWidth("100%");
    requirements.addStyleName(ValoTheme.TEXTAREA_SMALL);
    glayout.addComponent(requirements, 2, 1, 3, 2);

    Label lodging = new Label("Lodging: ");
    lodging.setWidthUndefined();
    glayout.addComponent(lodging, 0, 3);
    glayout.setComponentAlignment(lodging, Alignment.MIDDLE_CENTER);

    lodgingPax = new TextField("Pax: ");
    lodgingPax.setWidth("100%");
    lodgingPax.setValue("0");
    lodgingPax.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    lodgingPax.addStyleName("align-right");
    glayout.addComponent(lodgingPax, 1, 3);

    lodgingAmount = new TextField("Amount: ");
    lodgingAmount.setWidth("100%");
    lodgingAmount.setValue("0.00");
    lodgingAmount.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    lodgingAmount.addStyleName("align-right");
    lodgingAmount.setEnabled(false);
    lodgingAmount.setImmediate(true);
    glayout.addComponent(lodgingAmount, 3, 3);

    lodgingBudget = new TextField("Budget: ");
    lodgingBudget.setWidth("100%");
    lodgingBudget.setValue("0.00");
    lodgingBudget.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    lodgingBudget.addStyleName("align-right");
    lodgingBudget.addValueChangeListener((ValueChangeEvent event) -> {
        if (!CommonUtilities.checkInputIfInteger(lodgingPax.getValue().trim())) {
            Notification.show("Enter a numeric value for Pax", Notification.Type.ERROR_MESSAGE);
            return;
        }

        if (!CommonUtilities.checkInputIfDouble(lodgingBudget.getValue().trim())) {
            Notification.show("Enter a numeric value for Budget", Notification.Type.ERROR_MESSAGE);
            return;
        }

        lodgingAmount.setValue(String.valueOf(CommonUtilities.convertStringToInt(lodgingPax.getValue().trim())
                * CommonUtilities.convertStringToDouble(lodgingBudget.getValue().trim())));
    });
    lodgingBudget.setImmediate(true);
    glayout.addComponent(lodgingBudget, 2, 3);

    Label meals = new Label("Meals: ");
    meals.setWidthUndefined();
    glayout.addComponent(meals, 0, 4);
    glayout.setComponentAlignment(meals, Alignment.MIDDLE_CENTER);

    mealsPax = new TextField("Pax: ");
    mealsPax.setWidth("100%");
    mealsPax.setValue("0");
    mealsPax.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    mealsPax.addStyleName("align-right");
    glayout.addComponent(mealsPax, 1, 4);

    mealsAmount = new TextField("Amount: ");
    mealsAmount.setWidth("100%");
    mealsAmount.setValue("0.00");
    mealsAmount.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    mealsAmount.addStyleName("align-right");
    mealsAmount.setEnabled(false);
    mealsAmount.setImmediate(liquidated);
    glayout.addComponent(mealsAmount, 3, 4);

    mealsBudget = new TextField("Budget: ");
    mealsBudget.setWidth("100%");
    mealsBudget.setValue("0.00");
    mealsBudget.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    mealsBudget.addStyleName("align-right");
    mealsBudget.addValueChangeListener((ValueChangeEvent event) -> {
        if (!CommonUtilities.checkInputIfInteger(mealsPax.getValue().trim())) {
            Notification.show("Enter a numeric value for Pax", Notification.Type.ERROR_MESSAGE);
            return;
        }

        if (!CommonUtilities.checkInputIfDouble(mealsBudget.getValue().trim())) {
            Notification.show("Enter a numeric value for Budget", Notification.Type.ERROR_MESSAGE);
            return;
        }

        mealsAmount.setValue(String.valueOf(CommonUtilities.convertStringToInt(mealsPax.getValue().trim())
                * CommonUtilities.convertStringToDouble(mealsBudget.getValue().trim())));
    });
    mealsAmount.setImmediate(true);
    glayout.addComponent(mealsBudget, 2, 4);

    others = new TextArea("Others: ");
    others.setWidth("100%");
    others.setRows(3);
    others.addStyleName(ValoTheme.TEXTAREA_SMALL);
    glayout.addComponent(others, 0, 5, 2, 6);

    othersAmount = new TextField("Amount: ");
    othersAmount.setWidth("100%");
    othersAmount.setValue("0.00");
    othersAmount.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    othersAmount.addStyleName("align-right");
    glayout.addComponent(othersAmount, 3, 5);
    glayout.setComponentAlignment(othersAmount, Alignment.TOP_CENTER);

    Button rlButton = new Button();
    rlButton.setCaption("SAVE");
    rlButton.setWidth("100%");
    rlButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    rlButton.addStyleName(ValoTheme.BUTTON_SMALL);
    rlButton.addClickListener(buttonClickListener);
    glayout.addComponent(rlButton, 3, 6);
    glayout.setComponentAlignment(rlButton, Alignment.TOP_CENTER);

    if (getRequestId() != 0) {
        LiquidationForm lf = rls.getRLById(getRequestId());
        controlNo.setValue(String.valueOf(lf.getControlNo()));
        dateOfActivity.setValue(lf.getDateOfActivity());
        area.setValue(lf.getAreaId());
        activity.setValue(lf.getActivity());
        requirements.setValue(lf.getRequirements());
        venue.setValue(lf.getVenue());
        others.setValue(lf.getOthersRemarks());
        othersAmount.setValue(String.valueOf(lf.getOthersAmount()));
        lodgingAmount.setValue(String.valueOf(lf.getLodgingAmount()));
        mealsAmount.setValue(String.valueOf(lf.getMealsAmount()));
        if (getLiquidated() == true) {
            setCaption("LIQUIDATE FROM");
            rlButton.setCaption("LIQUIDATE");
            controlNo.setReadOnly(liquidated);
            dateOfActivity.setReadOnly(liquidated);
            area.setReadOnly(liquidated);
            activity.setReadOnly(liquidated);
            requirements.setReadOnly(liquidated);
            venue.setReadOnly(liquidated);
        } else {
            rlButton.setCaption("EDIT");
            lodgingPax.setValue(String.valueOf(lf.getLodgingPax()));
            lodgingBudget.setValue(String.valueOf(lf.getLodgingBudget()));
            mealsPax.setValue(String.valueOf(lf.getMealsPax()));
            mealsBudget.setValue(String.valueOf(lf.getMealsBudget()));
            rlButton.setEnabled(rls.getRLById(getRequestId()).getLiquidated() == 0);
        }
        //            delete.setVisible(true);
    }

    return glayout;
}

From source file:com.skysql.manager.ui.components.ScriptingControlsLayout.java

License:Open Source License

/**
 * Instantiates a new scripting controls layout.
 *
 * @param runningTask the running task/*from  w w  w  .  j  a v a2 s .  c  om*/
 * @param controls the controls
 */
public ScriptingControlsLayout(final RunningTask runningTask, Controls[] controls) {

    addStyleName("scriptingControlsLayout");
    setSizeUndefined();
    setSpacing(true);
    setMargin(true);

    for (Controls control : controls) {
        final Button button = new Button(control.name());
        button.setImmediate(true);
        button.setEnabled(false);
        button.setData(control);
        addComponent(button);
        setComponentAlignment(button, Alignment.MIDDLE_CENTER);
        ctrlButtons.put(control.name(), button);
        button.addClickListener(new Button.ClickListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            public void buttonClick(ClickEvent event) {
                event.getButton().setEnabled(false);
                runningTask.controlClicked((Controls) event.getButton().getData());
            }
        });
    }

}

From source file:com.skysql.manager.ui.components.ScriptingControlsLayout.java

License:Open Source License

/**
 * Enable controls.//from w w w .j  av a2 s. co  m
 *
 * @param enable the enable
 * @param control the control
 */
public void enableControls(boolean enable, Controls control) {
    String key = control.name();
    Button button = ctrlButtons.get(key);
    button.setEnabled(enable);
}

From source file:com.skysql.manager.ui.ErrorDialog.java

License:Open Source License

/**
 * Instantiates a new error dialog.//from ww w .  j  a  v  a 2  s. co  m
 *
 * @param e the exception
 * @param humanizedError the humanized error
 */
public ErrorDialog(Exception e, String humanizedError) {

    if (e != null) {
        ManagerUI.error(e.getMessage());
    }

    dialogWindow = new ModalWindow("An Error has occurred", "775px");
    dialogWindow.setHeight("340px");
    dialogWindow.addCloseListener(this);
    UI current = UI.getCurrent();
    if (current.getContent() == null) {
        current.setContent(new ErrorView(Notification.Type.ERROR_MESSAGE, null));
    }
    current.addWindow(dialogWindow);

    HorizontalLayout wrapper = new HorizontalLayout();
    wrapper.setSizeFull();
    wrapper.setMargin(true);

    VerticalLayout iconLayout = new VerticalLayout();
    iconLayout.setWidth("100px");
    wrapper.addComponent(iconLayout);
    Embedded image = new Embedded(null, new ThemeResource("img/error.png"));
    iconLayout.addComponent(image);

    VerticalLayout textLayout = new VerticalLayout();
    textLayout.setHeight("100%");
    textLayout.setSpacing(true);
    wrapper.addComponent(textLayout);
    wrapper.setExpandRatio(textLayout, 1.0f);

    if (humanizedError != null || e != null) {
        String error = (humanizedError != null) ? humanizedError : e.toString();
        ManagerUI.error(error);
        Label label = new Label(error, ContentMode.HTML);
        label.addStyleName("warning");
        textLayout.addComponent(label);
        textLayout.setComponentAlignment(label, Alignment.TOP_CENTER);
    }

    if (e != null) {
        TextArea stackTrace = new TextArea("Error Log");
        stackTrace.setSizeFull();
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        stackTrace.setValue(sw.toString());
        textLayout.addComponent(stackTrace);
        textLayout.setComponentAlignment(stackTrace, Alignment.TOP_LEFT);
        textLayout.setExpandRatio(stackTrace, 1.0f);
    }

    HorizontalLayout buttonsBar = new HorizontalLayout();
    buttonsBar.setStyleName("buttonsBar");
    buttonsBar.setSizeFull();
    buttonsBar.setSpacing(true);
    buttonsBar.setMargin(true);
    buttonsBar.setHeight("49px");

    Label filler = new Label();
    buttonsBar.addComponent(filler);
    buttonsBar.setExpandRatio(filler, 1.0f);

    Button cancelButton = new Button("Close");
    buttonsBar.addComponent(cancelButton);
    buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT);

    cancelButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            dialogWindow.close();
            //UI.getCurrent().close();
        }
    });

    Button okButton = new Button("Send Error");
    okButton.setEnabled(false);
    okButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            dialogWindow.close();
        }
    });
    buttonsBar.addComponent(okButton);
    buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

    VerticalLayout windowLayout = (VerticalLayout) dialogWindow.getContent();
    windowLayout.setHeight("100%");
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);
    windowLayout.addComponent(wrapper);
    windowLayout.setExpandRatio(wrapper, 1.0f);
    windowLayout.addComponent(buttonsBar);

}

From source file:com.skysql.manager.ui.PanelInfo.java

License:Open Source License

/**
 * Creates the info layout.//from   www.j  av a  2s.  c o m
 */
private void createInfoLayout() {

    infoLayout = new VerticalLayout();
    infoLayout.addStyleName("infoLayout");
    infoLayout.setWidth(PANEL_SPLIT_X, Unit.PIXELS);
    infoLayout.setSpacing(true);
    addComponent(infoLayout);

    final HorizontalLayout headerLayout = new HorizontalLayout();
    headerLayout.addStyleName("panelHeaderLayout");
    headerLayout.setWidth("100%");
    headerLayout.setSpacing(true);
    headerLayout.setMargin(new MarginInfo(false, true, false, true));
    infoLayout.addComponent(headerLayout);

    nameLabel = new Label();
    nameLabel.addStyleName("nameLabel");
    nameLabel.setSizeUndefined();
    headerLayout.addComponent(nameLabel);
    headerLayout.setComponentAlignment(nameLabel, Alignment.MIDDLE_LEFT);

    final Button editButton = new Button("Edit");
    editButton.setEnabled(false);
    headerLayout.addComponent(editButton);
    headerLayout.setComponentAlignment(editButton, Alignment.MIDDLE_RIGHT);

    // this will become the editing function of what properties are displayed in the info layout
    /***
    final Button saveButton = new Button("Done");
    editButton.addClickListener(new Button.ClickListener() {
            
       public void buttonClick(ClickEvent event) {
    nameField = new TextField();
    nameField.setImmediate(true);
    nameField.setValue(nameLabel.getValue());
    nameField.setWidth("12em");
    nameField.focus();
    nameField.addValueChangeListener(new ValueChangeListener() {
            
       public void valueChange(ValueChangeEvent event) {
          saveButton.click();
       }
    });
    headerLayout.replaceComponent(nameLabel, nameField);
    headerLayout.setComponentAlignment(nameField, Alignment.MIDDLE_LEFT);
    headerLayout.replaceComponent(editButton, saveButton);
    headerLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_RIGHT);
       }
    });
            
    saveButton.addClickListener(new Button.ClickListener() {
            
       public void buttonClick(ClickEvent event) {
    String name = nameField.getValue();
    nameLabel.setValue(name);
    headerLayout.replaceComponent(nameField, nameLabel);
    headerLayout.setComponentAlignment(nameLabel, Alignment.MIDDLE_LEFT);
    headerLayout.replaceComponent(saveButton, editButton);
    headerLayout.setComponentAlignment(editButton, Alignment.MIDDLE_RIGHT);
    lastComponent.setName(name);
    if (lastComponent instanceof NodeInfo) {
       //((NodeInfo) lastComponent).saveName(name);
    } else if (lastComponent instanceof SystemRecord) {
       //systemInfo.saveName(name);
    }
    ComponentButton componentButton = lastComponent.getButton();
    componentButton.setName(name);
       }
    });
     ***/

    systemLabels = new Label[systemLabelsStrings.length];
    systemGrid = createCurrentInfo(systemLabels, systemLabelsStrings);
    nodeLabels = new Label[nodeLabelsStrings.length];
    nodeGrid = createCurrentInfo(nodeLabels, nodeLabelsStrings);
}

From source file:com.snowy.Login.java

@PostConstruct
void init() {/*from w w w. j a  va2s . c o m*/
    d = ((MyVaadinUI) UI.getCurrent()).getDataObject();
    //Logger.getLogger(Login.class.getName()).info(d);
    this.setSizeFull();
    this.setSpacing(false);
    this.setMargin(true);
    Label MainL = new Label("<h1>Connect 4</h1?>", ContentMode.HTML);
    //layout.addComponent(MainL);
    MainL.setSizeUndefined();
    VerticalLayout lay = new VerticalLayout();
    lay.setMargin(false);
    lay.addComponent(MainL);
    lay.setComponentAlignment(MainL, Alignment.TOP_CENTER);
    HorizontalLayout hz = new HorizontalLayout();
    hz.setMargin(false);
    hz.setSpacing(false);
    LoginForm lf = new LoginForm();
    lf.addLoginListener((e) -> {
        String token = d.genToken(e.getLoginParameter("username"), e.getLoginParameter("password"));
        //String token="true";
        if (!token.equals("false")) {

            Cookie c = new Cookie("token", token);
            VaadinService.getCurrentResponse().addCookie(c);
            //https://vaadin.com/wiki/-/wiki/Main/Setting+and+reading+Cookies
            //Notification.show(VaadinService.getCurrentRequest().getCookies()[1].getValue(),Notification.Type.ERROR_MESSAGE);
            //this.getNavigator().navigateTo("main");
            //this.getUI().get
            this.getUI().getNavigator().navigateTo("main");
        } else {
            Label l = new Label("<h4 style=\"color:red\">Invalid Username or Password</h4>", ContentMode.HTML);
            l.setId("created");

            if (lay.getComponent(lay.getComponentIndex(lf) + 1).getId() == null) {
                //lay.addComponent(new Label(String.valueOf(lay.getComponentIndex(l))));
                lay.addComponent(l, lay.getComponentIndex(lf) + 1);
                l.setSizeUndefined();
                lay.setComponentAlignment(l, Alignment.TOP_CENTER);
            }

        }

    });

    lay.addComponent(lf);
    Button newUser = new Button("New User");
    newUser.addClickListener((e) -> {

        this.getUI().addWindow(new NewUserSubWindow(d));
    });
    //newUser.setWidth((float)5.5, Unit.EM);
    Button forgotPass = new Button("Forgot Password");
    //temp
    forgotPass.addClickListener((e) -> {
        //Notification.show(, Notification.Type.ERROR_MESSAGE);
    });
    forgotPass.setEnabled(false);
    forgotPass.setDescription("Feature Disabled, Contact Administrator for Assistance");
    //forgotPass.setWidth((float) 8.5,Unit.EM);
    forgotPass.setStyleName(ValoTheme.BUTTON_LINK);
    newUser.setStyleName(ValoTheme.BUTTON_LINK);

    hz.addComponent(newUser);
    hz.addComponent(forgotPass);
    lay.addComponent(hz);
    lay.setComponentAlignment(lf, Alignment.TOP_CENTER);
    lay.setComponentAlignment(hz, Alignment.MIDDLE_CENTER);
    this.addComponent(lay);
    this.setComponentAlignment(lay, Alignment.MIDDLE_CENTER);
}