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