Skip to content

Commit

Permalink
Bug 571581 - [Passage] LicensedAction flow defect
Browse files Browse the repository at this point in the history
- deprecate existing `LicensedAction`
- implement new one in `internal` package

Signed-off-by: eparovyshnaya <[email protected]>
  • Loading branch information
eparovyshnaya committed Mar 1, 2021
1 parent b0ff3ea commit 61fee0b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
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

0 comments on commit 61fee0b

Please sign in to comment.