Java Code Examples for org.eclipse.core.runtime.Status#CANCEL_STATUS

The following examples show how to use org.eclipse.core.runtime.Status#CANCEL_STATUS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtensionBuildHandler.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	project = getSelectedExtension(HandlerUtil.getCurrentSelection(event));
	Job job = new Job("[y] Build") {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				if (FixProjectsUtils.isAHybrisExtension(project)) {
					BuildUtils.refreshAndBuild(monitor, CFG_NAME, project);
					monitor.done();
					return Status.OK_STATUS;
				} else {
					return Status.CANCEL_STATUS;
				}
			} catch (Exception e) {
				Activator.logError("Failed to build project", e);
				throw new IllegalStateException("Failed to build project, see workspace logs for details", e);
			}

		}
	};
	job.setUser(true);
	job.schedule();
	return null;
}
 
Example 2
Source File: LayeredDisplayView.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected GamaUIJob createUpdateJob() {
	return new GamaUIJob() {

		@Override
		protected UpdatePriority jobPriority() {
			return UpdatePriority.HIGHEST;
		}

		@Override
		public IStatus runInUIThread(final IProgressMonitor monitor) {
			if (getDisplaySurface() == null) { return Status.CANCEL_STATUS; }
			getDisplaySurface().updateDisplay(false);
			return Status.OK_STATUS;
		}
	};
}
 
Example 3
Source File: WebPublisher.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
private Job createTransferJob(final Ftp ftp, final File file) {
  Job result = new Job("transfer file " + file.getName()) {
    @Override
    protected IStatus run(IProgressMonitor monitor) {
      try {
        IStatus ftpStatus = ftp.put(file);
        if (!ftpStatus.isOK()) {
          GPLogger.getLogger(WebPublisher.class).warning(ftpStatus.getMessage());
          return ftpStatus;
        }
        monitor.worked(1);
        return Status.OK_STATUS;
      } catch (IOException e) {
        if (!GPLogger.log(e)) {
          e.printStackTrace(System.err);
        }
        return Status.CANCEL_STATUS;
      } finally {
      }
    }
  };
  return result;
}
 
Example 4
Source File: XtextEditorErrorTickUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IStatus runInUIThread(final IProgressMonitor monitor) {
	IEditorSite site = null != editor ? editor.getEditorSite() : null;
	if (site != null) {
		if (!monitor.isCanceled() && editor != null) {
			if (titleImage != null && !titleImage.isDisposed()) {
				editor.updatedTitleImage(titleImage);
				titleImage = null;
			} else if (titleImageDescription != null) {
				Image image = imageHelper.getImage(titleImageDescription);
				if (editor.getTitleImage() != image) {
					editor.updatedTitleImage(image);
				}
				titleImageDescription = null;
			}
		}
	}
	if (monitor.isCanceled()) {
		return Status.CANCEL_STATUS;
	}
	return Status.OK_STATUS;
}
 
Example 5
Source File: APKInstallJob.java    From Flashtool with GNU General Public License v3.0 6 votes vote down vote up
protected IStatus run(IProgressMonitor monitor) {
 	try {
File files = new File(instpath);
File[] chld = files.listFiles(new APKFilter());
LogProgress.initProgress(chld.length);
for(int i = 0; i < chld.length; i++){
	if (chld[i].getName().toUpperCase().endsWith(".APK"))
		AdbUtility.install(chld[i].getPath());
	LogProgress.updateProgress();
}
LogProgress.initProgress(0);
logger.info("APK Installation finished");
return Status.OK_STATUS;
 	}
 	catch (Exception e) {
 		e.printStackTrace();
 		logger.error(e.getMessage());
 		LogProgress.initProgress(0);
 		return Status.CANCEL_STATUS;
 	}
 }
 
