Skip to content

Commit

Permalink
Merge pull request #740 from eclipse-passage/572833
Browse files Browse the repository at this point in the history
Bug 572833  protect the product with common-use license
  • Loading branch information
eparovyshnaya authored Apr 17, 2021
2 parents ce27eb9 + 5568f6b commit bda8e2e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,34 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.jface.actions;
package org.eclipse.passage.lic.internal.equinox;

import java.util.Optional;
import java.util.function.Supplier;

import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.access.GrantLockAttempt;
import org.eclipse.passage.lic.internal.equinox.EquinoxPassage;
import org.eclipse.passage.lic.internal.jface.EquinoxPassageUI;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public final class LicensedRunnable implements Runnable {
public abstract class LicensedRunnable implements Runnable {

private final Supplier<Shell> shell;
private final String feature;
private final Runnable action;

public LicensedRunnable(Supplier<Shell> shell, String feature, Runnable action) {
this.shell = shell;
public LicensedRunnable(String feature, Runnable action) {
this.feature = feature;
this.action = action;
}

public LicensedRunnable(String feature, Runnable action) {
this(Display.getDefault()::getActiveShell, feature, action);
}

@Override
public void run() {
public final void run() {
Optional<ServiceInvocationResult<GrantLockAttempt>> response = Optional.empty();
try {
response = Optional.of(new EquinoxPassageUI(shell).acquireLicense(feature));
response = Optional.of(acquireLicense(feature));
if (grantAcquired(response)) {
action.run();
}
} finally {
response.flatMap(ServiceInvocationResult::data)//
.ifPresent(lock -> new EquinoxPassage().releaseLicense(lock));
.ifPresent(new EquinoxPassage()::releaseLicense);
}
}

Expand All @@ -59,4 +48,20 @@ private boolean grantAcquired(Optional<ServiceInvocationResult<GrantLockAttempt>
.orElse(false);
}

@SuppressWarnings("hiding")
protected abstract ServiceInvocationResult<GrantLockAttempt> acquireLicense(String feature);

public static final class Default extends LicensedRunnable {

public Default(String feature, Runnable action) {
super(feature, action);
}

@Override
protected ServiceInvocationResult<GrantLockAttempt> acquireLicense(String feature) {
return new EquinoxPassage().acquireLicense(feature);
}

}

}
3 changes: 1 addition & 2 deletions bundles/org.eclipse.passage.lic.jface/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Automatic-Module-Name: org.eclipse.passage.lic.base.ui
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.passage.lic.jface
Bundle-Version: 1.2.0.qualifier
Bundle-Version: 2.0.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Expand All @@ -18,7 +18,6 @@ Export-Package: org.eclipse.passage.lic.internal.jface;x-friends:="org.eclipse.p
org.eclipse.passage.lic.internal.jface.dialogs.licensing;x-friends:="org.eclipse.passage.lic.e4.ui,org.eclipse.passage.loc.dashboard.ui,org.eclipse.passage.loc.licenses.ui",
org.eclipse.passage.lic.internal.jface.i18n;x-internal:=true,
org.eclipse.passage.lic.jface;x-friends:="org.eclipse.passage.loc.workbench",
org.eclipse.passage.lic.jface.actions,
org.eclipse.passage.lic.jface.resource;
x-friends:="org.eclipse.passage.loc.dashboard.ui,
org.eclipse.passage.loc.workbench,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final void run() {
}

private void runEverywhere(Display display) {
new LicensedRunnable(display::getActiveShell, getId(), this::doAction).run();
new LicensedRunnableUi(display::getActiveShell, getId(), this::doAction).run();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.jface.actions;

import java.util.function.Supplier;

import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.access.GrantLockAttempt;
import org.eclipse.passage.lic.internal.equinox.LicensedRunnable;
import org.eclipse.passage.lic.internal.jface.EquinoxPassageUI;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public final class LicensedRunnableUi extends LicensedRunnable {

private final Supplier<Shell> shell;

public LicensedRunnableUi(Supplier<Shell> shell, String feature, Runnable action) {
super(feature, action);
this.shell = shell;
}

public LicensedRunnableUi(String feature, Runnable action) {
this(Display.getDefault()::getActiveShell, feature, action);
}

@Override
protected ServiceInvocationResult<GrantLockAttempt> acquireLicense(String feature) {
return new EquinoxPassageUI(shell).acquireLicense(feature);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
* Copyright (c) 2020, 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -21,6 +21,7 @@
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.passage.lic.internal.jface.actions.LicensedRunnableUi;
import org.eclipse.passage.lic.jface.resource.LicensingImages;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.model.meta.LicensesPackage;
Expand All @@ -31,28 +32,33 @@
import org.eclipse.passage.loc.internal.api.OperatorLicenseService;
import org.eclipse.swt.widgets.Shell;

@SuppressWarnings("restriction")
public class DashboardIssueFloatingLicenseHandler {

private final String feature = "org.eclipse.passage.loc.operator.issuefloating"; //$NON-NLS-1$

@Execute
public void execute(IEclipseContext context,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional LicensePlanDescriptor plan,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional UserDescriptor user,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ProductVersionDescriptor product) {
open(context, //
new LicensedRunnableUi(feature, () -> open(context, //
new IssueFloatingLicenseWizard(//
context, //
new FloatingDataPack(//
java.util.Optional.ofNullable(plan), //
java.util.Optional.ofNullable(user), //
java.util.Optional.ofNullable(product))) //
);
)).run();
}

private void open(IEclipseContext context, Wizard wizard) {
WizardDialog dialog = new WizardDialog(context.get(Shell.class), wizard);
dialog.create();
dialog.getShell().setImage(LicensingImages.getImage(LicensesPackage.eINSTANCE.getLicensePack().getName()));
dialog.getShell().setSize(Math.max(800, dialog.getShell().getSize().x), 700);
Shell shell = dialog.getShell();
// TODO: floating license pack icon
shell.setImage(LicensingImages.getImage(LicensesPackage.eINSTANCE.getLicensePack().getName()));
shell.setSize(Math.max(800, shell.getSize().x), 700);
dialog.open();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 ArSysOp
* Copyright (c) 2019, 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -20,6 +20,7 @@
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.passage.lic.internal.jface.actions.LicensedRunnableUi;
import org.eclipse.passage.lic.jface.resource.LicensingImages;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.model.meta.LicensesPackage;
Expand All @@ -30,28 +31,43 @@
import org.eclipse.passage.loc.internal.api.OperatorLicenseService;
import org.eclipse.swt.widgets.Shell;

@SuppressWarnings("restriction")
public class DashboardIssueLicenseHandler {

private final String feature = "org.eclipse.passage.loc.operator.issuepersonal"; //$NON-NLS-1$

@Execute
public void execute(IEclipseContext context,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional LicensePlanDescriptor plan,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional UserDescriptor user,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ProductVersionDescriptor product) {
Shell shell = context.get(Shell.class);
new LicensedRunnableUi(() -> shell, feature, () -> startWizard(shell, context, plan, user, product)).run();
}

private void startWizard(Shell shell, IEclipseContext context, LicensePlanDescriptor plan, UserDescriptor user,
ProductVersionDescriptor product) {
IssueLicenseWizard wizard = new IssueLicenseWizard(context, new PersonalDataPack(//
java.util.Optional.ofNullable(plan), //
java.util.Optional.ofNullable(user), //
java.util.Optional.ofNullable(product)//
));
open(shell, wizard);
}

private void open(Shell shell, IssueLicenseWizard wizard) {
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.create();

Shell createdShell = dialog.getShell();
createdShell.setImage(LicensingImages.getImage(LicensesPackage.eINSTANCE.getLicensePack().getName()));
dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500);
shape(dialog);
dialog.open();
}

private void shape(WizardDialog dialog) {
Shell shell = dialog.getShell();
shell.setImage(LicensingImages.getImage(LicensesPackage.eINSTANCE.getLicensePack().getName()));
shell.setSize(Math.max(500, shell.getSize().x), 500);
}

@CanExecute
public boolean canExecute(IEclipseContext context) {
return context.get(OperatorLicenseService.class) != null;
Expand Down

0 comments on commit bda8e2e

Please sign in to comment.