Example usage for org.joda.time LocalDate getMonthOfYear

List of usage examples for org.joda.time LocalDate getMonthOfYear

Introduction

In this page you can find the example usage for org.joda.time LocalDate getMonthOfYear.

Prototype

public int getMonthOfYear() 

Source Link

Document

Get the month of year field value.

Usage

From source file:module.workingCapital.domain.EmailDigesterUtil.java

License:Open Source License

public static void executeTask() {
    final DateTime now = new DateTime();

    I18N.setLocale(new Locale(CoreConfiguration.getConfiguration().defaultLocale()));
    for (Person person : getPeopleToProcess()) {

        final User user = person.getUser();
        if (user.getPerson() != null && user.getExpenditurePerson() != null) {
            Authenticate.mock(user, "System Automation");

            try {
                final LocalizedString applicationTitle = Bennu.getInstance().getConfiguration()
                        .getApplicationSubTitle();
                final String applicationUrl = CoreConfiguration.getConfiguration().applicationUrl();
                final WorkingCapitalYear workingCapitalYear = WorkingCapitalYear.getCurrentYear();
                final LocalDate today = new LocalDate();
                final WorkingCapitalYear previousYear = today.getMonthOfYear() == Month.JANUARY
                        ? WorkingCapitalYear.findOrCreate(today.getYear() - 1)
                        : null;/*from  w ww  .  java 2s .  c  o m*/

                Map<String, List<WorkingCapitalProcessBean>> processesTypeMap = new LinkedHashMap<>();
                if (previousYear == null) {
                    processesTypeMap.put(TAKEN, getMissionProcessBeans(workingCapitalYear.getTaken()));
                    processesTypeMap.put(PENDING_APPROVAL,
                            getMissionProcessBeans(workingCapitalYear.getPendingAproval()));
                    processesTypeMap.put(PENDING_VERIFICATION,
                            getMissionProcessBeans(workingCapitalYear.getPendingVerification()));
                    processesTypeMap.put(PENDING_PROCESSING,
                            getMissionProcessBeans(workingCapitalYear.getPendingProcessing()));
                    processesTypeMap.put(PENDING_AUTHORIZATION,
                            getMissionProcessBeans(workingCapitalYear.getPendingAuthorization()));
                    processesTypeMap.put(PENDING_PAYMENT,
                            getMissionProcessBeans(workingCapitalYear.getPendingPayment()));
                } else {
                    processesTypeMap.put(TAKEN,
                            getMissionProcessBeans(previousYear.getTaken(workingCapitalYear.getTaken())));
                    processesTypeMap.put(PENDING_APPROVAL, getMissionProcessBeans(
                            previousYear.getPendingAproval(workingCapitalYear.getPendingAproval())));
                    processesTypeMap.put(PENDING_VERIFICATION, getMissionProcessBeans(
                            previousYear.getPendingVerification(workingCapitalYear.getPendingVerification())));
                    processesTypeMap.put(PENDING_PROCESSING, getMissionProcessBeans(
                            previousYear.getPendingProcessing(workingCapitalYear.getPendingProcessing())));
                    processesTypeMap.put(PENDING_AUTHORIZATION, getMissionProcessBeans(previousYear
                            .getPendingAuthorization(workingCapitalYear.getPendingAuthorization())));
                    processesTypeMap.put(PENDING_PAYMENT, getMissionProcessBeans(
                            previousYear.getPendingPayment(workingCapitalYear.getPendingPayment())));
                }

                final int totalPending = processesTypeMap.values().stream().map(Collection::size).reduce(0,
                        Integer::sum);

                if (totalPending > 0) {
                    Message.fromSystem().to(Group.users(user)).template("expenditures.capital.pending")
                            .parameter("applicationTitle", applicationTitle)
                            .parameter("applicationUrl", applicationUrl)
                            .parameter("processesByType", processesTypeMap)
                            .parameter("processesTotal", totalPending).and().send();
                }

                for (final WorkingCapital workingCapital : user.getPerson()
                        .getMovementResponsibleWorkingCapitalsSet()) {
                    final Integer year = workingCapital.getWorkingCapitalYear().getYear();
                    if (year.intValue() < now.getYear()
                            || (year.intValue() == now.getYear() && now.getMonthOfYear() == 12)
                                    && now.getDayOfMonth() > 15) {
                        final PresentableProcessState state = workingCapital
                                .getPresentableAcquisitionProcessState();
                        if (state == WorkingCapitalProcessState.WORKING_CAPITAL_AVAILABLE) {
                            Message.fromSystem().to(Group.users(user))
                                    .template("expenditures.capital.pending.termination")
                                    .parameter("applicationTitle", applicationTitle)
                                    .parameter("applicationUrl", applicationUrl)
                                    .parameter("unit", workingCapital.getUnit().getPresentationName())
                                    .parameter("year", workingCapital.getWorkingCapitalYear().getYear()).and()
                                    .send();
                        }
                    }
                }
            } finally {
                Authenticate.unmock();
            }
        }
    }
}