Example 6
Source File: SelectionListenerWithASTManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected final IStatus calculateASTandInform(ITypeRoot input, ITextSelection selection, IProgressMonitor monitor) {
	if (monitor.isCanceled()) {
		return Status.CANCEL_STATUS;
	}
	// create AST
	try {
		CompilationUnit astRoot= SharedASTProvider.getAST(input, SharedASTProvider.WAIT_ACTIVE_ONLY, monitor);

		if (astRoot != null && !monitor.isCanceled()) {
			Object[] listeners;
			synchronized (PartListenerGroup.this) {
				listeners= fAstListeners.getListeners();
			}
			for (int i= 0; i < listeners.length; i++) {
				((ISelectionListenerWithAST) listeners[i]).selectionChanged(fPart, selection, astRoot);
				if (monitor.isCanceled()) {
					return Status.CANCEL_STATUS;
				}
			}
			return Status.OK_STATUS;
		}
	} catch (OperationCanceledException e) {
		// thrown when canceling the AST creation
	}
	return Status.CANCEL_STATUS;
}
 
Example 7
Source File: XtextReconciler.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected IStatus run(final IProgressMonitor monitor) {
	if (monitor.isCanceled() || paused)
		return Status.CANCEL_STATUS;

	if (pendingChanges.isEmpty()) {
		return Status.OK_STATUS;
	}
	long start = System.currentTimeMillis();
	final IXtextDocument document = xtextDocumentUtil.getXtextDocument(textViewer);
	if (document instanceof XtextDocument) {
		((XtextDocument) document).internalModify(new IUnitOfWork.Void<XtextResource>() {
			@Override
			public void process(XtextResource state) throws Exception {
				doRun(state, monitor);
			}
		});
	}
	if (monitor.isCanceled()) {
		return Status.CANCEL_STATUS;
	}
	if (log.isDebugEnabled())
		log.debug("Reconciliation finished. Time required: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
	return Status.OK_STATUS;
}
 
Example 8
Source File: UndoManager.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public IStatus proceedRedoing(
    final IUndoableOperation operation, IOperationHistory history, IAdaptable info) {

  if (!enabled) return Status.OK_STATUS;

  if (currentActiveEditor == null) {
    log.info("Redo called on an unknown editor");
    return Status.OK_STATUS;
  }

  if (log.isDebugEnabled()) log.debug(opInfo(operation));

  if (operation.getLabel().equals(TYPING_LABEL)
      || operation.getLabel().equals(NullOperation.LABEL)) {

    updateCurrentLocalAtomicOperation(null);
    storeCurrentLocalOperation();

    SWTUtils.runSafeSWTSync(
        log,
        new Runnable() {
          @Override
          public void run() {
            log.debug("redoing operation " + operation);
            redo(currentActiveEditor);

            /*
             * For reactivating redo an undo has to be simulated, so
             * the Eclipse history knows, there is something to
             * redo.
             */
            if (undoHistory.canRedo(currentActiveEditor)) simulateUndo();
          }
        });
    return Status.CANCEL_STATUS;
  }
  return Status.OK_STATUS;
}
 
Example 9
Source File: NavigatorDropAssistant.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IStatus handleDrop(final CommonDropAdapter adapter, final DropTargetEvent event, final Object target) {
	if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
		final String[] files = (String[]) event.data;
		if (files != null && files.length > 0) {
			PasteAction.handlePaste(files);
			return Status.OK_STATUS;
		}
	} else if (ResourceTransfer.getInstance().isSupportedType(event.currentDataType)) {

	}
	return Status.CANCEL_STATUS;
}
 
Example 10
Source File: FileUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a symlink or shortcut folder.
 * 
 * @param symLinkName
 * @param sourcePath
 * @param targetPath
 * @return
 */
