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