use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project tdi-studio-se by Talend.
the class CodeView method refresh.
public void refresh() {
ICodeGeneratorService service = DesignerPlugin.getDefault().getCodeGeneratorService();
if (service.isInitializingJet()) {
return;
}
if (isGenerating()) {
return;
}
setGenerating(true);
final List<? extends INode> generatingNodes = selectedNode.getProcess().getGeneratingNodes();
Job job = new //$NON-NLS-1$
Job(//$NON-NLS-1$
Messages.getString("CodeView.initMessage")) {
@Override
protected IStatus run(IProgressMonitor monitor) {
if (selectedNode != null) {
//$NON-NLS-1$
generatedCode = "";
try {
// joblet or joblet node
boolean isJoblet = AbstractProcessProvider.isExtensionProcessForJoblet(selectedNode.getProcess());
if (!isJoblet && PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService jobletSservice = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (jobletSservice != null && jobletSservice.isJobletComponent(selectedNode)) {
isJoblet = true;
}
}
if (isJoblet) {
return org.eclipse.core.runtime.Status.OK_STATUS;
}
generatingNode = null;
for (INode node : generatingNodes) {
if (node.getUniqueName().equals(selectedNode.getUniqueName())) {
generatingNode = node;
}
}
if (generatingNode == null) {
//$NON-NLS-1$
generatedCode = Messages.getString("CodeView.MultipleComponentError");
return org.eclipse.core.runtime.Status.OK_STATUS;
}
ICodeGeneratorService service = DesignerPlugin.getDefault().getCodeGeneratorService();
// have to do this dirty change to avoid the side effect for BD component.
codeGenerator = service.createCodeGenerator(selectedNode.getProcess(), false, false);
viewStartAction.setChecked(false);
viewMainAction.setChecked(false);
viewEndAction.setChecked(false);
viewAllAction.setChecked(false);
switch(codeView) {
case CODE_START:
viewStartAction.setChecked(true);
generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.BEGIN);
break;
case CODE_MAIN:
viewMainAction.setChecked(true);
generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.MAIN);
break;
case CODE_END:
viewEndAction.setChecked(true);
generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.END);
break;
case CODE_ALL:
viewAllAction.setChecked(true);
generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.BEGIN);
generatedCode += codeGenerator.generateComponentCode(generatingNode, ECodePart.MAIN);
generatedCode += codeGenerator.generateComponentCode(generatingNode, ECodePart.END);
break;
default:
}
} catch (SystemException e) {
//$NON-NLS-1$
generatedCode = Messages.getString("CodeView.Error");
ExceptionHandler.process(e);
} catch (Exception e) {
// Some exceptions can appear in case we close some jobs while generating
// Just ignore them, and set blank directly to the code view
//$NON-NLS-1$
generatedCode = "";
}
}
return org.eclipse.core.runtime.Status.OK_STATUS;
}
};
job.setPriority(Job.INTERACTIVE);
job.schedule();
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
new UIJob("") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
document.set(generatedCode);
setGenerating(false);
return org.eclipse.core.runtime.Status.OK_STATUS;
}
}.schedule();
}
});
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project tdi-studio-se by Talend.
the class ModifyExtensionAction method run.
public void run() {
try {
final ModifyExtensionJob job = new ModifyExtensionJob(ExchangeManager.getInstance().getSelectedExtension());
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
updateUI(job, event);
}
});
}
});
ExchangeUtils.scheduleUserJob(job);
} catch (Throwable e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project bndtools by bndtools.
the class BndEditor method doAutoResolveOnSave.
private void doAutoResolveOnSave(IProgressMonitor monitor) {
final Shell shell = getEditorSite().getShell();
final IFile file = ResourceUtil.getFile(getEditorInput());
if (file == null) {
MessageDialog.openError(shell, "Resolution Error", "Unable to run resolution because the file is not in the workspace. NB.: the file will still be saved.");
reallySave(monitor);
return;
}
// Create resolver job and pre-validate
final ResolveJob job = new ResolveJob(model);
IStatus validation = job.validateBeforeRun();
if (!validation.isOK()) {
String message = "Unable to run the resolver. NB.: the file will still be saved.";
ErrorDialog.openError(shell, "Resolution Validation Problem", message, validation, IStatus.ERROR | IStatus.WARNING);
reallySave(monitor);
return;
}
// Add operation to perform at the end of resolution (i.e. display
// results and actually save the file)
final UIJob completionJob = new UIJob(shell.getDisplay(), "Display Resolution Results") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
ResolutionResult result = job.getResolutionResult();
ResolutionWizard wizard = new ResolutionWizard(model, file, result);
if (result.getOutcome() != ResolutionResult.Outcome.Resolved) /*|| !result.getResolve().getOptionalResources().isEmpty() */
{
WizardDialog dialog = new WizardDialog(shell, wizard);
if (dialog.open() != Window.OK) {
if (!wizard.performFinish()) {
MessageDialog.openError(shell, "Error", "Unable to store resolution results into Run Bundles list.");
}
}
} else {
if (!wizard.performFinish()) {
MessageDialog.openError(shell, "Error", "Unable to store resolution results into Run Bundles list.");
}
}
reallySave(monitor);
return Status.OK_STATUS;
}
};
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
completionJob.schedule();
}
});
// Start job
job.setUser(true);
job.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project bndtools by bndtools.
the class BundleCalculatedImportsPart method refresh.
@Override
public void refresh() {
super.refresh();
IFile file = getEditorFile();
if (file == null)
return;
IPath location = file.getLocation();
if (location == null)
return;
Set<BndFileCapReqLoader> loaders = Collections.singleton(new BndFileCapReqLoader(location.toFile()));
final AnalyseBundleResolutionJob job = new AnalyseBundleResolutionJob(Messages.BundleCalculatedImportsPart_jobAnalyse, loaders);
final Display display = tree.getDisplay();
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (job.getResult().isOK()) {
display.asyncExec(new Runnable() {
@Override
public void run() {
if (tree != null && !tree.isDisposed())
viewer.setInput(job.getRequirements());
}
});
}
}
});
job.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project bndtools by bndtools.
the class RunRequirementsPart method doResolve.
private void doResolve() {
// Make sure all the parts of this editor page have committed their
// dirty state to the model
IFormPart[] parts = getManagedForm().getParts();
for (IFormPart part : parts) {
if (part.isDirty())
part.commit(false);
}
final IFormPage page = (IFormPage) getManagedForm().getContainer();
final IEditorInput input = page.getEditorInput();
final IEditorPart editor = page.getEditor();
final IFile file = ResourceUtil.getFile(input);
final Shell parentShell = page.getEditor().getSite().getShell();
// Create the wizard and pre-validate
final ResolveJob job = new ResolveJob(model);
IStatus validation = job.validateBeforeRun();
if (!validation.isOK()) {
ErrorDialog errorDialog = new ErrorDialog(parentShell, "Validation Problem", null, validation, IStatus.ERROR | IStatus.WARNING) {
@Override
protected void createButtonsForButtonBar(Composite parent) {
// create OK, Cancel and Details buttons
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
createDetailsButton(parent);
}
};
int response = errorDialog.open();
if (Window.CANCEL == response || validation.getSeverity() >= IStatus.ERROR) {
btnResolveNow.setEnabled(true);
return;
}
}
// Add the operation to perform at the end of the resolution job (i.e.,
// showing the result)
final Runnable showResult = new Runnable() {
@Override
public void run() {
ResolutionWizard wizard = new ResolutionWizard(model, file, job.getResolutionResult());
WizardDialog dialog = new WizardDialog(parentShell, wizard);
boolean dirtyBeforeResolve = editor.isDirty();
if (dialog.open() == Dialog.OK && !dirtyBeforeResolve) {
// only save the editor, when no unsaved changes happened before resolution
editor.getEditorSite().getPage().saveEditor(editor, false);
}
btnResolveNow.setEnabled(true);
}
};
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
Outcome outcome = job.getResolutionResult().getOutcome();
if (outcome != Outcome.Cancelled)
parentShell.getDisplay().asyncExec(showResult);
}
});
job.setUser(true);
job.schedule();
}
Aggregations