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 560433 - [Passage] add org.eclipse.passage.loc.workbench.tests #143

Merged
merged 6 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ Manifest-Version: 1.0
Automatic-Module-Name: org.eclipse.passage.loc.api
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.passage.loc.api
Bundle-Version: 0.5.200.qualifier
Bundle-Version: 0.6.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.passage.loc.api,
org.eclipse.passage.loc.internal.api;x-friends:="org.eclipse.passage.loc.workbench,org.eclipse.passage.loc.licenses.ui"
org.eclipse.passage.loc.internal.api;x-friends:="org.eclipse.passage.loc.workbench,org.eclipse.passage.loc.licenses.ui,org.eclipse.passage.loc.users.ui"
Require-Bundle: org.eclipse.osgi.services;bundle-version="0.0.0",
org.eclipse.equinox.common;bundle-version="0.0.0";visibility:=reexport,
org.eclipse.e4.core.services;bundle-version="0.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.passage.lic.users.registry.UserRegistry;
import org.eclipse.passage.loc.internal.dashboard.ui.i18n.IssueLicensePageMessages;
import org.eclipse.passage.loc.internal.licenses.ui.SelectLicensePlan;
import org.eclipse.passage.loc.internal.workbench.SelectRoot;
import org.eclipse.passage.loc.jface.dialogs.DateDialog;
import org.eclipse.passage.loc.products.ui.ProductsUi;
import org.eclipse.passage.loc.users.ui.UsersUi;
Expand Down Expand Up @@ -129,7 +130,8 @@ private String selectLicensePlan(Text text) {
if (data instanceof LicensePlanDescriptor) {
initial.add((LicensePlanDescriptor) data);
}
LicensePlanDescriptor selected = new SelectLicensePlan(context).get().orElse(null);
LicensePlanDescriptor selected = new SelectRoot<>(new SelectLicensePlan(context).get(), context).get()
.orElse(null);
text.setData(selected);
licensePlanDescriptor = selected;
return labelProvider.getText(selected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,28 @@
*******************************************************************************/
package org.eclipse.passage.loc.internal.licenses.ui;

import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.passage.lic.jface.resource.LicensingImages;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.model.meta.LicensesPackage;
import org.eclipse.passage.lic.licenses.registry.LicenseRegistry;
import org.eclipse.passage.loc.internal.api.ZeroOneMany;
import org.eclipse.passage.loc.internal.licenses.ui.i18n.LicensesUiMessages;
import org.eclipse.passage.loc.internal.workbench.CreateRoot;
import org.eclipse.passage.loc.internal.workbench.SelectFromDialog;
import org.eclipse.passage.loc.internal.workbench.SelectRequest;
import org.eclipse.passage.loc.jface.dialogs.Appearance;
import org.eclipse.passage.loc.licenses.core.Licenses;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.passage.loc.users.core.Users;

/**
* Selects or creates {@link LicensePlanDescriptor}. Will return either
* {@link Optional} with selected/created license plan or
* {@link Optional#empty()}
* Creates {@link SelectRequest} for {@link LicensePlanDescriptor} from the
* given {@link IEclipseContext}.
*
* @since 0.6
*
*/
public final class SelectLicensePlan implements Supplier<Optional<LicensePlanDescriptor>> {
public final class SelectLicensePlan implements Supplier<SelectRequest<LicensePlanDescriptor>> {

private final IEclipseContext context;

Expand All @@ -45,17 +42,22 @@ public SelectLicensePlan(IEclipseContext context) {
}

@Override
public Optional<LicensePlanDescriptor> get() {
LicenseRegistry registry = context.get(LicenseRegistry.class);
Supplier<Iterable<LicensePlanDescriptor>> input = () -> StreamSupport
.stream(registry.getLicensePlans().spliterator(), false).collect(Collectors.toList());
ZeroOneMany<LicensePlanDescriptor> zeroOneMany = new ZeroOneMany<>(input);
String title = LicensesUiMessages.LicensesUi_select_license_plan;
Appearance appearance = new Appearance(title);
SelectFromDialog<LicensePlanDescriptor> select = new SelectFromDialog<LicensePlanDescriptor>(
() -> context.get(Shell.class), appearance);
return zeroOneMany.choose(new CreateRoot<LicensePlanDescriptor>(context, Licenses.DOMAIN_NAME,
LicensePlanDescriptor.class), select);
public SelectRequest<LicensePlanDescriptor> get() {
return new SelectRequest<LicensePlanDescriptor>(LicensePlanDescriptor.class, domain(), input(), appearance());
}

private Supplier<Iterable<LicensePlanDescriptor>> input() {
return () -> StreamSupport.stream(context.get(LicenseRegistry.class).getLicensePlans().spliterator(), false)//
.collect(Collectors.toList());
}

private Appearance appearance() {
return new Appearance(LicensesUiMessages.LicensesUi_select_license_plan, //
() -> LicensingImages.getImage(LicensesPackage.eINSTANCE.getLicensePlan().getName()));
}

private String domain() {
return Users.DOMAIN_NAME;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Require-Bundle: org.eclipse.osgi.services;bundle-version="0.0.0",
org.slf4j.api;bundle-version="0.0.0"
Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
javax.inject;version="1.0.0"
Export-Package: org.eclipse.passage.loc.internal.workbench;x-friends:="org.eclipse.passage.loc.licenses.ui",
Export-Package: org.eclipse.passage.loc.internal.workbench;x-friends:="org.eclipse.passage.loc.licenses.ui,org.eclipse.passage.loc.users.ui,org.eclipse.passage.loc.dashboard.ui",
org.eclipse.passage.loc.internal.workbench.i18n;x-internal:=true,
org.eclipse.passage.loc.jface,
org.eclipse.passage.loc.jface.dialogs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Optional<C> apply(Iterable<C> input) {
FilteredSelectionDialog<C> dialog = new FilteredSelectionDialog<C>(shellSupplier.get(), false,
new LabelSearchFilter());
dialog.setTitle(appearance.title());
dialog.setImage(appearance.image());
dialog.setImage(appearance.image().get());
dialog.setLabelProvider(appearance.labelProvider());
dialog.setInitialSelection(initial);
dialog.setInput(input);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*******************************************************************************
* Copyright (c) 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.loc.internal.workbench;

import java.util.Objects;
import java.util.function.Supplier;

import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages;
import org.eclipse.passage.loc.jface.dialogs.Appearance;

/**
* Encapsulates the information required to select the classifier
*
* @since 0.6
*
* @param <R> target type to be selected
*/
public final class SelectRequest<R> {
ruspl-afed marked this conversation as resolved.
Show resolved Hide resolved

private final Class<R> target;
private final String domain;
private final Supplier<Iterable<R>> input;
private final Appearance appearance;

/**
* Creates a {@link SelectRequest} instance for target classifier that belongs
* to a given domain, also specifies the input to select from and the dialog
* appearance
*
* @param target the type of object to be selected, must not be
* <code>null</code>
* @param domain the domain that target belongs to, must not be
* <code>null</code>
* @param input the input to select from, must not be <code>null</code>
* @param appearance the appearance of UI dialog, must not be <code>null</code>
*/
public SelectRequest(Class<R> target, String domain, Supplier<Iterable<R>> input, Appearance appearance) {
Objects.requireNonNull(target, WorkbenchMessages.SelectRequest_e_target_null);
Objects.requireNonNull(domain, WorkbenchMessages.SelectRequest_e_domain_null);
Objects.requireNonNull(input, WorkbenchMessages.SelectRequest_e_input_null);
Objects.requireNonNull(appearance, WorkbenchMessages.SelectRequest_e_appearance_null);
this.target = target;
this.domain = domain;
this.input = input;
this.appearance = appearance;
}
ruspl-afed marked this conversation as resolved.
Show resolved Hide resolved

/**
* The type of object to be selected
*
* @return non-<code>null</code> target
*/
public Class<R> target() {
return target;
}

/**
* The domain of object to be selected
*
* @return non-<code>null</code> domain
*/
public String domain() {
return domain;
}

/**
* The supplier of input to select from
*
* @return non-<code>null</code> supplier of input
*/
public Supplier<Iterable<R>> input() {
return input;
}

/**
* The appearance to use for UI
*
* @return non-<code>null</code> appearance
*/
public Appearance appearance() {
return appearance;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public class WorkbenchMessages extends NLS {
public static String SelectFromDialog_e_null_appearance;
public static String SelectFromDialog_e_null_initial;
public static String SelectFromDialog_e_null_shell;
public static String SelectRequest_e_appearance_null;
public static String SelectRequest_e_domain_null;
public static String SelectRequest_e_input_null;
public static String SelectRequest_e_target_null;
public static String UndoHandler_label_base;
public static String UndoHandler_label_handler;
static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ RootClassifierWizard_title_e_create=Create
SelectFromDialog_e_null_appearance=Appearance must not be null
SelectFromDialog_e_null_initial=Initial selection must not be null
SelectFromDialog_e_null_shell=Shell must not be null
SelectRequest_e_appearance_null=Appearance must not be null
SelectRequest_e_domain_null=Domain must not be null
SelectRequest_e_input_null=Input must not be null
SelectRequest_e_target_null=Target must not be null
UndoHandler_label_base=Undo
UndoHandler_label_handler={0} {1}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.passage.loc.jface.dialogs;

import java.util.Objects;
import java.util.function.Supplier;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.passage.lic.jface.resource.LicensingImages;
Expand All @@ -28,42 +29,42 @@
public final class Appearance {

private final String title;
private final Image image;
private final Supplier<Image> image;
private final LabelProvider labelProvider;

/**
* Creates the dialog appearance descriptor with the given non-<code>null</code>
* title, default image and default label provider will be used
* title, default image supplier and default label provider will be used
*
* @param title title for dialog, must not be <code>null</code>
*
*/
public Appearance(String title) {
this(title, LicensingImages.getImageRegistry().get(LicensingImages.IMG_DEFAULT));
this(title, () -> LicensingImages.getImageRegistry().get(LicensingImages.IMG_DEFAULT));
}

/**
* Creates the dialog appearance descriptor with the given non-<code>null</code>
* title and image, default label provider will be used
*
* @param title title for dialog, must not be <code>null</code>
* @param image image for dialog, must not be <code>null</code>
* @param image image supplier for dialog, must not be <code>null</code>
*
*/
public Appearance(String title, Image image) {
public Appearance(String title, Supplier<Image> image) {
this(title, image, new LabelProvider());
}

/**
* Creates the dialog appearance descriptor with the given non-<code>null</code>
* title, image, and label provider
* title, image supplier, and label provider
*
* @param title title for dialog, must not be <code>null</code>
* @param image image for dialog, must not be <code>null</code>
* @param image supplier of the image for dialog, must not be <code>null</code>
* @param labels label provider for dialog, must not be <code>null</code>
*
*/
public Appearance(String title, Image image, LabelProvider labels) {
public Appearance(String title, Supplier<Image> image, LabelProvider labels) {
Objects.requireNonNull(title, WorkbenchMessages.Appearance_e_null_title);
Objects.requireNonNull(image, WorkbenchMessages.Appearance_e_null_image);
Objects.requireNonNull(labels, WorkbenchMessages.Appearance_e_null_labels);
Expand All @@ -82,11 +83,11 @@ public String title() {
}

/**
* The image to use for dialog's shell
* The image supplier to use for dialog's shell
*
* @return non-<code>null</code> image
* @return non-<code>null</code> image supplier
*/
public Image image() {
public Supplier<Image> image() {
return image;
}

Expand Down
4 changes: 2 additions & 2 deletions releng/org.eclipse.passage.loc.aggregator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<module>../../bundles/org.eclipse.passage.loc.workbench</module>
<module>../../bundles/org.eclipse.passage.loc.workbench.emfforms</module>
<module>../../features/org.eclipse.passage.loc.workbench.feature</module>
<module>../../tests/org.eclipse.passage.loc.api.tests</module>
<module>../../tests/org.eclipse.passage.loc.workbench.tests</module>

<module>../../bundles/org.eclipse.passage.loc.edit.ui</module>
<module>../../features/org.eclipse.passage.loc.edit.ui.feature</module>
Expand Down Expand Up @@ -65,8 +67,6 @@
<module>../../bundles/org.eclipse.passage.loc.operator</module>
<module>../../features/org.eclipse.passage.loc.operator.feature</module>

<module>../../tests/org.eclipse.passage.loc.api.tests</module>

<module>../../bundles/org.eclipse.passage.loc.yars.api</module>
<module>../../tests/org.eclipse.passage.loc.yars.api.tests</module>

Expand Down
11 changes: 11 additions & 0 deletions tests/org.eclipse.passage.loc.workbench.tests/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
34 changes: 34 additions & 0 deletions tests/org.eclipse.passage.loc.workbench.tests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.passage.loc.workbench.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>
Loading