KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > build > FeatureExportJob


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.build;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.resources.ResourcesPlugin;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.MultiStatus;
19 import org.eclipse.core.runtime.Status;
20 import org.eclipse.core.runtime.jobs.ISchedulingRule;
21 import org.eclipse.core.runtime.jobs.Job;
22 import org.eclipse.jface.dialogs.ErrorDialog;
23 import org.eclipse.jface.dialogs.MessageDialog;
24 import org.eclipse.osgi.util.NLS;
25 import org.eclipse.pde.internal.core.exports.FeatureExportInfo;
26 import org.eclipse.pde.internal.core.exports.FeatureExportOperation;
27 import org.eclipse.pde.internal.ui.PDEPlugin;
28 import org.eclipse.pde.internal.ui.PDEUIMessages;
29 import org.eclipse.swt.widgets.Display;
30
31 public class FeatureExportJob extends Job {
32     
33     class SchedulingRule implements ISchedulingRule {
34         public boolean contains(ISchedulingRule rule) {
35             return rule instanceof SchedulingRule || rule instanceof IResource;
36         }
37
38         public boolean isConflicting(ISchedulingRule rule) {
39             return rule instanceof SchedulingRule;
40         }
41     }
42
43     protected FeatureExportInfo fInfo;
44
45     public FeatureExportJob(FeatureExportInfo info) {
46         this(info, PDEUIMessages.FeatureExportJob_name);
47     }
48     
49     protected FeatureExportJob(FeatureExportInfo info, String JavaDoc name) {
50         super(name);
51         fInfo = info;
52         setRule(ResourcesPlugin.getWorkspace().getRoot());
53     }
54
55     protected IStatus run(IProgressMonitor monitor) {
56         String JavaDoc errorMessage = null;
57         FeatureExportOperation op = createOperation();
58         try {
59             op.run(monitor);
60         } catch (final CoreException e) {
61             final Display display = getStandardDisplay();
62             display.asyncExec(new Runnable JavaDoc() {
63                 public void run() {
64                     MultiStatus status =
65                         new MultiStatus(e.getStatus().getPlugin(), e.getStatus().getCode(), new IStatus[] { e.getStatus() }, PDEUIMessages.FeatureExportJob_problems, e);
66                     ErrorDialog.openError(display.getActiveShell(), PDEUIMessages.FeatureExportJob_error, PDEUIMessages.FeatureExportJob_error, status); //
67
done(new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, "", null)); //$NON-NLS-1$
68
}
69             });
70             return Job.ASYNC_FINISH;
71         }
72         
73         if (errorMessage == null && op.hasErrors())
74             errorMessage = getLogFoundMessage();
75         
76         if (errorMessage != null) {
77             final String JavaDoc em = errorMessage;
78             getStandardDisplay().asyncExec(new Runnable JavaDoc() {
79                 public void run() {
80                     asyncNotifyExportException(em);
81                 }
82             });
83             return Job.ASYNC_FINISH;
84         }
85         return new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
86
}
87     
88     protected FeatureExportOperation createOperation() {
89         return new FeatureExportOperation(fInfo);
90     }
91     
92     /**
93      * Returns the standard display to be used. The method first checks, if the
94      * thread calling this method has an associated disaply. If so, this display
95      * is returned. Otherwise the method returns the default display.
96      */

97     public static Display getStandardDisplay() {
98         Display display = Display.getCurrent();
99         if (display == null)
100             display = Display.getDefault();
101         return display;
102     }
103
104     private void asyncNotifyExportException(String JavaDoc errorMessage) {
105         getStandardDisplay().beep();
106         MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.FeatureExportJob_error, errorMessage);
107         done(new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, "", null)); //$NON-NLS-1$
108
}
109
110     protected String JavaDoc getLogFoundMessage() {
111         return NLS.bind(PDEUIMessages.ExportJob_error_message, fInfo.destinationDirectory);
112     }
113
114 }
115
Popular Tags