public static IStatus createSymlink(String symLinkName, IPath sourcePath, IPath targetPath)
{
	if (PlatformUtil.isMac() || PlatformUtil.isLinux())
	{
		return new ProcessRunner().runInBackground(sourcePath, "ln", "-s", targetPath.toOSString(), symLinkName); //$NON-NLS-1$ //$NON-NLS-2$
	}
	else if (PlatformUtil.isWindows())
	{
		return new ProcessRunner()
				.runInBackground(sourcePath, "mklink", "/D", symLinkName, targetPath.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
	}
	return Status.CANCEL_STATUS;
}
 
Example 11
Source File: AbapGitStagingView.java    From ADT_Frontend with MIT License 5 votes vote down vote up
private IStatus getGitCredentials(String previousErrorMessage) {
	//get credentials
	if (this.repositoryCredentials == null) {
		this.repositoryCredentials = GitCredentialsService.getCredentialsFromUser(getSite().getShell(), this.repository.getUrl(), previousErrorMessage);
		if (this.repositoryCredentials == null) {
			return Status.CANCEL_STATUS;
		}
	}
	return Status.OK_STATUS;
}
 
Example 12
Source File: CodewindConnectionComposite.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IStatus updateConnection(IProgressMonitor monitor) {
	SubMonitor mon = SubMonitor.convert(monitor, 100);
	
	if (connection.isConnected()) {
		connection.disconnect();
	}
	try {
		ConnectionUtil.updateConnection(connection.getConid(), name, url, user, mon.split(20));
		if (mon.isCanceled()) {
			return Status.CANCEL_STATUS;
		}
		connection.setName(name);
		connection.setBaseURI(new URI(url));
		connection.setUsername(user);
		
		AuthToken token = AuthUtil.genAuthToken(user, pass, connection.getConid(), mon.split(30));
		if (mon.isCanceled()) {
			return Status.CANCEL_STATUS;
		}
		connection.setAuthToken(token);
		
		connection.connect(mon.split(50));
		if (mon.isCanceled()) {
			return Status.CANCEL_STATUS;
		}
	} catch (Exception e) {
		return new Status(IStatus.ERROR, CodewindUIPlugin.PLUGIN_ID, NLS.bind(Messages.CodewindConnectionUpdateError, name), e);
	} finally {
		ViewHelper.openCodewindExplorerView();
		CodewindUIPlugin.getUpdateHandler().updateConnection(connection);
	}
	
	return Status.OK_STATUS;
}
 
Example 13
Source File: UpdateDataOperation.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	CellEditorCanonicalValue newValue = null;
	Object obj = command.getNewValue();
	if (obj instanceof CellEditorCanonicalValue) {
		newValue = (CellEditorCanonicalValue) obj;
	}
	if (newValue == null) {
		return Status.CANCEL_STATUS;
	}
	TeActiveCellEditor.commit();
	return updateData(newValue.getNewFullValue(), true);
}
 
Example 14
Source File: TexDocumentModel.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
 */
public IStatus runInUIThread(IProgressMonitor monitor) {
    try {
    	//long time = System.currentTimeMillis();
        updateDocumentPositions(rootNodes, monitor);
        //System.out.println("updateDocPos: " + (System.currentTimeMillis() - time));
        
        pollCancel(monitor);
        
        //time = System.currentTimeMillis();
        editor.updateCodeFolder(rootNodes, monitor);
        //System.out.println("updateCodeFolder: " + (System.currentTimeMillis() - time));
        pollCancel(monitor);
        
        if (editor.getOutlinePage() != null) {
        	//time = System.currentTimeMillis();
        	editor.getOutlinePage().update(outlineInput);
        	//System.out.println("updateOutline: " + (System.currentTimeMillis() - time));
        }
        
        //Update FullOutline
        if (fullOutlineNodes != null) {

            pollCancel(monitor);
            if (editor.getFullOutline() != null) {
            	//time = System.currentTimeMillis();
            	//createOutlineInput(fullOutlineNodes, monitor);
            	editor.getFullOutline().update(new TexOutlineInput(new ArrayList<OutlineNode>(fullOutlineNodes)));
            	//System.out.println("updateFullOutline: " + (System.currentTimeMillis() - time));
            }
        }

        return Status.OK_STATUS;
    } catch (Exception e) {
        // npe when exiting eclipse and saving
        return Status.CANCEL_STATUS;
    }
}
 
