2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.newWizard
;
12 import java
.util
.List
;
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
;
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
;
39 * <p>ExternalReferenceServiceWizardPage class.</p>
42 * @created Sep 16, 2010
45 public class ExternalReferenceServiceWizardPage
extends WizardPage
implements SelectionListener
, ISelectionChangedListener
{
47 private ConversationHolder conversation
;
48 private CdmFormFactory formFactory
;
49 private Reference entity
;
50 private Composite control
;
51 private ListViewer viewer
;
53 private IIpniService ipniService
;
54 private Text text_query
;
55 private Button button_search
;
58 * <p>Constructor for ExternalReferenceServiceWizardPage.</p>
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.
64 protected ExternalReferenceServiceWizardPage(CdmFormFactory formFactory
, ConversationHolder conversation
, Reference entity
) {
65 super("ExternalReferenceServiceWizardPage");
66 this.formFactory
= formFactory
;
68 this.conversation
= conversation
;
69 ipniService
= new IpniService();
71 setDescription("Query IPNI service for references");
76 public void createControl(Composite parent
) {
77 control
= formFactory
.createComposite(parent
);
79 control
.setLayout(LayoutConstants
.LAYOUT(2, false));
81 text_query
= new Text(control
, SWT
.SINGLE
| SWT
.BORDER
);
82 text_query
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
84 button_search
= new Button(control
, SWT
.PUSH
);
85 button_search
.setLayoutData(LayoutConstants
.RIGHT());
86 button_search
.setText("Search");
88 button_search
.addSelectionListener(this);
90 viewer
= new ListViewer(control
);
91 viewer
.getControl().setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2,1));
93 viewer
.setContentProvider(new IStructuredContentProvider(){
96 public Object
[] getElements(Object inputElement
) {
97 if(inputElement
instanceof List
){
98 return ((List
) inputElement
).toArray();
104 public void inputChanged(Viewer viewer
, Object oldInput
,
108 public void dispose() {}
111 viewer
.setLabelProvider(new LabelProvider(){
113 public String
getText(Object element
) {
114 if(element
instanceof Reference
){
115 return ((Reference
) element
).getTitleCache();
117 return "Element is not a reference";
121 viewer
.addSelectionChangedListener(this);
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
);
136 public void widgetDefaultSelected(SelectionEvent e
) {}
140 public void selectionChanged(SelectionChangedEvent event
) {
141 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
143 Reference selectedReference
= (Reference
) selection
.getFirstElement();
144 if(selectedReference
!= null){
145 ((AbstractNewEntityWizard
) getWizard()).setEntity(selectedReference
);