Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.printpublisher / src / main / java / eu / etaxonomy / taxeditor / printpublisher / wizard / AbstractPublishWizardPage.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.printpublisher.wizard;
11
12 import java.net.URL;
13 import java.nio.channels.IllegalSelectorException;
14
15 import org.eclipse.jface.dialogs.IDialogSettings;
16 import org.eclipse.jface.wizard.WizardPage;
17
18 import eu.etaxonomy.cdm.print.PublishConfigurator;
19 import eu.etaxonomy.cdm.print.out.IPublishOutputModule;
20 import eu.etaxonomy.taxeditor.store.CdmStore;
21
22 /**
23 * <p>Abstract AbstractPublishWizardPage class.</p>
24 *
25 * @author n.hoffmann
26 * @created Apr 27, 2010
27 * @version 1.0
28 */
29 public abstract class AbstractPublishWizardPage extends WizardPage {
30
31 /**
32 * <p>Constructor for AbstractPublishWizardPage.</p>
33 *
34 * @param pageName a {@link java.lang.String} object.
35 */
36 protected AbstractPublishWizardPage(String pageName) {
37 super(pageName);
38 }
39
40 /**
41 * <p>getConfigurator</p>
42 *
43 * @return a {@link eu.etaxonomy.cdm.print.PublishConfigurator} object.
44 */
45 public PublishConfigurator getConfigurator(){
46 return ((AbstractPublishWizard) getWizard()).getConfigurator();
47 }
48
49 /**
50 * <p>setConfigurator</p>
51 *
52 * @param configurator a {@link eu.etaxonomy.cdm.print.PublishConfigurator} object.
53 */
54 public void setConfigurator(PublishConfigurator configurator){
55 ((AbstractPublishWizard) getWizard()).setConfigurator(configurator);
56 }
57
58 /**
59 * <p>getOutputModule</p>
60 *
61 * @return a {@link eu.etaxonomy.cdm.print.out.IPublishOutputModule} object.
62 */
63 public IPublishOutputModule getOutputModule(){
64 IPublishOutputModule outputModule = ((AbstractPublishWizard) getWizard()).getOutputModule();
65 if(outputModule == null)
66 throw new IllegalStateException("OutputModule may not be null at this moment");
67 return outputModule;
68 }
69
70 public void putDialogSettingValue(String key, String value){
71 getDialogSettingSection().put(key, value);
72 }
73
74 public String getDialogSettingValue(String key){
75 return getDialogSettingSection().get(key);
76 }
77
78 public boolean getDialogSettingBooleanValue(String key){
79 return getDialogSettingSection().getBoolean(key);
80 }
81
82 private IDialogSettings getDialogSettingSection(){
83 IDialogSettings wizardDialogSetting = getWizard().getDialogSettings();
84 if(wizardDialogSetting == null){
85 throw new IllegalStateException("Wizards dialog setting may not be null");
86 }
87
88 IDialogSettings specificWizardDialogSection = getOrCreateSettingSection(wizardDialogSetting, getWizard().getClass().getName());
89
90 String dataSource = null;
91 if(getConfigurator().isLocal()){
92 dataSource = CdmStore.getActiveCdmSource().getName();
93 }else if(getConfigurator().isRemote()){
94 URL serviceUrl = getConfigurator().getWebserviceUrl();
95 dataSource = serviceUrl.toExternalForm();
96 }else{
97 throw new IllegalStateException("Print publisher configurator should be either local or remote");
98 }
99
100 IDialogSettings specificDataSourceDialogSection = getOrCreateSettingSection(specificWizardDialogSection, dataSource);
101
102 return specificDataSourceDialogSection;
103 }
104
105 private IDialogSettings getOrCreateSettingSection(IDialogSettings setting, String sectionName){
106 IDialogSettings section = setting.getSection(sectionName);
107
108 if(section == null){
109 section = setting.addNewSection(sectionName);
110 }
111
112 return section;
113 }
114 }