use of org.eclipse.core.resources.IWorkspaceRunnable in project tdi-studio-se by Talend.
the class NewProcessWizard method performFinish.
/**
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
public boolean performFinish() {
RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>(this.getWindowTitle(), this) {
@Override
protected void run() throws LoginException, PersistenceException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRunnable operation = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
createProcessItem();
}
};
try {
workspace.run(operation, null);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
};
workUnit.setAvoidUnloadResources(true);
repositoryFactory.executeRepositoryWorkUnit(workUnit);
return processItem != null;
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project tdi-studio-se by Talend.
the class JSONWizard method performFinish.
/**
* This method determine if the 'Finish' button is enable This method is called when 'Finish' button is pressed in
* the wizard. We will create an operation and run it using wizard as execution context.
*/
@Override
public boolean performFinish() {
boolean formIsPerformed = false;
IWizardPage finalPage = getCurrentPage();
if (finalPage == null) {
finalPage = propertiesWizardPage;
}
// deleteTemFile();
if (connection.isInputModel()) {
if (finalPage instanceof JSONFileWizardPage) {
int step = ((JSONFileWizardPage) finalPage).step;
if (step == 2) {
formIsPerformed = finalPage.isPageComplete();
if (formIsPerformed) {
List schemas = connection.getSchema();
Set tables = ConnectionHelper.getTables(connection);
if (!schemas.isEmpty() && !tables.isEmpty()) {
JSONXPathLoopDescriptor currentSchema = (JSONXPathLoopDescriptor) schemas.get(0);
MetadataTable currentTable = (MetadataTable) tables.toArray(new MetadataTable[0])[0];
if (!currentSchema.getAbsoluteXPathQuery().equals(oldAbstractQueryPath)) {
resetMetadata(currentSchema.getSchemaTargets(), true);
} else {
resetMetadata(currentSchema.getSchemaTargets(), false);
}
}
}
} else {
formIsPerformed = finalPage.isPageComplete();
}
} else {
formIsPerformed = finalPage.isPageComplete();
}
} else {
formIsPerformed = finalPage.isPageComplete();
}
if (formIsPerformed) {
final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
if (creation) {
String nextId = factory.getNextId();
connectionProperty.setId(nextId);
// changed by hqzhang for TDI-19527, label=displayName
connectionProperty.setLabel(connectionProperty.getDisplayName());
final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
factory.create(connectionItem, propertiesWizardPage.getDestinationPath());
}
};
workUnit.setAvoidUnloadResources(true);
factory.executeRepositoryWorkUnit(workUnit);
} else {
// changed by hqzhang for TDI-19527, label=displayName
connectionProperty.setLabel(connectionProperty.getDisplayName());
// update schemas
Map<String, SchemaTarget> schemaTargetMap = new HashMap<String, SchemaTarget>();
EList<JSONXPathLoopDescriptor> schema = connection.getSchema();
if (schema != null && schema.size() > 0) {
JSONXPathLoopDescriptor jsonXPathLoopDescriptor = schema.get(0);
if (jsonXPathLoopDescriptor != null) {
EList<SchemaTarget> schemaTargets = jsonXPathLoopDescriptor.getSchemaTargets();
if (schemaTargets != null && schemaTargets.size() > 0) {
for (SchemaTarget schemaTarget : schemaTargets) {
schemaTargetMap.put(schemaTarget.getTagName(), schemaTarget);
}
}
}
}
Map<String, MetadataColumn> columnsMap = new HashMap<String, MetadataColumn>();
MetadataTable[] tables = ConnectionHelper.getTables(connectionItem.getConnection()).toArray(new MetadataTable[0]);
for (MetadataTable table : tables) {
EList<MetadataColumn> columns = table.getColumns();
Iterator<MetadataColumn> columnsIter = columns.iterator();
while (columnsIter.hasNext()) {
MetadataColumn column = columnsIter.next();
if (connection.isInputModel()) {
if (schemaTargetMap.get(column.getLabel()) == null) {
columnsIter.remove();
} else {
columnsMap.put(column.getLabel(), column);
}
} else {
columnsMap.put(column.getLabel(), column);
}
}
}
boolean hasAddedColumns = false;
Iterator<Entry<String, SchemaTarget>> schemaTargetIter = schemaTargetMap.entrySet().iterator();
while (schemaTargetIter.hasNext()) {
Map.Entry<String, SchemaTarget> entry = schemaTargetIter.next();
String key = entry.getKey();
if (columnsMap.get(key) == null) {
hasAddedColumns = true;
break;
}
}
if (hasAddedColumns) {
MessageDialog.openInformation(getShell(), "Detect new columns", "There are some new fields to extract, guess your schema manually if you want to apply the update.");
}
// update
RepositoryUpdateManager.updateFileConnection(connectionItem);
refreshInFinish(propertiesWizardPage.isNameModifiedByUser());
final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
factory.save(connectionItem);
}
};
workUnit.setAvoidUnloadResources(true);
factory.executeRepositoryWorkUnit(workUnit);
closeLockStrategy();
}
final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {
@Override
protected void run() throws LoginException, PersistenceException {
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
}
};
workUnit.setAvoidUnloadResources(true);
factory.executeRepositoryWorkUnit(workUnit);
}
});
}
};
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(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
try {
new ProgressMonitorDialog(null).run(true, true, iRunnableWithProgress);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
//
}
return true;
} else {
return false;
}
}
use of org.eclipse.core.resources.IWorkspaceRunnable 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.resources.IWorkspaceRunnable 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.resources.IWorkspaceRunnable in project tdi-studio-se by Talend.
the class AbstractJobSettingsPage method save.
protected void save() {
List<String> checkedObjects = new ArrayList<String>();
List<IRepositoryViewObject> allProcess = null;
try {
allProcess = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.PROCESS);
} catch (PersistenceException e1) {
ExceptionHandler.process(e1);
}
for (IRepositoryViewObject object : allProcess) {
if (isStatUseProjectSetting(object)) {
if (!checkedObjects.contains(object.getProperty().getId())) {
checkedObjects.add(object.getProperty().getId());
if (!checkedNodeObject.contains(object)) {
checkedNodeObject.add(object);
}
}
}
}
List<IProcess2> allOpenedProcessList = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(getEditors());
if (allOpenedProcessList != null) {
for (int i = 0; i < allOpenedProcessList.size(); i++) {
if (checkedObjects.contains(allOpenedProcessList.get(i).getProperty().getId())) {
openedProcessList.add(allOpenedProcessList.get(i));
}
}
}
//
final IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(getTaskMessages(), (checkedNodeObject.size()) * 100);
final Map<String, Set<String>> contextVars = DetectContextVarsUtils.detectByPropertyType(elem, true);
// must init this
addContextModel = false;
if (!contextVars.isEmpty()) {
// boolean showDialog = false;
Set<String> contextSet = new HashSet<String>();
for (String key : contextVars.keySet()) {
contextSet = contextVars.get(key);
break;
}
Connection connection = null;
IElementParameter ptParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (ptParam != null) {
IElementParameter propertyElem = ptParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
Object proValue = propertyElem.getValue();
if (proValue instanceof String && ((String) proValue).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
IElementParameter repositoryElem = ptParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
String value = (String) repositoryElem.getValue();
ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(value);
connection = connectionItem.getConnection();
if (connection != null && connection.isContextMode()) {
addContextModel = true;
// ContextItem contextItem =
// ContextUtils.getContextItemById(connection.getContextId());
// for (IProcess process : openedProcessList) {
// Set<String> addedContext =
// ConnectionContextHelper.checkAndAddContextVariables(contextItem,
// contextSet, process.getContextManager(), false);
// if (addedContext != null && !addedContext.isEmpty()) {
// showDialog = true;
// break;
// }
// }
}
}
}
if (addContextModel) {
// if the context is not existed in job, will add or not.
Display disp = Display.getCurrent();
if (disp == null) {
disp = Display.getDefault();
}
if (disp != null) {
disp.syncExec(new Runnable() {
@Override
public void run() {
showContextAndCheck(contextVars);
}
});
} else {
showContextAndCheck(contextVars);
}
}
}
monitor.worked(10);
IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
for (IRepositoryViewObject object : checkedNodeObject) {
saveProcess(object, addContextModel, contextVars, monitor);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
workspace.run(workspaceRunnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
monitor.done();
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(true, true, runnable);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
Aggregations