From fa552e1b6f952b0636e088a9853acb903b442ab3 Mon Sep 17 00:00:00 2001 From: Elena Parovyshnaia Date: Mon, 9 Aug 2021 12:46:34 +0300 Subject: [PATCH] Bug 575165 - [Passage][Operator] License Agreement management: gui rework static util to normal class Signed-off-by: eparovyshnaya --- .../AgreementsSelectionCommandAdvisor.java | 1 + .../AgreementIdentifierRenderer.java | 10 ++-- .../loc/agreements/ui/AgreementsUi.java | 21 ++------ .../loc/agreements/ui/SelectedAgreement.java | 50 +++++++++++++++++++ .../emfforms/renderers/MatchRuleRenderer.java | 10 ++-- 5 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 bundles/org.eclipse.passage.loc.agreements.ui/src/org/eclipse/passage/loc/agreements/ui/SelectedAgreement.java diff --git a/bundles/org.eclipse.passage.loc.agreements.core/src/org/eclipse/passage/loc/internal/agreements/core/AgreementsSelectionCommandAdvisor.java b/bundles/org.eclipse.passage.loc.agreements.core/src/org/eclipse/passage/loc/internal/agreements/core/AgreementsSelectionCommandAdvisor.java index e8484b75c..69e0863a5 100644 --- a/bundles/org.eclipse.passage.loc.agreements.core/src/org/eclipse/passage/loc/internal/agreements/core/AgreementsSelectionCommandAdvisor.java +++ b/bundles/org.eclipse.passage.loc.agreements.core/src/org/eclipse/passage/loc/internal/agreements/core/AgreementsSelectionCommandAdvisor.java @@ -22,6 +22,7 @@ import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; +@SuppressWarnings("restriction") @Component(property = { EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME + '=' + AgreementsPackage.eNAME }) public class AgreementsSelectionCommandAdvisor implements SelectionCommandAdvisor { diff --git a/bundles/org.eclipse.passage.loc.agreements.emfforms/src/org/eclipse/passage/loc/agreements/emfforms/renderers/AgreementIdentifierRenderer.java b/bundles/org.eclipse.passage.loc.agreements.emfforms/src/org/eclipse/passage/loc/agreements/emfforms/renderers/AgreementIdentifierRenderer.java index e32f672a6..6686b91e4 100644 --- a/bundles/org.eclipse.passage.loc.agreements.emfforms/src/org/eclipse/passage/loc/agreements/emfforms/renderers/AgreementIdentifierRenderer.java +++ b/bundles/org.eclipse.passage.loc.agreements.emfforms/src/org/eclipse/passage/loc/agreements/emfforms/renderers/AgreementIdentifierRenderer.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.passage.loc.agreements.emfforms.renderers; +import java.util.Optional; + import javax.inject.Inject; import org.eclipse.emf.ecp.view.spi.context.ViewModelContext; @@ -23,7 +25,7 @@ import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding; import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider; import org.eclipse.passage.lic.agreements.AgreementDescriptor; -import org.eclipse.passage.loc.agreements.ui.AgreementsUi; +import org.eclipse.passage.loc.agreements.ui.SelectedAgreement; import org.eclipse.passage.loc.internal.agreements.AgreementRegistry; import org.eclipse.passage.loc.workbench.emfforms.renderers.TextWithButtonRenderer; import org.eclipse.swt.events.SelectionAdapter; @@ -78,9 +80,9 @@ protected void selectIdentifier() { } catch (DatabindingFailedException e) { getReportService().report(new DatabindingFailedReport(e)); } - AgreementDescriptor descriptor = AgreementsUi.selectAgreementDescriptor(shell, registry, initial); - if (descriptor != null) { - String identifier = descriptor.getIdentifier(); + Optional descriptor = new SelectedAgreement(shell, registry, initial).get(); + if (descriptor.isPresent()) { + String identifier = descriptor.get().getIdentifier(); if (identifier != null) { text.setText(identifier); } diff --git a/bundles/org.eclipse.passage.loc.agreements.ui/src/org/eclipse/passage/loc/agreements/ui/AgreementsUi.java b/bundles/org.eclipse.passage.loc.agreements.ui/src/org/eclipse/passage/loc/agreements/ui/AgreementsUi.java index fe33bd6e2..68df6b721 100644 --- a/bundles/org.eclipse.passage.loc.agreements.ui/src/org/eclipse/passage/loc/agreements/ui/AgreementsUi.java +++ b/bundles/org.eclipse.passage.loc.agreements.ui/src/org/eclipse/passage/loc/agreements/ui/AgreementsUi.java @@ -12,25 +12,10 @@ *******************************************************************************/ package org.eclipse.passage.loc.agreements.ui; -import org.eclipse.passage.lic.agreements.AgreementDescriptor; -import org.eclipse.passage.lic.agreements.model.meta.AgreementsPackage; -import org.eclipse.passage.loc.internal.agreements.AgreementRegistry; -import org.eclipse.passage.loc.internal.agreements.ui.i18n.AgreementsUiMessages; -import org.eclipse.passage.loc.workbench.LocWokbench; -import org.eclipse.swt.widgets.Shell; +public interface AgreementsUi { -public final class AgreementsUi { + String BUNDLE_SYMBOLIC_NAME = "org.eclipse.passage.loc.agreements.ui"; //$NON-NLS-1$ - public static final String BUNDLE_SYMBOLIC_NAME = "org.eclipse.passage.loc.agreements.ui"; //$NON-NLS-1$ + String PERSPECTIVE_MAIN = BUNDLE_SYMBOLIC_NAME + '.' + "perspective.main"; //$NON-NLS-1$ - public static final String PERSPECTIVE_MAIN = BUNDLE_SYMBOLIC_NAME + '.' + "perspective.main"; //$NON-NLS-1$ - - public static AgreementDescriptor selectAgreementDescriptor(Shell shell, AgreementRegistry registry, - AgreementDescriptor initial) { - String classifier = AgreementsPackage.eINSTANCE.getAgreement().getName(); - String title = AgreementsUiMessages.AgreementsUi_select_agreement; - Iterable input = registry.agreements(); - Class clazz = AgreementDescriptor.class; - return LocWokbench.selectClassifier(shell, classifier, title, input, initial, clazz); - } } diff --git a/bundles/org.eclipse.passage.loc.agreements.ui/src/org/eclipse/passage/loc/agreements/ui/SelectedAgreement.java b/bundles/org.eclipse.passage.loc.agreements.ui/src/org/eclipse/passage/loc/agreements/ui/SelectedAgreement.java new file mode 100644 index 000000000..7a9ae7583 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.agreements.ui/src/org/eclipse/passage/loc/agreements/ui/SelectedAgreement.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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.loc.agreements.ui; + +import java.util.Optional; +import java.util.function.Supplier; + +import org.eclipse.passage.lic.agreements.AgreementDescriptor; +import org.eclipse.passage.lic.agreements.model.meta.AgreementsPackage; +import org.eclipse.passage.loc.internal.agreements.AgreementRegistry; +import org.eclipse.passage.loc.internal.agreements.ui.i18n.AgreementsUiMessages; +import org.eclipse.passage.loc.workbench.LocWokbench; +import org.eclipse.swt.widgets.Shell; + +public final class SelectedAgreement implements Supplier> { + + private final Shell shell; + private final AgreementRegistry registry; + private final AgreementDescriptor initial; + + public SelectedAgreement(Shell shell, AgreementRegistry registry, AgreementDescriptor initial) { + this.shell = shell; + this.registry = registry; + this.initial = initial; + } + + @Override + public Optional get() { + return Optional.ofNullable(// + LocWokbench.selectClassifier(// + shell, // + AgreementsPackage.eINSTANCE.getAgreement().getName(), // + AgreementsUiMessages.AgreementsUi_select_agreement, // + registry.agreements(), // + initial, // + AgreementDescriptor.class)// + ); + } + +} diff --git a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/renderers/MatchRuleRenderer.java b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/renderers/MatchRuleRenderer.java index b3becce9f..62c602150 100644 --- a/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/renderers/MatchRuleRenderer.java +++ b/bundles/org.eclipse.passage.loc.workbench.emfforms/src/org/eclipse/passage/loc/workbench/emfforms/renderers/MatchRuleRenderer.java @@ -36,13 +36,13 @@ import org.eclipse.passage.lic.base.conditions.MatchingRulePerfect; import org.eclipse.passage.lic.base.version.BaseSemanticVersion; import org.eclipse.passage.lic.base.version.SafeVersion; -import org.eclipse.passage.lic.licenses.PersonalFeatureGrantDescriptor; import org.eclipse.passage.lic.licenses.LicensePlanFeatureDescriptor; +import org.eclipse.passage.lic.licenses.PersonalFeatureGrantDescriptor; import org.eclipse.passage.lic.licenses.model.api.VersionMatch; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; -public class MatchRuleRenderer extends ExplainedComboControlRenderer { +public final class MatchRuleRenderer extends ExplainedComboControlRenderer { private final List values; private final List names; @@ -122,9 +122,11 @@ private SemanticVersion guideVersion() { private Optional guide() { EObject owner = getViewModelContext().getDomainModel(); if (owner instanceof LicensePlanFeatureDescriptor) { - return Optional.ofNullable(((LicensePlanFeatureDescriptor) owner).getFeature().getVersionMatch().getVersion()); + return Optional + .ofNullable(((LicensePlanFeatureDescriptor) owner).getFeature().getVersionMatch().getVersion()); } else if (owner instanceof PersonalFeatureGrantDescriptor) { - return Optional.ofNullable(((PersonalFeatureGrantDescriptor) owner).getFeature().getVersionMatch().getVersion()); + return Optional + .ofNullable(((PersonalFeatureGrantDescriptor) owner).getFeature().getVersionMatch().getVersion()); } else if (owner instanceof VersionMatch) { return Optional.ofNullable(((VersionMatch) owner).getVersion()); }