Revision 790e1587
Added by Patrick Plitzner over 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/AreasSelectionDialog.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet; |
|
10 |
|
|
11 |
import java.util.Arrays; |
|
12 |
import java.util.Collection; |
|
13 |
import java.util.HashSet; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Set; |
|
16 |
import java.util.stream.Collectors; |
|
17 |
|
|
18 |
import org.eclipse.jface.dialogs.Dialog; |
|
19 |
import org.eclipse.jface.layout.GridLayoutFactory; |
|
20 |
import org.eclipse.jface.viewers.StyledString.Styler; |
|
21 |
import org.eclipse.swt.SWT; |
|
22 |
import org.eclipse.swt.graphics.TextStyle; |
|
23 |
import org.eclipse.swt.layout.GridLayout; |
|
24 |
import org.eclipse.swt.widgets.Composite; |
|
25 |
import org.eclipse.swt.widgets.Control; |
|
26 |
import org.eclipse.swt.widgets.Display; |
|
27 |
import org.eclipse.swt.widgets.Shell; |
|
28 |
|
|
29 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
30 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
31 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
32 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
33 |
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider; |
|
34 |
import eu.etaxonomy.taxeditor.preference.wizard.AreaLabelProvider; |
|
35 |
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite; |
|
36 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
37 |
|
|
38 |
/** |
|
39 |
* @author pplitzner |
|
40 |
* @since Oct 29, 2018 |
|
41 |
* |
|
42 |
*/ |
|
43 |
public class AreasSelectionDialog extends Dialog{ |
|
44 |
|
|
45 |
private CheckBoxTreeComposite treeComposite; |
|
46 |
|
|
47 |
private Set<NamedArea> selectedAreas = new HashSet<>(); |
|
48 |
|
|
49 |
private Collection<TermVocabulary<NamedArea>> namedAreas; |
|
50 |
|
|
51 |
|
|
52 |
protected AreasSelectionDialog(Shell parentShell, Set<NamedArea> selectedAreas) { |
|
53 |
super(parentShell); |
|
54 |
this.selectedAreas = selectedAreas; |
|
55 |
this.namedAreas = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea, null); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
protected Control createDialogArea(Composite parent) { |
|
60 |
parent.setLayout(new GridLayout()); |
|
61 |
Styler styler = new Styler() { |
|
62 |
@Override |
|
63 |
public void applyStyles(TextStyle textStyle) { |
|
64 |
textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK); |
|
65 |
} |
|
66 |
}; |
|
67 |
treeComposite = new CheckBoxTreeComposite(parent, new TermContentProvider(), new AreaLabelProvider(styler), SWT.NONE); |
|
68 |
treeComposite.getViewer().setInput(namedAreas); |
|
69 |
treeComposite.setCheckedElements(selectedAreas.toArray()); |
|
70 |
treeComposite.getViewer().reveal(selectedAreas); |
|
71 |
GridLayoutFactory.fillDefaults().applyTo(treeComposite); |
|
72 |
return treeComposite; |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
protected void configureShell(Shell newShell) { |
|
77 |
super.configureShell(newShell); |
|
78 |
newShell.setText("Choose areas"); |
|
79 |
newShell.setSize(400, 600); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
protected void okPressed() { |
|
84 |
selectedAreas.clear(); |
|
85 |
List<Object> checkedElements = Arrays.asList(treeComposite.getViewer().getCheckedElements()); |
|
86 |
checkedElements = checkedElements.stream().filter(element->element instanceof NamedArea).collect(Collectors.toList()); |
|
87 |
selectedAreas = new HashSet(checkedElements); |
|
88 |
super.okPressed(); |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
protected boolean isResizable() { |
|
93 |
return true; |
|
94 |
} |
|
95 |
|
|
96 |
public Set<NamedArea> getSelectedAreas(){ |
|
97 |
return selectedAreas; |
|
98 |
} |
|
99 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetComposite.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.util.HashSet; |
12 | 12 |
import java.util.Set; |
13 |
import java.util.stream.Collectors; |
|
13 | 14 |
|
14 |
import org.apache.commons.lang.StringUtils; |
|
15 | 15 |
import org.eclipse.jface.viewers.TreeViewer; |
16 | 16 |
import org.eclipse.swt.SWT; |
17 | 17 |
import org.eclipse.swt.layout.GridData; |
... | ... | |
47 | 47 |
private Set<NamedArea> areas = new HashSet<>(); |
48 | 48 |
private Text textAreaText; |
49 | 49 |
private Button btnChooseArea; |
50 |
private Button btnRemoveArea; |
|
51 | 50 |
private Button btnRemoveRankMin; |
52 | 51 |
private Button btnRemoveRankMax; |
53 | 52 |
|
... | ... | |
119 | 118 |
|
120 | 119 |
Composite composite = new Composite(this, SWT.NONE); |
121 | 120 |
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); |
122 |
GridLayout gl_composite = new GridLayout(3, false);
|
|
121 |
GridLayout gl_composite = new GridLayout(2, false);
|
|
123 | 122 |
gl_composite.horizontalSpacing = 0; |
124 | 123 |
gl_composite.verticalSpacing = 0; |
125 | 124 |
gl_composite.marginHeight = 0; |
... | ... | |
134 | 133 |
btnChooseArea = new Button(composite, SWT.NONE); |
135 | 134 |
btnChooseArea.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON)); |
136 | 135 |
|
137 |
btnRemoveArea = new Button(composite, SWT.NONE); |
|
138 |
btnRemoveArea.setImage(ImageResources.getImage(ImageResources.TRASH_ICON)); |
|
139 |
|
|
140 | 136 |
featureTreeEditorComposite = new FeatureTreeEditorComposite(this, SWT.NONE); |
141 | 137 |
featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); |
142 | 138 |
} |
... | ... | |
182 | 178 |
} |
183 | 179 |
public void setAreas(Set<NamedArea> areas) { |
184 | 180 |
this.areas = areas; |
185 |
textAreaText.setText(StringUtils.join(areas, ", ")); |
|
186 |
} |
|
187 |
public void removeArea() { |
|
188 |
this.areas = null; |
|
189 |
textAreaText.setText(""); //$NON-NLS-1$ |
|
181 |
textAreaText.setText(areas.stream().map(area->area.getLabel()).collect(Collectors.joining(", "))); |
|
190 | 182 |
} |
191 | 183 |
public Button getBtnChooseArea() { |
192 | 184 |
return btnChooseArea; |
193 | 185 |
} |
194 |
public Button getBtnRemoveArea() { |
|
195 |
return btnRemoveArea; |
|
196 |
} |
|
197 | 186 |
public Button getBtnRemoveRankMin() { |
198 | 187 |
return btnRemoveRankMin; |
199 | 188 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetEditor.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet; |
10 | 10 |
|
11 | 11 |
import java.util.ArrayList; |
12 |
import java.util.Arrays; |
|
13 | 12 |
import java.util.Collection; |
14 | 13 |
import java.util.Collections; |
15 | 14 |
import java.util.HashSet; |
... | ... | |
33 | 32 |
import org.eclipse.e4.ui.services.EMenuService; |
34 | 33 |
import org.eclipse.e4.ui.services.IServiceConstants; |
35 | 34 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
36 |
import org.eclipse.jface.dialogs.Dialog; |
|
37 | 35 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
38 | 36 |
import org.eclipse.jface.viewers.IStructuredSelection; |
39 | 37 |
import org.eclipse.jface.viewers.StructuredSelection; |
40 |
import org.eclipse.jface.viewers.StyledString.Styler; |
|
41 | 38 |
import org.eclipse.jface.viewers.Viewer; |
39 |
import org.eclipse.jface.window.Window; |
|
42 | 40 |
import org.eclipse.swt.SWT; |
43 | 41 |
import org.eclipse.swt.dnd.DND; |
44 | 42 |
import org.eclipse.swt.dnd.Transfer; |
... | ... | |
49 | 47 |
import org.eclipse.swt.events.ModifyEvent; |
50 | 48 |
import org.eclipse.swt.events.ModifyListener; |
51 | 49 |
import org.eclipse.swt.events.SelectionAdapter; |
52 |
import org.eclipse.swt.graphics.TextStyle; |
|
53 | 50 |
import org.eclipse.swt.widgets.Composite; |
54 |
import org.eclipse.swt.widgets.Control; |
|
55 | 51 |
import org.eclipse.swt.widgets.Display; |
56 | 52 |
import org.eclipse.swt.widgets.Shell; |
57 | 53 |
|
... | ... | |
60 | 56 |
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService; |
61 | 57 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
62 | 58 |
import eu.etaxonomy.cdm.api.service.ITermService; |
63 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
64 | 59 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
65 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
66 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
67 | 60 |
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet; |
68 | 61 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
69 | 62 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
... | ... | |
77 | 70 |
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; |
78 | 71 |
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData; |
79 | 72 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
80 |
import eu.etaxonomy.taxeditor.preference.wizard.AreaLabelProvider; |
|
81 |
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite; |
|
82 |
import eu.etaxonomy.taxeditor.preference.wizard.DistributionContentProvider; |
|
83 | 73 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
84 | 74 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
85 | 75 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
... | ... | |
163 | 153 |
@Override |
164 | 154 |
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { |
165 | 155 |
AreasSelectionDialog areasSelectionDialog = new AreasSelectionDialog(composite.getShell(), composite.getAreas()); |
166 |
areasSelectionDialog.open(); |
|
167 |
Set<NamedArea> selectedAreas = areasSelectionDialog.getSelectedAreas(); |
|
168 |
if(selectedAreas!=null){ |
|
169 |
composite.setAreas(selectedAreas); |
|
170 |
dirty.setDirty(true); |
|
156 |
if(areasSelectionDialog.open()==Window.OK){ |
|
157 |
Set<NamedArea> selectedAreas = areasSelectionDialog.getSelectedAreas(); |
|
158 |
if(selectedAreas!=null){ |
|
159 |
composite.setAreas(selectedAreas); |
|
160 |
dirty.setDirty(true); |
|
161 |
} |
|
171 | 162 |
} |
172 | 163 |
} |
173 | 164 |
}); |
174 |
composite.getBtnRemoveArea().addSelectionListener(new SelectionAdapter() { |
|
175 |
|
|
176 |
@Override |
|
177 |
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { |
|
178 |
composite.removeArea(); |
|
179 |
dirty.setDirty(true); |
|
180 |
} |
|
181 |
}); |
|
182 | 165 |
|
183 | 166 |
composite.getFeatureTreeEditorComposite().init("Character Tree", null, null, e->selectionService.setSelection(e.getSelection()), this, null); |
184 | 167 |
|
... | ... | |
392 | 375 |
dirty.setDirty(true); |
393 | 376 |
} |
394 | 377 |
|
395 |
private class AreasSelectionDialog extends Dialog{ |
|
396 |
|
|
397 |
private CheckBoxTreeComposite treeComposite; |
|
398 |
|
|
399 |
private Set<NamedArea> selectedAreas = new HashSet<>(); |
|
400 |
|
|
401 |
private Collection<TermVocabulary<NamedArea>> namedAreas; |
|
402 |
|
|
403 |
|
|
404 |
protected AreasSelectionDialog(Shell parentShell, Set<NamedArea> selectedAreas) { |
|
405 |
super(parentShell); |
|
406 |
this.selectedAreas = selectedAreas; |
|
407 |
this.namedAreas = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea, null); |
|
408 |
} |
|
409 |
|
|
410 |
@Override |
|
411 |
protected Control createDialogArea(Composite parent) { |
|
412 |
Styler styler = new Styler() { |
|
413 |
@Override |
|
414 |
public void applyStyles(TextStyle textStyle) { |
|
415 |
textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK); |
|
416 |
} |
|
417 |
}; |
|
418 |
treeComposite = new CheckBoxTreeComposite(parent, new DistributionContentProvider(), new AreaLabelProvider(styler), SWT.NONE); |
|
419 |
treeComposite.getViewer().setInput(namedAreas); |
|
420 |
treeComposite.getViewer().setCheckedElements(selectedAreas.toArray()); |
|
421 |
return treeComposite; |
|
422 |
} |
|
423 |
|
|
424 |
@Override |
|
425 |
protected void configureShell(Shell newShell) { |
|
426 |
super.configureShell(newShell); |
|
427 |
newShell.setText("Choose areas"); |
|
428 |
} |
|
429 |
|
|
430 |
@Override |
|
431 |
protected void okPressed() { |
|
432 |
selectedAreas.clear(); |
|
433 |
selectedAreas = new HashSet(Arrays.asList(treeComposite.getViewer().getCheckedElements())); |
|
434 |
super.okPressed(); |
|
435 |
} |
|
436 |
|
|
437 |
@Override |
|
438 |
protected boolean isResizable() { |
|
439 |
return true; |
|
440 |
} |
|
441 |
|
|
442 |
public Set<NamedArea> getSelectedAreas(){ |
|
443 |
return selectedAreas; |
|
444 |
} |
|
445 |
} |
|
446 | 378 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/CheckBoxTreeComposite.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.preference.wizard; |
10 | 10 |
|
11 |
import org.eclipse.jface.viewers.AbstractTreeViewer; |
|
11 | 12 |
import org.eclipse.jface.viewers.CheckboxTreeViewer; |
12 | 13 |
import org.eclipse.jface.viewers.IBaseLabelProvider; |
13 | 14 |
import org.eclipse.jface.viewers.IContentProvider; |
... | ... | |
36 | 37 |
tree.addListener(SWT.Selection, event -> { |
37 | 38 |
if (event.detail == SWT.CHECK) { |
38 | 39 |
TreeItem item = (TreeItem) event.item; |
40 |
Object data = item.getData(); |
|
39 | 41 |
boolean checked = item.getChecked(); |
42 |
if(checked){ |
|
43 |
viewer.expandToLevel(data, AbstractTreeViewer.ALL_LEVELS); |
|
44 |
} |
|
40 | 45 |
checkItems(item, checked); |
41 | 46 |
checkPath(item.getParentItem(), checked, false); |
42 | 47 |
} |
... | ... | |
44 | 49 |
viewer = new CheckboxTreeViewer(tree); |
45 | 50 |
viewer.setContentProvider(contentProvider); |
46 | 51 |
viewer.setLabelProvider(labelProvider); |
47 |
|
|
48 | 52 |
} |
49 | 53 |
|
50 | 54 |
private void checkPath(TreeItem item, boolean checked, boolean grayed) { |
... | ... | |
83 | 87 |
return viewer; |
84 | 88 |
} |
85 | 89 |
|
90 |
public void setCheckedElements(Object[] elements) { |
|
91 |
for (Object object : elements) { |
|
92 |
viewer.setChecked(object, true); |
|
93 |
viewer.reveal(object); |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
86 | 97 |
} |
Also available in: Unified diff
ref #7875 Fix tree checkbox behavior + extract dialog class