--- /dev/null
+/**
+* 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<TermDto> selectedTerms;
+
+ public TermChooseWizard(){
+ }
+
+ public List<TermDto> getSelectedTerms() {
+ return selectedTerms;
+ }
+
+ @Override
+ public void addPages() {
+ page = new TermChooseWizardPage();
+ addPage(page);
+ }
+
+ @Override
+ public boolean performFinish() {
+ selectedTerms = page.getSelectedTerms();
+ return selectedTerms.size() > 0;
+ }
+
+}
--- /dev/null
+/**
+* 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<TermDto> getSelectedTerms() {
+ List<TermDto> termDtos = new ArrayList<>();
+ controller.getSelectedSearchResults().forEach(result->termDtos.add(result.getContent()));
+ return termDtos;
+ }
+
+}
*/
package eu.etaxonomy.taxeditor.featuretree.e4.handler;
-import java.util.Collection;
+import java.util.List;
import javax.inject.Named;
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;
}
- 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<Feature> additionalFeatures = wizard.getAdditionalFeatures();
- for (Feature feature : additionalFeatures) {
- AddFeatureOperation operation = new AddFeatureOperation(feature.getUuid(), tree.getRoot(), editor, editor);
+ List<TermDto> selectedTerms = wizard.getSelectedTerms();
+ for (TermDto termDto: selectedTerms) {
+ AddFeatureOperation operation = new AddFeatureOperation(termDto.getUuid(), tree.getRoot(), editor, editor);
AbstractUtility.executeOperation(operation, sync);
}
}
--- /dev/null
+/**
+* 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<T, S extends SearchResult<T>> 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;
+ }
+
+}
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;
* @since Jan 22, 2019
*
*/
-public abstract class SearchController<S extends SearchResult<T>, T> implements KeyListener{
+public abstract class SearchController<S extends SearchResult<T>, T> implements KeyListener, SelectionListener{
private SearchComposite composite;
private List<S> searchResults = new ArrayList<>();
private Set<Facet> appliedFacets = new HashSet<>();
+ private List<CheckBoxSearchResultComposite<T, S>> searchResultComposites = new ArrayList<>();
public SearchController(SearchComposite composite) {
this.composite = composite;
composite.getTxtSearch().addKeyListener(this);
+ composite.getBtnSearchButton().addSelectionListener(this);
}
protected abstract List<S> searchResults(String searchString);
- protected abstract void createResultComposite(S result, Composite parent);
+ protected abstract CheckBoxSearchResultComposite<T, S> createResultComposite(S result, Composite parent);
protected abstract Comparator<S> getResultComparator(String searchString);
+ protected abstract List<S> getSelectedResults();
+
private void search(String searchString){
searchResults.clear();
+ searchResultComposites.clear();
searchResults = searchResults(searchString);
if(searchResults.size()>500){
private Set<Facet> createResults(List<S> results) {
Set<Facet> 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();
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<S> getSelectedSearchResults(){
+ List<S> 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) {
+ }
+
}
}
@Override
- protected void createResultComposite(TermSearchResult result, Composite parent) {
- new TermSearchResultComposite(result, parent, SWT.NONE);
+ protected TermSearchResultComposite createResultComposite(TermSearchResult result, Composite parent) {
+ return new TermSearchResultComposite(result, parent, SWT.NONE);
+ }
+
+ @Override
+ protected List<TermSearchResult> getSelectedResults() {
+ return null;
}
}
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<TermDto, TermSearchResult> {
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));
}
});
- 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;
- }
}