Project

General

Profile

Download (4.78 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.conversation.ConversationHolder;
32
import eu.etaxonomy.cdm.ext.ipni.IIpniService;
33
import eu.etaxonomy.cdm.ext.ipni.IpniService;
34
import eu.etaxonomy.cdm.model.reference.Reference;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
37
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
38

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

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

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

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

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

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

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