use of org.eclipse.ui.progress.WorkbenchJob in project flux by eclipse.
the class LiveEditConnector method dispose.
public void dispose() {
this.liveEditCoordinator.removeLiveEditConnector(liveEditConnector);
this.repository.removeRepositoryListener(repositoryListener);
FileBuffers.getTextFileBufferManager().removeFileBufferListener(fileBufferListener);
ResourcesPlugin.getWorkspace().removeResourceChangeListener(workspaceListener);
WorkbenchJob jw = new WorkbenchJob("Removing listener") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
window.getActivePage().removePartListener(partListener);
}
return Status.OK_STATUS;
}
};
jw.setSystem(true);
jw.schedule();
for (IDocument document : documentMappings.values()) {
if (document != null) {
document.removeDocumentListener(documentListener);
}
}
resourceMappings.clear();
documentMappings.clear();
}
use of org.eclipse.ui.progress.WorkbenchJob in project cubrid-manager by CUBRID.
the class CubridDeferredTreeContentManager method addChildren.
/**
* Create a UIJob to add the children to the parent in the tree viewer.
*
* @param parent the parent tree container node
* @param children the added children array
* @param monitor the monitor object
*/
protected void addChildren(final Object parent, final Object[] children, IProgressMonitor monitor) {
WorkbenchJob updateJob = new WorkbenchJob(Messages.msgAddingChildren) {
public IStatus runInUIThread(IProgressMonitor updateMonitor) {
// Cancel the job if the tree viewer got closed
if (treeViewer.getControl().isDisposed() || updateMonitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
treeViewer.add(parent, children);
if (parent instanceof ICubridNode && ((ICubridNode) parent).isContainer()) {
treeViewer.update(parent, null);
ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
}
ICubridNode parentNode = null;
if (parent instanceof ICubridNode) {
parentNode = (ICubridNode) parent;
}
boolean isExpandNextLevel = parentNode != null && (parentNode.getType().equals(NodeType.USER_TABLE) || parentNode.getType().equals(NodeType.SERVER)) && expandedElements == null;
if (isExpandNextLevel) {
expandToNextLevel(children);
} else {
for (int i = 0; children != null && i < children.length; i++) {
if ((children[i] instanceof ICubridNode)) {
ICubridNode node = (ICubridNode) children[i];
for (int j = 0; expandedElements != null && j < expandedElements.length; j++) {
if (expandedElements[j] instanceof ICubridNode && node.getId().equals(((ICubridNode) expandedElements[j]).getId())) {
treeViewer.expandToLevel(children[i], 1);
}
}
}
}
}
// set user/table folder node label, add children count
if (hasChildCount(parentNode)) {
int count = 0;
if (parentNode.getType().equals(NodeType.TABLE_FOLDER)) {
count = 0;
for (ICubridNode tableNode : parentNode.getChildren()) {
if (tableNode.getType().equals(NodeType.USER_TABLE) || tableNode.getType().equals(NodeType.USER_PARTITIONED_TABLE_FOLDER)) {
count++;
}
}
} else if (parentNode.getType().equals(NodeType.VIEW_FOLDER)) {
for (ICubridNode viewNode : parentNode.getChildren()) {
if (viewNode.getType().equals(NodeType.USER_VIEW)) {
count++;
}
}
} else {
count = parentNode.getChildren().size();
}
String suffix = "(" + Integer.valueOf(count) + ")";
String beforeLable = parentNode.getLabel();
if (beforeLable.endsWith(")") && beforeLable.indexOf("(") > -1) {
String beforeCount = beforeLable.substring(beforeLable.indexOf("(") + 1, beforeLable.length() - 1);
// if children count not change, do not update label
if (String.valueOf(count).equals(beforeCount)) {
return Status.OK_STATUS;
}
beforeLable = beforeLable.substring(0, beforeLable.indexOf("("));
}
parentNode.setLabel(beforeLable + suffix);
treeViewer.refresh(parentNode, true);
}
return Status.OK_STATUS;
}
};
updateJob.setSystem(true);
updateJob.schedule();
}
use of org.eclipse.ui.progress.WorkbenchJob in project translationstudio8 by heartsome.
the class DeleteResourceAndCloseEditorAction method scheduleDeleteJob.
/**
* Schedule a job to delete the resources to delete.
* @param resourcesToDelete
*/
private void scheduleDeleteJob(final IResource[] resourcesToDelete) {
// use a non-workspace job with a runnable inside so we can avoid
// periodic updates
Job deleteJob = new Job(IDEWorkbenchMessages.DeleteResourceAction_jobName) {
public IStatus run(final IProgressMonitor monitor) {
try {
final DeleteResourcesOperation op = new DeleteResourcesOperation(resourcesToDelete, IDEWorkbenchMessages.DeleteResourceAction_operationLabel, deleteContent);
op.setModelProviderIds(getModelProviderIds());
// added to the undo history.
if (deleteContent && containsOnlyProjects(resourcesToDelete)) {
// We must compute the execution status first so that any user prompting
// or validation checking occurs. Do it in a syncExec because
// we are calling this from a Job.
WorkbenchJob statusJob = new //$NON-NLS-1$
WorkbenchJob(//$NON-NLS-1$
"Status checking") {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus runInUIThread(IProgressMonitor monitor) {
return op.computeExecutionStatus(monitor);
}
};
statusJob.setSystem(true);
statusJob.schedule();
try {
// block until the status is ready
statusJob.join();
} catch (InterruptedException e) {
// Do nothing as status will be a cancel
}
if (statusJob.getResult().isOK()) {
return op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
}
return statusJob.getResult();
}
return PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
} catch (ExecutionException e) {
if (e.getCause() instanceof CoreException) {
return ((CoreException) e.getCause()).getStatus();
}
return new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, e.getMessage(), e);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
*/
public boolean belongsTo(Object family) {
if (IDEWorkbenchMessages.DeleteResourceAction_jobName.equals(family)) {
return true;
}
return super.belongsTo(family);
}
};
deleteJob.setUser(true);
deleteJob.schedule();
}
Aggregations