merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / 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.ui.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.preference.IPreferenceKeys;
25 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
26 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
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 final MobotOpenUrlServiceWrapper openUrlServiceWrapper;
36
37 private final MobotOpenUrlQuery query;
38
39 private OpenUrlReference openUrlReference;
40
41 private final CdmFormFactory formFactory;
42
43 private URI openUrlReferenceImageUri;
44
45 private final Reference reference;
46
47 private final String referenceDetail;
48
49
50
51 /**
52 * @param openUrlSelectorElement
53 * @param reference
54 */
55 public OpenUrlSelectorWizard(Reference reference, String referenceDetail) {
56 if(reference == null){
57 throw new IllegalArgumentException("Reference may not be empty");
58 }
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.getAuthorship() != null){
75 query.authorName = reference.getAuthorship().getTitleCache();
76 }
77 query.abbreviation = reference.getTitle();
78 if(reference.getInReference() != null){
79 query.journalTitle = reference.getInReference().getTitle();
80 }
81 query.ISBN = reference.getIsbn();
82 query.ISSN = reference.getIssn();
83 if(reference.getDatePublished() != null){
84 query.publicationDate = reference.getDatePublished().toString();
85 }
86 query.publicationPlace = reference.getPlacePublished();
87 query.publisherName = reference.getPublisher();
88 query.volume = reference.getVolume();
89
90 query.startPage = referenceDetail;
91 }
92
93 /* (non-Javadoc)
94 * @see org.eclipse.jface.wizard.Wizard#addPages()
95 */
96 @Override
97 public void addPages() {
98
99 addPage(new OpenUrlResultPage());
100 addPage(new OpenUrlReferencePage());
101
102 super.addPages();
103 }
104
105 /* (non-Javadoc)
106 * @see org.eclipse.jface.wizard.Wizard#performFinish()
107 */
108 @Override
109 public boolean performFinish() {
110 return true;
111 }
112
113 /**
114 * @param openUrlReference the openUrlReference to set
115 */
116 public void setOpenUrlReference(OpenUrlReference openUrlReference) {
117 this.openUrlReference = openUrlReference;
118 this.openUrlReferenceImageUri = openUrlReference.getJpegImage(PreferencesUtil.getPreferenceStore().getInt(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH)
119 , PreferencesUtil.getPreferenceStore().getInt(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT));
120 }
121
122 /**
123 * @return the openUrlReference
124 */
125 public OpenUrlReference getOpenUrlReference() {
126 return openUrlReference;
127 }
128
129 /**
130 * @return
131 */
132 public List<OpenUrlReference> getResult() {
133 return openUrlServiceWrapper.doResolve(query);
134 }
135
136 /**
137 * @return the formFactory
138 */
139 public CdmFormFactory getFormFactory() {
140 return formFactory;
141 }
142
143 /**
144 * @return the openUrlServiceWrapper
145 */
146 public MobotOpenUrlServiceWrapper getOpenUrlServiceWrapper() {
147 return openUrlServiceWrapper;
148 }
149
150 /**
151 * @return
152 */
153 public URI getOpenUrlReferenceImageUri() {
154 return openUrlReferenceImageUri;
155 }
156
157 public Reference getReference() {
158 return reference;
159 }
160
161 public String getReferenceDetail() {
162 return referenceDetail;
163 }
164 }