From source file:module.workingCapital.domain.EmailDigesterUtil.java

License:Open Source License

private static Collection<Person> getPeopleToProcess() {
    final Set<Person> people = new HashSet<Person>();
    final LocalDate today = new LocalDate();
    final ExpenditureTrackingSystem instance = ExpenditureTrackingSystem.getInstance();
    for (final Authorization authorization : instance.getAuthorizationsSet()) {
        if (authorization.isValidFor(today)) {
            final Person person = authorization.getPerson();
            if (person.getOptions().getReceiveNotificationsByEmail()) {
                people.add(person);/*w w w.  j a  v  a  2s . c  o  m*/
            }
        }
    }
    for (final RoleType roleType : RoleType.values()) {
        addPeopleWithRole(people, roleType);
    }
    for (final AccountingUnit accountingUnit : instance.getAccountingUnitsSet()) {
        addPeople(people, accountingUnit.getPeopleSet());
        addPeople(people, accountingUnit.getProjectAccountantsSet());
        addPeople(people, accountingUnit.getResponsiblePeopleSet());
        addPeople(people, accountingUnit.getResponsibleProjectAccountantsSet());
        addPeople(people, accountingUnit.getTreasuryMembersSet());
    }
    final WorkingCapitalYear workingCapitalYear = WorkingCapitalYear.getCurrentYear();
    addMovementResponsibles(people, workingCapitalYear);
    if (today.getMonthOfYear() == Month.JANUARY) {
        final WorkingCapitalYear previousYear = WorkingCapitalYear.findOrCreate(today.getYear() - 1);
        addMovementResponsibles(people, previousYear);
    }

    return people;
}

From source file:module.workingCapital.presentationTier.action.WorkingCapitalAction.java

License:Open Source License

