Skip to content

Commit

Permalink
Bug 560060 - [Passage] provide "issued licenses" report
Browse files Browse the repository at this point in the history
 - functional yet ugly ui

Signed-off-by: elena.parovyshnaya <elena.parovyshnaya@gmail.com>
  • Loading branch information
eparovyshnaya committed Jun 7, 2020
1 parent e74710a commit 0c2c393
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.eclipse.passage.loc.report.internal.core.license;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.function.Function;
import java.util.function.Supplier;

/**
* @since 0.2
*/
public final class MovedNow implements Supplier<Date> {

private final Function<LocalDate, LocalDate> move;

public MovedNow(Function<LocalDate, LocalDate> move) {
this.move = move;
}

@Override
public Date get() {
return Date.from(//
move.apply(LocalDate.now())//
.atStartOfDay()//
.atZone(ZoneId.systemDefault())//
.toInstant());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class ExportLicenseReportWizardMessages extends NLS {
public static String ConfigPage_dateTo_title;
public static String ConfigPage_dates_description;

public static String ConfigPage_explain_title;

public static String VisibleProgress_task;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ ScopePage_title=Choose license plan for report

ConfigPage_title = Report configuration settings
ConfigPage_description = Alter supported report configuration parameters
ConfigPage_dateFrom_title = From
ConfigPage_dateTo_title = To
ConfigPage_dates_description = Define license issue date range
ConfigPage_dateFrom_title = From:
ConfigPage_dateTo_title = To:
ConfigPage_dates_description = Report will include only licenses issued in the period. Alter it here.
ConfigPage_explain_title=Explain details of issuing for all the reported licenses:

VisibleProgress_task=Export issued licenses report for {0} selected license plans
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Optional;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportCustomersWizardMessages;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportWizardMessages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,31 @@
*******************************************************************************/
package org.eclipse.passage.loc.report.internal.ui.jface.license;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Optional;
import java.util.function.Supplier;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportLicenseReportWizardMessages;
import org.eclipse.passage.loc.report.internal.ui.jface.PageObserver;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;

final class ConfigPage extends WizardPage {

private final PageObserver observer;
private Button explain;
private DateTime from;
private DateTime to;

protected ConfigPage(PageObserver observer) {
super("scope"); //$NON-NLS-1$
Expand All @@ -45,38 +55,88 @@ public void createControl(Composite parent) {
}

void installInitial() {
updateControls();
installDateToControl(from, initialFrom());
installDateToControl(to, initialTo());
explain.setSelection(initialExplain());
}

boolean explain() {
return explain.getSelection();
}

Date from() {
return new Date(System.currentTimeMillis() - 3600000);
return date(from, this::initialFrom);
}

Date to() {
return new Date(System.currentTimeMillis() + 3600000);
return date(to, this::initialTo);
}

boolean explain() {
return true;// explain.getSelection();
private Date date(DateTime control, Supplier<LocalDate> initial) {
LocalDate source = Optional.ofNullable(control).isPresent() //
? LocalDate.of(control.getYear(), control.getMonth() + 1, control.getDay())//
: initial.get();
return Date.from(source//
.atStartOfDay()//
.atZone(ZoneId.systemDefault())//
.toInstant());
}

private LocalDate initialFrom() {
return LocalDate.now().minus(6, ChronoUnit.MONTHS);
}

private LocalDate initialTo() {
return LocalDate.now().minus(1, ChronoUnit.DAYS);
}

private boolean initialExplain() {
return false;
}

private void installDateToControl(DateTime control, LocalDate date) {
control.setYear(date.getYear());
control.setMonth(date.getMonth().getValue() - 1);
control.setDay(date.getDayOfMonth());
}

private void createPeriodSection(Composite parent) {
Composite content = row(parent, 1);
describePeriodSection(content);
installPeriodControls(content);
}

private Composite row(Composite parent, int columns) {
Composite content = new Composite(parent, SWT.NONE);
content.setLayout(new GridLayout(1, false));
content.setLayout(new GridLayout(columns, false));
content.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
return content;
}

private void createAdditionalContentSection(Composite content) {
Composite controls = new Composite(content, SWT.NONE);
private void describePeriodSection(Composite parent) {
Label description = new Label(parent, SWT.NONE);
description.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
description.setText(ExportLicenseReportWizardMessages.ConfigPage_dates_description);
}

explain = new Button(controls, SWT.CHECK);
private void installPeriodControls(Composite parent) {
Composite content = row(parent, 4);
new Label(content, SWT.NONE).setText(ExportLicenseReportWizardMessages.ConfigPage_dateFrom_title);
from = new DateTime(content, SWT.CALENDAR | SWT.CALENDAR_WEEKNUMBERS);
SelectionListener listener = SelectionListener.widgetSelectedAdapter(e -> updateControls());
from.addSelectionListener(listener);
new Label(content, SWT.NONE).setText(ExportLicenseReportWizardMessages.ConfigPage_dateTo_title);
to = new DateTime(content, SWT.CALENDAR | SWT.CALENDAR_WEEKNUMBERS);
to.addSelectionListener(listener);
}

private void createAdditionalContentSection(Composite parent) {
Composite content = row(parent, 2);
new Label(content, SWT.WRAP).setText(ExportLicenseReportWizardMessages.ConfigPage_explain_title);
explain = new Button(content, SWT.CHECK);
explain.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> updateControls()));
}

/**
* Update {@code Select All}, {@code Select None}, wizard's {@code Finish}
* buttons and {@code Preview} page
*/
private void updateControls() {
observer.update();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ public IssuedLicensesReportWizard(LicenseStorage storage, LicenseReportExportSer
@Override
public void addPages() {
addPage(scope);
addPage(config);
addPage(target);
addPage(preview);
}

@Override
public void createPageControls(Composite pageContainer) {
super.createPageControls(pageContainer);
scope.installInitial();
public void createPageControls(Composite container) {
super.createPageControls(container);
target.installInitial();
scope.installInitial();
config.installInitial();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void update() {
updatePlans();
updatePeriod();
// TODO: show and update `explain`
getWizard().getContainer().updateButtons();
}

private void updateTargetPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportLicenseReportWizardMessages;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportWizardMessages;
import org.eclipse.passage.loc.report.internal.ui.jface.PageObserver;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
Expand All @@ -39,7 +40,7 @@ final class ScopePage extends WizardPage {

private final LicensePlanDescriptor[] plans;
private final Set<LicensePlanDescriptor> selected;
private final PreviewPage preview;
private final PageObserver preview;
private Button all;
private Button none;
private CheckboxTableViewer viewer;
Expand All @@ -65,7 +66,7 @@ public void createControl(Composite parent) {
void installInitial() {
selected.addAll(Arrays.asList(this.plans));
viewer.refresh();
updateControls();
updateLocalControls();
}

Set<String> identifiers() {
Expand Down Expand Up @@ -132,10 +133,13 @@ private void createButtons(Composite content) {
* buttons and {@code Preview} page
*/
private void updateControls() {
updateLocalControls();
preview.update();
}

private void updateLocalControls() {
all.setEnabled(plans.length > 0 && selected.size() < plans.length);
none.setEnabled(!selected.isEmpty());
getWizard().getContainer().updateButtons();
preview.update();
}

private void createColumns() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ExportCustomersWizard(ProductRegistry products, CustomerStorage customers
this.data = new DataForExport(this::identifiers, this::path, this::open);
this.preview = new PreviewPage(customers, data);
this.scope = new ScopePage(new Products(products, customers), preview);
this.target = new TargetPage(() -> preview.updateTargetPath());
this.target = new TargetPage(preview);
}

@Override
Expand All @@ -53,8 +53,8 @@ public void addPages() {
}

@Override
public void createPageControls(Composite pageContainer) {
super.createPageControls(pageContainer);
public void createPageControls(Composite container) {
super.createPageControls(container);
scope.installInitial();
target.installInitial();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
import org.eclipse.passage.lic.users.UserDescriptor;
import org.eclipse.passage.loc.report.internal.core.user.CustomerStorage;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportCustomersWizardMessages;
import org.eclipse.passage.loc.report.internal.ui.jface.PageObserver;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;

final class PreviewPage extends WizardPage {
final class PreviewPage extends WizardPage implements PageObserver {

private final CustomerStorage customers;
private List users;
Expand All @@ -50,11 +51,18 @@ public void createControl(Composite parent) {
setControl(content);
}

void updateTargetPath() {
@Override
public void update() {
updateTargetPath();
updateUsers();
getWizard().getContainer().updateButtons();
}

private void updateTargetPath() {
path.setText(data.target().toString());
}

void updateUsers() {
private void updateUsers() {
users.removeAll();
customers.forProducts(data.products()).stream() //
.map(this::userInfo) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.passage.lic.products.ProductDescriptor;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportCustomersWizardMessages;
import org.eclipse.passage.loc.report.internal.ui.i18n.ExportWizardMessages;
import org.eclipse.passage.loc.report.internal.ui.jface.PageObserver;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
Expand All @@ -39,12 +40,12 @@ final class ScopePage extends WizardPage {

private final ProductDescriptor[] products;
private final Set<ProductDescriptor> selected;
private final PreviewPage preview;
private final PageObserver preview;
private Button all;
private Button none;
private CheckboxTableViewer viewer;

protected ScopePage(Products products, PreviewPage preview) {
protected ScopePage(Products products, PageObserver preview) {
super("scope"); //$NON-NLS-1$
this.preview = preview;
this.products = products.get();
Expand All @@ -65,7 +66,7 @@ public void createControl(Composite parent) {
void installInitial() {
selected.addAll(Arrays.asList(this.products));
viewer.refresh();
updateControls();
updateLocalControls();
}

Set<String> identifiers() {
Expand Down Expand Up @@ -132,10 +133,13 @@ private void createButtons(Composite content) {
* buttons and {@code Preview} page
*/
private void updateControls() {
updateLocalControls();
preview.update();
}

private void updateLocalControls() {
all.setEnabled(products.length > 0 && selected.size() < products.length);
none.setEnabled(!selected.isEmpty());
getWizard().getContainer().updateButtons();
preview.updateUsers();
}

private void createColumns() {
Expand Down
Loading

0 comments on commit 0c2c393

Please sign in to comment.