From 487531a26f0710edd5ff0a749ce8764f75f9667a Mon Sep 17 00:00:00 2001 From: Alexander Fedorov Date: Tue, 26 Oct 2021 21:36:10 +0300 Subject: [PATCH] Bug 576904 issue personal license: dates are not shown correctly dispose and render license pack form each time Signed-off-by: Alexander Fedorov --- .../ui/wizards/IssueLicensePackPage.java | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/IssueLicensePackPage.java b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/IssueLicensePackPage.java index 558080575..d6b141d66 100644 --- a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/IssueLicensePackPage.java +++ b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/IssueLicensePackPage.java @@ -40,8 +40,9 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; -public class IssueLicensePackPage extends WizardPage { +class IssueLicensePackPage extends WizardPage { private final IEclipseContext context; private final Supplier data; @@ -59,25 +60,21 @@ protected IssueLicensePackPage(String name, Supplier dat setDescription(IssueLicensePageMessages.IssueLicensePackPage_page_description); } - public void init() { + void init() { PersonalLicenseRequest request = data.get(); if (license != null) { - license.getLicense().setPlan(request.plan()); - license.getLicense().getProduct().setIdentifier(request.productIdentifier()); - license.getLicense().getProduct().setVersion(request.productVersion()); - license.getLicense().getUser().setIdentifier(request.user()); - EList licenseGrants = license.getGrants(); - for (PersonalFeatureGrant grant : licenseGrants) { - ValidityPeriodClosed valid = (ValidityPeriodClosed) grant.getValid(); - valid.setFrom(request.validFrom()); - valid.setUntil(request.validUntil()); - } - return; + refillFormRequest(request); + } else { + createFormRequest(request); } - OperatorLicenseService operatorLicenseService = context.get(OperatorLicenseService.class); - PersonalLicensePackDescriptor licensePackDescriptor = operatorLicenseService.createLicensePack(request); - if (licensePackDescriptor instanceof PersonalLicensePack) { - license = (PersonalLicensePack) licensePackDescriptor; + buildPage(); + } + + private void createFormRequest(PersonalLicenseRequest request) { + OperatorLicenseService service = context.get(OperatorLicenseService.class); + PersonalLicensePackDescriptor descriptor = service.createLicensePack(request); + if (descriptor instanceof PersonalLicensePack) { + license = (PersonalLicensePack) descriptor; license.eAdapters().add(new EContentAdapter() { @Override public void notifyChanged(Notification notification) { @@ -85,7 +82,22 @@ public void notifyChanged(Notification notification) { } }); } - updatePage(); + } + + private void refillFormRequest(PersonalLicenseRequest request) { + license.getLicense().setPlan(request.plan()); + license.getLicense().getProduct().setIdentifier(request.productIdentifier()); + license.getLicense().getProduct().setVersion(request.productVersion()); + license.getLicense().getUser().setIdentifier(request.user()); + EList grants = license.getGrants(); + for (PersonalFeatureGrant grant : grants) { + ValidityPeriodClosed valid = (ValidityPeriodClosed) grant.getValid(); + valid.setFrom(request.validFrom()); + valid.setUntil(request.validUntil()); + } + ValidityPeriodClosed valid = (ValidityPeriodClosed) license.getLicense().getValid(); + valid.setFrom(request.validFrom()); + valid.setUntil(request.validUntil()); } @Override @@ -100,16 +112,22 @@ public void createControl(Composite parent) { properties = VViewFactory.eINSTANCE.createViewModelLoadingProperties(); properties.addInheritableProperty(EMFFormsSWTConstants.USE_ON_MODIFY_DATABINDING_KEY, EMFFormsSWTConstants.USE_ON_MODIFY_DATABINDING_VALUE); - updatePage(); + buildPage(); Dialog.applyDialogFont(composite); } - private void updatePage() { + private void buildPage() { if (base == null || base.isDisposed()) { setPageComplete(false); return; } if (license != null) { + // FIXME: AF: rework this hotfix for + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=576904 + Control[] children = base.getChildren(); + for (Control control : children) { + control.dispose(); + } try { ECPSWTViewRenderer.INSTANCE.render(base, license, properties); base.layout(); @@ -125,7 +143,7 @@ protected boolean validatePage() { return errors.isEmpty(); } - public PersonalLicensePackDescriptor pack() { + PersonalLicensePackDescriptor pack() { return license; }