Skip to content

Commit

Permalink
Merge pull request #930 from eclipse-passage/576904_2_1
Browse files Browse the repository at this point in the history
Bug 576904 issue personal license: dates are not shown correctly
  • Loading branch information
eparovyshnaya authored Oct 26, 2021
2 parents 4f32749 + 487531a commit 65b36b5
Showing 1 changed file with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PersonalLicenseRequest> data;
Expand All @@ -59,33 +60,44 @@ protected IssueLicensePackPage(String name, Supplier<PersonalLicenseRequest> 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<PersonalFeatureGrant> 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) {
setPageComplete(validatePage());
}
});
}
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<PersonalFeatureGrant> 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
Expand All @@ -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();
Expand All @@ -125,7 +143,7 @@ protected boolean validatePage() {
return errors.isEmpty();
}

public PersonalLicensePackDescriptor pack() {
PersonalLicensePackDescriptor pack() {
return license;
}

Expand Down

0 comments on commit 65b36b5

Please sign in to comment.