private ActionForward exportInfoToExcel(Set<WorkingCapitalProcess> processes, WorkingCapitalContext context,
        HttpServletResponse response) throws Exception {

    final Integer year = context.getWorkingCapitalYear().getYear();
    SheetData<WorkingCapitalProcess> sheetData = new SheetData<WorkingCapitalProcess>(processes) {
        @Override/*from  w  w  w.  j av  a 2 s .c o  m*/
        protected void makeLine(WorkingCapitalProcess workingCapitalProcess) {
            if (workingCapitalProcess == null) {
                return;
            }
            final WorkingCapital workingCapital = workingCapitalProcess.getWorkingCapital();
            final WorkingCapitalInitialization initialization = workingCapital
                    .getWorkingCapitalInitialization();
            final AccountingUnit accountingUnit = workingCapital.getAccountingUnit();

            addCell(getLocalizedMessate("label.module.workingCapital.year"), year);
            addCell(getLocalizedMessate("label.module.workingCapital"),
                    workingCapitalProcess.getWorkingCapital().getUnit().getPresentationName());
            addCell(getLocalizedMessate("WorkingCapitalProcessState"),
                    workingCapitalProcess.getPresentableAcquisitionProcessState().getLocalizedName());
            addCell(getLocalizedMessate("label.module.workingCapital.unit.responsible"),
                    getUnitResponsibles(workingCapital));
            addCell(getLocalizedMessate("label.module.workingCapital.initialization.accountingUnit"),
                    accountingUnit == null ? "" : accountingUnit.getName());

            addCell(getLocalizedMessate("label.module.workingCapital.requestingDate"),
                    initialization.getRequestCreation().toString("yyyy-MM-dd HH:mm:ss"));
            addCell(getLocalizedMessate("label.module.workingCapital.requester"),
                    initialization.getRequestor().getName());
            final Person movementResponsible = workingCapital.getMovementResponsible();
            addCell(getLocalizedMessate("label.module.workingCapital.movementResponsible"),
                    movementResponsible == null ? "" : movementResponsible.getName());
            addCell(getLocalizedMessate("label.module.workingCapital.fiscalId"), initialization.getFiscalId());
            addCell(getLocalizedMessate("label.module.workingCapital.internationalBankAccountNumber"),
                    initialization.getInternationalBankAccountNumber());
            addCell(getLocalizedMessate("label.module.workingCapital.fundAllocationId"),
                    initialization.getFundAllocationId());
            final Money requestedAnualValue = initialization.getRequestedAnualValue();
            addCell(getLocalizedMessate("label.module.workingCapital.requestedAnualValue.requested"),
                    requestedAnualValue);
            addCell(getLocalizedMessate("label.module.workingCapital.requestedMonthlyValue.requested"),
                    requestedAnualValue.divideAndRound(new BigDecimal(6)));
            final Money authorizedAnualValue = initialization.getAuthorizedAnualValue();
            addCell(getLocalizedMessate("label.module.workingCapital.authorizedAnualValue"),
                    authorizedAnualValue == null ? "" : authorizedAnualValue);
            final Money maxAuthorizedAnualValue = initialization.getMaxAuthorizedAnualValue();
            addCell(getLocalizedMessate("label.module.workingCapital.maxAuthorizedAnualValue"),
                    maxAuthorizedAnualValue == null ? "" : maxAuthorizedAnualValue);
            final DateTime lastSubmission = initialization.getLastSubmission();
            addCell(getLocalizedMessate("label.module.workingCapital.initialization.lastSubmission"),
                    lastSubmission == null ? "" : lastSubmission.toString("yyyy-MM-dd"));
            final DateTime refundRequested = initialization.getRefundRequested();
            addCell(getLocalizedMessate("label.module.workingCapital.initialization.refundRequested"),
                    refundRequested == null ? "" : refundRequested.toString("yyyy-MM-dd"));

            final WorkingCapitalTransaction lastTransaction = workingCapital.getLastTransaction();
            if (lastTransaction == null) {
                addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"),
                        Money.ZERO);
                addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"), Money.ZERO);
                addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), Money.ZERO);
            } else {
                addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"),
                        lastTransaction.getAccumulatedValue());
                addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"),
                        lastTransaction.getBalance());
                addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"),
                        lastTransaction.getDebt());
            }

            for (final AcquisitionClassification classification : WorkingCapitalSystem.getInstance()
                    .getAcquisitionClassificationsSet()) {
                final String description = classification.getDescription();
                final String pocCode = classification.getPocCode();
                final String key = pocCode + " - " + description;

                final Money value = calculateValueForClassification(workingCapital, classification);

                addCell(key, value);
            }

        }

        private Money calculateValueForClassification(final WorkingCapital workingCapital,
                final AcquisitionClassification classification) {
            Money result = Money.ZERO;
            for (final WorkingCapitalTransaction transaction : workingCapital
                    .getWorkingCapitalTransactionsSet()) {
                if (transaction.isAcquisition()) {
                    final WorkingCapitalAcquisitionTransaction acquisitionTransaction = (WorkingCapitalAcquisitionTransaction) transaction;
                    final WorkingCapitalAcquisition acquisition = acquisitionTransaction
                            .getWorkingCapitalAcquisition();
                    final AcquisitionClassification acquisitionClassification = acquisition
                            .getAcquisitionClassification();
                    if (acquisitionClassification == classification) {
                        result = result.add(acquisition.getValueAllocatedToSupplier());
                    }
                }
            }
            return result;
        }

        private String getUnitResponsibles(final WorkingCapital workingCapital) {
            final StringBuilder builder = new StringBuilder();
            final SortedMap<Person, Set<Authorization>> authorizations = workingCapital
                    .getSortedAuthorizations();
            if (!authorizations.isEmpty()) {
                for (final Entry<Person, Set<Authorization>> entry : authorizations.entrySet()) {
                    if (builder.length() > 0) {
                        builder.append("; ");
                    }
                    builder.append(entry.getKey().getName());
                }
            }

            return builder.toString();
        }

    };

    final LocalDate currentLocalDate = new LocalDate();
    final SpreadsheetBuilder builder = new SpreadsheetBuilder();
    builder.addConverter(Money.class, new CellConverter() {

        @Override
        public Object convert(final Object source) {
            final Money money = (Money) source;
            return money == null ? null : money.getRoundedValue().doubleValue();
        }

    });

    builder.addSheet(getLocalizedMessate("label.module.workingCapital") + " " + year + " - "
            + currentLocalDate.toString(), sheetData);

    final List<WorkingCapitalTransaction> transactions = new ArrayList<WorkingCapitalTransaction>();
    for (final WorkingCapitalProcess process : processes) {
        final WorkingCapital workingCapital = process.getWorkingCapital();
        transactions.addAll(workingCapital.getSortedWorkingCapitalTransactions());
    }
    final SheetData<WorkingCapitalTransaction> transactionsSheet = new SheetData<WorkingCapitalTransaction>(
            transactions) {
        @Override
        protected void makeLine(WorkingCapitalTransaction transaction) {
            final WorkingCapital workingCapital = transaction.getWorkingCapital();
            final WorkingCapitalProcess workingCapitalProcess = workingCapital.getWorkingCapitalProcess();

            addCell(getLocalizedMessate("label.module.workingCapital.year"), year);
            addCell(getLocalizedMessate("label.module.workingCapital"),
                    workingCapitalProcess.getWorkingCapital().getUnit().getPresentationName());
            addCell(getLocalizedMessate("label.module.workingCapital.transaction.number"),
                    transaction.getNumber());
            addCell(getLocalizedMessate("WorkingCapitalProcessState.CANCELED"),
                    transaction.isCanceledOrRejected() ? getLocalizedMessate("label.yes")
                            : getLocalizedMessate("label.no"));
            addCell(getLocalizedMessate("label.module.workingCapital.transaction.description") + " "
                    + getLocalizedMessate("label.module.workingCapital.transaction.number"),
                    transaction.getDescription());
            addCell(getLocalizedMessate("label.module.workingCapital.transaction.approval"),
                    approvalLabel(transaction));
            addCell(getLocalizedMessate("label.module.workingCapital.transaction.verification"),
                    verificationLabel(transaction));
            addCell(getLocalizedMessate("label.module.workingCapital.transaction.value"),
                    transaction.getValue());
            addCell(getLocalizedMessate("label.module.workingCapital.transaction.accumulatedValue"),
                    transaction.getAccumulatedValue());
            addCell(getLocalizedMessate("label.module.workingCapital.transaction.balance"),
                    transaction.getBalance());
            addCell(getLocalizedMessate("label.module.workingCapital.transaction.debt"), transaction.getDebt());

            if (transaction.isAcquisition()) {
                final WorkingCapitalAcquisitionTransaction acquisitionTx = (WorkingCapitalAcquisitionTransaction) transaction;
                final WorkingCapitalAcquisition acquisition = acquisitionTx.getWorkingCapitalAcquisition();
                final AcquisitionClassification acquisitionClassification = acquisition
                        .getAcquisitionClassification();
                final String economicClassification = acquisitionClassification.getEconomicClassification();
                final String pocCode = acquisitionClassification.getPocCode();
                addCell(getLocalizedMessate(
                        "label.module.workingCapital.configuration.acquisition.classifications.economicClassification"),
                        economicClassification);
                addCell(getLocalizedMessate(
                        "label.module.workingCapital.configuration.acquisition.classifications.pocCode"),
                        pocCode);
                addCell(getLocalizedMessate(
                        "label.module.workingCapital.configuration.acquisition.classifications.description"),
                        acquisition.getDescription());
            }
        }

        private Object verificationLabel(final WorkingCapitalTransaction transaction) {
            if (transaction.isAcquisition()) {
                final WorkingCapitalAcquisitionTransaction acquisition = (WorkingCapitalAcquisitionTransaction) transaction;
                if (acquisition.getWorkingCapitalAcquisition().getVerified() != null) {
                    return getLocalizedMessate("label.verified");
                }
                if (acquisition.getWorkingCapitalAcquisition().getNotVerified() != null) {
                    return getLocalizedMessate("label.notVerified");
                }
            }
            return "-";
        }

        private String approvalLabel(final WorkingCapitalTransaction transaction) {
            if (transaction.isAcquisition()) {
                final WorkingCapitalAcquisitionTransaction acquisition = (WorkingCapitalAcquisitionTransaction) transaction;
                if (acquisition.getWorkingCapitalAcquisition().getApproved() != null) {
                    return getLocalizedMessate("label.approved");
                }
                if (acquisition.getWorkingCapitalAcquisition().getRejectedApproval() != null) {
                    return getLocalizedMessate("label.rejected");
                }
            }
            return "-";
        }

    };
    builder.addSheet(getLocalizedMessate("label.module.workingCapital.transactions"), transactionsSheet);

    return streamSpreadsheet(response, "FundosManeio_" + year + "-" + currentLocalDate.getDayOfMonth() + "-"
            + currentLocalDate.getMonthOfYear() + "-" + currentLocalDate.getYear(), builder);

}

