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
.printpublisher
.wizard
;
13 import java
.lang
.reflect
.InvocationTargetException
;
14 import java
.net
.MalformedURLException
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
20 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
21 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
22 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
23 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
24 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
25 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
26 import org
.eclipse
.jface
.viewers
.TreeViewer
;
27 import org
.eclipse
.jface
.viewers
.Viewer
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.events
.ModifyEvent
;
30 import org
.eclipse
.swt
.events
.ModifyListener
;
31 import org
.eclipse
.swt
.events
.SelectionAdapter
;
32 import org
.eclipse
.swt
.events
.SelectionEvent
;
33 import org
.eclipse
.swt
.layout
.GridData
;
34 import org
.eclipse
.swt
.layout
.GridLayout
;
35 import org
.eclipse
.swt
.widgets
.Button
;
36 import org
.eclipse
.swt
.widgets
.Composite
;
37 import org
.eclipse
.swt
.widgets
.Display
;
38 import org
.eclipse
.swt
.widgets
.Group
;
39 import org
.eclipse
.swt
.widgets
.Text
;
40 import org
.jdom
.Element
;
42 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
43 import eu
.etaxonomy
.cdm
.print
.IXMLEntityFactory
;
44 import eu
.etaxonomy
.cdm
.print
.PublishConfigurator
;
45 import eu
.etaxonomy
.cdm
.print
.XMLHelper
;
46 import eu
.etaxonomy
.cdm
.print
.XMLHelper
.EntityType
;
47 import eu
.etaxonomy
.taxeditor
.model
.CdmProgressMonitorAdapter
;
48 import eu
.etaxonomy
.taxeditor
.printpublisher
.PrintUtil
;
49 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
50 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
53 * <p>SelectServiceWizardPage class.</p>
56 * @created Apr 6, 2010
59 public class SelectServiceWizardPage
extends AbstractPublishWizardPage
{
61 private Composite composite
;
62 private Button button_local
;
63 private Button button_remote
;
64 private Text text_serviceUrl
;
66 private TreeViewer treeViewer
;
69 * <p>Constructor for SelectServiceWizardPage.</p>
71 * @param pageName a {@link java.lang.String} object.
73 protected SelectServiceWizardPage(String pageName
) {
75 setTitle("Select a Service");
79 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
82 public void createControl(Composite parent
) {
84 composite
= new Composite(parent
, SWT
.NULL
);
85 composite
.setLayout(new GridLayout());
87 RadioSelectionListener listener
= new RadioSelectionListener();
89 Group radioGroup
= new Group(composite
, SWT
.SHADOW_ETCHED_IN
);
90 radioGroup
.setLayout(new GridLayout());
92 button_local
= new Button(radioGroup
, SWT
.RADIO
);
94 button_local
.setText("Local (By selecting this option the database you are currently " +
95 "connected to will be used to gather data.)");
97 button_local
.addSelectionListener(listener
);
101 button_remote
= new Button(radioGroup
, SWT
.RADIO
);
102 button_remote
.setText("Remote");
103 button_remote
.addSelectionListener(listener
);
105 text_serviceUrl
= new Text(radioGroup
, SWT
.BORDER
);
106 text_serviceUrl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
107 text_serviceUrl
.setText("http://");
108 text_serviceUrl
.addModifyListener(new ModifyListener() {
110 public void modifyText(ModifyEvent e
) {
111 String text
= text_serviceUrl
.getText();
113 if(!text
.endsWith("/")){
114 SelectServiceWizardPage
.this.setErrorMessage("Webservice URL has to end with \"/\"");
115 setPageComplete(false);
122 } catch (MalformedURLException e1
) {
123 SelectServiceWizardPage
.this.setErrorMessage("Webservice URL is malformed.");
124 setPageComplete(false);
128 getConfigurator().setWebserviceUrl(url
);
130 SelectServiceWizardPage
.this.setErrorMessage(null);
135 treeViewer
= new TreeViewer(composite
);
137 treeViewer
.setContentProvider(new ContentProvider());
138 treeViewer
.setLabelProvider(new LabelProvider());
140 treeViewer
.addSelectionChangedListener(new SelectionChangedListener());
142 treeViewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
145 if(CdmStore
.isActive()){
149 button_local
.setEnabled(false);
152 setControl(composite
);
156 private class RadioSelectionListener
extends SelectionAdapter
{
158 public void widgetSelected(SelectionEvent e
) {
159 if(button_local
.getSelection()){
161 }else if(button_remote
.getSelection()){
167 private void enableRemote() {
168 button_local
.setSelection(false);
169 button_remote
.setSelection(true);
171 text_serviceUrl
.setEnabled(true);
173 setConfigurator(PublishConfigurator
.NewRemoteInstance());
174 getConfigurator().addOutputModule(getOutputModule());
177 private void enableLocal() {
178 button_remote
.setSelection(false);
179 button_local
.setSelection(true);
181 text_serviceUrl
.setEnabled(false);
183 setConfigurator(PublishConfigurator
.NewLocalInstance((ICdmApplicationConfiguration
) CdmStore
.getCurrentApplicationConfiguration()));
184 getConfigurator().addOutputModule(getOutputModule());
190 * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage()
194 public boolean canFlipToNextPage() {
195 return isPageComplete();
201 public void refresh(){
203 if(getConfigurator() != null){
205 IRunnableWithProgress runnable
= new IRunnableWithProgress(){
208 public void run(IProgressMonitor monitor
) {
209 monitor
.beginTask("Loading classifications", IProgressMonitor
.UNKNOWN
);
210 IXMLEntityFactory factory
= getConfigurator().getFactory();
211 final List
<Element
> classifications
= factory
.getClassifications();
213 Display
.getDefault().asyncExec(new Runnable(){
217 treeViewer
.setInput(classifications
);
226 getContainer().run(true, false, runnable
);
227 } catch (InvocationTargetException e
) {
228 StoreUtil
.error(this.getClass(), e
);
229 } catch (InterruptedException e
) {
230 StoreUtil
.error(this.getClass(), e
);
237 * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
241 public boolean isPageComplete() {
242 boolean complete
= true;
243 if(getConfigurator().isLocal()){
245 }else if(getConfigurator().isRemote()
246 && getConfigurator().getWebserviceUrl() != null
247 && getConfigurator().getWebserviceUrl().toString().endsWith("/")){
253 List
<Element
> selectedTaxonNodes
= getConfigurator().getSelectedTaxonNodeElements();
255 complete
&= !selectedTaxonNodes
.isEmpty();
260 private class SelectionChangedListener
implements ISelectionChangedListener
{
262 public void selectionChanged(SelectionChangedEvent event
) {
263 StructuredSelection selection
= (StructuredSelection
) treeViewer
.getSelection();
265 List
<Element
> selectedElements
= selection
.toList();
266 if(selectedElements
.size() > 0){
267 getConfigurator().setSelectedTaxonNodeElements(selectedElements
);
268 setPageComplete(true);
274 private class ContentProvider
implements ITreeContentProvider
{
276 public Object
[] getChildren(Object parentElement
) {
277 if(parentElement
instanceof List
){
278 return ((List
)parentElement
).toArray();
280 else if(parentElement
instanceof Element
){
281 Element element
= (Element
) parentElement
;
283 IXMLEntityFactory factory
= getConfigurator().getFactory();
285 return factory
!= null ? factory
.getChildNodes(element
).toArray() : new Object
[]{};
289 return new Object
[]{};
292 public Object
getParent(Object element
) {
296 public boolean hasChildren(Object element
) {
297 return getChildren(element
).length
> 0;
300 public Object
[] getElements(Object inputElement
) {
301 return getChildren(inputElement
);
304 public void dispose() {
308 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
314 private class LabelProvider
extends ColumnLabelProvider
315 implements ILabelProvider
{
318 public String
getText(Object element
) {
319 if(element
instanceof Element
){
320 Element xmlElement
= (Element
) element
;
321 EntityType entityType
= XMLHelper
.getEntityType(xmlElement
);
322 if(EntityType
.TAXON_NODE
.equals(entityType
)){
323 xmlElement
= getConfigurator().getFactory().getTaxonForTaxonNode(xmlElement
);
325 return XMLHelper
.getTitleCache(xmlElement
);
327 return "no title cache";