From 61fee0b4a01100e49f20c656a03816ff4877a7bc Mon Sep 17 00:00:00 2001 From: Elena Parovyshnaia Date: Mon, 1 Mar 2021 17:30:30 +0300 Subject: [PATCH] Bug 571581 - [Passage] LicensedAction flow defect - deprecate existing `LicensedAction` - implement new one in `internal` package Signed-off-by: eparovyshnaya --- .../META-INF/MANIFEST.MF | 3 +- .../jface/actions/LicensedAction.java | 62 +++++++++++++++++++ .../lic/jface/actions/LicensedAction.java | 5 ++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/actions/LicensedAction.java diff --git a/bundles/org.eclipse.passage.lic.jface/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.jface/META-INF/MANIFEST.MF index f1d5b04ed..fca26633c 100644 --- a/bundles/org.eclipse.passage.lic.jface/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.jface/META-INF/MANIFEST.MF @@ -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.0.200.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright @@ -18,6 +18,7 @@ Export-Package: org.eclipse.passage.lic.internal.jface;x-friends:="org.eclipse.p 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.internal.jface.actions, org.eclipse.passage.lic.jface.resource; x-friends:="org.eclipse.passage.loc.dashboard.ui, org.eclipse.passage.loc.workbench, diff --git a/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/actions/LicensedAction.java b/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/actions/LicensedAction.java new file mode 100644 index 000000000..e1ae42717 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/actions/LicensedAction.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2018, 2020 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.Optional; + +import org.eclipse.jface.action.Action; +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.Event; + +/** + * @since 1.1 + */ +public abstract class LicensedAction extends Action { + + protected abstract void doAction(); + + @Override + public final void runWithEvent(Event event) { + runEverywhere(event.display); + } + + @Override + public final void run() { + runEverywhere(Display.getDefault()); + } + + private void runEverywhere(Display display) { + Optional> response = Optional.empty(); + try { + response = Optional.of(new EquinoxPassageUI(display::getActiveShell).acquireLicense(getId())); + if (grantAcquired(response)) { + doAction(); + } + } finally { + response.flatMap(ServiceInvocationResult::data)// + .ifPresent(lock -> new EquinoxPassage().releaseLicense(lock)); + } + } + + private boolean grantAcquired(Optional> response) { + return response// + .flatMap(ServiceInvocationResult::data)// + .map(GrantLockAttempt::successful)// + .orElse(false); + } + +} diff --git a/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/jface/actions/LicensedAction.java b/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/jface/actions/LicensedAction.java index 10e9fa2c9..bfd591b43 100644 --- a/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/jface/actions/LicensedAction.java +++ b/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/jface/actions/LicensedAction.java @@ -21,6 +21,11 @@ import org.eclipse.passage.lic.internal.jface.EquinoxPassageUI; import org.eclipse.swt.widgets.Event; +/** + * @deprecated use + * {@link org.eclipse.passage.lic.internal.jface.actions.LicensedAction} + */ +@Deprecated public class LicensedAction extends Action { @Override