automated build configuration is on its way
[taxeditor.git] / taxeditor-printpublisher / src / main / java / eu / etaxonomy / taxeditor / printpublisher / wizard / AbstractPublishWizard.java
index 9444228555154ae337d80b6d2fcdd06d82ed4eb4..1b50191f3e3442bb6c95ef20fd2ebf37ddba2663 100644 (file)
@@ -3,38 +3,42 @@
  */
 package eu.etaxonomy.taxeditor.printpublisher.wizard;
 
-import java.lang.reflect.InvocationTargetException;
-
-import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.ui.IExportWizard;
 import org.eclipse.ui.IWorkbench;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.print.IHarvestObserver;
 import eu.etaxonomy.cdm.print.PublishConfigurator;
 import eu.etaxonomy.cdm.print.Publisher;
 import eu.etaxonomy.cdm.print.out.IPublishOutputModule;
+import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
- * 
+ * <p>AbstractPublishWizard class.</p>
+ *
  * @author n.hoffmann
  * @created Apr 1, 2010
  * @version 1.0
  */
 public class AbstractPublishWizard extends Wizard implements IExportWizard{
-       private static final Logger logger = Logger
-                       .getLogger(AbstractPublishWizard.class);
        
+       /** Constant <code>PAGE_SERVICE="PAGE_SERVICE"</code> */
        public static final String PAGE_SERVICE = "PAGE_SERVICE";
+       /** Constant <code>PAGE_TAXA="PAGE_TAXA"</code> */
        public static final String PAGE_TAXA = "PAGE_TAXA";
+       /** Constant <code>PAGE_OPTIONS="PAGE_OPTIONS"</code> */
        public static final String PAGE_OPTIONS = "PAGE_OPTIONS";
+       /** Constant <code>PAGE_FOLDER="PAGE_FOLDER"</code> */
        public static final String PAGE_FOLDER = "PAGE_FOLDER";
+       /** Constant <code>PAGE_OVERVIEW="PAGE_OVERVIEW"</code> */
        public static final String PAGE_OVERVIEW = "PAGE_OVERVIEW";
+       /** Constant <code>PAGE_FEATURETREE="PAGE_FEATURETREE"</code> */
        public static final String PAGE_FEATURETREE = "PAGE_FEATURETREE";
        
        protected SelectServiceWizardPage pageService;
@@ -48,6 +52,9 @@ public class AbstractPublishWizard extends Wizard implements IExportWizard{
 
        private IPublishOutputModule outputModule;
 
+       /**
+        * <p>Constructor for AbstractPublishWizard.</p>
+        */
        public AbstractPublishWizard(){         
                setNeedsProgressMonitor(true);
        }
@@ -55,54 +62,41 @@ public class AbstractPublishWizard extends Wizard implements IExportWizard{
        /* (non-Javadoc)
         * @see org.eclipse.jface.wizard.Wizard#performFinish()
         */
+       /** {@inheritDoc} */
        @Override
        public boolean performFinish() {
                
-               IRunnableWithProgress runnable = new IRunnableWithProgress() {
+               Job job = new Job("Running Print Publisher") {
 
-                       public void run(final IProgressMonitor monitor)
-                                       throws InvocationTargetException, InterruptedException {
-                               monitor.beginTask("Exporting Printable Output", getConfigurator().calculateNumberOfNodes() + 1);
-                               try{
-                                       IHarvestObserver observer = new IHarvestObserver() {
-                                               
-                                               public void update(String taskName) {
-                                                       monitor.setTaskName(taskName);
-                                                       monitor.worked(1);
-                                                       
-                                               }
-                                       };
-                                       getConfigurator().addObserver(observer);
+                       @Override
+                       protected IStatus run(IProgressMonitor monitor) {
+                               monitor.beginTask("Print Publisher", getConfigurator().calculateNumberOfNodes() + 1);
+                               ConversationHolder conversation = null;
+                               try{                                    
+                                       getConfigurator().setProgressMonitor(CdmProgressMonitorAdapter.CreateMonitor(monitor));
+                                       
+                                       if(getConfigurator().isLocal()){
+                                               conversation= CdmStore.createConversation();
+                                       }
+                                       
+                                       Publisher.publish(getConfigurator());
                                        
-                                       Publisher.publish(configurator);
                                }finally{
                                        monitor.done();
+                                       if(conversation != null) conversation.close();
                                }
-                               
-                       }                       
-               };
-               
-               ConversationHolder conversation = null;
-               
-               try {
-                       if(getConfigurator().isLocal()){
-                               conversation= CdmStore.createConversation();
+                               return Status.OK_STATUS;
                        }
-                       getContainer().run(false, true, runnable);
                        
-               } catch (InvocationTargetException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (InterruptedException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }finally{
-                       if(conversation != null) conversation.close();
-               }
+               };
+               
+               job.setPriority(Job.BUILD);
+               job.schedule();
                
                return true;
        }
 
+       /** {@inheritDoc} */
        @Override
        public void addPages() {
                super.addPages();
@@ -129,12 +123,14 @@ public class AbstractPublishWizard extends Wizard implements IExportWizard{
        /* (non-Javadoc)
         * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
         */
+       /** {@inheritDoc} */
        public void init(IWorkbench workbench, IStructuredSelection selection) {
-               logger.warn("Instantiating wizard: " + this.getClass().getSimpleName());
+               PrintUtil.info("Instantiating wizard: " + this.getClass().getSimpleName());
        }
        
 
        
+       /** {@inheritDoc} */
        @Override
        public boolean canFinish() {
                return pageService.isPageComplete() && 
@@ -143,18 +139,38 @@ public class AbstractPublishWizard extends Wizard implements IExportWizard{
                                pageFolder.isPageComplete();
        }
        
+       /**
+        * <p>Getter for the field <code>configurator</code>.</p>
+        *
+        * @return a {@link eu.etaxonomy.cdm.print.PublishConfigurator} object.
+        */
        protected PublishConfigurator getConfigurator() {
                return configurator;
        }
        
+       /**
+        * <p>Setter for the field <code>configurator</code>.</p>
+        *
+        * @param configurator a {@link eu.etaxonomy.cdm.print.PublishConfigurator} object.
+        */
        protected void setConfigurator(PublishConfigurator configurator){
                this.configurator = configurator;
        }
        
+       /**
+        * <p>Setter for the field <code>outputModule</code>.</p>
+        *
+        * @param outputModule a {@link eu.etaxonomy.cdm.print.out.IPublishOutputModule} object.
+        */
        protected void setOutputModule(IPublishOutputModule outputModule){
                this.outputModule = outputModule;
        }
        
+       /**
+        * <p>Getter for the field <code>outputModule</code>.</p>
+        *
+        * @return a {@link eu.etaxonomy.cdm.print.out.IPublishOutputModule} object.
+        */
        public IPublishOutputModule getOutputModule(){
                return outputModule;
        }