Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 571581 - [Passage] LicensedAction flow defect #672

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 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.0.200.qualifier
Bundle-Version: 1.1.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ServiceInvocationResult<GrantLockAttempt>> 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<ServiceInvocationResult<GrantLockAttempt>> response) {
return response//
.flatMap(ServiceInvocationResult::data)//
.map(GrantLockAttempt::successful)//
.orElse(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down