From 08267c16fdba63996f1319ad12db49201b3270d3 Mon Sep 17 00:00:00 2001
From: Patrick Plitzner
Date: Thu, 14 Feb 2019 11:37:00 +0100
Subject: [PATCH] ref #8011 Use term search in feature tree context menu to add
features
---
.../featuretree/TermChooseWizard.java | 49 ++++++++++++++
.../featuretree/TermChooseWizardPage.java | 52 +++++++++++++++
.../e4/handler/AddFeatureHandler.java | 15 +++--
.../facet/CheckBoxSearchResultComposite.java | 57 +++++++++++++++++
.../view/search/facet/SearchController.java | 64 ++++++++++++++-----
.../facet/term/TermSearchController.java | 9 ++-
.../facet/term/TermSearchResultComposite.java | 57 ++++-------------
7 files changed, 235 insertions(+), 68 deletions(-)
create mode 100644 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/TermChooseWizard.java
create mode 100644 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/TermChooseWizardPage.java
create mode 100644 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/CheckBoxSearchResultComposite.java
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/TermChooseWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/TermChooseWizard.java
new file mode 100644
index 000000000..de17944ee
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/TermChooseWizard.java
@@ -0,0 +1,49 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.featuretree;
+
+import java.util.List;
+
+import org.eclipse.jface.wizard.Wizard;
+
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+
+/**
+ *
+ * @author pplitzner
+ * @since Feb 14, 2019
+ *
+ */
+public class TermChooseWizard extends Wizard {
+
+ private TermChooseWizardPage page;
+
+ private List selectedTerms;
+
+ public TermChooseWizard(){
+ }
+
+ public List getSelectedTerms() {
+ return selectedTerms;
+ }
+
+ @Override
+ public void addPages() {
+ page = new TermChooseWizardPage();
+ addPage(page);
+ }
+
+ @Override
+ public boolean performFinish() {
+ selectedTerms = page.getSelectedTerms();
+ return selectedTerms.size() > 0;
+ }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/TermChooseWizardPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/TermChooseWizardPage.java
new file mode 100644
index 000000000..72ea68d69
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/TermChooseWizardPage.java
@@ -0,0 +1,52 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.featuretree;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.taxeditor.view.search.facet.SearchComposite;
+import eu.etaxonomy.taxeditor.view.search.facet.term.TermSearchController;
+
+/**
+ *
+ * @author pplitzner
+ * @since Feb 14, 2019
+ *
+ */
+public class TermChooseWizardPage extends WizardPage {
+
+ private TermSearchController controller;
+
+ protected TermChooseWizardPage() {
+ super("Term Choose Wizard");
+ setTitle("Term Choose Wizard");
+ setDescription("Please search and select the terms you want to add to the tree.");
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ SearchComposite searchComposite = new SearchComposite(parent, SWT.NONE);
+ controller = new TermSearchController(searchComposite);
+ setControl(searchComposite);
+ }
+
+ public List getSelectedTerms() {
+ List termDtos = new ArrayList<>();
+ controller.getSelectedSearchResults().forEach(result->termDtos.add(result.getContent()));
+ return termDtos;
+ }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddFeatureHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddFeatureHandler.java
index 994661e34..e0eb2cbdc 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddFeatureHandler.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddFeatureHandler.java
@@ -8,7 +8,7 @@
*/
package eu.etaxonomy.taxeditor.featuretree.e4.handler;
-import java.util.Collection;
+import java.util.List;
import javax.inject.Named;
@@ -24,9 +24,9 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
-import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.FeatureTree;
-import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.taxeditor.featuretree.TermChooseWizard;
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
import eu.etaxonomy.taxeditor.featuretree.e4.operation.AddFeatureOperation;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
@@ -50,14 +50,15 @@ public class AddFeatureHandler {
}
- AvailableFeaturesWizard wizard = new AvailableFeaturesWizard();
+ TermChooseWizard wizard = new TermChooseWizard();
+ // AvailableFeaturesWizard wizard = new AvailableFeaturesWizard();
WizardDialog dialog = new WizardDialog(shell, wizard);
if (dialog.open() == IStatus.OK) {
FeatureTree tree = (FeatureTree) selection.getFirstElement();
- Collection additionalFeatures = wizard.getAdditionalFeatures();
- for (Feature feature : additionalFeatures) {
- AddFeatureOperation operation = new AddFeatureOperation(feature.getUuid(), tree.getRoot(), editor, editor);
+ List selectedTerms = wizard.getSelectedTerms();
+ for (TermDto termDto: selectedTerms) {
+ AddFeatureOperation operation = new AddFeatureOperation(termDto.getUuid(), tree.getRoot(), editor, editor);
AbstractUtility.executeOperation(operation, sync);
}
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/CheckBoxSearchResultComposite.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/CheckBoxSearchResultComposite.java
new file mode 100644
index 000000000..8e7ed2631
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/CheckBoxSearchResultComposite.java
@@ -0,0 +1,57 @@
+/**
+* Copyright (C) 2019 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.search.facet;
+
+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;
+
+/**
+ * @author pplitzner
+ * @since Feb 14, 2019
+ *
+ */
+public abstract class CheckBoxSearchResultComposite> extends Composite {
+
+ protected S result;
+ private Button btnCheck;
+
+ public CheckBoxSearchResultComposite(S result, Composite parent, int style) {
+ super(parent, style);
+ this.result = result;
+ setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.marginWidth = 0;
+ gridLayout.horizontalSpacing = 0;
+ gridLayout.numColumns = 2;
+ setLayout(gridLayout);
+
+ Composite composite = new Composite(this, SWT.NONE);
+ composite.setLayout(new GridLayout(1, false));
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+
+ btnCheck = new Button(composite, SWT.CHECK);
+ btnCheck.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
+
+ createContent(this);
+ }
+
+ public abstract Composite createContent(Composite parent);
+
+ public S getResult() {
+ return result;
+ }
+
+ public Button getBtnCheck() {
+ return btnCheck;
+ }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/SearchController.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/SearchController.java
index 5e3b9c191..751e5694d 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/SearchController.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/SearchController.java
@@ -18,6 +18,8 @@ import java.util.Set;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Composite;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
@@ -27,25 +29,30 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
* @since Jan 22, 2019
*
*/
-public abstract class SearchController, T> implements KeyListener{
+public abstract class SearchController, T> implements KeyListener, SelectionListener{
private SearchComposite composite;
private List searchResults = new ArrayList<>();
private Set appliedFacets = new HashSet<>();
+ private List> searchResultComposites = new ArrayList<>();
public SearchController(SearchComposite composite) {
this.composite = composite;
composite.getTxtSearch().addKeyListener(this);
+ composite.getBtnSearchButton().addSelectionListener(this);
}
protected abstract List searchResults(String searchString);
- protected abstract void createResultComposite(S result, Composite parent);
+ protected abstract CheckBoxSearchResultComposite createResultComposite(S result, Composite parent);
protected abstract Comparator getResultComparator(String searchString);
+ protected abstract List getSelectedResults();
+
private void search(String searchString){
searchResults.clear();
+ searchResultComposites.clear();
searchResults = searchResults(searchString);
if(searchResults.size()>500){
@@ -73,25 +80,14 @@ public abstract class SearchController, T> implements
private Set createResults(List results) {
Set facets = new HashSet<>();
+ searchResultComposites.clear();
for (S result : results) {
- createResultComposite(result, composite.getSearchResultComposite());
+ searchResultComposites.add(createResultComposite(result, composite.getSearchResultComposite()));
facets.addAll(result.getFacets());
}
return facets;
}
- @Override
- public void keyPressed(KeyEvent e) {
- if(e.keyCode==SWT.CR && e.widget==composite.getTxtSearch()){
- composite.clear();
- search(composite.getTxtSearch().getText());
- }
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- }
-
public void applyFilter(FilterComposite filterComposite) {
composite.clearResults();
@@ -104,13 +100,49 @@ public abstract class SearchController, T> implements
appliedFacets.remove(facet);
}
+ searchResultComposites.clear();
for (S searchResult : searchResults) {
if(searchResult.hasAnyFacet(appliedFacets)){
- createResultComposite(searchResult, composite.getSearchResultComposite());
+ searchResultComposites.add(createResultComposite(searchResult, composite.getSearchResultComposite()));
}
}
composite.refresh();
}
+ private void search(){
+ composite.clear();
+ search(composite.getTxtSearch().getText());
+ }
+
+ public List getSelectedSearchResults(){
+ List selectedSearchResults = new ArrayList<>();
+ searchResultComposites.stream()
+ .filter(resultComposite->resultComposite.getBtnCheck().getSelection())
+ .forEach(selected->selectedSearchResults.add(selected.getResult()));
+ return selectedSearchResults;
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if(e.keyCode==SWT.CR && e.widget==composite.getTxtSearch()){
+ search();
+ }
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if(e.widget==composite.getBtnSearchButton()){
+ search();
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchController.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchController.java
index e25284fdb..09dbd1a91 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchController.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchController.java
@@ -56,8 +56,13 @@ public class TermSearchController extends SearchController getSelectedResults() {
+ return null;
}
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchResultComposite.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchResultComposite.java
index 7196d0aef..c15bbe7cc 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchResultComposite.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchResultComposite.java
@@ -15,50 +15,31 @@ import org.eclipse.swt.events.DragDetectEvent;
import org.eclipse.swt.events.DragDetectListener;
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.Label;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.taxeditor.view.search.facet.CheckBoxSearchResultComposite;
+
/**
* @author pplitzner
* @since Jan 23, 2019
*
*/
-public class TermSearchResultComposite extends Composite {
+public class TermSearchResultComposite extends CheckBoxSearchResultComposite {
private Label label;
- private boolean isSelected;
- private TermSearchResult result;
- private Button btnCheck;
- private Composite composite_1;
- /**
- * Create the composite.
- * @param result
- * @param parent
- * @param style
- */
public TermSearchResultComposite(TermSearchResult result, Composite parent, int style) {
- super(parent, style);
- this.result = result;
- setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- GridLayout gridLayout = new GridLayout();
- gridLayout.marginWidth = 0;
- gridLayout.horizontalSpacing = 0;
- gridLayout.numColumns = 2;
- setLayout(gridLayout);
-
- Composite composite = new Composite(this, SWT.NONE);
- composite.setLayout(new GridLayout(1, false));
- composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
-
- btnCheck = new Button(composite, SWT.CHECK);
- btnCheck.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
+ super(result, parent, style);
+ }
- composite_1 = new Composite(this, SWT.NONE);
- composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
- composite_1.setLayout(new GridLayout(1, false));
- label = new Label(composite_1, SWT.NONE);
+ @Override
+ public Composite createContent(Composite parent) {
+ Composite content = new Composite(this, SWT.NONE);
+ content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
+ content.setLayout(new GridLayout(1, false));
+ label = new Label(content, SWT.NONE);
label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
label.setText(result.getContent().getRepresentation_L10n());
label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
@@ -71,22 +52,12 @@ public class TermSearchResultComposite extends Composite {
}
});
- Label lblDescription = new Label(composite_1, SWT.NONE);
+ Label lblDescription = new Label(content, SWT.NONE);
String representation_L10n_text = result.getContent().getRepresentation_L10n_text();
if(representation_L10n_text!=null){
lblDescription.setText(representation_L10n_text);
}
+ return content;
}
- public TermSearchResult getResult() {
- return result;
- }
-
- @Override
- protected void checkSubclass() {
- // Disable the check that prevents subclassing of SWT components
- }
- public Button getBtnCheck() {
- return btnCheck;
- }
}
--
2.34.1