Skip to content

Commit

Permalink
Bug 575165 - [Passage][Operator] License Agreement management: gui
Browse files Browse the repository at this point in the history
rework static util to normal class

Signed-off-by: eparovyshnaya <[email protected]>
  • Loading branch information
eparovyshnaya committed Aug 9, 2021
1 parent 0561b13 commit fa552e1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<AgreementDescriptor> descriptor = new SelectedAgreement(shell, registry, initial).get();
if (descriptor.isPresent()) {
String identifier = descriptor.get().getIdentifier();
if (identifier != null) {
text.setText(identifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends AgreementDescriptor> input = registry.agreements();
Class<AgreementDescriptor> clazz = AgreementDescriptor.class;
return LocWokbench.selectClassifier(shell, classifier, title, input, initial, clazz);
}
}
Original file line number Diff line number Diff line change
@@ -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<Optional<AgreementDescriptor>> {

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<AgreementDescriptor> get() {
return Optional.ofNullable(//
LocWokbench.selectClassifier(//
shell, //
AgreementsPackage.eINSTANCE.getAgreement().getName(), //
AgreementsUiMessages.AgreementsUi_select_agreement, //
registry.agreements(), //
initial, //
AgreementDescriptor.class)//
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MatchingRule> values;
private final List<String> names;
Expand Down Expand Up @@ -122,9 +122,11 @@ private SemanticVersion guideVersion() {
private Optional<String> 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());
}
Expand Down

0 comments on commit fa552e1

Please sign in to comment.