Example usage for java.time.temporal WeekFields of

List of usage examples for java.time.temporal WeekFields of

Introduction

In this page you can find the example usage for java.time.temporal WeekFields of.

Prototype

public static WeekFields of(Locale locale) 

Source Link

Document

Obtains an instance of WeekFields appropriate for a locale.

Usage

From source file:mesclasses.util.NodeUtil.java

public static int getWeekNumber(LocalDate date) {
    WeekFields wf = WeekFields.of(Locale.FRANCE);
    return date.get(wf.weekOfWeekBasedYear());
}

From source file:net.resheim.eclipse.timekeeper.ui.Activator.java

/**
 * Returns a list of weekday names and dates, using the default locale to
 * determine the first day of the week (Sunday or Monday).
 *
 * @param date//from   ww w . j  av a 2 s.  c o m
 *            starting date
 * @return an array with weekday names and dates
 */
public String[] getHeadings(LocalDate date) {
    String[] headings = new String[7];
    WeekFields weekFields = WeekFields.of(Locale.getDefault());
    // Current day in the week
    int day = date.get(weekFields.dayOfWeek());
    // First date of the week
    LocalDate first = date.minusDays(day - 1);
    for (int i = 0; i < 7; i++) {
        headings[i] = formatter.format(first);
        first = first.plusDays(1);
    }
    return headings;
}

From source file:net.resheim.eclipse.timekeeper.ui.views.WorkWeekView.java

private LocalDate calculateFirstDayOfWeek(LocalDate date) {
    WeekFields weekFields = WeekFields.of(Locale.getDefault());
    int day = date.get(weekFields.dayOfWeek());
    LocalDate firstDayOfWeek = date.minusDays(day - 1);
    return firstDayOfWeek;
}

From source file:net.resheim.eclipse.timekeeper.ui.views.WorkWeekView.java

@Override
public void createPartControl(Composite parent) {
    FormToolkit ft = new FormToolkit(parent.getDisplay());
    ScrolledComposite root = new ScrolledComposite(parent, SWT.V_SCROLL);
    ft.adapt(root);/*from  w w w.  j  av  a  2  s  . co  m*/
    GridLayout layout = new GridLayout();
    root.setLayout(layout);
    root.setExpandHorizontal(true);
    root.setExpandVertical(true);

    Composite main = ft.createComposite(root);
    ft.adapt(main);
    root.setContent(main);
    GridLayout layout2 = new GridLayout(3, false);
    layout2.horizontalSpacing = 0;
    main.setLayout(layout2);

    dateTimeLabel = new Text(main, SWT.NONE);
    GridData gdLabel = new GridData();
    gdLabel.verticalIndent = 3;
    gdLabel.verticalAlignment = SWT.BEGINNING;
    dateTimeLabel.setLayoutData(gdLabel);

    dateChooser = new DateTime(main, SWT.DROP_DOWN | SWT.DATE | SWT.LONG);
    GridData gdChooser = new GridData();
    gdChooser.verticalAlignment = SWT.BEGINNING;
    dateChooser.setLayoutData(gdChooser);
    ft.adapt(dateChooser);
    dateChooser.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            // Determine the first date of the week
            LocalDate date = LocalDate.of(dateChooser.getYear(), dateChooser.getMonth() + 1,
                    dateChooser.getDay());
            contentProvider.setFirstDayOfWeek(calculateFirstDayOfWeek(date));
            viewer.setInput(this);
        }
    });

    statusLabel = new Text(main, SWT.NONE);
    GridData gdStatusLabel = new GridData();
    gdStatusLabel.grabExcessHorizontalSpace = true;
    gdStatusLabel.horizontalAlignment = SWT.FILL;
    gdStatusLabel.verticalIndent = 3;
    gdStatusLabel.verticalAlignment = SWT.BEGINNING;
    statusLabel.setLayoutData(gdStatusLabel);

    viewer = new TreeViewer(main, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    // Make the tree view provide selections
    getSite().setSelectionProvider(viewer);
    contentProvider = new ViewContentProvider();
    viewer.setContentProvider(contentProvider);
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.horizontalSpan = 3;
    viewer.getControl().setLayoutData(layoutData);

    createTitleColumn();
    for (int i = 0; i < 7; i++) {
        createTimeColumn(i);
    }

    Tree tree = viewer.getTree();
    viewer.setComparator(new ViewerComparatorExtension());
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);

    // Adjust column width when view is resized
    root.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle area = root.getClientArea();
            int width = area.width - 2 * tree.getBorderWidth();
            Point vBarSize = tree.getVerticalBar().getSize();
            width -= vBarSize.x;
            TreeColumn[] columns = tree.getColumns();
            int cwidth = 0;
            for (int i = 1; i < columns.length; i++) {
                columns[i].pack();
                if (columns[i].getWidth() < 50) {
                    columns[i].setWidth(50);
                }
                cwidth += columns[i].getWidth();
            }
            tree.getColumns()[0].setWidth(width - cwidth);
        }
    });

    // Determine the first date of the week
    LocalDate date = LocalDate.now();
    WeekFields weekFields = WeekFields.of(Locale.getDefault());
    int day = date.get(weekFields.dayOfWeek());
    contentProvider.setFirstDayOfWeek(date.minusDays(day - 1));

    makeActions();
    hookContextMenu();
    hookDoubleClickAction();
    contributeToActionBars();
    taskListener = new TaskListener();
    TasksUiPlugin.getTaskActivityManager().addActivationListener(taskListener);
    TasksUiPlugin.getTaskList().addChangeListener(taskListener);
    viewer.setInput(getViewSite());
    // Force a redraw so content is visible
    root.pack();
    installStatusUpdater();
}