use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class VersionManagementPage method updateItemsVersion.
@Override
protected void updateItemsVersion() {
final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
RepositoryWorkUnit<Object> rwu = new RepositoryWorkUnit<Object>(project, "Update items version") {
@Override
protected void run() throws LoginException, PersistenceException {
//$NON-NLS-1$
monitor.beginTask("Update items version", checkedObjects.size());
Map<String, String> versions = new HashMap<String, String>();
for (int i = 0; i < checkedObjects.size(); i++) {
ItemVersionObject object = checkedObjects.get(i);
versions.put(object.getItem().getProperty().getId(), object.getOldVersion());
}
for (ItemVersionObject object : checkedObjects) {
IRepositoryViewObject repositoryObject = object.getRepositoryNode().getObject();
if (repositoryObject != null && repositoryObject.getProperty() != null) {
if (!object.getNewVersion().equals(repositoryObject.getVersion())) {
final Item item = object.getItem();
Property itemProperty = item.getProperty();
itemProperty.setVersion(object.getNewVersion());
monitor.subTask(itemProperty.getLabel());
try {
// for bug 12853 ,version management doesn't work for joblet because eResource
// is null
IRepositoryViewObject obj = null;
if (itemProperty.eResource() == null) {
ItemState state = item.getState();
if (state != null && state.getPath() != null) {
obj = FACTORY.getLastVersion(project, itemProperty.getId(), state.getPath(), object.getRepositoryNode().getObjectType());
} else {
obj = FACTORY.getLastVersion(project, itemProperty.getId());
}
}
if (obj != null) {
// obj.setVersion(object.getNewVersion());
FACTORY.save(project, obj.getProperty());
builder.addOrUpdateItem(obj.getProperty().getItem(), true);
} else {
String id = itemProperty.getId();
FACTORY.save(project, itemProperty);
if (versionLatest.getSelection()) {
builder.updateItemVersion(item, object.getOldVersion(), id, versions, true);
}
builder.addOrUpdateItem(item, true);
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
monitor.worked(1);
}
try {
FACTORY.saveProject(project);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
};
rwu.setAvoidUnloadResources(true);
rwu.executeRun();
monitor.done();
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all notification
// of changes before the end of the modifications.
workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
};
// final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(null);
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class GuessSchemaController method useMockJob.
private void useMockJob() {
/*
* get the select node,it's the input node of the process. then transfer selected context varriable to
* openContextChooseDialog, added by hyWang
*/
final IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
final Shell parentShell = this.composite.getShell();
final Node inputNode = (Node) this.curParameter.getElement();
if (connParameters == null) {
initConnectionParameters();
}
final String tmpMemoSql = this.memoSQL;
final DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
IMetadataConnection iMetadataConnection = null;
boolean isStatus = false;
try {
if (connt != null) {
iMetadataConnection = ConvertionHelper.convert(connt);
isStatus = checkConnection(iMetadataConnection);
}
if (isStatus) {
if (EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(iMetadataConnection.getDbType())) {
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getAdditionalParams());
} else if (EDatabaseTypeName.HIVE.getDisplayName().equals(iMetadataConnection.getDbType())) {
String jobTracker = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL)));
String nameNode = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL)));
String thrifturi = null;
if (HiveModeInfo.get(iMetadataConnection.getDbVersionString()) == HiveModeInfo.EMBEDDED) {
thrifturi = "thrift://" + iMetadataConnection.getServerName() + ":" + iMetadataConnection.getPort();
}
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), jobTracker, nameNode, thrifturi, iMetadataConnection.getDriverJarPath());
String hiveServerVersion = String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.HIVE_SERVER_VERSION));
//$NON-NLS-1$
String driverClass = "";
if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServerVersion)) {
driverClass = EDatabase4DriverClassName.HIVE2.getDriverClass();
} else {
driverClass = EDatabase4DriverClassName.HIVE.getDriverClass();
}
info.setDriverClassName(driverClass);
} else {
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverJarPath());
}
final Property property = GuessSchemaProcess.getNewmockProperty();
List<IContext> allcontexts = inputNode.getProcess().getContextManager().getListContext();
OpenContextChooseComboDialog dialog = new OpenContextChooseComboDialog(parentShell, allcontexts);
dialog.create();
dialog.getShell().setText(CONTEXT_CHOOSE_DIALOG_TITLE);
IContext selectContext = null;
// job only have defoult context,or the query isn't context mode
if (allcontexts.size() == 1 || TalendTextUtils.isCommonString(tmpMemoSql)) {
selectContext = inputNode.getProcess().getContextManager().getDefaultContext();
} else if (Window.OK == dialog.open()) {
selectContext = dialog.getSelectedContext();
}
final IContext context = selectContext;
if (context != null) {
//
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
pmd.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
runShadowProcess(property, inputNode, context, switchParam);
}
});
}
});
}
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = Messages.getString("GuessSchemaController.connectionFailed");
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(composite.getShell(), part.getProcess().getContextManager());
}
}
});
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
// else {
// try {
// pmd2.run(true, true, new IRunnableWithProgress() {
// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Display.getDefault().asyncExec(new Runnable() {
//
// public void run() {
// String pid = SqlBuilderPlugin.PLUGIN_ID;
// String mainMsg = Messages.getString("GuessSchemaController.connectionFailed"); //$NON-NLS-1$
// ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite
// .getShell(), pid, mainMsg, connParameters.getConnectionComment());
// if (dialog.getCodeOfButton() == Window.OK) {
// openParamemerDialog(composite.getShell(), part.getTalendEditor().getProcess().getContextManager());
// }
// }
// });
// }
// });
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class JobHierarchyLifeCycle method ensureRefreshedTypeHierarchy.
public void ensureRefreshedTypeHierarchy(final IProcess2 element, IRunnableContext context) throws InvocationTargetException, InterruptedException {
if (element == null) {
freeHierarchy();
return;
}
// boolean hierachyCreationNeeded = (fHierarchy == null || !element.equals(inputProcess));
boolean hierachyCreationNeeded = true;
if (hierachyCreationNeeded || fHierarchyRefreshNeeded) {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException {
try {
doHierarchyRefresh(element, pm);
} catch (JavaModelException e) {
throw new InvocationTargetException(e);
} catch (OperationCanceledException e) {
throw new InterruptedException();
}
}
};
fHierarchyRefreshNeeded = true;
context.run(true, true, op);
fHierarchyRefreshNeeded = false;
}
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class DeleteAllJobWhenStartUp method earlyStartup.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IStartup#earlyStartup()
*/
@Override
public void earlyStartup() {
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
return;
}
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject codeProject = root.getProject(TalendMavenConstants.PROJECT_NAME);
if (!codeProject.exists() || !codeProject.isAccessible()) {
return;
}
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendJavaProject = processService.getTalendProcessJavaProject();
if (talendJavaProject != null) {
IJavaProject jProject = talendJavaProject.getJavaProject();
if (!jProject.isOpen()) {
jProject.open(monitor);
}
// empty the src/main/java...
IFolder srcFolder = talendJavaProject.getSrcFolder();
talendJavaProject.cleanFolder(monitor, srcFolder);
// contexts
IFolder resourcesFolder = talendJavaProject.getResourcesFolder();
emptyContexts(monitor, resourcesFolder, talendJavaProject);
// empty the outputs, target
IFolder targetFolder = talendJavaProject.getTargetFolder();
talendJavaProject.cleanFolder(monitor, targetFolder);
// empty the src/test/java
IFolder testSrcFolder = talendJavaProject.getTestSrcFolder();
talendJavaProject.cleanFolder(monitor, testSrcFolder);
// empty the src/test/java (main for contexts)
IFolder testResourcesFolder = talendJavaProject.getTestResourcesFolder();
talendJavaProject.cleanFolder(monitor, testResourcesFolder);
// empty temp
IFolder tempFolder = talendJavaProject.getTempFolder();
talendJavaProject.cleanFolder(monitor, tempFolder);
// empty lib/...
IFolder libFolder = talendJavaProject.getLibFolder();
talendJavaProject.cleanFolder(monitor, libFolder);
// rules
IFolder rulesResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_RULES_DIRECTORY);
talendJavaProject.cleanFolder(monitor, rulesResFolder);
// sqltempalte
IFolder sqlTemplateResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_SQLPATTERNS_DIRECTORY);
talendJavaProject.cleanFolder(monitor, sqlTemplateResFolder);
}
}
;
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
if (e.getCause() != null) {
ExceptionHandler.process(e.getCause());
} else {
ExceptionHandler.process(e);
}
}
executed = true;
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class OpenDeclarationAction method searchSource.
/**
* Searches the source for the given class name with progress monitor.
*
* @return The source
* @throws InterruptedException if operation is canceled
*/
private IType searchSource() throws InterruptedException {
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
dialog.setOpenOnRun(false);
// search source corresponding to the class name
final IType[] source = new IType[1];
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (!searchEngineInitialized) {
monitor.subTask(Messages.searchingSoruceMsg);
searchEngineInitialized = true;
}
// open progress monitor dialog when it takes long time
new Timer().schedule(new TimerTask() {
@Override
public void run() {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
dialog.open();
}
});
}
}, 400);
if (className == null) {
return;
}
try {
source[0] = doSearchSource(className);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
if (monitor.isCanceled()) {
throw new InterruptedException();
}
}
};
try {
dialog.run(true, true, op);
} catch (InvocationTargetException e) {
Activator.log(IStatus.ERROR, NLS.bind(Messages.searchClassFailedMsg, className), e);
}
return source[0];
}
Aggregations