Project

General

Profile

Download (6.19 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.printpublisher.wizard;
5

    
6
import org.eclipse.core.runtime.IProgressMonitor;
7
import org.eclipse.core.runtime.IStatus;
8
import org.eclipse.core.runtime.Status;
9
import org.eclipse.core.runtime.jobs.Job;
10
import org.eclipse.jface.dialogs.MessageDialog;
11
import org.eclipse.jface.viewers.IStructuredSelection;
12
import org.eclipse.jface.wizard.IWizardPage;
13
import org.eclipse.jface.wizard.Wizard;
14
import org.eclipse.swt.widgets.Display;
15
import org.eclipse.ui.IExportWizard;
16
import org.eclipse.ui.IWorkbench;
17

    
18
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19
import eu.etaxonomy.cdm.print.PublishConfigurator;
20
import eu.etaxonomy.cdm.print.Publisher;
21
import eu.etaxonomy.cdm.print.out.IPublishOutputModule;
22
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
23
import eu.etaxonomy.taxeditor.printpublisher.PrintUtil;
24
import eu.etaxonomy.taxeditor.printpublisher.internal.PrintpublisherPlugin;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

    
27
/**
28
 * <p>AbstractPublishWizard class.</p>
29
 *
30
 * @author n.hoffmann
31
 * @created Apr 1, 2010
32
 * @version 1.0
33
 */
34
public abstract class AbstractPublishWizard extends Wizard implements IExportWizard, IHasPersistableSettings{
35
			
36
	/** Constant <code>PAGE_SERVICE="PAGE_SERVICE"</code> */
37
	public static final String PAGE_SERVICE = "PAGE_SERVICE";
38
	/** Constant <code>PAGE_TAXA="PAGE_TAXA"</code> */
39
	public static final String PAGE_TAXA = "PAGE_TAXA";
40
	/** Constant <code>PAGE_OPTIONS="PAGE_OPTIONS"</code> */
41
	public static final String PAGE_OPTIONS = "PAGE_OPTIONS";
42
	/** Constant <code>PAGE_FOLDER="PAGE_FOLDER"</code> */
43
	public static final String PAGE_FOLDER = "PAGE_FOLDER";
44
	/** Constant <code>PAGE_OVERVIEW="PAGE_OVERVIEW"</code> */
45
	public static final String PAGE_OVERVIEW = "PAGE_OVERVIEW";
46
	/** Constant <code>PAGE_FEATURETREE="PAGE_FEATURETREE"</code> */
47
	public static final String PAGE_FEATURETREE = "PAGE_FEATURETREE";
48
	/** Constant <code>PAGE_STYLESHEET="PAGE_STYLESHEET"</code> */
49
	public static final String PAGE_STYLESHEET = "PAGE_STYLESHEET";
50
		
51
	protected SelectServiceWizardPage pageService;
52
	protected SelectTaxaWizardPage pageTaxa;
53
	protected SelectOptionsWizardPage pageOptions;
54
	protected SelectFeatureTreeWizardPage pageFeatureTree;
55
	protected SelectDirectoryWizardPage pageFolder;
56
	protected SelectStylesheetWizardPage pageStylesheet;
57

    
58
	private PublishConfigurator configurator;
59

    
60
	private IPublishOutputModule outputModule;
61

    
62
	/**
63
	 * <p>Constructor for AbstractPublishWizard.</p>
64
	 */
65
	public AbstractPublishWizard(){		
66
		setNeedsProgressMonitor(true);
67
		setDialogSettings(PrintpublisherPlugin.getDefault().getDialogSettings());
68
	}
69
	
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
72
	 */
73
	/** {@inheritDoc} */
74
	@Override
75
	public boolean performFinish() {
76
		
77
		Job job = new Job("Running Print Publisher") {
78

    
79
			@Override
80
			protected IStatus run(IProgressMonitor monitor) {
81
				monitor.beginTask("Print Publisher", getConfigurator().calculateNumberOfNodes() + 1);
82
				ConversationHolder conversation = null;
83
				try{					
84
					getConfigurator().setProgressMonitor(CdmProgressMonitorAdapter.CreateMonitor(monitor));
85
					
86
					if(getConfigurator().isLocal()){
87
						conversation = CdmStore.createConversation();
88
						// we want to enforce that the session is closed and nothing is 
89
						// instantiated beneath the regular cdmlib-remote object boundaries 
90
						conversation.commit(false);
91
					}
92
					
93
					Publisher.publish(getConfigurator());
94
					
95
				}finally{
96
					monitor.done();
97
					if(conversation != null) conversation.close();
98
					Display.getDefault().asyncExec(new Runnable() {
99
						@Override
100
						public void run() {
101
							MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Print Publisher", "Your document was created.");
102
						}
103
					});
104
				}
105
				return Status.OK_STATUS;
106
			}
107
			
108
		};
109
		
110
		job.setPriority(Job.BUILD);
111
		job.schedule();
112
		
113
		return true;
114
	}
115

    
116
	/** {@inheritDoc} */
117
	@Override
118
	public void addPages() {
119
		super.addPages();
120
		
121
		pageService = new SelectServiceWizardPage(PAGE_SERVICE);
122
		addPage(pageService);
123
				
124
		pageOptions = new SelectOptionsWizardPage(PAGE_OPTIONS);
125
		addPage(pageOptions);
126
		
127
		pageFeatureTree = new SelectFeatureTreeWizardPage(PAGE_FEATURETREE);
128
		addPage(pageFeatureTree);
129
		
130
		pageStylesheet = new SelectStylesheetWizardPage(PAGE_STYLESHEET);
131
		addPage(pageStylesheet);
132

    
133
		pageFolder = new SelectDirectoryWizardPage(PAGE_FOLDER);
134
		addPage(pageFolder);
135
		
136
	}
137
	
138
	@Override
139
	public void loadSettings() {
140
		for(IWizardPage page : getPages()){
141
			if(page instanceof IHasPersistableSettings){
142
				((IHasPersistableSettings) page).loadSettings();
143
			}
144
		}		
145
	}
146
	
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
149
	 */
150
	/** {@inheritDoc} */
151
	public void init(IWorkbench workbench, IStructuredSelection selection) {
152
		PrintUtil.info("Instantiating wizard: " + this.getClass().getSimpleName());
153
	}
154
	
155

    
156
	
157
	/** {@inheritDoc} */
158
	@Override
159
	public boolean canFinish() {
160
		boolean canFinish = true;
161
		
162
		canFinish &= pageService.isPageComplete(); 
163
		
164
		// persistable settings pages
165
		canFinish &= pageFeatureTree.isPageComplete();
166
		canFinish &= pageFolder.isPageComplete();
167
		canFinish &= pageStylesheet.isPageComplete();
168
		
169
		return canFinish;
170
	}
171
	
172
	/**
173
	 * <p>Getter for the field <code>configurator</code>.</p>
174
	 *
175
	 * @return a {@link eu.etaxonomy.cdm.print.PublishConfigurator} object.
176
	 */
177
	protected PublishConfigurator getConfigurator() {
178
		return configurator;
179
	}
180
	
181
	/**
182
	 * <p>Setter for the field <code>configurator</code>.</p>
183
	 *
184
	 * @param configurator a {@link eu.etaxonomy.cdm.print.PublishConfigurator} object.
185
	 */
186
	protected void setConfigurator(PublishConfigurator configurator){
187
		this.configurator = configurator;
188
	}
189
	
190
	/**
191
	 * <p>Setter for the field <code>outputModule</code>.</p>
192
	 *
193
	 * @param outputModule a {@link eu.etaxonomy.cdm.print.out.IPublishOutputModule} object.
194
	 */
195
	protected void setOutputModule(IPublishOutputModule outputModule){
196
		this.outputModule = outputModule;
197
	}
198
	
199
	/**
200
	 * <p>Getter for the field <code>outputModule</code>.</p>
201
	 *
202
	 * @return a {@link eu.etaxonomy.cdm.print.out.IPublishOutputModule} object.
203
	 */
204
	public IPublishOutputModule getOutputModule(){
205
		return outputModule;
206
	}
207
}
(1-1/14)