下面列出了org.eclipse.ui.services.ISourceProviderService#org.eclipse.jface.dialogs.ProgressMonitorDialog 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Run the processor.
*
* @param pmd the monitor dialog
* @param monitor the process monitor
* @throws MergeUnitException
* @throws SftpUtilException
* @throws MergeCancelException
*/
private void run(final ProgressMonitorDialog pmd, final IProgressMonitor monitor)
throws MergeUnitException, SftpUtilException, MergeCancelException {
this.monitor = monitor;
run(Messages.GitMergeUtil_createRepositoryDirectory, this::createLocalRepositoryIfNotExisting);
run(Messages.GitMergeUtil_clone, this::cloneRepositoryIfNotExisting);
run(Messages.GitMergeUtil_pull, this::pull);
run(Messages.GitMergeUtil_evaluteCommitMessage, this::evaluteCommitMessage);
run(Messages.GitMergeUtil_checkoutBranch, this::checkout);
run(Messages.GitMergeUtil_checkStatus, this::checkStatus);
run(Messages.GitMergeUtil_cherryPick, this::cherryPick);
run(Messages.GitMergeUtil_commit, this::commit);
// When pushed, no way of return
pmd.setCancelable(false);
run(Messages.GitMergeUtil_push, this::push);
monitor.subTask(Messages.GitMergeUtil_moveMergeUnit);
SftpUtil.getInstance().moveMergeUnitFromRemoteToDone(mergeUnit);
monitor.worked(1);
}
/**
* Executes the merge in a separate minimal working copy.
*
* @throws InterruptedException
* @throws InvocationTargetException
* @throws SvnClientException
*/
private void mergeInMinimalWorkingCopy() throws InvocationTargetException, InterruptedException {
LogUtil.entering();
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shellProvider.getShell());
Dashboard.setShellProgressMonitorDialog(pmd);
pmd.run(true, true, monitor -> {
try {
boolean cancelled = MergeProcessorUtil.merge(pmd, monitor, configuration, mergeUnit);
if (cancelled) {
mergeUnit.setStatus(MergeUnitStatus.CANCELLED);
MergeProcessorUtil.canceled(mergeUnit);
} else {
mergeUnit.setStatus(MergeUnitStatus.DONE);
}
} catch (Throwable e) {
pmd.getShell().getDisplay().syncExec(() -> {
MultiStatus status = createMultiStatus(e);
ErrorDialog.openError(pmd.getShell(), "Error dusrching merge process",
"An Exception occured during the merge process. The merge didn't run successfully.",
status);
});
}
});
LogUtil.exiting();
}
/**
* Same as {@link #runInModalDialog(OperationCanceledManager, IRunnableWithProgress)}, but allows reacting to
* exceptions.
*
* @param throwableHandler
* will be invoked on the runnable's thread in case the runnable throws an exception other than a
* {@link OperationCanceledManager#isOperationCanceledException(Throwable) cancellation exception}. May
* be <code>null</code> if no handling of exceptions is required.
*/
public static void runInModalDialog(OperationCanceledManager ocm, IRunnableWithProgress runnable,
Consumer<Throwable> throwableHandler) {
try {
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
final ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell);
dlg.run(true, true, monitor -> {
try {
runnable.run(monitor);
} catch (Throwable th) {
// translate cancellation exceptions from Eclipse/Xtext to SWT/JFace world
if (ocm.isOperationCanceledException(th)) {
throw new InterruptedException();
}
if (throwableHandler != null) {
throwableHandler.accept(th);
}
throw th;
}
});
} catch (InvocationTargetException | InterruptedException e) {
// ignore
}
}
@Override
public boolean performOk() {
final MultiStatus multistatus = statusHelper
.createMultiStatus("Status of importing target platform.");
try {
new ProgressMonitorDialog(getShell()).run(true, false, monitor -> {
final IStatus status = store.save(monitor);
if (!status.isOK()) {
setMessage(status.getMessage(), ERROR);
multistatus.merge(status);
} else {
updateInput(viewer, store.getLocations());
}
});
} catch (final InvocationTargetException | InterruptedException exc) {
multistatus.merge(statusHelper.createError("Error while building external libraries.", exc));
}
if (multistatus.isOK())
return super.performOk();
else
return false;
}
/**
* Attaches the sources.
*/
private void attachSources()
{
final File sourceArchive = page2.getSourceFile();
if (sourceArchive == null)
{
return; //nothing to do
}
IRunnableWithProgress runner = ProjectSourceUtil.getRunner(sourceArchive);
try
{
new ProgressMonitorDialog( getContainer().getShell() ).run( true, false, runner );
}
catch( InvocationTargetException | InterruptedException e )
{
Throwable t = (e instanceof InvocationTargetException) ? e.getCause() : e;
MessageDialog.openError( getShell(), "Error attaching sources", t.toString() );
}
}
@Override
public void run(IAction action) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
dialog.setText("Select text file...");
String sourceFile = dialog.open();
if (sourceFile == null)
return;
ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell());
try {
List<Type> types = TypeCollector.getData(new File(sourceFile), "UTF-8");
pd.setBlockOnOpen(false);
pd.open();
pd.getProgressMonitor().beginTask("Generating cloud...", 200);
TagCloudViewer viewer = getViewer();
viewer.setInput(types, pd.getProgressMonitor());
// viewer.getCloud().layoutCloud(pd.getProgressMonitor(), false);
} catch (IOException e) {
e.printStackTrace();
} finally {
pd.close();
}
}
@Override
public void run() {
Shell shell= JavaPlugin.getActiveWorkbenchShell();
SelectionDialog dialog= null;
try {
dialog= JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell),
SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_ALL_TYPES, false);
} catch (JavaModelException e) {
String title= getDialogTitle();
String message= PackagesMessages.GotoType_error_message;
ExceptionHandler.handle(e, title, message);
return;
}
dialog.setTitle(getDialogTitle());
dialog.setMessage(PackagesMessages.GotoType_dialog_message);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return;
}
Object[] types= dialog.getResult();
if (types != null && types.length > 0) {
gotoType((IType) types[0]);
}
}
private void doFilter(final TmxEditorFilterBean filter) {
TeActiveCellEditor.commit();
final String srcSearchStr = getSearchText(srcSearchText);
final String tgtSearchStr = getSearchText(tgtSearchText);
IRunnableWithProgress progress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
tmxDataAccess.loadDisplayTuIdentifierByFilter(monitor, filter, srcLangCode, tgtLangCode, srcSearchStr,
tgtSearchStr);
}
};
try {
new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, progress);
} catch (Exception e) {
e.printStackTrace();
}
tmxEditorImpWithNattable.setSrcSearchStr(srcSearchStr);
tmxEditorImpWithNattable.setTgtSearchStr(tgtSearchStr);
tmxEditorImpWithNattable.getTable().setFocus();
tmxEditorImpWithNattable.refrush();
tmxEditorImpWithNattable.selectCell(getTgtColumnIndex(), 0);
}
/**
* Moves the specified source file to the specified target file.
*
* @param srcFile
* the source file.
* @param targetFile
* the target file
* @exception InvocationTargetException
* if the run method must propagate a checked exception, it
* should wrap it inside an
* <code>InvocationTargetException</code>; runtime exceptions
* and errors are automatically wrapped in an
* <code>InvocationTargetException</code> by this method
* @exception InterruptedException
* if the operation detects a request to cancel, using
* <code>IProgressMonitor.isCanceled()</code>, it should exit
* by throwing <code>InterruptedException</code>; this method
* propagates the exception
*/
private void moveFile( File srcFile, File targetFile )
throws InvocationTargetException, InterruptedException
{
if ( targetFile.exists( ) )
{
if ( !MessageDialog.openQuestion( getShell( ),
Messages.getString( "MoveResourceAction.Dialog.Title" ), //$NON-NLS-1$
Messages.getString( "MoveResourceAction.Dialog.Message" ) ) ) //$NON-NLS-1$
{
return;
}
new ProgressMonitorDialog( getShell( ) ).run( true,
true,
createDeleteRunnable( Arrays.asList( new File[]{
targetFile
} ) ) );
}
new ProgressMonitorDialog( getShell( ) ).run( true,
true,
createRenameFileRunnable( srcFile, targetFile ) );
}
private void refreshReportProject( final IProject project )
{
WorkspaceModifyOperation op = new WorkspaceModifyOperation( ) {
protected void execute( IProgressMonitor monitor )
throws CoreException
{
project.refreshLocal( IResource.DEPTH_INFINITE, monitor );
}
};
try
{
new ProgressMonitorDialog( composite.getShell( ) ).run( false,
true,
op );
}
catch ( Exception e )
{
ExceptionUtil.handle( e );
}
}
/**
* Test code below
*/
public static void main(String[] arg) {
Shell shl = new Shell();
ProgressMonitorDialog dlg = new AsynchronousProgressMonitorDialog(shl);
long l = System.currentTimeMillis();
try {
dlg.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Testing", 100000);
for (long i = 0; i < 100000 && !monitor.isCanceled(); i++) {
//monitor.worked(1);
monitor.setTaskName("Task " + i);
}
}
});
} catch (Exception e) {
Log.log(e);
}
System.out.println("Took " + ((System.currentTimeMillis() - l)));
}
@Override
public void rename(String newName) {
try {
new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, false,
new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor)
throws CoreException, InvocationTargetException, InterruptedException {
closeAllEditors();
projectListeners.stream().forEach(l -> l.projectClosed(Repository.this, monitor));
disableBuild();
getProject().move(org.eclipse.core.runtime.Path.fromOSString(newName), true, monitor);
RepositoryManager.getInstance().setRepository(newName, monitor);
}
});
} catch (InvocationTargetException | InterruptedException e) {
new BonitaErrorDialog(Display.getDefault().getActiveShell(), "Rename failed", e.getMessage(), e).open();
}
}
@Override
protected void okPressed(){
ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell());
QueryProposalRunnable runnable = new QueryProposalRunnable();
try {
progress.run(true, true, runnable);
if (runnable.isCanceled()) {
return;
} else {
proposal = runnable.getProposal();
}
} catch (InvocationTargetException | InterruptedException e) {
LoggerFactory.getLogger(BillingProposalWizardDialog.class)
.error("Error running proposal query", e);
MessageDialog.openError(getShell(), "Fehler",
"Fehler beim Ausführen des Rechnungs-Vorschlags.");
return;
}
super.okPressed();
}
public static void aquireAndRun(IPersistentObject lockPo, ILockHandler handler){
if (LocalLockServiceHolder.get().getStatus() == ILocalLockService.Status.STANDALONE) {
handler.lockAcquired();
return;
}
Display display = Display.getDefault();
display.syncExec(new Runnable() {
@Override
public void run(){
ProgressMonitorDialog progress =
new ProgressMonitorDialog(display.getActiveShell());
try {
progress.run(true, true, new AcquireLockRunnable(lockPo, handler));
} catch (InvocationTargetException | InterruptedException e) {
logger.warn("Exception during acquire lock.", e);
}
}
});
}
public static void aquireAndRun(Identifiable identifiable, ILockHandler handler){
Display display = Display.getDefault();
display.syncExec(new Runnable() {
@Override
public void run(){
ProgressMonitorDialog progress =
new ProgressMonitorDialog(display.getActiveShell());
try {
progress.run(true, true, new AcquireLockRunnable(identifiable, handler));
} catch (InvocationTargetException | InterruptedException e) {
logger.warn("Exception during acquire lock.", e);
}
}
});
}
public static void aquireAndRun(Identifiable identifiable, ILockHandler handler){
Display display = Display.getDefault();
display.syncExec(new Runnable() {
@Override
public void run(){
ProgressMonitorDialog progress =
new ProgressMonitorDialog(display.getActiveShell());
try {
progress.run(true, true, new AcquireLockRunnable(identifiable, handler));
} catch (InvocationTargetException | InterruptedException e) {
logger.warn("Exception during acquire lock.", e);
}
}
});
}
public static void validate(Collection<INavigationElement<?>> selection) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
ValidationView instance = (ValidationView) page.showView("views.problems");
List<ModelStatus> result = new ArrayList<>();
ProgressMonitorDialog dialog = new ProgressMonitorDialog(UI.shell());
dialog.run(true, true, (monitor) -> {
monitor.beginTask(M.Initializing, IProgressMonitor.UNKNOWN);
Set<CategorizedDescriptor> descriptors = Navigator.collectDescriptors(selection);
DatabaseValidation validation = DatabaseValidation.with(monitor);
result.addAll(validation.evaluate(descriptors));
});
StatusList[] model = createModel(result);
instance.viewer.setInput(model);
if (model.length == 0)
MsgBox.info(M.DatabaseValidationCompleteNoErrorsWereFound);
} catch (Exception e) {
log.error("Error validating database", e);
}
}
private void doCheckout(Commit commit) throws Exception {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(UI.shell());
dialog.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor m) throws InvocationTargetException, InterruptedException {
try {
FetchNotifierMonitor monitor = new FetchNotifierMonitor(m, M.CheckingOutCommit);
RepositoryClient client = Database.getRepositoryClient();
client.checkout(commit.id, monitor);
} catch (WebRequestException e) {
throw new InvocationTargetException(e, e.getMessage());
}
}
});
}
/**
* Creates a new default comparison of all API / implementation projects in the default workspace (i.e. the one
* accessed via {@link IN4JSCore}) and shows this comparison in the widget.
*/
public void setComparison() {
final ProgressMonitorDialog dlg = new ProgressMonitorDialog(getTree().getShell());
try {
dlg.run(false, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
setComparison(monitor);
}
});
} catch (InvocationTargetException | InterruptedException e) {
// ignore
}
}
private Collection<? extends IChange> wrapWithMonitor(String msg, String errMsg,
Function<IProgressMonitor, IStatus> f) throws Exception {
MultiStatus multiStatus = statusHelper.createMultiStatus(msg);
new ProgressMonitorDialog(UIUtils.getShell()).run(true, false, (monitor) -> {
try {
IStatus status = f.apply(monitor);
multiStatus.merge(status);
} catch (Exception e) {
multiStatus.merge(statusHelper.createError(errMsg, e));
}
});
if (!multiStatus.isOK()) {
N4JSActivator.getInstance().getLog().log(multiStatus);
UIUtils.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
String title = "Failed: " + msg;
String descr = StatusUtils.getErrorMessage(multiStatus, true);
ErrorDialog.openError(UIUtils.getShell(), title, descr, multiStatus);
}
});
}
return Collections.emptyList();
}
protected void search() {
DirectoryDialog directoryDialog = new DirectoryDialog(getShell());
directoryDialog.setText("search solc ");
String open = directoryDialog.open();
final File file = new File(open);
final Set<SolC> list = new HashSet<SolC>();
IRunnableWithProgress withProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("file:" + file.getAbsolutePath(), IProgressMonitor.UNKNOWN);
searchAndAdd(file, list, monitor);
monitor.done();
}
};
try {
new ProgressMonitorDialog(getShell()).run(true, true, withProgress);
installedSolCs.addAll(list);
fCompilerList.setInput(installedSolCs.toArray());
} catch (InvocationTargetException | InterruptedException e) {
Activator.logError("", e);
}
}
@Override
public boolean performFinish()
{
if (!page.validatePage())
{
MessageDialog
.openError(
getShell(),
"Unreadable or non-existing file specified",
"Please make sure the archive you selected is readable to the current user and exists." );
// and ... abort
return false;
}
File sourceArchive = page.getSourceFile();
IRunnableWithProgress runner = ProjectSourceUtil.getRunner(sourceArchive);
try
{
new ProgressMonitorDialog( getContainer().getShell() ).run( true, false, runner );
}
catch( InvocationTargetException | InterruptedException e )
{
Throwable t = (e instanceof InvocationTargetException) ? e.getCause() : e;
MessageDialog.openError( getShell(), "Error attaching sources", t.toString() );
}
return true;
}
/**
* Workhorse to do the actual import of the projects into this workspace.
*/
private void synchronizePlatform()
{
boolean autobuildEnabled = isAutoBuildEnabled();
enableAutoBuild( false );
final boolean fixClasspath = page1.isFixClasspath();
final boolean removeHybrisBuilder = page1.isRemoveHybrisGenerator();
final boolean createWorkingSets = page1.isCreateWorkingSets();
final boolean useMultiThread = page1.isUseMultiThread();
final boolean skipJarScanning = page1.isSkipJarScanning();
Preferences preferences = InstanceScope.INSTANCE.getNode("com.hybris.hyeclipse.preferences");
final String platformDir = preferences.get("platform_home", null);
if (platformDir == null)
{
throw new IllegalStateException("not platform has been set, try importing again");
}
IRunnableWithProgress importer = new IRunnableWithProgress()
{
public void run( IProgressMonitor monitor ) throws InvocationTargetException
{
List<IProject> projects = Arrays.asList( ResourcesPlugin.getWorkspace().getRoot().getProjects() );
synchronizePlatform( monitor, projects, new File(platformDir), fixClasspath, removeHybrisBuilder, createWorkingSets, useMultiThread, skipJarScanning);
}
};
try
{
new ProgressMonitorDialog( getContainer().getShell() ).run( true, false, importer );
}
catch( InvocationTargetException | InterruptedException e )
{
Activator.logError("Failed to synchronize platform", e);
Throwable t = (e instanceof InvocationTargetException) ? e.getCause() : e;
MessageDialog.openError( this.page1.getControl().getShell(), "Error", t.toString() );
enableAutoBuild( autobuildEnabled );
}
enableAutoBuild( autobuildEnabled );
}
@Override
public boolean performFinish() {
if (!page.validatePage()) {
MessageDialog.openError(getShell(), "Not option selected", "Select at least one option");
// and ... abort
return false;
}
final boolean createFromLocalExtensions = page.getCreateFromLocalExtensions().getSelection();
final boolean createFromExtensionDirectories = page.getCreateFromExtensionDirectories().getSelection();
IRunnableWithProgress importer = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
if (createFromLocalExtensions) {
WorkingSetsUtils.organizeWorkingSetsFromLocalExtensions(monitor);
}
if (createFromExtensionDirectories) {
WorkingSetsUtils.organizeWorkingSetsFromExtensionDirectories(monitor);
}
}
};
try {
new ProgressMonitorDialog(getContainer().getShell()).run(true, false, importer);
} catch (InvocationTargetException | InterruptedException e) {
Throwable t = (e instanceof InvocationTargetException) ? e.getCause() : e;
MessageDialog.openError(this.page.getControl().getShell(), "Error", t.toString());
}
return true;
}
@Override
protected void perfomeOK() throws Exception {
try {
final ProgressMonitorDialog monitor = new ProgressMonitorDialog(getShell());
final ExportWithProgressManager manager = getExportWithProgressManager(settings.getExportSetting());
manager.init(diagram, getBaseDir());
final ExportManagerRunner runner = new ExportManagerRunner(manager);
monitor.run(true, true, runner);
if (runner.getException() != null) {
throw runner.getException();
}
if (openAfterSavedButton != null && openAfterSavedButton.getSelection()) {
final File openAfterSaved = openAfterSaved();
final URI uri = openAfterSaved.toURI();
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (openWithExternalEditor()) {
IDE.openEditor(page, uri, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);
} else {
final IFileStore fileStore = EFS.getStore(uri);
IDE.openEditorOnFileStore(page, fileStore);
}
}
// there is a case in another project
diagram.getEditor().refreshProject();
} catch (final InterruptedException e) {
throw new InputException();
}
}
static void build() {
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(WorkbenchHelper.getShell());
dialog.setBlockOnOpen(false);
dialog.setCancelable(false);
dialog.setOpenOnRun(true);
try {
dialog.run(true, false, monitor -> doBuild(monitor));
} catch (InvocationTargetException | InterruptedException e1) {
e1.printStackTrace();
}
}
/**
* this is called whenever a new repository location is added for example
* or when user wants to refresh
*/
protected void refreshViewer(Object object, boolean refreshRepositoriesFolders) {
if (treeViewer == null) return;
if (refreshRepositoriesFolders) {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
SVNProviderPlugin.getPlugin().getRepositories().refreshRepositoriesFolders(monitor);
}
};
try {
new ProgressMonitorDialog(getShell()).run(true, false, runnable);
} catch (Exception e) {
SVNUIPlugin.openError(getShell(), null, null, e, SVNUIPlugin.LOG_TEAM_EXCEPTIONS);
}
}
if (object == null) treeViewer.refresh();
else {
if (object instanceof ISVNRemoteFolder) {
ISVNRemoteFolder parent = ((ISVNRemoteFolder)object).getParent();
if (parent == null) {
treeViewer.refresh();
return;
}
}
treeViewer.refresh(object);
}
}
private void refreshRepositoriesFolders() {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
SVNProviderPlugin.getPlugin().getRepositories().refreshRepositoriesFolders(monitor);
needsRefresh = false;
}
};
try {
new ProgressMonitorDialog(getShell()).run(true, false, runnable);
} catch (Exception e) {
SVNUIPlugin.openError(getShell(), null, null, e, SVNUIPlugin.LOG_TEAM_EXCEPTIONS);
}
}
@Override
protected void save(IEditorPart editorPart, GraphicalViewer viewer, String saveFilePath) {
final ProgressMonitorDialog monitor = new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
try {
if (outputImage(monitor, viewer, saveFilePath) != -1) {
Activator.showMessageDialog("dialog.message.export.finish");
}
} catch (final InterruptedException e) {}
}
public static void startCutRefactoring(final Object[] elements, final Shell shell) throws InterruptedException, InvocationTargetException {
JavaDeleteProcessor processor= new JavaDeleteProcessor(elements);
processor.setSuggestGetterSetterDeletion(false);
processor.setQueries(new ReorgQueries(shell));
Refactoring refactoring= new DeleteRefactoring(processor);
int stopSeverity= RefactoringCore.getConditionCheckingFailedSeverity();
new RefactoringExecutionHelper(refactoring, stopSeverity, RefactoringSaveHelper.SAVE_NOTHING, shell, new ProgressMonitorDialog(shell)).perform(false, false);
}