From cf9c499dfa53b4271b25a8d639fe7606ae79ef39 Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Mon, 26 Feb 2024 20:46:25 +0300 Subject: [PATCH] [#1300] license issuing dialogs: keep selection --- .../ui/wizards/license/LabeledField.java | 11 +-- .../ui/wizards/license/LicensePlanField.java | 5 +- .../wizards/license/ProductVersionField.java | 7 +- .../ui/wizards/license/SelectableField.java | 14 +++- .../ui/wizards/license/UserField.java | 5 +- .../ui/wizards/license/UsersField.java | 10 ++- .../licenses/ui/SelectLicensePlan.java | 12 +++- .../internal/products/ui/SelectProduct.java | 9 ++- .../products/ui/SelectProductVersion.java | 11 ++- .../loc/internal/users/ui/SelectUser.java | 13 ++-- .../loc/internal/users/ui/SelectUsers.java | 69 +++++++++++++++++++ .../loc/internal/workbench/SelectInner.java | 17 +++-- .../loc/internal/workbench/SelectRequest.java | 27 +++++++- .../loc/internal/workbench/SelectRoot.java | 14 +++- .../loc/internal/workbench/SelectRoots.java | 15 ++-- .../workbench/SupplySelectRequest.java | 16 ++++- .../workbench/i18n/WorkbenchMessages.java | 4 +- .../i18n/WorkbenchMessages.properties | 4 +- 18 files changed, 218 insertions(+), 45 deletions(-) create mode 100644 bundles/org.eclipse.passage.loc.users.ui/src/org/eclipse/passage/loc/internal/users/ui/SelectUsers.java diff --git a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/LabeledField.java b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/LabeledField.java index 7481a8dd7..ae11c61f1 100644 --- a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/LabeledField.java +++ b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/LabeledField.java @@ -62,10 +62,13 @@ private void installLabel(Composite parent) { } protected final void installData(Optional origin) { - origin.ifPresent(data -> { - widget.ifPresent(w -> w.setData(data)); - reflectData(data); - }); + T data = origin.orElse(null); + widget.ifPresent(w -> w.setData(data)); + reflectData(data); + } + + protected final Optional source() { + return source; } protected final Shell shell() { diff --git a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/LicensePlanField.java b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/LicensePlanField.java index 48c6ebc80..cdc343e83 100644 --- a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/LicensePlanField.java +++ b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/LicensePlanField.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,6 +9,7 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further evolution *******************************************************************************/ package org.eclipse.passage.loc.dashboard.ui.wizards.license; @@ -41,7 +42,7 @@ protected String errorText() { @Override protected Optional select(Text control) { - return new SelectRoot<>(new SelectLicensePlan(context).get(), context).get(); + return new SelectRoot<>(new SelectLicensePlan(context, data()).get(), context).get(); } } diff --git a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/ProductVersionField.java b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/ProductVersionField.java index ec5105f21..990e6fc43 100644 --- a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/ProductVersionField.java +++ b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/ProductVersionField.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,6 +9,7 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further evolution *******************************************************************************/ package org.eclipse.passage.loc.dashboard.ui.wizards.license; @@ -44,8 +45,8 @@ protected String errorText() { @Override protected Optional select(Text control) { return new SelectInner(// - new SelectProductVersion(context).get(), // - new SelectProduct(context).get(), // + new SelectProductVersion(context, data()).get(), // + new SelectProduct(context, data().map(ProductVersionDescriptor::getProduct)).get(), // context// ).get(); } diff --git a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/SelectableField.java b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/SelectableField.java index 96f61f0f6..c9eb1dc3c 100644 --- a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/SelectableField.java +++ b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/SelectableField.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,6 +9,7 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.dashboard.ui.wizards.license; @@ -53,12 +54,19 @@ protected Control control(Composite parent) { @Override protected void reflectData(T data) { if (data instanceof Collection) { - String altogether = StreamSupport.stream(((Collection) data).spliterator(), false)// + Collection collection = (Collection) data; + String altogether = StreamSupport.stream(collection.spliterator(), false)// .map(labels::getText)// .collect(Collectors.joining(", ")); //$NON-NLS-1$ - text.setText(altogether); + String fit = altogether; + if (altogether.length() > 100) { + fit = altogether.substring(0, 80) + String.format("... %d users", collection.size()); //$NON-NLS-1$ + } + text.setText(fit); + text.setToolTipText(altogether); } else { text.setText(labels.getText(data)); + text.setToolTipText(""); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/UserField.java b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/UserField.java index 0c319b68e..d42950d9f 100644 --- a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/UserField.java +++ b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/UserField.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,6 +9,7 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.dashboard.ui.wizards.license; @@ -40,7 +41,7 @@ protected String errorText() { @Override protected Optional select(Text control) { - return new SelectRoot<>(new SelectUser(context).get(), context).get(); + return new SelectRoot<>(new SelectUser(context, data()).get(), context).get(); } } diff --git a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/UsersField.java b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/UsersField.java index ce201f929..4d31a0026 100644 --- a/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/UsersField.java +++ b/bundles/org.eclipse.passage.loc.dashboard.ui/src/org/eclipse/passage/loc/dashboard/ui/wizards/license/UsersField.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,17 +9,19 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.dashboard.ui.wizards.license; import java.util.Collection; +import java.util.Collections; import java.util.Optional; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.passage.lic.api.MandatoryService; import org.eclipse.passage.lic.users.UserDescriptor; import org.eclipse.passage.loc.internal.dashboard.ui.i18n.IssueLicensePageMessages; -import org.eclipse.passage.loc.internal.users.ui.SelectUser; +import org.eclipse.passage.loc.internal.users.ui.SelectUsers; import org.eclipse.passage.loc.internal.workbench.SelectRoots; import org.eclipse.swt.widgets.Text; @@ -41,7 +43,9 @@ protected String errorText() { @Override protected Optional> select(Text control) { - return Optional.of(new SelectRoots<>(new SelectUser(context).get(), context).get()); + return Optional.of(// + new SelectRoots<>(// + new SelectUsers(context, data().orElseGet(Collections::emptyList)).get(), context).get()); } } diff --git a/bundles/org.eclipse.passage.loc.licenses.ui/src/org/eclipse/passage/loc/internal/licenses/ui/SelectLicensePlan.java b/bundles/org.eclipse.passage.loc.licenses.ui/src/org/eclipse/passage/loc/internal/licenses/ui/SelectLicensePlan.java index 0377824da..91a52c945 100644 --- a/bundles/org.eclipse.passage.loc.licenses.ui/src/org/eclipse/passage/loc/internal/licenses/ui/SelectLicensePlan.java +++ b/bundles/org.eclipse.passage.loc.licenses.ui/src/org/eclipse/passage/loc/internal/licenses/ui/SelectLicensePlan.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,9 +9,11 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further evolution *******************************************************************************/ 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; @@ -36,12 +38,16 @@ public final class SelectLicensePlan extends SupplySelectRequest { public SelectLicensePlan(MandatoryService context) { - super(context); + this(context, Optional.empty()); + } + + public SelectLicensePlan(MandatoryService context, Optional selection) { + super(context, selection); } @Override public SelectRequest get() { - return new SelectRequest<>(LicensePlanDescriptor.class, domain(), input(), appearance()); + return new SelectRequest<>(LicensePlanDescriptor.class, domain(), input(), () -> initial, appearance()); } private Supplier> input() { diff --git a/bundles/org.eclipse.passage.loc.products.ui/src/org/eclipse/passage/loc/internal/products/ui/SelectProduct.java b/bundles/org.eclipse.passage.loc.products.ui/src/org/eclipse/passage/loc/internal/products/ui/SelectProduct.java index 508c253b4..0a4696683 100644 --- a/bundles/org.eclipse.passage.loc.products.ui/src/org/eclipse/passage/loc/internal/products/ui/SelectProduct.java +++ b/bundles/org.eclipse.passage.loc.products.ui/src/org/eclipse/passage/loc/internal/products/ui/SelectProduct.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,6 +9,7 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.internal.products.ui; @@ -36,7 +37,11 @@ public final class SelectProduct extends SupplySelectRequest { public SelectProduct(MandatoryService context) { - super(context); + this(context, Optional.empty()); + } + + public SelectProduct(MandatoryService context, Optional selection) { + super(context, selection); } @Override diff --git a/bundles/org.eclipse.passage.loc.products.ui/src/org/eclipse/passage/loc/internal/products/ui/SelectProductVersion.java b/bundles/org.eclipse.passage.loc.products.ui/src/org/eclipse/passage/loc/internal/products/ui/SelectProductVersion.java index abab83601..55a636683 100644 --- a/bundles/org.eclipse.passage.loc.products.ui/src/org/eclipse/passage/loc/internal/products/ui/SelectProductVersion.java +++ b/bundles/org.eclipse.passage.loc.products.ui/src/org/eclipse/passage/loc/internal/products/ui/SelectProductVersion.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,6 +9,7 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further evolution *******************************************************************************/ package org.eclipse.passage.loc.internal.products.ui; @@ -36,12 +37,16 @@ public final class SelectProductVersion extends SupplySelectRequest { public SelectProductVersion(MandatoryService context) { - super(context); + this(context, Optional.empty()); + } + + public SelectProductVersion(MandatoryService context, Optional selection) { + super(context, selection); } @Override public SelectRequest get() { - return new SelectRequest<>(ProductVersionDescriptor.class, domain(), input(), appearance()); + return new SelectRequest<>(ProductVersionDescriptor.class, domain(), input(), () -> initial, appearance()); } private Supplier> input() { diff --git a/bundles/org.eclipse.passage.loc.users.ui/src/org/eclipse/passage/loc/internal/users/ui/SelectUser.java b/bundles/org.eclipse.passage.loc.users.ui/src/org/eclipse/passage/loc/internal/users/ui/SelectUser.java index 95809c7a5..11f10f4cf 100644 --- a/bundles/org.eclipse.passage.loc.users.ui/src/org/eclipse/passage/loc/internal/users/ui/SelectUser.java +++ b/bundles/org.eclipse.passage.loc.users.ui/src/org/eclipse/passage/loc/internal/users/ui/SelectUser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,6 +9,7 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.internal.users.ui; @@ -30,19 +31,23 @@ /** * Selects or creates {@link UserOriginDescriptor}. Will return either - * {@link Optional} with selected/created license plan or + * {@link Optional} with selected/created {@link UserOriginDescriptor} or * {@link Optional#empty()} * */ public final class SelectUser extends SupplySelectRequest { public SelectUser(MandatoryService context) { - super(context); + this(context, Optional.empty()); + } + + public SelectUser(MandatoryService context, Optional selection) { + super(context, selection); } @Override public SelectRequest get() { - return new SelectRequest<>(UserDescriptor.class, domain(), input(), appearance()); + return new SelectRequest<>(UserDescriptor.class, domain(), input(), () -> initial, appearance()); } private Supplier> input() { diff --git a/bundles/org.eclipse.passage.loc.users.ui/src/org/eclipse/passage/loc/internal/users/ui/SelectUsers.java b/bundles/org.eclipse.passage.loc.users.ui/src/org/eclipse/passage/loc/internal/users/ui/SelectUsers.java new file mode 100644 index 000000000..d5ccf687f --- /dev/null +++ b/bundles/org.eclipse.passage.loc.users.ui/src/org/eclipse/passage/loc/internal/users/ui/SelectUsers.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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.loc.internal.users.ui; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import org.eclipse.passage.lic.api.MandatoryService; +import org.eclipse.passage.lic.jface.resource.LicensingImages; +import org.eclipse.passage.lic.users.UserDescriptor; +import org.eclipse.passage.lic.users.UserOriginDescriptor; +import org.eclipse.passage.lic.users.model.meta.UsersPackage; +import org.eclipse.passage.loc.internal.users.UserRegistry; +import org.eclipse.passage.loc.internal.users.ui.i18n.UsersUiMessages; +import org.eclipse.passage.loc.internal.workbench.SelectRequest; +import org.eclipse.passage.loc.internal.workbench.SupplySelectRequest; +import org.eclipse.passage.loc.jface.dialogs.Appearance; + +/** + * Selects or creates {@link UserOriginDescriptor}. Will return either + * {@link Optional} with selected/created {@link UserOriginDescriptor} or + * {@link Optional#empty()} + * + */ +public final class SelectUsers extends SupplySelectRequest { + + public SelectUsers(MandatoryService context) { + this(context, Collections.emptyList()); + } + + public SelectUsers(MandatoryService context, Collection selection) { + super(context, selection); + } + + @Override + public SelectRequest get() { + return new SelectRequest<>(UserDescriptor.class, domain(), input(), () -> initial, appearance()); + } + + private Supplier> input() { + return () -> StreamSupport.stream(context.get(UserRegistry.class).getUsers().spliterator(), false)// + .collect(Collectors.toList()); + } + + private Appearance appearance() { + return new Appearance(UsersUiMessages.SelectUser_title, // + () -> LicensingImages.getImage(UsersPackage.eINSTANCE.getUser().getName()), labels()); + } + + private String domain() { + return UsersPackage.eNAME; + } + +} diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectInner.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectInner.java index ed8158aee..b5dfb4ee8 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectInner.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectInner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,12 +9,16 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.internal.workbench; +import java.util.Collection; import java.util.Objects; import java.util.Optional; import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import org.eclipse.passage.lic.api.MandatoryService; import org.eclipse.passage.loc.internal.api.ZeroOrOne; @@ -52,9 +56,14 @@ public SelectInner(SelectRequest inner, SelectRequest root, MandatoryServi @Override public final Optional get() { - return new ZeroOrOne<>(inner.input()).choose( - new CreateInner(context, root.domain(), inner.target(), root), - new SelectFromDialog<>(() -> context.get(Shell.class), inner.appearance())); + return new ZeroOrOne<>(inner.input()) + .choose(new CreateInner(context, root.domain(), inner.target(), root), new SelectFromDialog<>( + () -> context.get(Shell.class), inner.appearance(), collection(inner.initial()))); + } + + private Collection collection(Supplier> iterable) { + return StreamSupport.stream(iterable.get().spliterator(), false)// + .collect(Collectors.toList()); } } diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRequest.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRequest.java index 65b51ae22..6d3a8f125 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRequest.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRequest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 ArSysOp + * 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 @@ -9,9 +9,11 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.internal.workbench; +import java.util.Collections; import java.util.Objects; import java.util.function.Supplier; @@ -28,6 +30,7 @@ public final class SelectRequest { private final Class target; private final String domain; private final Supplier> input; + private final Supplier> initial; private final Appearance appearance; /** @@ -40,19 +43,30 @@ public final class SelectRequest { * @param domain the domain that target belongs to, must not be * null * @param input the input to select from, must not be null + * @param initial preventive selection, must not be null * @param appearance the appearance of UI dialog, must not be null */ - public SelectRequest(Class target, String domain, Supplier> input, Appearance appearance) { + public SelectRequest(Class target, String domain, Supplier> input, Supplier> initial, + 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(initial, WorkbenchMessages.SelectRequest_e_selection_null); Objects.requireNonNull(appearance, WorkbenchMessages.SelectRequest_e_appearance_null); this.target = target; this.domain = domain; this.input = input; + this.initial = initial; this.appearance = appearance; } + /** + * Convenience constructor for empty initial selection + */ + public SelectRequest(Class target, String domain, Supplier> input, Appearance appearance) { + this(target, domain, input, Collections::emptyList, appearance); + } + /** * The type of object to be selected * @@ -80,6 +94,15 @@ public Supplier> input() { return input; } + /** + * The supplier of initial selection + * + * @return non-null supplier of input + */ + public Supplier> initial() { + return initial; + } + /** * The appearance to use for UI * diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRoot.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRoot.java index b82f697ec..125d289bd 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRoot.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRoot.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,12 +9,16 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.internal.workbench; +import java.util.Collection; import java.util.Objects; import java.util.Optional; import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import org.eclipse.passage.lic.api.MandatoryService; import org.eclipse.passage.loc.internal.api.ZeroOrOne; @@ -49,7 +53,13 @@ public SelectRoot(SelectRequest request, MandatoryService context) { @Override public final Optional get() { return new ZeroOrOne<>(request.input()).choose(new CreateRoot(context, request.domain(), request.target()), - new SelectFromDialog<>(() -> context.get(Shell.class), request.appearance())); + new SelectFromDialog<>(() -> context.get(Shell.class), request.appearance(), + collection(request.initial()))); + } + + private Collection collection(Supplier> iterable) { + return StreamSupport.stream(iterable.get().spliterator(), false)// + .collect(Collectors.toList()); } } diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRoots.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRoots.java index 8766cca6e..ee38d1cf5 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRoots.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SelectRoots.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,6 +9,7 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.internal.workbench; @@ -50,15 +51,19 @@ public SelectRoots(SelectRequest request, MandatoryService context) { @Override public final Collection get() { - return new ZeroOrMany<>(// - () -> StreamSupport.stream(request.input().get().spliterator(), false)// - .collect(Collectors.toList())// + return new ZeroOrMany<>(() -> collection(request.input())// ).choose(// new CreateRoot(context, request.domain(), request.target()), // new SelectSeveralFromDialog(// () -> context.get(Shell.class), // - request.appearance())// + request.appearance(), // + collection(request.initial()))// ); } + private Collection collection(Supplier> iterable) { + return StreamSupport.stream(iterable.get().spliterator(), false)// + .collect(Collectors.toList()); + } + } diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SupplySelectRequest.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SupplySelectRequest.java index a684b7203..3cc000953 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SupplySelectRequest.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/SupplySelectRequest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 ArSysOp + * 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 @@ -9,9 +9,13 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further evolution *******************************************************************************/ package org.eclipse.passage.loc.internal.workbench; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; import java.util.function.Supplier; import org.eclipse.jface.viewers.LabelProvider; @@ -21,9 +25,19 @@ public abstract class SupplySelectRequest implements Supplier> { protected final MandatoryService context; + protected final Collection initial; public SupplySelectRequest(MandatoryService context) { + this(context, Collections.emptyList()); + } + + public SupplySelectRequest(MandatoryService context, Optional initial) { + this(context, initial.map(Collections::singletonList).orElseGet(Collections::emptyList)); + } + + public SupplySelectRequest(MandatoryService context, Collection initial) { this.context = context; + this.initial = initial; } protected LabelProvider labels() { diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.java index bca9138e1..4633180a0 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 ArSysOp + * Copyright (c) 2019, 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 @@ -9,6 +9,7 @@ * * Contributors: * ArSysOp - initial API and implementation + * ArSysOp - further support *******************************************************************************/ package org.eclipse.passage.loc.internal.workbench.i18n; @@ -60,6 +61,7 @@ public class WorkbenchMessages extends NLS { 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_selection_null; public static String SelectRequest_e_target_null; public static String SelectRoot_e_null_context; public static String SelectRoot_e_null_inner_request; diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.properties b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.properties index 5cf4ece1a..6aa9c958a 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.properties +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/i18n/WorkbenchMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2019, 2020 ArSysOp and others +# Copyright (c) 2019, 2024 ArSysOp and others # # This program and the accompanying materials are made available under the # terms of the Eclipse Public License 2.0 which is available at @@ -9,6 +9,7 @@ # # Contributors: # ArSysOp - initial API and implementation +# ArSysOp - further support ############################################################################### Appearance_e_null_title=Title must not be null @@ -55,6 +56,7 @@ 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_selection_null=Selection can be empty, but must not be null SelectRequest_e_target_null=Target must not be null SelectRoot_e_null_context=Context must not be null SelectRoot_e_null_inner_request=Request for inner must not be null