use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.
the class MultiSchemasUI method fetchCodes.
@SuppressWarnings("restriction")
private void fetchCodes() {
try {
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
dialog.run(true, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Fetch...", IProgressMonitor.UNKNOWN);
monitor.setCanceled(false);
final CsvArray csvArray = processor.getCsvArray();
Display.getDefault().syncExec(new Runnable() {
public void run() {
SchemasKeyData schemasModel = null;
boolean checked = (csvArray != null && csvArray.getRows().size() > 0);
CSVArrayAndSeparator uniqueCsvArray = null;
if (useMultiSaparators.getSelection()) {
getMultiSchemaManager().setKeyValues(keyValuesText.getText());
}
if (multiSchemasFilePreview.getSelectColumnIndex() < 0 && multiSchemaManager.getSelectedColumnIndex() != 0) {
uniqueCsvArray = getMultiSchemaManager().retrieveCsvArrayInUniqueModel(getProcessDescription(), checked, multiSchemaManager.getSelectedColumnIndex(), useMultiSaparators.getSelection());
schemasModel = getMultiSchemaManager().createSchemasTree(uniqueCsvArray, multiSchemaManager.getSelectedColumnIndex());
} else {
uniqueCsvArray = getMultiSchemaManager().retrieveCsvArrayInUniqueModel(getProcessDescription(), checked, multiSchemasFilePreview.getSelectColumnIndex(), useMultiSaparators.getSelection());
schemasModel = getMultiSchemaManager().createSchemasTree(uniqueCsvArray, multiSchemasFilePreview.getSelectColumnIndex());
getMultiSchemaManager().setSelectedColumnIndex(multiSchemasFilePreview.getSelectColumnIndex());
schemaTreeViewer.setInput(schemasModel);
getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
clearSchemaDetail();
checkDialog();
}
}
});
monitor.done();
}
});
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.
the class ImportItemWizardPage method updateItemsList.
public void updateItemsList(final String path, boolean isneedUpdate) {
if (!isneedUpdate) {
if (path.equals(lastPath)) {
return;
}
}
lastPath = path;
if (path == null || path.length() == 0) {
selectedItems = new ArrayList<ItemRecord>();
checkTreeViewer.refresh(true);
// get the top item to check if tree is empty, if not then uncheck everything
TreeItem topItem = checkTreeViewer.getTree().getTopItem();
if (topItem != null) {
checkTreeViewer.setSubtreeChecked(topItem.getData(), false);
}
// else not root element, tree is already empty
checkValidItems();
return;
}
final boolean dirSelected = this.itemFromDirectoryRadio.getSelection();
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
// monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_SearchingMessage, 100);
//$NON-NLS-1$
monitor.beginTask(Messages.getString("DataTransferMessages.WizardProjectsImportPage_SearchingMessage"), 100);
File directory = new File(path);
monitor.worked(10);
if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
sourceTarFile = getSpecifiedTarSourceFile(path);
if (sourceTarFile == null) {
return;
}
TarLeveledStructureProvider provider = new TarLeveledStructureProvider(sourceTarFile);
manager = ResourcesManagerFactory.getInstance().createResourcesManager(provider);
if (!manager.collectPath2Object(provider.getRoot())) {
return;
}
} else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
sourceFile = getSpecifiedZipSourceFile(path);
if (sourceFile == null) {
return;
}
ZipLeveledStructureProvider provider = new ZipLeveledStructureProvider(sourceFile);
manager = ResourcesManagerFactory.getInstance().createResourcesManager(provider);
if (!manager.collectPath2Object(provider.getRoot())) {
return;
}
} else if (dirSelected && directory.isDirectory()) {
manager = ResourcesManagerFactory.getInstance().createResourcesManager();
if (!manager.collectPath2Object(directory)) {
return;
}
} else {
monitor.worked(60);
}
monitor.done();
}
});
} catch (InvocationTargetException e) {
IDEWorkbenchPlugin.log(e.getMessage(), e);
} catch (InterruptedException e) {
// Nothing to do if the user interrupts.
}
populateItems();
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.
the class ImportItemWizardPage method performFinish.
public boolean performFinish() {
final List<ItemRecord> itemRecords = new ArrayList<ItemRecord>();
final List<ItemRecord> checkedItemRecords = getCheckedElements();
itemRecords.addAll(checkedItemRecords);
itemRecords.addAll(getHadoopSubrecords(itemRecords));
for (ItemRecord itemRecord : itemRecords) {
Item item = itemRecord.getProperty().getItem();
if (item instanceof JobletProcessItem) {
needToRefreshPalette = true;
}
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (item.getState().isLocked()) {
try {
factory.unlock(item);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
} catch (LoginException e) {
ExceptionHandler.process(e);
}
}
ERepositoryStatus status = factory.getStatus(item);
if (status != null && status == ERepositoryStatus.LOCK_BY_USER) {
try {
factory.unlock(item);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
} catch (LoginException e) {
ExceptionHandler.process(e);
}
}
}
try {
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IPath destinationPath = null;
String contentType = "";
if (rNode != null && rNode.getType().equals(ENodeType.SIMPLE_FOLDER)) {
destinationPath = RepositoryNodeUtilities.getPath(rNode);
contentType = rNode.getContentType().name();
}
repositoryUtil.setErrors(false);
repositoryUtil.clear();
repositoryUtil.importItemRecords(manager, itemRecords, monitor, overwrite, destinationPath, contentType);
if (repositoryUtil.hasErrors()) {
throw new InvocationTargetException(new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), //$NON-NLS-1$
"Import errors")));
}
}
};
new ProgressMonitorDialog(getShell()).run(true, true, iRunnableWithProgress);
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
if (repositoryUtil.getRoutineExtModulesMap().isEmpty()) {
if (targetException instanceof CoreException) {
//$NON-NLS-1$
MessageDialog.openWarning(//$NON-NLS-1$
getShell(), //$NON-NLS-1$
Messages.getString("ImportItemWizardPage.ImportSelectedItems"), //$NON-NLS-1$
Messages.getString("ImportItemWizardPage.ErrorsOccured"));
}
}
} catch (InterruptedException e) {
//
}
ResourcesManager curManager = this.manager;
if (curManager instanceof ProviderManager) {
curManager.closeResource();
}
selectedItems = null;
itemRecords.clear();
return true;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.
the class PaletteSettingPage method okPressed.
protected void okPressed() {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayUtils.getDefaultShell());
IRunnableWithProgress rwp = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
try {
prf.saveProject(project);
ShowStandardAction.getInstance().doRun();
if (needCodeGen) {
Job refreshTemplates = CorePlugin.getDefault().getCodeGeneratorService().refreshTemplates();
refreshTemplates.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
}
});
}
// ComponentUtilities.updatePalette();
} catch (Exception ex) {
ExceptionHandler.process(ex);
}
}
};
try {
pmd.run(true, false, rwp);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.
the class MavenVersionManagementProjectSettingPage method updateItemsVersion.
protected void updateItemsVersion() {
List<ItemVersionObject> JobsOpenedInEditor = new ArrayList<ItemVersionObject>();
List<ItemVersionObject> closedJobs = new ArrayList<ItemVersionObject>();
boolean hasJobOpenedInEditor = false;
StringBuilder builder = new StringBuilder();
for (ItemVersionObject object : checkedObjects) {
if (RepositoryManager.isOpenedItemInEditor(object.getRepositoryNode().getObject())) {
hasJobOpenedInEditor = true;
JobsOpenedInEditor.add(object);
//$NON-NLS-1$
builder.append(object.getRepositoryNode().getObject().getLabel() + ", ");
} else {
closedJobs.add(object);
}
}
if (builder.length() > 0) {
builder.delete(builder.length() - 2, builder.length());
}
if (hasJobOpenedInEditor) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), //$NON-NLS-1$
Messages.getString("VersionManagementDialog.WarningTitle2"), //$NON-NLS-1$
Messages.getString("VersionManagementDialog.openedInEditorMessage", builder.toString()));
IWorkbenchWindow workBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workBench != null) {
IWorkbenchPage page = workBench.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
IDesignerCoreUIService service = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
if (service != null) {
for (IEditorReference editorRef : editorRefs) {
IEditorPart editor = editorRef.getEditor(false);
if (editor instanceof IMultiPageTalendEditor) {
IProcess2 process = ((IMultiPageTalendEditor) editor).getProcess();
String version = null;
for (ItemVersionObject object : JobsOpenedInEditor) {
if (object.getItem().getProperty().getId().equals(process.getId())) {
version = object.getNewVersion();
break;
}
}
if (version != null) {
String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(process.getProperty().getVersion());
if (version.equals(jobDefaultVersion)) {
// if default, set null to remove key from property.
version = null;
}
Command command = service.crateMavenDeploymentValueChangeCommand(process, MavenConstants.NAME_USER_VERSION, version);
if (process instanceof IGEFProcess) {
service.executeCommand((IGEFProcess) process, command);
}
}
}
}
}
}
}
}
final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
RepositoryWorkUnit<Object> rwu = new //$NON-NLS-1$
RepositoryWorkUnit<Object>(//$NON-NLS-1$
project, //$NON-NLS-1$
"Update items Maven version") {
@Override
protected void run() throws LoginException, PersistenceException {
//$NON-NLS-1$
monitor.beginTask("Update items Maven version", closedJobs.size());
for (ItemVersionObject object : closedJobs) {
final Item item = object.getItem();
Property itemProperty = item.getProperty();
MavenVersionUtils.setItemMavenVersion(itemProperty, object.getNewVersion());
monitor.subTask(itemProperty.getLabel());
FACTORY.save(project, itemProperty);
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 ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException | InterruptedException e) {
ExceptionHandler.process(e);
}
}
Aggregations