Revision 0661b3e6
Added by Patrick Plitzner about 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionSection.java | ||
---|---|---|
141 | 141 |
toolBarManager.add(browseAction); |
142 | 142 |
} |
143 | 143 |
|
144 |
addAction(toolBarManager); |
|
145 |
|
|
144 | 146 |
return toolBarManager.createControl(this); |
145 | 147 |
} |
146 | 148 |
|
147 |
/** |
|
149 |
protected void addAction(ToolBarManager toolBarManager) { |
|
150 |
// default implementation empty |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
148 | 154 |
* using this method is discouraged, use updateToolBar() instead |
149 | 155 |
*/ |
150 | 156 |
public void showToolbar(){ |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/TypeDesignationSection.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import java.util.Collection; |
13 | 13 |
import java.util.Comparator; |
14 |
import java.util.List; |
|
15 |
import java.util.stream.Collectors; |
|
16 |
|
|
17 |
import org.eclipse.core.runtime.IStatus; |
|
18 |
import org.eclipse.jface.action.Action; |
|
19 |
import org.eclipse.jface.action.IAction; |
|
20 |
import org.eclipse.jface.action.ToolBarManager; |
|
21 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
22 |
import org.eclipse.jface.wizard.WizardDialog; |
|
23 |
import org.eclipse.swt.graphics.ImageData; |
|
14 | 24 |
|
15 | 25 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
16 | 26 |
import eu.etaxonomy.cdm.api.service.INameService; |
... | ... | |
22 | 32 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
23 | 33 |
import eu.etaxonomy.cdm.model.name.TypeDesignationBase; |
24 | 34 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
35 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
25 | 36 |
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; |
26 | 37 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
27 | 38 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
39 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
28 | 40 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
29 | 41 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
30 | 42 |
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection; |
31 | 43 |
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection; |
44 |
import eu.etaxonomy.taxeditor.ui.section.name.type.CloneTypeWizard; |
|
32 | 45 |
|
33 | 46 |
/** |
34 | 47 |
* <p>TypeDesignationSection class.</p> |
... | ... | |
53 | 66 |
super(formFactory, conversation, parentElement, "Type Designations", style); |
54 | 67 |
} |
55 | 68 |
|
69 |
@Override |
|
70 |
protected void addAction(ToolBarManager toolBarManager) { |
|
71 |
if(!isSpecimenType() || |
|
72 |
getEntity().getTypeDesignations().isEmpty() |
|
73 |
|| getEntity().getTypeDesignations().stream().noneMatch(designation->designation instanceof SpecimenTypeDesignation)){ |
|
74 |
return; |
|
75 |
} |
|
76 |
Action addAction = new Action("Create type duplicate", IAction.AS_PUSH_BUTTON){ |
|
77 |
@Override |
|
78 |
public void run() { |
|
79 |
List<SpecimenTypeDesignation> typeDesigations = getEntity().getTypeDesignations().stream() |
|
80 |
.filter(designation -> designation instanceof SpecimenTypeDesignation) |
|
81 |
.map(specimenTypeDesignation -> (SpecimenTypeDesignation)specimenTypeDesignation) |
|
82 |
.collect(Collectors.toList()); |
|
83 |
CloneTypeWizard wizard = new CloneTypeWizard(typeDesigations); |
|
84 |
WizardDialog dialog = new WizardDialog(getShell(), wizard); |
|
85 |
|
|
86 |
if (dialog.open() == IStatus.OK) { |
|
87 |
StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true); |
|
88 |
} |
|
89 |
} |
|
90 |
}; |
|
91 |
addAction.setImageDescriptor(new ImageDescriptor() { |
|
92 |
|
|
93 |
@Override |
|
94 |
public ImageData getImageData() { |
|
95 |
return ImageResources.getImage(ImageResources.COPY_ICON).getImageData(); |
|
96 |
} |
|
97 |
}); |
|
98 |
addAction.setToolTipText("Create type duplicate"); |
|
99 |
|
|
100 |
toolBarManager.add(addAction); |
|
101 |
} |
|
102 |
|
|
56 | 103 |
/** {@inheritDoc} */ |
57 | 104 |
@Override |
58 | 105 |
public void addElement(TypeDesignationBase element) { |
... | ... | |
75 | 122 |
if (entity == null){ |
76 | 123 |
return null; |
77 | 124 |
} |
78 |
return (Collection)entity.getTypeDesignations();
|
|
125 |
return entity.getTypeDesignations(); |
|
79 | 126 |
} |
80 | 127 |
|
81 | 128 |
@Override |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/type/CloneTypeWizard.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2019 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.ui.section.name.type; |
|
10 |
|
|
11 |
import java.util.Collection; |
|
12 |
|
|
13 |
import org.eclipse.jface.wizard.Wizard; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
16 |
|
|
17 |
/** |
|
18 |
* @author pplitzner |
|
19 |
* @since Mar 13, 2019 |
|
20 |
* |
|
21 |
*/ |
|
22 |
public class CloneTypeWizard extends Wizard{ |
|
23 |
|
|
24 |
private CloneTypeWizardPage page; |
|
25 |
|
|
26 |
private final Collection<SpecimenTypeDesignation> typeDesignations; |
|
27 |
|
|
28 |
public CloneTypeWizard(Collection<SpecimenTypeDesignation> typeDesignations) { |
|
29 |
this.typeDesignations = typeDesignations; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public void addPages() { |
|
34 |
page = new CloneTypeWizardPage(typeDesignations); |
|
35 |
addPage(page); |
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
@Override |
|
41 |
public boolean performFinish() { |
|
42 |
return true; |
|
43 |
} |
|
44 |
|
|
45 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/type/CloneTypeWizardComposite.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2019 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.ui.section.name.type; |
|
10 |
|
|
11 |
import org.eclipse.jface.viewers.ComboViewer; |
|
12 |
import org.eclipse.swt.SWT; |
|
13 |
import org.eclipse.swt.layout.GridData; |
|
14 |
import org.eclipse.swt.layout.GridLayout; |
|
15 |
import org.eclipse.swt.widgets.Button; |
|
16 |
import org.eclipse.swt.widgets.Combo; |
|
17 |
import org.eclipse.swt.widgets.Composite; |
|
18 |
import org.eclipse.swt.widgets.Label; |
|
19 |
import org.eclipse.swt.widgets.Text; |
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
22 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
23 |
import eu.etaxonomy.taxeditor.ui.combo.TermUuidComboViewer; |
|
24 |
|
|
25 |
/** |
|
26 |
* @author pplitzner |
|
27 |
* @since Mar 13, 2019 |
|
28 |
* |
|
29 |
*/ |
|
30 |
public class CloneTypeWizardComposite extends Composite { |
|
31 |
private Text txtAccNumber; |
|
32 |
private Text txtCollection; |
|
33 |
private Button btnBrowseCollection; |
|
34 |
private TermUuidComboViewer comboTypeStatus; |
|
35 |
private ComboViewer comboViewerBaseType; |
|
36 |
|
|
37 |
/** |
|
38 |
* Create the composite. |
|
39 |
* @param parent |
|
40 |
* @param style |
|
41 |
*/ |
|
42 |
public CloneTypeWizardComposite(Composite parent, int style) { |
|
43 |
super(parent, style); |
|
44 |
setLayout(new GridLayout(3, false)); |
|
45 |
|
|
46 |
Label lblNewLabel_3 = new Label(this, SWT.NONE); |
|
47 |
lblNewLabel_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
|
48 |
lblNewLabel_3.setText("Base Type"); |
|
49 |
|
|
50 |
comboViewerBaseType = new ComboViewer(this, SWT.NONE); |
|
51 |
Combo combo = comboViewerBaseType.getCombo(); |
|
52 |
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); |
|
53 |
|
|
54 |
Label lblNewLabel = new Label(this, SWT.NONE); |
|
55 |
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
|
56 |
lblNewLabel.setText("Accession Number"); |
|
57 |
|
|
58 |
txtAccNumber = new Text(this, SWT.BORDER); |
|
59 |
txtAccNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); |
|
60 |
|
|
61 |
Label lblNewLabel_2 = new Label(this, SWT.NONE); |
|
62 |
lblNewLabel_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
|
63 |
lblNewLabel_2.setText("Collection"); |
|
64 |
|
|
65 |
txtCollection = new Text(this, SWT.BORDER); |
|
66 |
txtCollection.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); |
|
67 |
|
|
68 |
btnBrowseCollection = new Button(this, SWT.NONE); |
|
69 |
btnBrowseCollection.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON)); |
|
70 |
|
|
71 |
Label lblNewLabel_1 = new Label(this, SWT.NONE); |
|
72 |
lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
|
73 |
lblNewLabel_1.setText("Type Status"); |
|
74 |
|
|
75 |
comboTypeStatus = new TermUuidComboViewer(this, SWT.NONE); |
|
76 |
comboTypeStatus.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); |
|
77 |
comboTypeStatus.setInput(TermType.SpecimenTypeDesignationStatus); |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
protected void checkSubclass() { |
|
83 |
// Disable the check that prevents subclassing of SWT components |
|
84 |
} |
|
85 |
|
|
86 |
public Button getBtnBrowseCollection() { |
|
87 |
return btnBrowseCollection; |
|
88 |
} |
|
89 |
public TermUuidComboViewer getComboTypeStatus() { |
|
90 |
return comboTypeStatus; |
|
91 |
} |
|
92 |
public Text getTxtCollection() { |
|
93 |
return txtCollection; |
|
94 |
} |
|
95 |
public ComboViewer getComboViewerBaseType() { |
|
96 |
return comboViewerBaseType; |
|
97 |
} |
|
98 |
public Text getTxtAccNumber() { |
|
99 |
return txtAccNumber; |
|
100 |
} |
|
101 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/type/CloneTypeWizardPage.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2019 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.ui.section.name.type; |
|
10 |
|
|
11 |
import java.util.Collection; |
|
12 |
|
|
13 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
14 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
15 |
import org.eclipse.jface.viewers.LabelProvider; |
|
16 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
17 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
18 |
import org.eclipse.jface.wizard.WizardPage; |
|
19 |
import org.eclipse.swt.SWT; |
|
20 |
import org.eclipse.swt.events.ModifyEvent; |
|
21 |
import org.eclipse.swt.events.ModifyListener; |
|
22 |
import org.eclipse.swt.events.SelectionAdapter; |
|
23 |
import org.eclipse.swt.events.SelectionEvent; |
|
24 |
import org.eclipse.swt.widgets.Composite; |
|
25 |
|
|
26 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
27 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
28 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.CollectionSelectionDialog; |
|
29 |
|
|
30 |
/** |
|
31 |
* @author pplitzner |
|
32 |
* @since Mar 13, 2019 |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class CloneTypeWizardPage extends WizardPage implements ISelectionChangedListener, ModifyListener { |
|
36 |
|
|
37 |
private CloneTypeWizardComposite composite; |
|
38 |
|
|
39 |
private eu.etaxonomy.cdm.model.occurrence.Collection selectedCollection = null; |
|
40 |
|
|
41 |
private final Collection<SpecimenTypeDesignation> typeDesignations; |
|
42 |
|
|
43 |
protected CloneTypeWizardPage(Collection<SpecimenTypeDesignation> typeDesignations) { |
|
44 |
super("Duplicate Type"); |
|
45 |
setTitle("Duplicate Type"); |
|
46 |
setDescription("Create a type duplicate based on an existing type specimen."); |
|
47 |
this.typeDesignations = typeDesignations; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public void createControl(Composite parent) { |
|
52 |
|
|
53 |
composite = new CloneTypeWizardComposite(parent, SWT.NONE); |
|
54 |
|
|
55 |
// fill combo with available types |
|
56 |
composite.getComboViewerBaseType().setContentProvider(new ArrayContentProvider()); |
|
57 |
composite.getComboViewerBaseType().setLabelProvider(new LabelProvider(){ |
|
58 |
@Override |
|
59 |
public String getText(Object element) { |
|
60 |
if(element instanceof SpecimenTypeDesignation){ |
|
61 |
return ((SpecimenTypeDesignation) element).getTypeSpecimen().getTitleCache(); |
|
62 |
} |
|
63 |
return super.getText(element); |
|
64 |
} |
|
65 |
}); |
|
66 |
composite.getComboViewerBaseType().setInput(typeDesignations); |
|
67 |
if(typeDesignations.size()==1){ |
|
68 |
composite.getComboViewerBaseType().setSelection(new StructuredSelection(typeDesignations.iterator().next())); |
|
69 |
} |
|
70 |
|
|
71 |
composite.getBtnBrowseCollection().addSelectionListener(new SelectionAdapter() { |
|
72 |
@Override |
|
73 |
public void widgetSelected(SelectionEvent e) { |
|
74 |
selectedCollection = CollectionSelectionDialog.select(getShell(), selectedCollection); |
|
75 |
composite.getTxtCollection().setText(selectedCollection.getTitleCache()); |
|
76 |
getWizard().getContainer().updateButtons(); |
|
77 |
} |
|
78 |
}); |
|
79 |
|
|
80 |
// add listeners for update buttons |
|
81 |
composite.getComboViewerBaseType().addSelectionChangedListener(this); |
|
82 |
composite.getTxtAccNumber().addModifyListener(this); |
|
83 |
composite.getComboTypeStatus().addSelectionChangedListener(this); |
|
84 |
|
|
85 |
setControl(composite); |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public boolean isPageComplete() { |
|
90 |
return composite.getComboViewerBaseType().getSelection()!=null |
|
91 |
&& CdmUtils.isNotBlank(composite.getTxtAccNumber().getText()) |
|
92 |
&& selectedCollection!=null |
|
93 |
&& composite.getComboTypeStatus().getSelection()!=null; |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public void selectionChanged(SelectionChangedEvent event) { |
|
98 |
getWizard().getContainer().updateButtons(); |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public void modifyText(ModifyEvent e) { |
|
103 |
getWizard().getContainer().updateButtons(); |
|
104 |
|
|
105 |
} |
|
106 |
|
|
107 |
} |
Also available in: Unified diff
ref #6413 Add "Clone Type Duplicate" option to name details view