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
.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
;
40 * <p>ExternalReferenceServiceWizardPage class.</p>
43 * @created Sep 16, 2010
46 public class ExternalReferenceServiceWizardPage
extends WizardPage
implements SelectionListener
, ISelectionChangedListener
{
48 private ConversationHolder conversation
;
49 private CdmFormFactory formFactory
;
50 private Reference entity
;
51 private Composite control
;
52 private ListViewer viewer
;
54 private IIpniService ipniService
;
55 private Text text_query
;
56 private Button button_search
;
59 * <p>Constructor for ExternalReferenceServiceWizardPage.</p>
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.
65 protected ExternalReferenceServiceWizardPage(CdmFormFactory formFactory
, ConversationHolder conversation
, Reference entity
) {
66 super("ExternalReferenceServiceWizardPage");
67 this.formFactory
= formFactory
;
69 this.conversation
= conversation
;
70 ipniService
= new IpniService();
72 setDescription("Query IPNI service for references");
76 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
80 public void createControl(Composite parent
) {
81 control
= formFactory
.createComposite(parent
);
83 control
.setLayout(LayoutConstants
.LAYOUT(2, false));
85 text_query
= new Text(control
, SWT
.SINGLE
| SWT
.BORDER
);
86 text_query
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
88 button_search
= new Button(control
, SWT
.PUSH
);
89 button_search
.setLayoutData(LayoutConstants
.RIGHT());
90 button_search
.setText("Search");
92 button_search
.addSelectionListener(this);
94 viewer
= new ListViewer(control
);
95 viewer
.getControl().setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2,1));
97 viewer
.setContentProvider(new IStructuredContentProvider(){
100 public Object
[] getElements(Object inputElement
) {
101 if(inputElement
instanceof List
){
102 return ((List
) inputElement
).toArray();
108 public void inputChanged(Viewer viewer
, Object oldInput
,
112 public void dispose() {}
115 viewer
.setLabelProvider(new LabelProvider(){
117 public String
getText(Object element
) {
118 if(element
instanceof Reference
){
119 return ((Reference
) element
).getTitleCache();
121 return "Element is not a reference";
125 viewer
.addSelectionChangedListener(this);
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
);
140 public void widgetDefaultSelected(SelectionEvent e
) {}
144 public void selectionChanged(SelectionChangedEvent event
) {
145 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
147 Reference selectedReference
= (Reference
) selection
.getFirstElement();
148 if(selectedReference
!= null){
149 ((AbstractNewEntityWizard
) getWizard()).setEntity(selectedReference
);