Project

General

Profile

Download (5.81 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.dialogs.filteredSelection;
5

    
6
import java.util.List;
7
import java.util.UUID;
8

    
9
import org.eclipse.jface.viewers.ILabelProvider;
10
import org.eclipse.swt.SWT;
11
import org.eclipse.swt.events.SelectionEvent;
12
import org.eclipse.swt.events.SelectionListener;
13
import org.eclipse.swt.layout.GridData;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Combo;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Control;
18
import org.eclipse.swt.widgets.Label;
19
import org.eclipse.swt.widgets.Shell;
20

    
21
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
23
import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
24
import eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

    
27
/**
28
 * <p>FilteredTaxonNodeSelectionDialog class.</p>
29
 *
30
 * @author p.ciardelli
31
 * @version $Id: $
32
 */
33
public class FilteredTaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<TaxonNode> implements SelectionListener{	
34
	
35
	/**
36
	 * <p>select</p>
37
	 *
38
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
39
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
40
	 * @param title a {@link java.lang.String} object.
41
	 * @param excludeTaxa a {@link java.util.List} object.
42
	 * @param node a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
43
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
44
	 */
45
	public static TaxonNode select(Shell shell, ConversationHolder conversation, String title, List<UUID> excludeTaxa, TaxonNode node) {
46
		FilteredTaxonNodeSelectionDialog dialog = new FilteredTaxonNodeSelectionDialog(shell, 
47
				conversation,
48
				title,
49
				excludeTaxa,
50
				false,
51
				node);
52
		return getSelectionFromDialog(dialog);
53
	}
54

    
55
	private Combo classificationSelectionCombo;
56

    
57
	private List<TaxonomicTree> classifications;
58
	
59
	private TaxonomicTree selectedClassification;
60
	
61

    
62
	/**
63
	 * <p>Constructor for FilteredTaxonNodeSelectionDialog.</p>
64
	 *
65
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
66
	 * @param title a {@link java.lang.String} object.
67
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
68
	 * @param excludeTaxa a {@link java.util.List} object.
69
	 * @param multi a boolean.
70
	 * @param node a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
71
	 */
72
	protected FilteredTaxonNodeSelectionDialog(Shell shell, ConversationHolder conversation, String title, List<UUID> excludeTaxa, boolean multi, TaxonNode node) {
73
		super(shell, conversation, title, multi, FilteredTaxonNodeSelectionDialog.class.getCanonicalName(), node);
74
		
75
		ILabelProvider labelProvider = new FilteredCdmResourceLabelProvider();
76

    
77
		setListLabelProvider(labelProvider);
78
		setDetailsLabelProvider(labelProvider);
79
		
80
	}
81

    
82

    
83
	/* (non-Javadoc)
84
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
85
	 */
86
	/** {@inheritDoc} */
87
	@Override
88
	protected Control createExtendedContentArea(Composite parent) {
89
		return createTreeSelectionCombo(parent);
90
	}
91
	
92
	/*
93
	 * currently disabled tree selection composite
94
	 */
95
	private Control createTreeSelectionCombo(Composite parent){
96
//		classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
97
		
98
		Composite classificationSelection = new Composite(parent, SWT.NULL);
99
		classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
100
		
101
		GridLayout layout = new GridLayout();
102
		classificationSelection.setLayout(layout);
103
		
104
		Label label = new Label(classificationSelection, SWT.NULL);
105
		// TODO not working is not really true but leave it there to remind everyone that this is under construction
106
		label.setText("Select Classification (experimental)");
107
		classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
108
		classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
109
		
110
		for(TaxonomicTree tree : classifications){
111
			classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
112
		}
113
		
114
		classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
115
		
116
		// TODO remember last selection
117
		
118
		classificationSelectionCombo.addSelectionListener(this);
119
		
120
		return classificationSelection;
121
	}
122

    
123
	/** {@inheritDoc} */
124
	@Override
125
	protected String getTitle(TaxonNode taxonNode) {
126
		return taxonNode.getTaxon().getTitleCache();
127
	}
128
	
129
	/* (non-Javadoc)
130
	 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
131
	 */
132
	/** {@inheritDoc} */
133
	@Override
134
	protected TaxonNode getPersistentObject(UUID uuid) {
135
		return CdmStore.getTaxonTreeService().getTaxonNodeByUuid(uuid);
136
	}
137

    
138
	/* (non-Javadoc)
139
	 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
140
	 */
141
	/** {@inheritDoc} */
142
	@Override
143
	protected void initModel() {
144
		// default to first tree 
145
		// TODO this will be problematic and can only be seen as workaround 
146
		
147
		
148
		if(classifications == null){
149
			classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
150
			selectedClassification = classifications.iterator().next();
151
		}
152
		
153
		model = CdmStore.getTaxonTreeService().getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByTaxonomicTree(selectedClassification);
154
	}
155

    
156
	/** {@inheritDoc} */
157
	@Override
158
	protected AbstractNewEntityWizard getNewEntityWizard() {
159
		return null;
160
	}
161

    
162
	/** {@inheritDoc} */
163
	@Override
164
	protected String getNewWizardLinkText() {
165
		return null;
166
	}
167
	
168
	/** {@inheritDoc} */
169
	public void widgetSelected(SelectionEvent e) {
170
		selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
171
		refresh();
172
	}
173

    
174
	/** {@inheritDoc} */
175
	public void widgetDefaultSelected(SelectionEvent e) {}
176

    
177

    
178
}
(14-14/15)