use of org.eclipse.ui.progress.IProgressService in project tmdm-studio-se by Talend.
the class ImportDataContentProcess method processDatas.
/*
* (non-Javadoc)
*
* @see org.talend.mdm.repository.core.datacontent.IDataContentProcess#processDatas(org.talend.mdm.repository.core.
* datacontent.DataProcessRule, org.eclipse.core.runtime.IProgressMonitor)
*/
public void processDatas(DataProcessRule rule) throws InterruptedException, InvocationTargetException {
IProgressService progressService = getProcessService();
ImportProcess process = new ImportProcess(rule);
progressService.run(true, true, process);
}
use of org.eclipse.ui.progress.IProgressService in project tdi-studio-se by Talend.
the class DebugProcessTosComposite method debug.
@Override
public void debug() {
if (manager.getClearBeforeExec()) {
processContext.clearMessages();
}
setHideconsoleLine(false);
if ((processContext.getProcess()) instanceof org.talend.designer.core.ui.editor.process.Process) {
((org.talend.designer.core.ui.editor.process.Process) processContext.getProcess()).checkDifferenceWithRepository();
}
// final IPreferenceStore preferenceStore = DebugUIPlugin.getDefault().getPreferenceStore();
final IPreferenceStore preferenceStore = DebugUITools.getPreferenceStore();
final boolean oldValueConsoleOnOut = preferenceStore.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT);
final boolean oldValueConsoleOnErr = preferenceStore.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR);
preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, false);
preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, false);
// java debug to collect when tos
int num = RunProcessPlugin.getDefault().getPreferenceStore().getInt(RunProcessTokenCollector.TOS_COUNT_DEBUG_RUNS.getPrefKey());
RunProcessPlugin.getDefault().getPreferenceStore().setValue(RunProcessTokenCollector.TOS_COUNT_DEBUG_RUNS.getPrefKey(), num + 1);
checkSaveBeforeRunSelection();
if (contextComposite.promptConfirmLauch()) {
setRunnable(false);
final IContext context = contextComposite.getSelectedContext();
IRunnableWithProgress worker = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
IProcessor processor = ProcessorUtilities.getProcessor(processContext.getProcess(), processContext.getProcess().getProperty(), context);
//$NON-NLS-1$
monitor.beginTask("Launching debugger", IProgressMonitor.UNKNOWN);
try {
// use this function to generate childrens also.
ProcessorUtilities.generateCode(processContext.getProcess(), context, false, false, true, monitor);
ILaunchConfiguration config = ((Processor) processor).getDebugConfiguration(processContext.getStatisticsPort(), processContext.getTracesPort(), null);
// code is correct before launching
if (!JobErrorsChecker.hasErrors(DebugProcessTosComposite.this.getShell())) {
if (config != null) {
// PlatformUI.getWorkbench().
// getActiveWorkbenchWindow
// ().addPerspectiveListener(new
// DebugInNewWindowListener());
DebugUITools.launch(config, ILaunchManager.DEBUG_MODE);
} else {
//$NON-NLS-1$
MessageDialog.openInformation(//$NON-NLS-1$
getShell(), //$NON-NLS-1$
Messages.getString("ProcessDebugDialog.debugBtn"), //$NON-NLS-1$
Messages.getString("ProcessDebugDialog.errortext"));
}
}
} catch (ProcessorException e) {
IStatus status = new Status(IStatus.ERROR, RunProcessPlugin.PLUGIN_ID, IStatus.OK, "Debug launch failed.", //$NON-NLS-1$
e);
RunProcessPlugin.getDefault().getLog().log(status);
//$NON-NLS-1$ //$NON-NLS-2$
MessageDialog.openError(getShell(), Messages.getString("ProcessDebugDialog.debugBtn"), "");
} finally {
monitor.done();
}
}
};
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.runInUI(PlatformUI.getWorkbench().getProgressService(), worker, ResourcesPlugin.getWorkspace().getRoot());
} catch (InvocationTargetException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
} catch (InterruptedException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
debugMode = true;
try {
Thread thread = new Thread() {
@Override
public void run() {
while (debugMode) {
final IProcess process = DebugUITools.getCurrentProcess();
if (process != null && process.isTerminated()) {
Display dis = Display.getCurrent();
if (dis == null) {
dis = Display.getDefault();
}
dis.asyncExec(new Runnable() {
@Override
public void run() {
setRunnable(true);
if (!killBtn.isDisposed() && killBtn != null) {
killBtn.setEnabled(false);
}
preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, oldValueConsoleOnOut);
preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, oldValueConsoleOnErr);
if (isAddedStreamListener) {
process.getStreamsProxy().getOutputStreamMonitor().removeListener(streamListener);
isAddedStreamListener = false;
if (processContext.isRunning()) {
//$NON-NLS-1$
final String endingPattern = Messages.getString("ProcessComposite.endPattern");
MessageFormat mf = new MessageFormat(endingPattern);
String byeMsg;
try {
byeMsg = //$NON-NLS-1$
"\n" + mf.format(new Object[] { processContext.getProcess().getName(), new Date(), new Integer(process.getExitValue()) });
processContext.addDebugResultToConsole(new ProcessMessage(MsgType.CORE_OUT, byeMsg));
} catch (DebugException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
processContext.setRunning(false);
}
}
debugMode = false;
}
});
} else {
if (process != null) {
// (one at leat) process
// still running
Display dis = Display.getCurrent();
if (dis == null) {
dis = Display.getDefault();
}
dis.asyncExec(new Runnable() {
@Override
public void run() {
setRunnable(false);
if (!killBtn.isDisposed() && killBtn != null) {
killBtn.setEnabled(true);
}
processContext.setRunning(true);
processContext.setDebugProcess(process);
if (!isAddedStreamListener) {
process.getStreamsProxy().getOutputStreamMonitor().addListener(streamListener);
// if (clearBeforeExec.getSelection()) {
// processContext.clearMessages();
// }
// if (watchBtn.getSelection()) {
// processContext.switchTime();
// }
ClearPerformanceAction clearPerfAction = new ClearPerformanceAction();
clearPerfAction.setProcess(processContext.getProcess());
clearPerfAction.run();
ClearTraceAction clearTraceAction = new ClearTraceAction();
clearTraceAction.setProcess(processContext.getProcess());
clearTraceAction.run();
isAddedStreamListener = true;
//$NON-NLS-1$
final String startingPattern = Messages.getString("ProcessComposite.startPattern");
MessageFormat mf = new MessageFormat(startingPattern);
String welcomeMsg = mf.format(new Object[] { processContext.getProcess().getName(), new Date() });
processContext.addDebugResultToConsole(new ProcessMessage(MsgType.CORE_OUT, //$NON-NLS-1$
welcomeMsg + "\r\n"));
}
}
});
} else {
// no process running
Display dis = Display.getCurrent();
if (dis == null) {
dis = Display.getDefault();
}
dis.asyncExec(new Runnable() {
@Override
public void run() {
setRunnable(true);
if (!killBtn.isDisposed() && killBtn != null) {
killBtn.setEnabled(false);
}
}
});
}
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
}
};
thread.start();
} catch (Exception e) {
ExceptionHandler.process(e);
processContext.addErrorMessage(e);
kill();
}
}
use of org.eclipse.ui.progress.IProgressService in project tdi-studio-se by Talend.
the class ProcessComposite method debug.
public void debug() {
setHideconsoleLine(false);
if ((processContext.getProcess()) instanceof org.talend.designer.core.ui.editor.process.Process) {
((org.talend.designer.core.ui.editor.process.Process) processContext.getProcess()).checkDifferenceWithRepository();
}
// final IPreferenceStore preferenceStore = DebugUIPlugin.getDefault().getPreferenceStore();
final IPreferenceStore preferenceStore = DebugUITools.getPreferenceStore();
final boolean oldValueConsoleOnOut = preferenceStore.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT);
final boolean oldValueConsoleOnErr = preferenceStore.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR);
preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, false);
preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, false);
checkSaveBeforeRunSelection();
if (contextComposite.promptConfirmLauch()) {
setRunnable(false);
final IContext context = contextComposite.getSelectedContext();
IRunnableWithProgress worker = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
IProcessor processor = ProcessorUtilities.getProcessor(processContext.getProcess(), processContext.getProcess().getProperty(), context);
//$NON-NLS-1$
monitor.beginTask("Launching debugger", IProgressMonitor.UNKNOWN);
try {
// use this function to generate childrens also.
ProcessorUtilities.generateCode(processContext.getProcess(), context, false, false, true, monitor);
ILaunchConfiguration config = ((Processor) processor).getDebugConfiguration(processContext.getStatisticsPort(), processContext.getTracesPort(), null);
// code is correct before launching
if (!JobErrorsChecker.hasErrors(ProcessComposite.this.getShell())) {
if (config != null) {
// PlatformUI.getWorkbench().
// getActiveWorkbenchWindow
// ().addPerspectiveListener(new
// DebugInNewWindowListener());
DebugUITools.launch(config, ILaunchManager.DEBUG_MODE);
} else {
//$NON-NLS-1$
MessageDialog.openInformation(//$NON-NLS-1$
getShell(), //$NON-NLS-1$
Messages.getString("ProcessDebugDialog.debugBtn"), //$NON-NLS-1$
Messages.getString("ProcessDebugDialog.errortext"));
}
}
} catch (ProcessorException e) {
IStatus status = new Status(IStatus.ERROR, RunProcessPlugin.PLUGIN_ID, IStatus.OK, "Debug launch failed.", //$NON-NLS-1$
e);
RunProcessPlugin.getDefault().getLog().log(status);
//$NON-NLS-1$ //$NON-NLS-2$
MessageDialog.openError(getShell(), Messages.getString("ProcessDebugDialog.debugBtn"), "");
} finally {
monitor.done();
}
}
};
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.runInUI(PlatformUI.getWorkbench().getProgressService(), worker, ResourcesPlugin.getWorkspace().getRoot());
} catch (InvocationTargetException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
} catch (InterruptedException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
debugMode = true;
try {
Thread thread = new Thread() {
@Override
public void run() {
while (debugMode) {
final IProcess process = DebugUITools.getCurrentProcess();
if (process != null && process.isTerminated()) {
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
setRunnable(true);
killBtn.setEnabled(false);
preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, oldValueConsoleOnOut);
preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, oldValueConsoleOnErr);
if (isAddedStreamListener) {
process.getStreamsProxy().getOutputStreamMonitor().removeListener(streamListener);
isAddedStreamListener = false;
if (processContext.isRunning()) {
//$NON-NLS-1$
final String endingPattern = Messages.getString("ProcessComposite.endPattern");
MessageFormat mf = new MessageFormat(endingPattern);
String byeMsg;
try {
byeMsg = //$NON-NLS-1$
"\n" + mf.format(new Object[] { processContext.getProcess().getName(), new Date(), new Integer(process.getExitValue()) });
processContext.addDebugResultToConsole(new ProcessMessage(MsgType.CORE_OUT, byeMsg));
} catch (DebugException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
processContext.setRunning(false);
}
}
debugMode = false;
}
});
} else {
if (process != null) {
// (one at leat) process
// still running
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
setRunnable(false);
killBtn.setEnabled(true);
processContext.setRunning(true);
processContext.setDebugProcess(process);
if (!isAddedStreamListener) {
process.getStreamsProxy().getOutputStreamMonitor().addListener(streamListener);
// if (clearBeforeExec.getSelection()) {
// processContext.clearMessages();
// }
// if (watchBtn.getSelection()) {
// processContext.switchTime();
// }
ClearPerformanceAction clearPerfAction = new ClearPerformanceAction();
clearPerfAction.setProcess(processContext.getProcess());
clearPerfAction.run();
ClearTraceAction clearTraceAction = new ClearTraceAction();
clearTraceAction.setProcess(processContext.getProcess());
clearTraceAction.run();
isAddedStreamListener = true;
//$NON-NLS-1$
final String startingPattern = Messages.getString("ProcessComposite.startPattern");
MessageFormat mf = new MessageFormat(startingPattern);
String welcomeMsg = mf.format(new Object[] { processContext.getProcess().getName(), new Date() });
processContext.addDebugResultToConsole(new ProcessMessage(MsgType.CORE_OUT, //$NON-NLS-1$
welcomeMsg + "\r\n"));
}
}
});
} else {
// no process running
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
setRunnable(true);
killBtn.setEnabled(false);
}
});
}
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
}
};
thread.start();
} catch (Exception e) {
ExceptionHandler.process(e);
processContext.addErrorMessage(e);
kill();
}
}
use of org.eclipse.ui.progress.IProgressService in project tdi-studio-se by Talend.
the class ProcessDebugDialog method okPressed.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override
protected void okPressed() {
if (contextComposite.promptConfirmLauch()) {
final IContext context = contextComposite.getSelectedContext();
super.okPressed();
IRunnableWithProgress worker = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
IProcessor processor = ProcessorUtilities.getProcessor(process, process.getProperty(), context);
//$NON-NLS-1$
monitor.beginTask("Launching debugger", IProgressMonitor.UNKNOWN);
try {
// use this function to generate childrens also.
ProcessorUtilities.generateCode(process, context, false, false, true, monitor);
ILaunchConfiguration config = ((IEclipseProcessor) processor).debug();
if (config != null) {
// PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new
// DebugInNewWindowListener());
DebugUITools.launch(config, ILaunchManager.DEBUG_MODE);
} else {
MessageDialog.openInformation(getShell(), Messages.getString("ProcessDebugDialog.debugBtn"), //$NON-NLS-1$
Messages.getString(//$NON-NLS-1$ //$NON-NLS-2$
"ProcessDebugDialog.errortext"));
}
} catch (ProcessorException e) {
IStatus status = new Status(IStatus.ERROR, RunProcessPlugin.PLUGIN_ID, IStatus.OK, "Debug launch failed.", //$NON-NLS-1$
e);
RunProcessPlugin.getDefault().getLog().log(status);
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
getShell(), //$NON-NLS-1$
Messages.getString("ProcessDebugDialog.debugBtn"), //$NON-NLS-1$
"");
} finally {
monitor.done();
}
}
};
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.runInUI(PlatformUI.getWorkbench().getProgressService(), worker, ResourcesPlugin.getWorkspace().getRoot());
} catch (InvocationTargetException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
} catch (InterruptedException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
}
use of org.eclipse.ui.progress.IProgressService in project tdi-studio-se by Talend.
the class RunProcessContext method exec.
/**
* Launch the process.
*/
public void exec(final Shell shell) {
if (process instanceof org.talend.designer.core.ui.editor.process.Process) {
org.talend.designer.core.ui.editor.process.Process prs = (org.talend.designer.core.ui.editor.process.Process) process;
prs.checkDifferenceWithRepository();
}
checkTraces();
if (ProcessContextComposite.promptConfirmLauch(shell, getSelectedContext(), process)) {
if (getSelectedTargetExecutionConfig() == null || !getSelectedTargetExecutionConfig().isRemote()) {
// tos run to collect
IPreferenceStore preferenceStore = RunProcessPlugin.getDefault().getPreferenceStore();
int num = preferenceStore.getInt(RunProcessTokenCollector.TOS_COUNT_RUNS.getPrefKey());
preferenceStore.setValue(RunProcessTokenCollector.TOS_COUNT_RUNS.getPrefKey(), num + 1);
}
ClearPerformanceAction clearPerfAction = new ClearPerformanceAction();
clearPerfAction.setProcess(process);
clearPerfAction.run();
ClearTraceAction clearTraceAction = new ClearTraceAction();
clearTraceAction.setProcess(process);
clearTraceAction.run();
if (monitorPerf) {
this.getStatisticsPort();
}
final IProcessor processor = getProcessor(process, process.getProperty());
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.run(false, true, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) {
final IProgressMonitor progressMonitor = new EventLoopProgressMonitor(monitor);
//$NON-NLS-1$
progressMonitor.beginTask(Messages.getString("ProcessComposite.buildTask"), IProgressMonitor.UNKNOWN);
testPort();
// findNewStatsPort();
if (monitorPerf || monitorTrace) {
if (traceConnectionsManager != null) {
traceConnectionsManager.clear();
}
traceConnectionsManager = getTraceConnectionsManager(process);
traceConnectionsManager.init();
}
final IContext context = getSelectedContext();
if (monitorPerf) {
clearThreads();
perfMonitor = getPerformanceMonitor();
//$NON-NLS-1$
new Thread(perfMonitor, "PerfMonitor_" + process.getLabel()).start();
perMonitorList.add(perfMonitor);
}
// findNewTracesPort();
if (monitorTrace) {
traceMonitor = new TraceMonitor();
//$NON-NLS-1$
new Thread(traceMonitor, "TraceMonitor_" + process.getLabel()).start();
}
final String watchParam = RunProcessContext.this.isWatchAllowed() ? TalendProcessArgumentConstant.CMD_ARG_WATCH : null;
final String log4jRuntimeLevel = getLog4jRuntimeLevel();
processor.setContext(context);
((IEclipseProcessor) processor).setTargetExecutionConfig(getSelectedTargetExecutionConfig());
final boolean oldMeasureActived = TimeMeasure.measureActive;
if (!oldMeasureActived) {
// not active before.
TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
}
//$NON-NLS-1$
final String generateCodeId = "Generate job source codes and compile before run";
TimeMeasure.begin(generateCodeId);
try {
ProcessorUtilities.generateCode(processor, process, context, getStatisticsPort() != IProcessor.NO_STATISTICS, getTracesPort() != IProcessor.NO_TRACES && hasConnectionTrace(), true, progressMonitor);
} catch (Throwable e) {
// catch any Exception or Error to kill the process,
// see bug 0003567
running = true;
ExceptionHandler.process(e);
kill();
} finally {
progressMonitor.done();
// System.out.println("exitValue:" +
// ps.exitValue());
}
TimeMeasure.end(generateCodeId);
// if active before, not disable and active still.
if (!oldMeasureActived) {
TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = false;
}
final boolean[] refreshUiAndWait = new boolean[1];
refreshUiAndWait[0] = true;
final Display display = shell.getDisplay();
new Thread(new Runnable() {
@Override
public void run() {
display.syncExec(new Runnable() {
@Override
public void run() {
try {
startingMessageWritten = false;
// before launching
if (!JobErrorsChecker.hasErrors(shell)) {
ps = processor.run(getStatisticsPort(), getTracesPort(), watchParam, log4jRuntimeLevel, progressMonitor, processMessageManager);
}
if (ps != null && !progressMonitor.isCanceled()) {
setRunning(true);
psMonitor = createProcessMonitor(ps);
startingMessageWritten = true;
final String startingPattern = Messages.getString(//$NON-NLS-1$
"ProcessComposite.startPattern");
MessageFormat mf = new MessageFormat(startingPattern);
String welcomeMsg = mf.format(new Object[] { process.getLabel(), new Date() });
processMessageManager.addMessage(new ProcessMessage(MsgType.CORE_OUT, //$NON-NLS-1$
welcomeMsg + "\r\n"));
processMonitorThread = new Thread(psMonitor);
processMonitorThread.start();
} else {
kill();
running = true;
setRunning(false);
}
} catch (Throwable e) {
// catch any Exception or Error
// to kill the process, see bug
// 0003567
running = true;
Throwable cause = e.getCause();
if (cause != null && cause.getClass().equals(InterruptedException.class)) {
setRunning(false);
addErrorMessage(e);
} else {
ExceptionHandler.process(e);
addErrorMessage(e);
kill();
}
} finally {
// progressMonitor.done();
refreshUiAndWait[0] = false;
}
}
});
}
}, "RunProcess_" + process.getLabel()).start();
while (refreshUiAndWait[0] && !progressMonitor.isCanceled()) {
if (!display.readAndDispatch()) {
display.sleep();
}
synchronized (this) {
try {
final long waitTime = 50;
wait(waitTime);
} catch (InterruptedException e) {
// Do nothing
}
}
}
}
});
} catch (InvocationTargetException e1) {
addErrorMessage(e1);
} catch (InterruptedException e1) {
addErrorMessage(e1);
}
} else {
// See bug 0003567: When a prompt from context is cancelled or a
// fatal error occurs during a job exec the
// Kill button have to be pressed manually.
this.running = true;
setRunning(false);
}
}
Aggregations