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