Project

General

Profile

Download (4.85 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.newWizard;
12

    
13
import java.util.List;
14

    
15
import org.eclipse.jface.viewers.ISelectionChangedListener;
16
import org.eclipse.jface.viewers.IStructuredContentProvider;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.viewers.LabelProvider;
19
import org.eclipse.jface.viewers.ListViewer;
20
import org.eclipse.jface.viewers.SelectionChangedEvent;
21
import org.eclipse.jface.viewers.Viewer;
22
import org.eclipse.jface.wizard.WizardPage;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.events.SelectionListener;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Text;
29

    
30
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
31
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
32
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
33
import eu.etaxonomy.cdm.ext.ipni.IIpniService;
34
import eu.etaxonomy.cdm.ext.ipni.IpniService;
35
import eu.etaxonomy.cdm.model.reference.Reference;
36
import eu.etaxonomy.taxeditor.store.CdmStore;
37
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
38
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
39

    
40
/**
41
 * <p>ExternalReferenceServiceWizardPage class.</p>
42
 *
43
 * @author n.hoffmann
44
 * @created Sep 16, 2010
45
 * @version 1.0
46
 */
47
public class ExternalReferenceServiceWizardPage extends WizardPage implements SelectionListener, ISelectionChangedListener {
48

    
49
	private ConversationHolder conversation;
50
	private CdmFormFactory formFactory;
51
	private Reference entity;
52
	private Composite control;
53
	private ListViewer viewer;
54
	
55
	private IIpniService ipniService;
56
	private Text text_query;
57
	private Button button_search;
58

    
59
	/**
60
	 * <p>Constructor for ExternalReferenceServiceWizardPage.</p>
61
	 *
62
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
63
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
64
	 * @param entity a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
65
	 */
66
	protected ExternalReferenceServiceWizardPage(CdmFormFactory formFactory, ConversationHolder conversation, Reference entity) {
67
		super("ExternalReferenceServiceWizardPage");
68
		this.formFactory = formFactory;
69
		this.entity = entity;
70
		this.conversation = conversation;
71
		ipniService = new IpniService();
72
		
73
		setDescription("Query IPNI service for references");
74
	}
75
	
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
78
	 */
79
	/** {@inheritDoc} */
80
	@Override
81
	public void createControl(Composite parent) {
82
		control = formFactory.createComposite(parent);
83
		
84
		control.setLayout(LayoutConstants.LAYOUT(2, false));
85
		
86
		text_query = new Text(control, SWT.SINGLE | SWT.BORDER);
87
		text_query.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
88
		
89
		button_search = new Button(control, SWT.PUSH);
90
		button_search.setLayoutData(LayoutConstants.RIGHT());
91
		button_search.setText("Search");
92
		
93
		button_search.addSelectionListener(this);
94
		
95
		viewer = new ListViewer(control);
96
		viewer.getControl().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2,1));
97
		
98
		viewer.setContentProvider(new IStructuredContentProvider(){
99

    
100
			@Override
101
			public Object[] getElements(Object inputElement) {
102
				if(inputElement instanceof List){
103
					return ((List) inputElement).toArray();
104
				}
105
				return null;
106
			}
107
			
108
			@Override
109
			public void inputChanged(Viewer viewer, Object oldInput,
110
					Object newInput) {}
111
			
112
			@Override
113
			public void dispose() {}
114
			
115
		});
116
		viewer.setLabelProvider(new LabelProvider(){
117
			@Override
118
			public String getText(Object element) {
119
				if(element instanceof Reference){
120
					return ((Reference) element).getTitleCache();
121
				}
122
				return "Element is not a reference";
123
			}
124
		});
125
		
126
		viewer.addSelectionChangedListener(this);
127
		
128
		setControl(control);
129
	}
130

    
131
	/** {@inheritDoc} */
132
	@Override
133
	public void widgetSelected(SelectionEvent e) {
134
		String query = text_query.getText();
135
		List<Reference> publications = ipniService.getPublications(query, null, (ICdmApplicationConfiguration) CdmStore.getCurrentApplicationConfiguration(), null);
136
		viewer.setInput(publications);
137
	}
138

    
139
	/** {@inheritDoc} */
140
	@Override
141
	public void widgetDefaultSelected(SelectionEvent e) {}
142

    
143
	/** {@inheritDoc} */
144
	@Override
145
	public void selectionChanged(SelectionChangedEvent event) {
146
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
147
		
148
		Reference selectedReference = (Reference) selection.getFirstElement();
149
		if(selectedReference != null){
150
			((AbstractNewEntityWizard) getWizard()).setEntity(selectedReference);
151
		}
152
	}
153
	
154
	
155
}
(5-5/23)