Revision 7eda66ff
Added by Niels Hoffmann almost 13 years ago
eu.etaxonomy.taxeditor.printpublisher/src/main/java/eu/etaxonomy/taxeditor/printpublisher/wizard/SelectServiceWizardPage.java | ||
---|---|---|
12 | 12 |
|
13 | 13 |
import java.lang.reflect.InvocationTargetException; |
14 | 14 |
import java.net.MalformedURLException; |
15 |
import java.net.URL; |
|
16 |
import java.util.List; |
|
15 | 17 |
|
16 | 18 |
import org.eclipse.core.runtime.IProgressMonitor; |
17 | 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; |
|
18 | 28 |
import org.eclipse.swt.SWT; |
19 | 29 |
import org.eclipse.swt.events.ModifyEvent; |
20 | 30 |
import org.eclipse.swt.events.ModifyListener; |
... | ... | |
24 | 34 |
import org.eclipse.swt.layout.GridLayout; |
25 | 35 |
import org.eclipse.swt.widgets.Button; |
26 | 36 |
import org.eclipse.swt.widgets.Composite; |
27 |
import org.eclipse.swt.widgets.Label; |
|
37 |
import org.eclipse.swt.widgets.Display; |
|
38 |
import org.eclipse.swt.widgets.Group; |
|
28 | 39 |
import org.eclipse.swt.widgets.Text; |
40 |
import org.jdom.Element; |
|
29 | 41 |
|
42 |
import eu.etaxonomy.cdm.print.IXMLEntityFactory; |
|
30 | 43 |
import eu.etaxonomy.cdm.print.PublishConfigurator; |
44 |
import eu.etaxonomy.cdm.print.XMLHelper; |
|
45 |
import eu.etaxonomy.cdm.print.XMLHelper.EntityType; |
|
31 | 46 |
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter; |
47 |
import eu.etaxonomy.taxeditor.printpublisher.PrintUtil; |
|
32 | 48 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
33 | 49 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
34 | 50 |
|
... | ... | |
44 | 60 |
private Composite composite; |
45 | 61 |
private Button button_local; |
46 | 62 |
private Button button_remote; |
47 |
private Label label_serviceUrl; |
|
48 | 63 |
private Text text_serviceUrl; |
64 |
|
|
65 |
private TreeViewer treeViewer; |
|
49 | 66 |
|
50 | 67 |
/** |
51 | 68 |
* <p>Constructor for SelectServiceWizardPage.</p> |
... | ... | |
68 | 85 |
|
69 | 86 |
RadioSelectionListener listener = new RadioSelectionListener(); |
70 | 87 |
|
71 |
button_local = new Button(composite, SWT.RADIO); |
|
88 |
Group radioGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); |
|
89 |
radioGroup.setLayout(new GridLayout()); |
|
90 |
|
|
91 |
button_local = new Button(radioGroup, SWT.RADIO); |
|
92 |
|
|
72 | 93 |
button_local.setText("Local (By selecting this option the database you are currently " + |
73 | 94 |
"connected to will be used to gather data.)"); |
74 | 95 |
|
... | ... | |
76 | 97 |
|
77 | 98 |
|
78 | 99 |
|
79 |
button_remote = new Button(composite, SWT.RADIO);
|
|
100 |
button_remote = new Button(radioGroup, SWT.RADIO);
|
|
80 | 101 |
button_remote.setText("Remote"); |
81 | 102 |
button_remote.addSelectionListener(listener); |
82 | 103 |
|
83 |
|
|
84 |
label_serviceUrl = new Label(composite, SWT.NULL); |
|
85 |
label_serviceUrl.setText("Service URL"); |
|
86 |
|
|
87 |
text_serviceUrl = new Text(composite, SWT.BORDER); |
|
104 |
text_serviceUrl = new Text(radioGroup, SWT.BORDER); |
|
88 | 105 |
text_serviceUrl.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); |
89 | 106 |
text_serviceUrl.setText("http://"); |
90 | 107 |
text_serviceUrl.addModifyListener(new ModifyListener() { |
... | ... | |
92 | 109 |
public void modifyText(ModifyEvent e) { |
93 | 110 |
String text = text_serviceUrl.getText(); |
94 | 111 |
|
95 |
try {
|
|
96 |
getConfigurator().setWebserviceUrl(text);
|
|
97 |
} catch (MalformedURLException e1) {
|
|
98 |
StoreUtil.warn(this.getClass(), "Malformed Url");
|
|
112 |
if(!text.endsWith("/")){
|
|
113 |
SelectServiceWizardPage.this.setErrorMessage("Webservice URL has to end with \"/\"");
|
|
114 |
setPageComplete(false);
|
|
115 |
return;
|
|
99 | 116 |
} |
100 | 117 |
|
101 |
if(isPageComplete()){
|
|
102 |
SelectServiceWizardPage.this.setErrorMessage(null);
|
|
103 |
setPageComplete(true);
|
|
104 |
}else{
|
|
105 |
SelectServiceWizardPage.this.setErrorMessage("Webservice URL has to end with \"/\"");
|
|
118 |
URL url = null;
|
|
119 |
try {
|
|
120 |
url = new URL(text);
|
|
121 |
} catch (MalformedURLException e1) {
|
|
122 |
SelectServiceWizardPage.this.setErrorMessage("Webservice URL is malformed.");
|
|
106 | 123 |
setPageComplete(false); |
124 |
return; |
|
107 | 125 |
} |
126 |
|
|
127 |
getConfigurator().setWebserviceUrl(url); |
|
128 |
|
|
129 |
SelectServiceWizardPage.this.setErrorMessage(null); |
|
130 |
|
|
108 | 131 |
} |
109 | 132 |
}); |
110 | 133 |
|
134 |
treeViewer = new TreeViewer(composite); |
|
135 |
|
|
136 |
treeViewer.setContentProvider(new ContentProvider()); |
|
137 |
treeViewer.setLabelProvider(new LabelProvider()); |
|
138 |
|
|
139 |
treeViewer.addSelectionChangedListener(new SelectionChangedListener()); |
|
140 |
|
|
141 |
treeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
142 |
|
|
143 |
|
|
111 | 144 |
if(CdmStore.isActive()){ |
112 | 145 |
enableLocal(); |
113 | 146 |
}else{ |
... | ... | |
122 | 155 |
private class RadioSelectionListener extends SelectionAdapter{ |
123 | 156 |
@Override |
124 | 157 |
public void widgetSelected(SelectionEvent e) { |
125 |
if(e.widget == button_local){
|
|
158 |
if(button_local.getSelection()){
|
|
126 | 159 |
enableLocal(); |
127 |
}else{ |
|
160 |
}else if(button_remote.getSelection()){
|
|
128 | 161 |
enableRemote(); |
129 | 162 |
} |
130 | 163 |
} |
... | ... | |
134 | 167 |
button_local.setSelection(false); |
135 | 168 |
button_remote.setSelection(true); |
136 | 169 |
|
137 |
label_serviceUrl.setEnabled(true); |
|
138 | 170 |
text_serviceUrl.setEnabled(true); |
139 | 171 |
|
140 | 172 |
setConfigurator(PublishConfigurator.NewRemoteInstance()); |
... | ... | |
145 | 177 |
button_remote.setSelection(false); |
146 | 178 |
button_local.setSelection(true); |
147 | 179 |
|
148 |
label_serviceUrl.setEnabled(false); |
|
149 | 180 |
text_serviceUrl.setEnabled(false); |
150 | 181 |
|
151 | 182 |
setConfigurator(PublishConfigurator.NewLocalInstance(CdmStore.getCurrentApplicationConfiguration())); |
152 | 183 |
getConfigurator().addOutputModule(getOutputModule()); |
184 |
refresh(); |
|
153 | 185 |
} |
154 | 186 |
|
155 | 187 |
/* |
... | ... | |
158 | 190 |
*/ |
159 | 191 |
/** {@inheritDoc} */ |
160 | 192 |
@Override |
161 |
public boolean canFlipToNextPage() { |
|
162 |
if(isPageComplete()){ |
|
163 |
try { |
|
164 |
getContainer().run(false, false, new IRunnableWithProgress() { |
|
193 |
public boolean canFlipToNextPage() { |
|
194 |
return isPageComplete(); |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* <p>refresh</p> |
|
199 |
*/ |
|
200 |
public void refresh(){ |
|
201 |
|
|
202 |
if(getConfigurator() != null){ |
|
203 |
|
|
204 |
IRunnableWithProgress runnable = new IRunnableWithProgress(){ |
|
205 |
|
|
206 |
@Override |
|
207 |
public void run(IProgressMonitor monitor) { |
|
208 |
monitor.beginTask("Loading classifications", IProgressMonitor.UNKNOWN); |
|
209 |
IXMLEntityFactory factory = getConfigurator().getFactory(); |
|
210 |
final List<Element> classifications = factory.getClassifications(); |
|
165 | 211 |
|
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(); |
|
212 |
Display.getDefault().asyncExec(new Runnable(){ |
|
213 |
|
|
214 |
@Override |
|
215 |
public void run() { |
|
216 |
treeViewer.setInput(classifications); |
|
217 |
} |
|
176 | 218 |
|
177 |
} |
|
178 |
}); |
|
219 |
}); |
|
220 |
monitor.done(); |
|
221 |
} |
|
222 |
|
|
223 |
}; |
|
224 |
try { |
|
225 |
getContainer().run(true, false, runnable); |
|
179 | 226 |
} catch (InvocationTargetException e) { |
180 |
PrintUtil.error(getClass(), e);
|
|
227 |
StoreUtil.error(this.getClass(), e);
|
|
181 | 228 |
} catch (InterruptedException e) { |
182 |
PrintUtil.error(getClass(), e);
|
|
229 |
StoreUtil.error(this.getClass(), e);
|
|
183 | 230 |
} |
184 |
|
|
185 |
return true; |
|
186 | 231 |
} |
187 |
return false; |
|
188 | 232 |
} |
189 | 233 |
|
190 | 234 |
/* |
... | ... | |
194 | 238 |
/** {@inheritDoc} */ |
195 | 239 |
@Override |
196 | 240 |
public boolean isPageComplete() { |
241 |
boolean complete = true; |
|
197 | 242 |
if(getConfigurator().isLocal()){ |
198 |
return true;
|
|
243 |
complete &= true;
|
|
199 | 244 |
}else if(getConfigurator().isRemote() |
200 | 245 |
&& getConfigurator().getWebserviceUrl() != null |
201 | 246 |
&& getConfigurator().getWebserviceUrl().toString().endsWith("/")){ |
202 |
return true;
|
|
247 |
complete &= true;
|
|
203 | 248 |
}else{ |
204 | 249 |
return false; |
205 | 250 |
} |
251 |
|
|
252 |
List<Element> selectedTaxonNodes = getConfigurator().getSelectedTaxonNodeElements(); |
|
253 |
|
|
254 |
complete &= !selectedTaxonNodes.isEmpty(); |
|
255 |
|
|
256 |
return complete; |
|
257 |
} |
|
258 |
|
|
259 |
private class SelectionChangedListener implements ISelectionChangedListener { |
|
260 |
|
|
261 |
public void selectionChanged(SelectionChangedEvent event) { |
|
262 |
StructuredSelection selection = (StructuredSelection) treeViewer.getSelection(); |
|
263 |
|
|
264 |
List<Element> selectedElements = selection.toList(); |
|
265 |
if(selectedElements.size() > 0){ |
|
266 |
getConfigurator().setSelectedTaxonNodeElements(selectedElements); |
|
267 |
setPageComplete(true); |
|
268 |
} |
|
269 |
} |
|
270 |
|
|
271 |
} |
|
272 |
|
|
273 |
private class ContentProvider implements ITreeContentProvider{ |
|
274 |
|
|
275 |
public Object[] getChildren(Object parentElement) { |
|
276 |
if(parentElement instanceof List){ |
|
277 |
return ((List)parentElement).toArray(); |
|
278 |
} |
|
279 |
else if(parentElement instanceof Element){ |
|
280 |
Element element = (Element) parentElement; |
|
281 |
|
|
282 |
IXMLEntityFactory factory = getConfigurator().getFactory(); |
|
283 |
|
|
284 |
return factory != null ? factory.getChildNodes(element).toArray() : new Object[]{}; |
|
285 |
|
|
286 |
} |
|
287 |
|
|
288 |
return new Object[]{}; |
|
289 |
} |
|
290 |
|
|
291 |
public Object getParent(Object element) { |
|
292 |
return null; |
|
293 |
} |
|
294 |
|
|
295 |
public boolean hasChildren(Object element) { |
|
296 |
return getChildren(element).length > 0; |
|
297 |
} |
|
298 |
|
|
299 |
public Object[] getElements(Object inputElement) { |
|
300 |
return getChildren(inputElement); |
|
301 |
} |
|
302 |
|
|
303 |
public void dispose() { |
|
304 |
|
|
305 |
} |
|
306 |
|
|
307 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
308 |
|
|
309 |
} |
|
310 |
|
|
311 |
} |
|
312 |
|
|
313 |
private class LabelProvider extends ColumnLabelProvider |
|
314 |
implements ILabelProvider{ |
|
315 |
|
|
316 |
@Override |
|
317 |
public String getText(Object element) { |
|
318 |
if(element instanceof Element){ |
|
319 |
Element xmlElement = (Element) element; |
|
320 |
EntityType entityType = XMLHelper.getEntityType(xmlElement); |
|
321 |
if(EntityType.TAXON_NODE.equals(entityType)){ |
|
322 |
xmlElement = getConfigurator().getFactory().getTaxonForTaxonNode(xmlElement); |
|
323 |
} |
|
324 |
return XMLHelper.getTitleCache(xmlElement); |
|
325 |
} |
|
326 |
return "no title cache"; |
|
327 |
} |
|
328 |
|
|
206 | 329 |
} |
207 | 330 |
|
208 | 331 |
} |
Also available in: Unified diff
Improved PrintPublisher Wizard; Integrated SpecimenCdmExcel import