1 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 name) { 50 super(name); 51 fInfo = info; 52 setRule(ResourcesPlugin.getWorkspace().getRoot()); 53 } 54 55 protected IStatus run(IProgressMonitor monitor) { 56 String 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 () { 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); done(new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, "", null)); } 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 em = errorMessage; 78 getStandardDisplay().asyncExec(new Runnable () { 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); } 87 88 protected FeatureExportOperation createOperation() { 89 return new FeatureExportOperation(fInfo); 90 } 91 92 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 errorMessage) { 105 getStandardDisplay().beep(); 106 MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.FeatureExportJob_error, errorMessage); 107 done(new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, "", null)); } 109 110 protected String getLogFoundMessage() { 111 return NLS.bind(PDEUIMessages.ExportJob_error_message, fInfo.destinationDirectory); 112 } 113 114 } 115 | Popular Tags |