Fixing bugs in open url dialog
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / forms / openurl / OpenUrlSelectorWizard.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.forms.openurl;
12
13 import java.net.URI;
14 import java.util.List;
15
16 import org.eclipse.jface.wizard.Wizard;
17 import org.eclipse.swt.widgets.Display;
18
19 import eu.etaxonomy.cdm.ext.openurl.MobotOpenUrlQuery;
20 import eu.etaxonomy.cdm.ext.openurl.MobotOpenUrlServiceWrapper;
21 import eu.etaxonomy.cdm.ext.openurl.MobotOpenUrlServiceWrapper.ReferenceType;
22 import eu.etaxonomy.cdm.ext.openurl.OpenUrlReference;
23 import eu.etaxonomy.cdm.model.reference.Reference;
24 import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
25 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
26 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27
28 /**
29 * @author n.hoffmann
30 * @created Jan 31, 2011
31 * @version 1.0
32 */
33 public class OpenUrlSelectorWizard extends Wizard {
34
35 private MobotOpenUrlServiceWrapper openUrlServiceWrapper;
36
37 private MobotOpenUrlQuery query;
38
39 private Reference reference;
40
41
42 private OpenUrlReference openUrlReference;
43
44 private CdmFormFactory formFactory;
45
46 private URI openUrlReferenceImageUri;
47
48 private String referenceDetail;
49
50
51
52 /**
53 * @param openUrlSelectorElement
54 * @param reference
55 */
56 public OpenUrlSelectorWizard(Reference reference, String referenceDetail) {
57 if(reference == null){
58 throw new IllegalArgumentException("Reference may not be empty.");
59 }
60 this.reference = reference;
61 this.referenceDetail = referenceDetail;
62
63 setWindowTitle("Mobot Open Url");
64 setNeedsProgressMonitor(true);
65
66 formFactory = new CdmFormFactory(Display.getDefault());
67
68 openUrlServiceWrapper = new MobotOpenUrlServiceWrapper();
69 openUrlServiceWrapper.setBaseUrl(PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.OPENURL_ACCESS_POINT));
70
71 query = new MobotOpenUrlQuery();
72
73 query.refType = ReferenceType.getReferenceType(reference);
74 if(reference.getAuthorTeam() != null){
75 query.authorName = reference.getAuthorTeam().getTitleCache();
76 }
77 query.abbreviation = reference.getTitle();
78
79 if(reference.getInReference() != null){
80 query.journalTitle = reference.getInReference().getTitle();
81 }
82 query.ISBN = reference.getIsbn();
83 query.ISSN = reference.getIssn();
84 if(reference.getDatePublished() != null){
85 query.publicationDate = reference.getDatePublished().toString();
86 }
87 query.publicationPlace = reference.getPlacePublished();
88 query.publisherName = reference.getPublisher();
89 query.volume = reference.getVolume();
90
91 query.startPage = referenceDetail;
92 }
93
94 /* (non-Javadoc)
95 * @see org.eclipse.jface.wizard.Wizard#addPages()
96 */
97 @Override
98 public void addPages() {
99
100 addPage(new OpenUrlResultPage());
101 addPage(new OpenUrlReferencePage());
102
103 super.addPages();
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.jface.wizard.Wizard#performFinish()
108 */
109 @Override
110 public boolean performFinish() {
111 return true;
112 }
113
114 /**
115 * @param openUrlReference the openUrlReference to set
116 */
117 public void setOpenUrlReference(OpenUrlReference openUrlReference) {
118 this.openUrlReference = openUrlReference;
119 this.openUrlReferenceImageUri = openUrlReference.getJpegImage(PreferencesUtil.getPreferenceStore().getInt(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH)
120 , PreferencesUtil.getPreferenceStore().getInt(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT));
121 }
122
123 /**
124 * @return the openUrlReference
125 */
126 public OpenUrlReference getOpenUrlReference() {
127 return openUrlReference;
128 }
129
130 /**
131 * @return
132 */
133 public List<OpenUrlReference> getResult() {
134 return openUrlServiceWrapper.doResolve(query);
135 }
136
137 /**
138 * @return the formFactory
139 */
140 public CdmFormFactory getFormFactory() {
141 return formFactory;
142 }
143
144 /**
145 * @return the openUrlServiceWrapper
146 */
147 public MobotOpenUrlServiceWrapper getOpenUrlServiceWrapper() {
148 return openUrlServiceWrapper;
149 }
150
151 /**
152 * @return
153 */
154 public URI getOpenUrlReferenceImageUri() {
155 return openUrlReferenceImageUri;
156 }
157
158
159 public Reference getReference() {
160 return reference;
161 }
162
163 public String getReferenceDetail() {
164 return referenceDetail;
165 }
166 }