3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.newWizard
;
13 import java
.util
.List
;
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
;
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
;
41 * <p>ExternalReferenceServiceWizardPage class.</p>
44 * @created Sep 16, 2010
47 public class ExternalReferenceServiceWizardPage
extends WizardPage
implements SelectionListener
, ISelectionChangedListener
{
49 private ConversationHolder conversation
;
50 private CdmFormFactory formFactory
;
51 private Reference entity
;
52 private Composite control
;
53 private ListViewer viewer
;
55 private IIpniService ipniService
;
56 private Text text_query
;
57 private Button button_search
;
60 * <p>Constructor for ExternalReferenceServiceWizardPage.</p>
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.
66 protected ExternalReferenceServiceWizardPage(CdmFormFactory formFactory
, ConversationHolder conversation
, Reference entity
) {
67 super("ExternalReferenceServiceWizardPage");
68 this.formFactory
= formFactory
;
70 this.conversation
= conversation
;
71 ipniService
= new IpniService();
73 setDescription("Query IPNI service for references");
77 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
81 public void createControl(Composite parent
) {
82 control
= formFactory
.createComposite(parent
);
84 control
.setLayout(LayoutConstants
.LAYOUT(2, false));
86 text_query
= new Text(control
, SWT
.SINGLE
| SWT
.BORDER
);
87 text_query
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
89 button_search
= new Button(control
, SWT
.PUSH
);
90 button_search
.setLayoutData(LayoutConstants
.RIGHT());
91 button_search
.setText("Search");
93 button_search
.addSelectionListener(this);
95 viewer
= new ListViewer(control
);
96 viewer
.getControl().setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2,1));
98 viewer
.setContentProvider(new IStructuredContentProvider(){
101 public Object
[] getElements(Object inputElement
) {
102 if(inputElement
instanceof List
){
103 return ((List
) inputElement
).toArray();
109 public void inputChanged(Viewer viewer
, Object oldInput
,
113 public void dispose() {}
116 viewer
.setLabelProvider(new LabelProvider(){
118 public String
getText(Object element
) {
119 if(element
instanceof Reference
){
120 return ((Reference
) element
).getTitleCache();
122 return "Element is not a reference";
126 viewer
.addSelectionChangedListener(this);
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
);
141 public void widgetDefaultSelected(SelectionEvent e
) {}
145 public void selectionChanged(SelectionChangedEvent event
) {
146 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
148 Reference selectedReference
= (Reference
) selection
.getFirstElement();
149 if(selectedReference
!= null){
150 ((AbstractNewEntityWizard
) getWizard()).setEntity(selectedReference
);