performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-printpublisher / src / main / java / eu / etaxonomy / taxeditor / printpublisher / wizard / SelectServiceWizardPage.java
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.printpublisher.wizard;
12
13 import java.net.MalformedURLException;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.ModifyEvent;
17 import org.eclipse.swt.events.ModifyListener;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Button;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Text;
26
27 import eu.etaxonomy.cdm.print.PublishConfigurator;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29 import eu.etaxonomy.taxeditor.store.StoreUtil;
30
31 /**
32 * <p>SelectServiceWizardPage class.</p>
33 *
34 * @author n.hoffmann
35 * @created Apr 6, 2010
36 * @version 1.0
37 */
38 public class SelectServiceWizardPage extends AbstractPublishWizardPage {
39
40 private Composite composite;
41 private Button button_local;
42 private Button button_remote;
43 private Label label_serviceUrl;
44 private Text text_serviceUrl;
45
46 /**
47 * <p>Constructor for SelectServiceWizardPage.</p>
48 *
49 * @param pageName a {@link java.lang.String} object.
50 */
51 protected SelectServiceWizardPage(String pageName) {
52 super(pageName);
53 setTitle("Select a Service");
54 }
55
56 /* (non-Javadoc)
57 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
58 */
59 /** {@inheritDoc} */
60 public void createControl(Composite parent) {
61
62 composite = new Composite(parent, SWT.NULL);
63 composite.setLayout(new GridLayout());
64
65 RadioSelectionListener listener = new RadioSelectionListener();
66
67 button_local = new Button(composite, SWT.RADIO);
68 button_local.setText("Local (By selecting this option the database you are currently " +
69 "connected to will be used to gather data.)");
70
71 button_local.addSelectionListener(listener);
72
73
74
75 button_remote = new Button(composite, SWT.RADIO);
76 button_remote.setText("Remote");
77 button_remote.addSelectionListener(listener);
78
79
80 label_serviceUrl = new Label(composite, SWT.NULL);
81 label_serviceUrl.setText("Service URL");
82
83 text_serviceUrl = new Text(composite, SWT.BORDER);
84 text_serviceUrl.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
85 text_serviceUrl.setText("http://");
86 text_serviceUrl.addModifyListener(new ModifyListener() {
87
88 public void modifyText(ModifyEvent e) {
89 String text = text_serviceUrl.getText();
90
91 try {
92 getConfigurator().setWebserviceUrl(text);
93 } catch (MalformedURLException e1) {
94 StoreUtil.warn(this.getClass(), "Malformed Url");
95 }
96
97 if(isPageComplete()){
98 SelectServiceWizardPage.this.setErrorMessage(null);
99 setPageComplete(true);
100 }else{
101 SelectServiceWizardPage.this.setErrorMessage("Webservice URL has to end with \"/\"");
102 setPageComplete(false);
103 }
104 }
105 });
106
107 if(CdmStore.isActive()){
108 enableLocal();
109 }else{
110 enableRemote();
111 button_local.setEnabled(false);
112 }
113
114 setControl(composite);
115
116 }
117
118 private class RadioSelectionListener extends SelectionAdapter{
119 @Override
120 public void widgetSelected(SelectionEvent e) {
121 if(e.widget == button_local){
122 enableLocal();
123 }else{
124 enableRemote();
125 }
126 }
127 }
128
129 private void enableRemote() {
130 button_local.setSelection(false);
131 button_remote.setSelection(true);
132
133 label_serviceUrl.setEnabled(true);
134 text_serviceUrl.setEnabled(true);
135
136 setConfigurator(PublishConfigurator.NewRemoteInstance());
137 getConfigurator().addOutputModule(getOutputModule());
138 }
139
140 private void enableLocal() {
141 button_remote.setSelection(false);
142 button_local.setSelection(true);
143
144 label_serviceUrl.setEnabled(false);
145 text_serviceUrl.setEnabled(false);
146
147 setConfigurator(PublishConfigurator.NewLocalInstance(CdmStore.getCurrentApplicationController()));
148 getConfigurator().addOutputModule(getOutputModule());
149 }
150
151 /*
152 * (non-Javadoc)
153 * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage()
154 */
155 /** {@inheritDoc} */
156 @Override
157 public boolean canFlipToNextPage() {
158 if(isPageComplete()){
159 SelectTaxaWizardPage selectTaxaPage = (SelectTaxaWizardPage) getWizard().getPage(AbstractPublishWizard.PAGE_TAXA);
160 selectTaxaPage.refresh();
161
162 SelectFeatureTreeWizardPage selectFeatureTreePage = (SelectFeatureTreeWizardPage) getWizard().getPage(AbstractPublishWizard.PAGE_FEATURETREE);
163 selectFeatureTreePage.refresh();
164
165 return true;
166 }
167 return false;
168 }
169
170 /*
171 * (non-Javadoc)
172 * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
173 */
174 /** {@inheritDoc} */
175 @Override
176 public boolean isPageComplete() {
177 if(getConfigurator().isLocal()){
178 return true;
179 }else if(getConfigurator().isRemote()
180 && getConfigurator().getWebserviceUrl() != null
181 && getConfigurator().getWebserviceUrl().toString().endsWith("/")){
182 return true;
183 }else{
184 return false;
185 }
186 }
187
188 }