From source file:name.martingeisse.wicket.panel.simple.DateTimeTextFieldPanel.java

License:Open Source License

@Override
protected void convertInput() {

    // get all required objects. Note: This method is invoked *before* the sub-text-fields
    // have stored their model values in this object, so we must get them manually.
    final Class<?> modelType = getType();
    final LocalDate date = getDateTextField().getConvertedInput();
    final LocalTime time = getTimeTextField().getConvertedInput();

    // convert the input
    if (modelType == DateTime.class) {
        final DateTime localizedDateTime = new DateTime(date.getYear(), date.getMonthOfYear(),
                date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(),
                time.getMillisOfSecond(), localizedChronology);
        setConvertedInputUnsafe(localizedDateTime.withChronology(originalChronology));
    } else if (modelType == LocalDateTime.class) {
        setConvertedInputUnsafe(new LocalDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
                time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(),
                localizedChronology));/*from   w w  w.ja  va 2  s  . c  om*/
    } else {
        throw new IllegalStateException("unsupported model type for DateTimeTextFieldPanel: " + modelType);
    }

}

From source file:net.jrkatz.minero.data.MonthlyPeriodDefinition.java

License:Open Source License

private Period periodForMonth(final int year, final int month) {
    LocalDate start = startForMonth(year, month);
    LocalDate nextMonth = start.plusMonths(1);
    LocalDate end = startForMonth(nextMonth.getYear(), nextMonth.getMonthOfYear());
    return new Period(start, end);
}

