-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
ImportLicenseDialog is extended with proper hooks
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020, 2024 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 | ||
* ArSysOp - further support | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.jface.dialogs.licensing; | ||
|
||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.passage.lic.api.agreements.AgreementToAccept; | ||
import org.eclipse.passage.lic.api.diagnostic.Diagnostic; | ||
import org.eclipse.passage.lic.api.restrictions.ExaminationCertificate; | ||
import org.eclipse.passage.lic.base.diagnostic.DiagnosticExplained; | ||
import org.eclipse.passage.lic.base.diagnostic.NoErrors; | ||
import org.eclipse.passage.lic.base.diagnostic.RequirementStatus; | ||
import org.eclipse.passage.lic.base.diagnostic.RequirementsCoverage; | ||
import org.eclipse.passage.lic.base.restrictions.ExaminationExplained; | ||
import org.eclipse.passage.lic.equinox.ProductContacts; | ||
import org.eclipse.passage.lic.internal.jface.i18n.LicenseStatusDialogMessages; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.custom.StyledText; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Shell; | ||
|
||
public abstract class BaseLicenseStatusDialog extends NotificationDialog { | ||
|
||
protected final ExaminationCertificate certificate; | ||
protected final Diagnostic diagnostic; | ||
private GoodIntention intention = new GoodIntention.Nope(); // truly mutable ^:( | ||
private StyledText notice; | ||
|
||
protected BaseLicenseStatusDialog(Shell shell, ExaminationCertificate certificate, Diagnostic diagnostic) { | ||
super(shell); | ||
this.certificate = certificate; | ||
this.diagnostic = diagnostic; | ||
} | ||
Check warning on line 46 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L43-L46
|
||
|
||
public final GoodIntention goodIntention() { | ||
return intention; | ||
Check warning on line 49 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L49
|
||
} | ||
|
||
@Override | ||
protected final void configureShell(Shell shell) { | ||
super.configureShell(shell); | ||
shell.setText(LicenseStatusDialogMessages.LicenseStatusDialog_title); | ||
shell.setImage(getDefaultImage()); | ||
shell.setSize(840, 600); | ||
} | ||
Check warning on line 58 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L54-L58
|
||
|
||
@Override | ||
protected final void buildUI(Composite parent) { | ||
viewer = new HereTable<RequirementStatus>(parent, RequirementStatus.class) // | ||
.withColumn(LicenseStatusDialogMessages.LicenseStatusDialog_column_id, // | ||
600, RequirementStatus::feature) | ||
.withColumn(LicenseStatusDialogMessages.LicenseStatusDialog_column_status, // | ||
200, RequirementStatus::status) | ||
.viewer(); | ||
notice = new StyledText(parent, SWT.BORDER | SWT.READ_ONLY); | ||
notice.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
} | ||
Check warning on line 70 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L62-L70
|
||
|
||
@Override | ||
protected final void inplaceData() { | ||
viewer.setInput(new RequirementsCoverage(certificate).get()); | ||
notice.setText(new ProductContacts().get()); | ||
} | ||
Check warning on line 76 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L74-L76
|
||
|
||
@Override | ||
protected final void initButtons() { | ||
int button = 1; | ||
new ButtonConfig(button++, this::requestLicense, // | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_request, // | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_request_tooltip, "")//$NON-NLS-1$ | ||
.reside(buttons); | ||
new ButtonConfig(button++, this::importLicense, // | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_import, // | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_import_tooltip, "") //$NON-NLS-1$ | ||
.reside(buttons); | ||
new ButtonConfig(button++, copy(), // | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_copy, | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_copy_tooltip, "") //$NON-NLS-1$ | ||
.reside(buttons); | ||
Check warning on line 92 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L80-L92
|
||
if (haveUnacceptedAgreements()) { | ||
new ButtonConfig(button++, this::exposeAgreements, // | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_accept, | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_accept_tooltip, "") //$NON-NLS-1$ | ||
.reside(buttons); | ||
Check warning on line 97 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L94-L97
|
||
} | ||
if (!new NoErrors().test(diagnostic)) { | ||
new ButtonConfig(button++, this::diagnose, // | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_diagnose, | ||
LicenseStatusDialogMessages.LicenseStatusDialog_intention_diagnose_tooltip, "") //$NON-NLS-1$ | ||
.reside(buttons); | ||
Check warning on line 103 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L100-L103
|
||
} | ||
} | ||
Check warning on line 105 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L105
|
||
|
||
@Override | ||
protected final void updateButtonsEnablement() { | ||
// do nothing | ||
} | ||
Check warning on line 110 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L110
|
||
|
||
@Override | ||
protected final void initMessage() { | ||
new CertificateSummary(certificate).accept(this); | ||
} | ||
Check warning on line 115 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L114-L115
|
||
|
||
protected abstract GoodIntention requestLicenseIntention(); | ||
|
||
protected abstract GoodIntention importLicenseIntention(); | ||
|
||
protected abstract GoodIntention diagnoseIntention(); | ||
|
||
protected abstract GoodIntention exposeLicenseAgreementsIntention(Collection<AgreementToAccept> collection); | ||
|
||
private void requestLicense() { | ||
intention = requestLicenseIntention(); | ||
super.okPressed(); | ||
} | ||
Check warning on line 128 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L126-L128
|
||
|
||
private void importLicense() { | ||
intention = importLicenseIntention(); | ||
super.okPressed(); | ||
} | ||
Check warning on line 133 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L131-L133
|
||
|
||
private void diagnose() { | ||
intention = diagnoseIntention(); | ||
super.okPressed(); | ||
} | ||
Check warning on line 138 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L136-L138
|
||
|
||
private void exposeAgreements() { | ||
intention = exposeLicenseAgreementsIntention(toExpose(certificate.agreements())); | ||
super.okPressed(); | ||
} | ||
Check warning on line 143 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L141-L143
|
||
|
||
private Collection<AgreementToAccept> toExpose(Collection<AgreementToAccept> agreements) { | ||
return agreements.stream()// | ||
.filter(this::toExpose)// | ||
.collect(Collectors.toList()); | ||
Check warning on line 148 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L146-L148
|
||
} | ||
|
||
private boolean toExpose(AgreementToAccept agreement) { | ||
return !agreement.acceptance().accepted() && !agreement.acceptance().error().isPresent(); | ||
} | ||
|
||
private boolean haveUnacceptedAgreements() { | ||
return certificate.agreements().stream()// | ||
.filter(this::toExpose)// | ||
.findAny()// | ||
.isPresent(); | ||
Check warning on line 159 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L156-L159
|
||
} | ||
|
||
private Runnable copy() { | ||
return new CopyToClipboard(this::getShell, // | ||
new ExaminationExplained(certificate), // | ||
new DiagnosticExplained(diagnostic)); | ||
Check warning on line 165 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/BaseLicenseStatusDialog.java#L163-L165
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.eclipse.passage.lic.internal.jface.dialogs.licensing; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
import org.eclipse.passage.lic.internal.jface.i18n.ImportLicenseDialogMessages; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Button; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.DirectoryDialog; | ||
import org.eclipse.swt.widgets.Label; | ||
import org.eclipse.swt.widgets.Text; | ||
|
||
public final class FromLocalFileSystem implements LicenseFilesControl { | ||
Check warning on line 18 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java#L18
|
||
|
||
private Text path; | ||
|
||
@Override | ||
public void install(Composite parent, Consumer<List<Path>> onLicenses) { | ||
Composite composite = row(parent, 3); | ||
new Label(composite, SWT.NONE).setText(ImportLicenseDialogMessages.ImportLicenseDialog_path_label); | ||
path = new Text(composite, SWT.BORDER | SWT.READ_ONLY); | ||
path.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
Button browse = new Button(composite, SWT.PUSH); | ||
browse.setText(ImportLicenseDialogMessages.ImportLicenseDialog_browse); | ||
browse.addListener(SWT.Selection, e -> browseAndLoad(onLicenses)); | ||
} | ||
Check warning on line 31 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java#L24-L31
|
||
|
||
private void browseAndLoad(Consumer<List<Path>> onLicenses) { | ||
onLicenses.accept(browse()); | ||
} | ||
Check warning on line 35 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java#L34-L35
|
||
|
||
private Composite row(Composite parent, int columns) { | ||
Composite row = new Composite(parent, SWT.NONE); | ||
row.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
row.setLayout(new GridLayout(columns, false)); | ||
return row; | ||
Check warning on line 41 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java#L38-L41
|
||
} | ||
|
||
private List<Path> browse() { | ||
DirectoryDialog dialog = new DirectoryDialog(path.getShell(), SWT.OPEN | SWT.SHEET); | ||
dialog.setText(ImportLicenseDialogMessages.ImportLicenseDialog_browse_dialog_title); | ||
String folder = dialog.open(); | ||
Check warning on line 47 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java#L45-L47
|
||
if (folder == null) { | ||
return Collections.emptyList(); | ||
Check warning on line 49 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java#L49
|
||
} | ||
path.setText(folder); | ||
List<Path> licenses = new AllLicensesFromFolder(folder).get(); | ||
path.setData(licenses); | ||
return licenses; | ||
Check warning on line 54 in bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java Codecov / codecov/patchbundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/FromLocalFileSystem.java#L51-L54
|
||
} | ||
|
||
} |