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