From source file:net.jrkatz.minero.data.MonthlyPeriodDefinition.java

License:Open Source License

@Override
public Period periodForDate(final LocalDate date) {
    return periodForMonth(date.getYear(), date.getMonthOfYear());
}

From source file:net.karlmartens.ui.widget.CalendarCombo.java

License:Apache License

public void setText(String text) {
    checkWidget();//from  w  ww .  j a v  a2s  .  c o  m
    if (text == null)
        error(ERROR_NULL_ARGUMENT);

    if (text.equals(_text.getText()))
        return;

    _text.setText(text);

    int[] selection;
    try {
        final LocalDate ld = _dateFormat.parseLocalDate(text);
        selection = new int[] { ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth() };
    } catch (IllegalArgumentException e) {
        selection = NO_SELECTION;
    }
    setSelection(selection[0], selection[1], selection[2]);
}

From source file:net.karlmartens.ui.widget.CalendarCombo.java

License:Apache License

private void handleTextEvent(Event event) {
    switch (event.type) {
    case SWT.FocusIn: {
        handleFocus(SWT.FocusIn);//  w w  w.j  av a 2s. c  om
        break;
    }

    case SWT.DefaultSelection: {
        dropDown(false);
        final Event e = new Event();
        e.time = event.time;
        e.stateMask = event.stateMask;
        notifyListeners(SWT.DefaultSelection, e);
        break;
    }

    case SWT.DragDetect:
    case SWT.MouseDoubleClick:
    case SWT.MouseMove:
    case SWT.MouseEnter:
    case SWT.MouseExit:
    case SWT.MouseHover: {
        final Point pt = getDisplay().map(_text, this, event.x, event.y);
        event.x = pt.x;
        event.y = pt.y;
        notifyListeners(event.type, event);
        event.type = SWT.None;
        break;
    }

    case SWT.KeyDown: {
        final Event keyEvent = new Event();
        keyEvent.time = event.time;
        keyEvent.character = event.character;
        keyEvent.keyCode = event.keyCode;
        keyEvent.keyLocation = event.keyLocation;
        keyEvent.stateMask = event.stateMask;
        notifyListeners(SWT.KeyDown, keyEvent);
        if (isDisposed())
            break;
        event.doit = keyEvent.doit;
        if (!event.doit)
            break;
        if (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN) {
            event.doit = false;
            if ((event.stateMask & SWT.ALT) != 0) {
                final boolean dropped = isDropped();
                _text.selectAll();
                if (!dropped)
                    setFocus();
                dropDown(!dropped);
                break;
            }

            if (event.keyCode == SWT.ARROW_UP) {
                addDays(-1);
            } else {
                addDays(1);
            }

            if (isDisposed())
                break;
        }

        break;
    }

    case SWT.KeyUp: {
        final Event e = new Event();
        e.time = event.time;
        e.character = event.character;
        e.keyCode = event.keyCode;
        e.keyLocation = event.keyLocation;
        e.stateMask = event.stateMask;
        notifyListeners(SWT.KeyUp, e);
        event.doit = e.doit;
        break;
    }

    case SWT.MenuDetect: {
        final Event e = new Event();
        e.time = event.time;
        e.detail = event.detail;
        e.x = event.x;
        e.y = event.y;
        notifyListeners(SWT.MenuDetect, e);
        event.doit = e.doit;
        event.x = e.x;
        event.y = e.y;
        break;
    }

    case SWT.Modify: {
        final int id = ++_modifyId[0];
        getDisplay().timerExec(1000, new Runnable() {
            @Override
            public void run() {
                if (isDisposed() || id != _modifyId[0])
                    return;

                try {
                    final LocalDate ld = _dateFormat.parseLocalDate(_text.getText());
                    setSelection(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
                } catch (IllegalArgumentException e) {
                    setSelection(Calendar.NO_SELECTION[0], Calendar.NO_SELECTION[1], Calendar.NO_SELECTION[2]);
                }
            }
        });

        final Event e = new Event();
        e.time = event.time;
        notifyListeners(SWT.Modify, e);
        break;
    }

    case SWT.MouseDown: {
        final Point pt = getDisplay().map(_text, this, event.x, event.y);
        final Event mouseEvent = new Event();
        mouseEvent.button = event.button;
        mouseEvent.count = event.count;
        mouseEvent.stateMask = event.stateMask;
        mouseEvent.time = event.time;
        mouseEvent.x = pt.x;
        mouseEvent.y = pt.y;
        notifyListeners(SWT.MouseDown, mouseEvent);
        if (isDisposed())
            break;
        event.doit = mouseEvent.doit;
        if (!event.doit)
            break;
        if (event.button != 1)
            return;
        if (_text.getEditable())
            return;
        boolean dropped = isDropped();
        _text.selectAll();
        if (!dropped)
            setFocus();
        dropDown(!dropped);
        break;
    }

    case SWT.MouseUp: {
        final Point pt = getDisplay().map(_text, this, event.x, event.y);
        final Event mouseEvent = new Event();
        mouseEvent.button = event.button;
        mouseEvent.count = event.count;
        mouseEvent.stateMask = event.stateMask;
        mouseEvent.time = event.time;
        mouseEvent.x = pt.x;
        mouseEvent.y = pt.y;
        notifyListeners(SWT.MouseUp, mouseEvent);
        if (isDisposed())
            break;
        event.doit = mouseEvent.doit;
        if (!event.doit)
            break;
        if (event.button != 1)
            return;
        if (_text.getEditable())
            return;
        _text.selectAll();
        break;
    }

    case SWT.MouseWheel: {
        notifyListeners(SWT.MouseWheel, event);
        event.type = SWT.None;
        if (isDisposed())
            break;
        if (!event.doit)
            break;
        if (event.count != 0) {
            event.doit = false;
            if (event.count > 0) {
                addDays(-1);
            } else {
                addDays(1);
            }

            if (isDisposed())
                break;
        }
        break;
    }

    case SWT.Traverse: {
        switch (event.detail) {
        case SWT.TRAVERSE_ARROW_PREVIOUS:
        case SWT.TRAVERSE_ARROW_NEXT:
            // The enter causes default selection and
            // the arrow keys are used to manipulate the list contents so
            // do not use them for traversal.
            event.doit = false;
            break;
        case SWT.TRAVERSE_TAB_PREVIOUS:
            event.doit = traverse(SWT.TRAVERSE_TAB_PREVIOUS);
            event.detail = SWT.TRAVERSE_NONE;
            return;
        }
        final Event e = new Event();
        e.time = event.time;
        e.detail = event.detail;
        e.doit = event.doit;
        e.character = event.character;
        e.keyCode = event.keyCode;
        e.keyLocation = event.keyLocation;
        notifyListeners(SWT.Traverse, e);
        event.doit = e.doit;
        event.detail = e.detail;
        break;
    }

    case SWT.Verify: {
        final Event e = new Event();
        e.text = event.text;
        e.start = event.start;
        e.end = event.end;
        e.character = event.character;
        e.keyCode = event.keyCode;
        e.keyLocation = event.keyLocation;
        e.stateMask = event.stateMask;
        notifyListeners(SWT.Verify, e);
        event.text = e.text;
        event.doit = e.doit;
        break;
    }
    }
}

From source file:net.objectlab.kit.datecalc.joda.LocalDateIMMDateCalculator.java

License:Apache License

@Override
protected LocalDate getNextIMMDate(final boolean requestNextIMM, final LocalDate start,
        final IMMPeriod period) {
    LocalDate date = start;

    final int month = date.getMonthOfYear();
    date = calculateIMMMonth(requestNextIMM, date, month);

    LocalDate imm = calculate3rdWednesday(date);
    final int immMonth = imm.getMonthOfYear();
    final boolean isMarchSept = immMonth == MARCH || immMonth == SEPTEMBER;

    switch (period) {

    case BI_ANNUALY_JUN_DEC:
        if (isMarchSept) {
            imm = getNextIMMDate(requestNextIMM, imm, period);
        }/*from w ww  .ja  va 2s  .  co m*/
        break;

    case BI_ANNUALY_MAR_SEP:
        if (!isMarchSept) {
            imm = getNextIMMDate(requestNextIMM, imm, period);
        }
        break;

    case ANNUALLY:
        // second jump
        imm = getNextIMMDate(requestNextIMM, imm, QUARTERLY);
        // third jump
        imm = getNextIMMDate(requestNextIMM, imm, QUARTERLY);
        // fourth jump
        imm = getNextIMMDate(requestNextIMM, imm, QUARTERLY);
        // fifth jump
        imm = getNextIMMDate(requestNextIMM, imm, QUARTERLY);
        break;

    case QUARTERLY:
    default:
        break;
    }

    return imm;
}

From source file:net.objectlab.kit.datecalc.joda.LocalDateModifiedFollowingHandler.java

License:Apache License

public LocalDate adjustDate(LocalDate startDate, int increment, NonWorkingDayChecker<LocalDate> checker) {
    LocalDate date = startDate;
    final int month = date.getMonthOfYear();
    int stepToUse = increment;
    while (checker.isNonWorkingDay(date)) {
        date = date.plusDays(stepToUse);
        if (date.getMonthOfYear() != month) {
            // flick to backward
            stepToUse *= -1;/*  w w  w.  j ava 2s  .c om*/
            date = date.plusDays(stepToUse);
        }
    }
    return date;
}