use of org.eclipse.core.resources.IWorkspace in project dbeaver by serge-rider.
the class NavigatorHandlerProjectRefresh method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IWorkspace workspace = DBeaverCore.getInstance().getWorkspace();
try {
workbenchWindow.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
workspace.getRoot().refreshLocal(IResource.DEPTH_INFINITE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
UIUtils.showErrorDialog(workbenchWindow.getShell(), "Refresh workspace", "Can't refresh workspace", e.getTargetException());
} catch (InterruptedException e) {
// do nothing
}
return null;
}
use of org.eclipse.core.resources.IWorkspace in project azure-tools-for-java by Microsoft.
the class SparkSubmissionExDialog method getProjects.
private String[] getProjects() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
String[] projects = null;
ArrayList<String> projList = new ArrayList<String>();
try {
for (IProject wRoot : root.getProjects()) {
if (wRoot.hasNature(HDInsightProjectNature.NATURE_ID)) {
projList.add(wRoot.getProject().getName());
}
}
projects = new String[projList.size()];
projects = projList.toArray(projects);
} catch (Exception e) {
PluginUtil.displayErrorDialogAndLog(this.getShell(), "Project Selection Error", "Error occurred while selecting the project.", e);
}
return projects;
}
use of org.eclipse.core.resources.IWorkspace in project azure-tools-for-java by Microsoft.
the class AIStartup method earlyStartup.
@Override
public void earlyStartup() {
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
// register resource change listener
AIResourceChangeListener listener = new AIResourceChangeListener();
workspace.addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
// load application insights preferences
ApplicationInsightsPreferences.load();
for (IProject iProject : root.getProjects()) {
AIResourceChangeListener.initializeAIRegistry(iProject);
}
ApplicationInsightsPreferences.save();
} catch (Exception ex) {
Activator.getDefault().log(Messages.startUpErr, ex);
}
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class UpdateManagerUtils method doExecuteUpdates.
private static boolean doExecuteUpdates(final List<UpdateResult> results, final boolean updateAllJobs) {
if (results == null || results.isEmpty()) {
return false;
}
try {
IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
monitor.setCanceled(false);
int size = (results.size() * 2 + 1) * UpdatesConstants.SCALE;
//$NON-NLS-1$
monitor.beginTask(Messages.getString("UpdateManagerUtils.Update"), size);
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
// first list by job we need to update
Map<String, Set<String>> jobIdToVersion = new HashMap<String, Set<String>>();
Map<String, Boolean> jobIdClosed = new HashMap<String, Boolean>();
for (UpdateResult result : results) {
// if (!result.isChecked()) {
// continue;
// }
String id = result.getObjectId();
String version = result.getObjectVersion();
if (id == null) {
if (result.getJob() != null && result.getJob() instanceof IProcess) {
IProcess process = (IProcess) result.getJob();
if (process instanceof IProcess2 && ERepositoryStatus.LOCK_BY_OTHER.equals(factory.getStatus(((IProcess2) process).getProperty().getItem()))) {
// file.
continue;
}
id = process.getId();
version = process.getVersion();
result.setObjectId(id);
result.setObjectVersion(version);
} else {
continue;
}
}
Set<String> versionList;
if (!jobIdToVersion.containsKey(id)) {
versionList = new HashSet<String>();
jobIdToVersion.put(id, versionList);
} else {
versionList = jobIdToVersion.get(id);
}
versionList.add(version);
//$NON-NLS-1$
jobIdClosed.put(id + " - " + version, result.isFromItem());
}
// now will execute updates only for the job selected depends this list.
for (String currentId : jobIdToVersion.keySet()) {
for (String version : jobIdToVersion.get(currentId)) {
IRepositoryViewObject currentObj = null;
//$NON-NLS-1$
boolean closedItem = jobIdClosed.get(currentId + " - " + version);
IProcess process = null;
Item item = null;
if (closedItem) {
// if item is closed, then just load it.
boolean checkOnlyLastVersion = Boolean.parseBoolean(DesignerPlugin.getDefault().getPreferenceStore().getString(//$NON-NLS-1$
"checkOnlyLastVersion"));
try {
if (checkOnlyLastVersion || version == null) {
currentObj = factory.getLastVersion(currentId);
} else {
List<IRepositoryViewObject> allVersion = factory.getAllVersion(currentId);
for (IRepositoryViewObject obj : allVersion) {
if (obj.getVersion().equals(version)) {
currentObj = obj;
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (currentObj == null) {
// item not found, don't do anything
continue;
}
item = currentObj.getProperty().getItem();
IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
if (item instanceof ProcessItem) {
process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
} else if (item instanceof JobletProcessItem) {
process = designerCoreService.getProcessFromJobletProcessItem((JobletProcessItem) item);
}
}
for (UpdateResult result : results) {
// }
if (!StringUtils.equals(currentId, result.getObjectId())) {
// not the current job we need to update
continue;
}
if (closedItem) {
if (result.getJob() == null) {
result.setJob(process);
} else {
process = (IProcess) result.getJob();
}
IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
if (process != null && jobletContextType != null && (jobletContextType.equals(result.getUpdateType()))) {
if ((result.getParameter() instanceof List) && process.getContextManager() != null) {
process.getContextManager().setListContext((List<IContext>) result.getParameter());
}
}
}
// execute
executeUpdate(result, monitor, updateAllJobs);
if (closedItem) {
result.setJob(null);
}
}
boolean isTestContainer = false;
ITestContainerProviderService testContainerService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
isTestContainer = testContainerService.isTestContainerItem(item);
}
}
if (closedItem && process instanceof IProcess2) {
IProcess2 process2 = (IProcess2) process;
ProcessType processType;
try {
processType = process2.saveXmlFile(false);
if (isTestContainer) {
testContainerService.setTestContainerProcess(processType, item);
} else if (item instanceof JobletProcessItem) {
((JobletProcessItem) item).setJobletProcess((JobletProcess) processType);
} else {
((ProcessItem) item).setProcess(processType);
}
factory.save(item);
} catch (IOException e) {
ExceptionHandler.process(e);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
if (closedItem && !ERepositoryStatus.LOCK_BY_USER.equals(factory.getStatus(item))) {
// unload item from memory, but only if this one is not locked by current user.
try {
factory.unloadResources(item.getProperty());
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
}
UpdateManagerProviderDetector.INSTANCE.postUpdate(results);
// update joblet reference
upadateJobletReferenceInfor();
final List<UpdateResult> tempResults = new ArrayList<UpdateResult>(results);
// refresh
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
refreshRelatedViewers(tempResults);
// hyWang add method checkandRefreshProcess for bug7248
checkandRefreshProcess(tempResults);
}
});
monitor.worked(1 * UpdatesConstants.SCALE);
monitor.done();
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
try {
new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
}
return !results.isEmpty();
} finally {
results.clear();
}
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class AbstractTalendEditor method doSaveAs.
@Override
public void doSaveAs() {
SaveAsDialog dialog = new SaveAsDialog(getSite().getWorkbenchWindow().getShell());
dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile());
dialog.open();
IPath path = dialog.getResult();
if (path == null) {
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IFile file = workspace.getRoot().getFile(path);
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
@Override
public void execute(final IProgressMonitor monitor) throws CoreException {
try {
savePreviewPictures();
getProcess().saveXmlFile();
// file.refreshLocal(IResource.DEPTH_ONE, monitor);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
};
try {
new ProgressMonitorDialog(getSite().getWorkbenchWindow().getShell()).run(false, true, op);
// setInput(new FileEditorInput((IFile) file));
getCommandStack().markSaveLocation();
setDirty(false);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
Aggregations