Example 15
Source File: DropAdapterAssistant.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
    if (target instanceof TmfTraceFolder) {
        return Status.OK_STATUS;
    }
    if (target instanceof TmfExperimentElement) {
        return Status.OK_STATUS;
    }
    if (target instanceof TmfTraceElement) {
        ITmfProjectModelElement parent = ((TmfTraceElement) target).getParent();
        if (parent instanceof TmfTraceFolder) {
            return Status.OK_STATUS;
        }
        if (parent instanceof TmfExperimentElement) {
            return Status.OK_STATUS;
        }
    }

    if (target instanceof TmfProjectElement) {
        return Status.OK_STATUS;
    }

    if (target instanceof IProject) {
        return Status.CANCEL_STATUS;
    }

    return Status.CANCEL_STATUS;
}
 
Example 16
Source File: DevicesSyncJob.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
protected IStatus run(IProgressMonitor monitor) {
try {
	logger.info("Syncing devices from github");
	DevicesGit.gitSync();
   	logger.info("Devices sync finished.");
	return Status.OK_STATUS;
}
catch (Exception e) {
	e.printStackTrace();
	logger.error("Cannot sync devices : "+e.getMessage());
	return Status.CANCEL_STATUS;
}
  }
 
Example 17
Source File: NavigatorDropAssistant.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IStatus validateDrop(final Object target, final int operation, final TransferData transferType) {
	return target instanceof NavigatorRoot ? Status.OK_STATUS : Status.CANCEL_STATUS;
}
 
Example 18
Source File: HistoryFilteredList.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
    if (fTable.isDisposed()) {
        return Status.CANCEL_STATUS;
    }
    int itemCount = fTable.getItemCount();

    // Remove excess items
    if (fCount < itemCount) {
        fTable.setRedraw(false);
        fTable.remove(fCount, itemCount - 1);
        fTable.setRedraw(true);
        itemCount = fTable.getItemCount();
    }
    // table empty -> no selection
    if (fCount == 0) {
        fTable.notifyListeners(SWT.Selection, new Event());
        return Status.OK_STATUS;
    }
    // How many we are going to do this time.
    int iterations = Math.min(250, fCount - currentIndex);
    for (int i = 0; i < iterations; i++) {
        if (monitor.isCanceled()) {
            return Status.CANCEL_STATUS;
        }
        final TableItem item = (currentIndex < itemCount) ? fTable.getItem(currentIndex) : new TableItem(
                fTable, SWT.NONE);
        final Label label = fLabels[fFilteredIndices[fFoldedIndices[currentIndex]]];
        item.setText(label.string);
        item.setImage(label.image);
        currentIndex++;
    }
    if (monitor.isCanceled()) {
        return Status.CANCEL_STATUS;
    }
    if (currentIndex < fCount) {
        schedule(0);
    } else {
        if (indicesToSelect == null) {
            // Make a default selection in the table if there is none.
            // If a selection has already been made, honor it.
            // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=112146
            if (fCount > 0) {
                if (fTable.getSelectionIndices().length == 0) {
                    defaultSelect();
                } else {
                    // There is a selection, but it likely hasn't changed since the
                    // job started.  Force a selection notification, since the
                    // items represented by the selection have changed.
                    // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=119456
                    fTable.notifyListeners(SWT.Selection, new Event());
                }
            }
        } else {
            // Set the selection as indicated.
            selectAndNotify(indicesToSelect);
        }
        // This flag signifies that the selection can now be directly
        // updated in the widget.
        readyForSelection = true;
    }
    return Status.OK_STATUS;
}
 
