-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from eclipse/548112/select_from_dialog
Bug 548112 - [Passage] create license plan from issue license wizard
- Loading branch information
Showing
9 changed files
with
218 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...g.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/jface/dialogs/Appearance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/******************************************************************************* | ||
* 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.jface.dialogs; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.jface.viewers.LabelProvider; | ||
import org.eclipse.passage.lic.jface.resource.LicensingImages; | ||
import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages; | ||
import org.eclipse.swt.graphics.Image; | ||
|
||
/** | ||
* Encapsulates dialog appearance to reduce the number of arguments in methods | ||
* | ||
* @since 0.6 | ||
* | ||
*/ | ||
public final class Appearance { | ||
|
||
private final String title; | ||
private final 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 | ||
* | ||
* @param title title for dialog, should not be <code>null</code> | ||
* @param image image for dialog, should not be <code>null</code> | ||
* | ||
*/ | ||
public Appearance(String title) { | ||
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, should not be <code>null</code> | ||
* @param image image for dialog, should not be <code>null</code> | ||
* | ||
*/ | ||
public Appearance(String title, Image image) { | ||
this(title, image, new LabelProvider()); | ||
} | ||
|
||
/** | ||
* Creates the dialog appearance descriptor with the given non-<code>null</code> | ||
* title, image, and label provider | ||
* | ||
* @param title title for dialog, should not be <code>null</code> | ||
* @param image image for dialog, should not be <code>null</code> | ||
* @param labels label provider for dialog, should not be <code>null</code> | ||
* | ||
*/ | ||
public Appearance(String title, Image image, LabelProvider labels) { | ||
Objects.requireNonNull(title, WorkbenchMessages.Appearance_e_null_title); | ||
Objects.requireNonNull(title, WorkbenchMessages.Appearance_e_null_image); | ||
Objects.requireNonNull(title, WorkbenchMessages.Appearance_e_null_labels); | ||
this.title = title; | ||
this.image = image; | ||
this.labelProvider = labels; | ||
} | ||
|
||
/** | ||
* The title to use for dialog's shell | ||
* | ||
* @return non-<code>null</code> title | ||
*/ | ||
public String title() { | ||
return title; | ||
} | ||
|
||
/** | ||
* The image to use for dialog's shell | ||
* | ||
* @return non-<code>null</code> image | ||
*/ | ||
public Image image() { | ||
return image; | ||
} | ||
|
||
/** | ||
* The {@link LabelProvider} to use for dialog | ||
* | ||
* @return non-<code>null</code> label provider | ||
*/ | ||
public LabelProvider labelProvider() { | ||
return labelProvider; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/workbench/SelectFromDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/******************************************************************************* | ||
* 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.workbench; | ||
|
||
import java.util.Collections; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.emf.ecore.EClass; | ||
import org.eclipse.jface.dialogs.Dialog; | ||
import org.eclipse.jface.viewers.LabelProvider; | ||
import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages; | ||
import org.eclipse.passage.loc.jface.dialogs.Appearance; | ||
import org.eclipse.passage.loc.jface.dialogs.FilteredSelectionDialog; | ||
import org.eclipse.passage.loc.jface.dialogs.LabelSearchFilter; | ||
import org.eclipse.swt.widgets.Shell; | ||
|
||
/** | ||
* Selects the classifier from the given input with | ||
* {@link FilteredSelectionDialog} | ||
* | ||
* @since 0.6 | ||
* | ||
* @param <C> classifier to be selected see {@link EClass#getName()} | ||
*/ | ||
public final class SelectFromDialog<C> implements Function<Iterable<C>, Optional<C>> { | ||
|
||
private final FilteredSelectionDialog<C> dialog; | ||
|
||
/** | ||
* | ||
* @param shell the {@link Shell} to use for | ||
* {@link FilteredSelectionDialog}, must not be | ||
* <code>null</code> | ||
* @param appearance the title, image and {@link LabelProvider} to use for | ||
* {@link FilteredSelectionDialog}, must not be | ||
* <code>null</code> | ||
*/ | ||
public SelectFromDialog(Shell shell, Appearance appearance) { | ||
Objects.requireNonNull(shell, WorkbenchMessages.SelectFromDialog_e_null_shell); | ||
Objects.requireNonNull(appearance, WorkbenchMessages.SelectFromDialog_e_null_appearance); | ||
this.dialog = new FilteredSelectionDialog<C>(shell, false, new LabelSearchFilter()); | ||
dialog.setTitle(appearance.title()); | ||
dialog.setImage(appearance.image()); | ||
dialog.setLabelProvider(appearance.labelProvider()); | ||
} | ||
|
||
/** | ||
* | ||
* @param shell the {@link Shell} to use for | ||
* {@link FilteredSelectionDialog}, must not be | ||
* <code>null</code> | ||
* @param appearance the title, image and {@link LabelProvider} to use for | ||
* {@link FilteredSelectionDialog}, must not be | ||
* <code>null</code> | ||
* @param initial the object to be a default choice for | ||
* {@link FilteredSelectionDialog}, must not be | ||
* <code>null</code> | ||
*/ | ||
public SelectFromDialog(Shell shell, Appearance appearance, C initial) { | ||
this(shell, appearance); | ||
Objects.requireNonNull(initial, WorkbenchMessages.SelectFromDialog_e_null_initial); | ||
dialog.setInitialSelection(Collections.singletonList(initial)); | ||
} | ||
|
||
/** | ||
* Returns the selected object or {@link Optional#empty()} | ||
*/ | ||
@Override | ||
public Optional<C> apply(Iterable<C> input) { | ||
dialog.setInput(input); | ||
if (dialog.open() == Dialog.OK) { | ||
return dialog.getFirstResult(); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters