Skip to content

Commit

Permalink
[#1300] license issuing dialogs: keep selection
Browse files Browse the repository at this point in the history
  • Loading branch information
eparovyshnaya authored and ruspl-afed committed Feb 26, 2024
1 parent c518268 commit cf9c499
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ private void installLabel(Composite parent) {
}

protected final void installData(Optional<T> 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<T> source() {
return source;
}

protected final Shell shell() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* ArSysOp - initial API and implementation
* ArSysOp - further evolution
*******************************************************************************/
package org.eclipse.passage.loc.dashboard.ui.wizards.license;

Expand Down Expand Up @@ -41,7 +42,7 @@ protected String errorText() {

@Override
protected Optional<LicensePlanDescriptor> select(Text control) {
return new SelectRoot<>(new SelectLicensePlan(context).get(), context).get();
return new SelectRoot<>(new SelectLicensePlan(context, data()).get(), context).get();
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* ArSysOp - initial API and implementation
* ArSysOp - further evolution
*******************************************************************************/
package org.eclipse.passage.loc.dashboard.ui.wizards.license;

Expand Down Expand Up @@ -44,8 +45,8 @@ protected String errorText() {
@Override
protected Optional<ProductVersionDescriptor> select(Text control) {
return new SelectInner<ProductVersionDescriptor, ProductDescriptor>(//
new SelectProductVersion(context).get(), //
new SelectProduct(context).get(), //
new SelectProductVersion(context, data()).get(), //
new SelectProduct(context, data().map(ProductVersionDescriptor::getProduct)).get(), //
context//
).get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* ArSysOp - initial API and implementation
* ArSysOp - further support
*******************************************************************************/
package org.eclipse.passage.loc.dashboard.ui.wizards.license;

Expand Down Expand Up @@ -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$
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* ArSysOp - initial API and implementation
* ArSysOp - further support
*******************************************************************************/
package org.eclipse.passage.loc.dashboard.ui.wizards.license;

Expand Down Expand Up @@ -40,7 +41,7 @@ protected String errorText() {

@Override
protected Optional<UserDescriptor> select(Text control) {
return new SelectRoot<>(new SelectUser(context).get(), context).get();
return new SelectRoot<>(new SelectUser(context, data()).get(), context).get();
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand All @@ -41,7 +43,9 @@ protected String errorText() {

@Override
protected Optional<Collection<UserDescriptor>> 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());
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -36,12 +38,16 @@
public final class SelectLicensePlan extends SupplySelectRequest<LicensePlanDescriptor> {

public SelectLicensePlan(MandatoryService context) {
super(context);
this(context, Optional.empty());
}

public SelectLicensePlan(MandatoryService context, Optional<LicensePlanDescriptor> selection) {
super(context, selection);
}

@Override
public SelectRequest<LicensePlanDescriptor> get() {
return new SelectRequest<>(LicensePlanDescriptor.class, domain(), input(), appearance());
return new SelectRequest<>(LicensePlanDescriptor.class, domain(), input(), () -> initial, appearance());
}

private Supplier<Iterable<LicensePlanDescriptor>> input() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* ArSysOp - initial API and implementation
* ArSysOp - further support
*******************************************************************************/
package org.eclipse.passage.loc.internal.products.ui;

Expand Down Expand Up @@ -36,7 +37,11 @@
public final class SelectProduct extends SupplySelectRequest<ProductDescriptor> {

public SelectProduct(MandatoryService context) {
super(context);
this(context, Optional.empty());
}

public SelectProduct(MandatoryService context, Optional<ProductDescriptor> selection) {
super(context, selection);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* ArSysOp - initial API and implementation
* ArSysOp - further evolution
*******************************************************************************/
package org.eclipse.passage.loc.internal.products.ui;

Expand Down Expand Up @@ -36,12 +37,16 @@
public final class SelectProductVersion extends SupplySelectRequest<ProductVersionDescriptor> {

public SelectProductVersion(MandatoryService context) {
super(context);
this(context, Optional.empty());
}

public SelectProductVersion(MandatoryService context, Optional<ProductVersionDescriptor> selection) {
super(context, selection);
}

@Override
public SelectRequest<ProductVersionDescriptor> get() {
return new SelectRequest<>(ProductVersionDescriptor.class, domain(), input(), appearance());
return new SelectRequest<>(ProductVersionDescriptor.class, domain(), input(), () -> initial, appearance());
}

private Supplier<Iterable<ProductVersionDescriptor>> input() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* ArSysOp - initial API and implementation
* ArSysOp - further support
*******************************************************************************/
package org.eclipse.passage.loc.internal.users.ui;

Expand All @@ -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<UserDescriptor> {

public SelectUser(MandatoryService context) {
super(context);
this(context, Optional.empty());
}

public SelectUser(MandatoryService context, Optional<UserDescriptor> selection) {
super(context, selection);
}

@Override
public SelectRequest<UserDescriptor> get() {
return new SelectRequest<>(UserDescriptor.class, domain(), input(), appearance());
return new SelectRequest<>(UserDescriptor.class, domain(), input(), () -> initial, appearance());
}

private Supplier<Iterable<UserDescriptor>> input() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UserDescriptor> {

public SelectUsers(MandatoryService context) {
this(context, Collections.emptyList());
}

public SelectUsers(MandatoryService context, Collection<UserDescriptor> selection) {
super(context, selection);
}

@Override
public SelectRequest<UserDescriptor> get() {
return new SelectRequest<>(UserDescriptor.class, domain(), input(), () -> initial, appearance());
}

private Supplier<Iterable<UserDescriptor>> 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;
}

}
Loading

0 comments on commit cf9c499

Please sign in to comment.