Example 19
Source File: ICEJob.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
	final int ticks = 100;
	int worked = 0;
	monitor.beginTask("Executing the Job Launch Action...", ticks);
	status = FormStatus.Processing;

	// Clear any existing Eclipse Console content
	Action.clearConsole();

	// Execute the Actions
	for (Action action : actions) {
		// Get a reference to the Current Action
		currentlyRunningAction = action;
		monitor.subTask("Executing " + currentlyRunningAction.getActionName() + "...");

		// Execute the Action
		FormStatus tempStatus = currentlyRunningAction.execute(actionDataMap);

		// If the Action returned with an InfoError status,
		// then we need to report that and throw an Error
		// Eclipse Status
		if (tempStatus.equals(FormStatus.InfoError)) {
			return error("Error in executing the " + action.getActionName() + " Action.", null);
		}

		// Check for Eclipse Job cancellations.
		if (monitor.isCanceled()) {
			currentlyRunningAction.cancel();
			status = FormStatus.Processed;
			return Status.CANCEL_STATUS;
		}

		// If the Action is still processing, then
		// lets just wait until its done.
		while (tempStatus.equals(FormStatus.Processing)) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException e1) {
				// Complain
				return error("Error in executing the " + action.getActionName() + " Action.", e1);
			}
			tempStatus = currentlyRunningAction.getStatus();
		}

		// Increment the worked ticker
		worked += ticks / actions.size();
		monitor.worked(worked);
	}

	// Once done executing all Actions, indicate
	// so by setting the status flag.
	status = FormStatus.Processed;
	monitor.worked(ticks);
	monitor.done();

	// Clean up the docker container if this was a 
	// launch using docker
	if (actionDataMap.get("containerId") != null) {
		cleanDockerExecution();
	}
	return Status.OK_STATUS;
}
 
Example 20
Source File: SVNFileModificationValidator.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public IStatus validateEdit(IFile[] files, Object context) {
     String comment = "";
     boolean stealLock = false;
     // reduce the array to just read only files
     ReadOnlyFiles readOnlyFiles = processFileArray(files);
     if (readOnlyFiles.size() == 0) return Status.OK_STATUS;
     // of the read-only files, get array of ones which are versioned
  IFile[] managedFiles = readOnlyFiles.getManaged();
  if (managedFiles.length > 0) {
  	// Prompt user to lock files
  	if (context != null) {
  		ISVNFileModificationValidatorPrompt svnFileModificationValidatorPrompt = 
  			SVNProviderPlugin.getPlugin().getSvnFileModificationValidatorPrompt();
  		if (svnFileModificationValidatorPrompt != null) {
  			if (!svnFileModificationValidatorPrompt.prompt(managedFiles, context))
  				return Status.CANCEL_STATUS;
  			comment = svnFileModificationValidatorPrompt.getComment();
  			stealLock = svnFileModificationValidatorPrompt.isStealLock();
  		}
  	}
  	// Run the svn lock command
  	RepositoryProvider provider = RepositoryProvider.getProvider(managedFiles[0].getProject());
  	if ((provider != null) && (provider instanceof SVNTeamProvider)) {
  		SVNTeamProvider svnTeamProvider = (SVNTeamProvider) provider;
  		LockResourcesCommand command = new LockResourcesCommand(svnTeamProvider.getSVNWorkspaceRoot(), managedFiles, stealLock, comment, false);
  		try {
  			command.run(new NullProgressMonitor());
  		} catch (SVNException e) {
  			SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
  			return Status.CANCEL_STATUS;
  		}
  	}
     }
  // Process any unmanaged but read-only files.  For
  // those we need to prompt the user to flip the read only bit
  IFile[] unManagedFiles = readOnlyFiles.getUnManaged();
  if (unManagedFiles.length > 0) {
   synchronized (this) {
       if (uiValidator == null) 
           uiValidator = loadUIValidator();
   }
   if (uiValidator != null) {
       return uiValidator.validateEdit(unManagedFiles, context);
   }
   // There was no plugged in validator so fail gracefully
return getStatus(unManagedFiles); 
  }
  return Status.OK_STATUS;
 }