1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.taxeditor.newWizard;
|
11
|
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
15
|
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
16
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
17
|
import org.eclipse.jface.viewers.LabelProvider;
|
18
|
import org.eclipse.jface.viewers.ListViewer;
|
19
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
20
|
import org.eclipse.jface.viewers.Viewer;
|
21
|
import org.eclipse.jface.wizard.WizardPage;
|
22
|
import org.eclipse.swt.SWT;
|
23
|
import org.eclipse.swt.events.SelectionEvent;
|
24
|
import org.eclipse.swt.events.SelectionListener;
|
25
|
import org.eclipse.swt.widgets.Button;
|
26
|
import org.eclipse.swt.widgets.Composite;
|
27
|
import org.eclipse.swt.widgets.Text;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
30
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
31
|
import eu.etaxonomy.cdm.ext.ipni.IIpniService;
|
32
|
import eu.etaxonomy.cdm.ext.ipni.IpniService;
|
33
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
34
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
35
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
36
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
37
|
|
38
|
/**
|
39
|
* <p>ExternalReferenceServiceWizardPage class.</p>
|
40
|
*
|
41
|
* @author n.hoffmann
|
42
|
* @created Sep 16, 2010
|
43
|
* @version 1.0
|
44
|
*/
|
45
|
public class ExternalReferenceServiceWizardPage extends WizardPage implements SelectionListener, ISelectionChangedListener {
|
46
|
|
47
|
private ConversationHolder conversation;
|
48
|
private CdmFormFactory formFactory;
|
49
|
private Reference entity;
|
50
|
private Composite control;
|
51
|
private ListViewer viewer;
|
52
|
|
53
|
private IIpniService ipniService;
|
54
|
private Text text_query;
|
55
|
private Button button_search;
|
56
|
|
57
|
/**
|
58
|
* <p>Constructor for ExternalReferenceServiceWizardPage.</p>
|
59
|
*
|
60
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
61
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
62
|
* @param entity a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
63
|
*/
|
64
|
protected ExternalReferenceServiceWizardPage(CdmFormFactory formFactory, ConversationHolder conversation, Reference entity) {
|
65
|
super("ExternalReferenceServiceWizardPage");
|
66
|
this.formFactory = formFactory;
|
67
|
this.entity = entity;
|
68
|
this.conversation = conversation;
|
69
|
ipniService = new IpniService();
|
70
|
|
71
|
setDescription("Query IPNI service for references");
|
72
|
}
|
73
|
|
74
|
/** {@inheritDoc} */
|
75
|
@Override
|
76
|
public void createControl(Composite parent) {
|
77
|
control = formFactory.createComposite(parent);
|
78
|
|
79
|
control.setLayout(LayoutConstants.LAYOUT(2, false));
|
80
|
|
81
|
text_query = new Text(control, SWT.SINGLE | SWT.BORDER);
|
82
|
text_query.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
|
83
|
|
84
|
button_search = new Button(control, SWT.PUSH);
|
85
|
button_search.setLayoutData(LayoutConstants.RIGHT());
|
86
|
button_search.setText("Search");
|
87
|
|
88
|
button_search.addSelectionListener(this);
|
89
|
|
90
|
viewer = new ListViewer(control);
|
91
|
viewer.getControl().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2,1));
|
92
|
|
93
|
viewer.setContentProvider(new IStructuredContentProvider(){
|
94
|
|
95
|
@Override
|
96
|
public Object[] getElements(Object inputElement) {
|
97
|
if(inputElement instanceof List){
|
98
|
return ((List) inputElement).toArray();
|
99
|
}
|
100
|
return null;
|
101
|
}
|
102
|
|
103
|
@Override
|
104
|
public void inputChanged(Viewer viewer, Object oldInput,
|
105
|
Object newInput) {}
|
106
|
|
107
|
@Override
|
108
|
public void dispose() {}
|
109
|
|
110
|
});
|
111
|
viewer.setLabelProvider(new LabelProvider(){
|
112
|
@Override
|
113
|
public String getText(Object element) {
|
114
|
if(element instanceof Reference){
|
115
|
return ((Reference) element).getTitleCache();
|
116
|
}
|
117
|
return "Element is not a reference";
|
118
|
}
|
119
|
});
|
120
|
|
121
|
viewer.addSelectionChangedListener(this);
|
122
|
|
123
|
setControl(control);
|
124
|
}
|
125
|
|
126
|
/** {@inheritDoc} */
|
127
|
@Override
|
128
|
public void widgetSelected(SelectionEvent e) {
|
129
|
String query = text_query.getText();
|
130
|
List<Reference> publications = ipniService.getPublications(query, null, (ICdmRepository) CdmStore.getCurrentApplicationConfiguration(), null);
|
131
|
viewer.setInput(publications);
|
132
|
}
|
133
|
|
134
|
/** {@inheritDoc} */
|
135
|
@Override
|
136
|
public void widgetDefaultSelected(SelectionEvent e) {}
|
137
|
|
138
|
/** {@inheritDoc} */
|
139
|
@Override
|
140
|
public void selectionChanged(SelectionChangedEvent event) {
|
141
|
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
|
142
|
|
143
|
Reference selectedReference = (Reference) selection.getFirstElement();
|
144
|
if(selectedReference != null){
|
145
|
((AbstractNewEntityWizard) getWizard()).setEntity(selectedReference);
|
146
|
}
|
147
|
}
|
148
|
|
149
|
|
150
|
}
|