Search in sources :

Example 31 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project xtext-eclipse by eclipse.

the class RefactoringWizardOpenOperation_NonForking method checkInitialConditions.

/**
 * CHANGED to protected
 * CHANGED do not fork as we are keeping the resource lock.
 */
protected RefactoringStatus checkInitialConditions(Refactoring refactoring, Shell parent, String title, IRunnableContext context) throws InterruptedException {
    try {
        CheckConditionsOperation cco = new CheckConditionsOperation(refactoring, CheckConditionsOperation.INITIAL_CONDITONS);
        WorkbenchRunnableAdapter workbenchRunnableAdapter = new WorkbenchRunnableAdapter(cco, ResourcesPlugin.getWorkspace().getRoot());
        /* CHANGE: don't fork (or use busyCursorWhile) as this will cause a deadlock */
        if (context == null) {
            PlatformUI.getWorkbench().getProgressService().run(false, true, workbenchRunnableAdapter);
        } else if (context instanceof IProgressService) {
            ((IProgressService) context).run(false, true, workbenchRunnableAdapter);
        } else {
            context.run(false, true, workbenchRunnableAdapter);
        }
        return cco.getStatus();
    } catch (InvocationTargetException e) {
        ExceptionHandler.handle(e, parent, title, RefactoringUIMessages.RefactoringUI_open_unexpected_exception);
        return RefactoringStatus.createFatalErrorStatus(RefactoringUIMessages.RefactoringUI_open_unexpected_exception);
    }
}
Also used : IProgressService(org.eclipse.ui.progress.IProgressService) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) WorkbenchRunnableAdapter(org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 32 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project archi-modelrepository-plugin by archi-contribs.

the class CloneModelAction method run.

@Override
public void run() {
    // Check primary key set
    try {
        if (!EncryptedCredentialsStorage.checkPrimaryKeySet()) {
            return;
        }
    } catch (GeneralSecurityException ex) {
        displayCredentialsErrorDialog(ex);
        return;
    } catch (Exception ex) {
        displayErrorDialog(Messages.CloneModelAction_0, ex);
        return;
    }
    CloneInputDialog dialog = new CloneInputDialog(fWindow.getShell());
    if (dialog.open() != Window.OK) {
        return;
    }
    final String repoURL = dialog.getURL();
    final boolean storeCredentials = dialog.doStoreCredentials();
    final UsernamePassword npw = dialog.getUsernamePassword();
    if (!StringUtils.isSet(repoURL)) {
        return;
    }
    if (GraficoUtils.isHTTP(repoURL) && !StringUtils.isSet(npw.getUsername()) && npw.getPassword().length == 0) {
        MessageDialog.openError(fWindow.getShell(), Messages.CloneModelAction_0, Messages.CloneModelAction_1);
        return;
    }
    // Create a new local folder
    File localRepoFolder = GraficoUtils.getUniqueLocalFolder(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), repoURL);
    setRepository(new ArchiRepository(localRepoFolder));
    try {
        // Clone
        Exception[] exception = new Exception[1];
        IProgressService ps = PlatformUI.getWorkbench().getProgressService();
        ps.busyCursorWhile(new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor pm) {
                try {
                    // Update Proxy
                    ProxyAuthenticator.update();
                    pm.beginTask(Messages.CloneModelAction_4, -1);
                    getRepository().cloneModel(repoURL, npw, new ProgressMonitorWrapper(pm));
                } catch (Exception ex) {
                    exception[0] = ex;
                } finally {
                    // Clear Proxy
                    ProxyAuthenticator.clear();
                }
            }
        });
        if (exception[0] != null) {
            throw exception[0];
        }
        // Load it from the Grafico files if we can
        IArchimateModel graficoModel = new GraficoModelLoader(getRepository()).loadModel();
        // We couldn't load it from Grafico so create a new blank model
        if (graficoModel == null) {
            // New one. This will open in the tree
            IArchimateModel model = IEditorModelManager.INSTANCE.createNewModel();
            model.setFile(getRepository().getTempModelFile());
            // And Save it
            IEditorModelManager.INSTANCE.saveModel(model);
            // Export to Grafico
            getRepository().exportModelToGraficoFiles();
            // And do a first commit
            getRepository().commitChanges(Messages.CloneModelAction_3, false);
            // Save the checksum
            getRepository().saveChecksum();
        }
        // Store repo credentials if HTTP and option is set
        if (GraficoUtils.isHTTP(repoURL) && storeCredentials) {
            EncryptedCredentialsStorage cs = EncryptedCredentialsStorage.forRepository(getRepository());
            cs.store(npw);
        }
        // Notify listeners
        notifyChangeListeners(IRepositoryListener.REPOSITORY_ADDED);
    } catch (Exception ex) {
        displayErrorDialog(Messages.CloneModelAction_0, ex);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) CloneInputDialog(org.archicontribs.modelrepository.dialogs.CloneInputDialog) ArchiRepository(org.archicontribs.modelrepository.grafico.ArchiRepository) GeneralSecurityException(java.security.GeneralSecurityException) UsernamePassword(org.archicontribs.modelrepository.authentication.UsernamePassword) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) EncryptedCredentialsStorage(org.archicontribs.modelrepository.authentication.EncryptedCredentialsStorage) IProgressService(org.eclipse.ui.progress.IProgressService) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 33 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project archi-modelrepository-plugin by archi-contribs.

the class CreateRepoFromModelAction method run.

@Override
public void run() {
    try {
        if (!EncryptedCredentialsStorage.checkPrimaryKeySet()) {
            return;
        }
    } catch (GeneralSecurityException ex) {
        displayCredentialsErrorDialog(ex);
        return;
    } catch (IOException ex) {
        displayErrorDialog(Messages.CreateRepoFromModelAction_7, ex);
        return;
    }
    NewModelRepoDialog dialog = new NewModelRepoDialog(fWindow.getShell());
    if (dialog.open() != Window.OK) {
        return;
    }
    final String repoURL = dialog.getURL();
    final boolean storeCredentials = dialog.doStoreCredentials();
    final UsernamePassword npw = dialog.getUsernamePassword();
    if (!StringUtils.isSet(repoURL)) {
        return;
    }
    if (GraficoUtils.isHTTP(repoURL) && !StringUtils.isSet(npw.getUsername()) && npw.getPassword().length == 0) {
        MessageDialog.openError(fWindow.getShell(), Messages.CreateRepoFromModelAction_0, Messages.CreateRepoFromModelAction_3);
        return;
    }
    // Create a new local folder
    File localRepoFolder = GraficoUtils.getUniqueLocalFolder(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), repoURL);
    setRepository(new ArchiRepository(localRepoFolder));
    try {
        // Create a new repo
        try (Git git = getRepository().createNewLocalGitRepository(repoURL)) {
        }
        // TODO: If the model has not been saved yet this is fine but if the model already exists
        // We should tell the user this is the case
        // Set new file location
        fModel.setFile(getRepository().getTempModelFile());
        // And Save it
        IEditorModelManager.INSTANCE.saveModel(fModel);
        // Export to Grafico
        getRepository().exportModelToGraficoFiles();
        // Commit changes
        getRepository().commitChanges(Messages.CreateRepoFromModelAction_5, false);
        // Push
        Exception[] exception = new Exception[1];
        IProgressService ps = PlatformUI.getWorkbench().getProgressService();
        ps.busyCursorWhile(new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor pm) {
                try {
                    // Update Proxy
                    ProxyAuthenticator.update();
                    pm.beginTask(Messages.CreateRepoFromModelAction_4, -1);
                    getRepository().pushToRemote(npw, new ProgressMonitorWrapper(pm));
                } catch (Exception ex) {
                    exception[0] = ex;
                } finally {
                    // Clear Proxy
                    ProxyAuthenticator.clear();
                }
            }
        });
        if (exception[0] != null) {
            throw exception[0];
        }
        // Store repo credentials if HTTP and option is set
        if (GraficoUtils.isHTTP(repoURL) && storeCredentials) {
            EncryptedCredentialsStorage cs = EncryptedCredentialsStorage.forRepository(getRepository());
            cs.store(npw);
        }
        // Save the checksum
        getRepository().saveChecksum();
    } catch (Exception ex) {
        displayErrorDialog(Messages.CreateRepoFromModelAction_7, ex);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) NewModelRepoDialog(org.archicontribs.modelrepository.dialogs.NewModelRepoDialog) IOException(java.io.IOException) ArchiRepository(org.archicontribs.modelrepository.grafico.ArchiRepository) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException) UsernamePassword(org.archicontribs.modelrepository.authentication.UsernamePassword) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Git(org.eclipse.jgit.api.Git) EncryptedCredentialsStorage(org.archicontribs.modelrepository.authentication.EncryptedCredentialsStorage) IProgressService(org.eclipse.ui.progress.IProgressService) File(java.io.File)

Example 34 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project egit by eclipse.

the class GitScopeUtil method findRelatedChanges.

private static IResource[] findRelatedChanges(final IWorkbenchPart part, final IResource[] selectedResources) throws InvocationTargetException, InterruptedException {
    final List<IResource> relatedChanges = new ArrayList<>();
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.beginTask(UIText.CommitActionHandler_lookingForChanges, 100);
                List<IResource> collectedResources = collectRelatedChanges(selectedResources, part, monitor);
                relatedChanges.addAll(collectedResources);
            } finally {
                monitor.done();
            }
        }
    };
    IProgressService progressService = CommonUtils.getService(part.getSite(), IProgressService.class);
    progressService.run(true, true, runnable);
    return relatedChanges.toArray(new IResource[relatedChanges.size()]);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProgressService(org.eclipse.ui.progress.IProgressService) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 35 with IProgressService

use of org.eclipse.ui.progress.IProgressService in project gemoc-studio by eclipse.

the class GemocPackageDiscovery method openModelingDiscoveryWizard.

public static void openModelingDiscoveryWizard(IWorkbenchWindow window) {
    final DiscoveryContentProvider provider = new GemocPackageDiscovery();
    IWorkbench wb = PlatformUI.getWorkbench();
    IProgressService ps = wb.getProgressService();
    try {
        ps.busyCursorWhile(new IRunnableWithProgress() {

            public void run(IProgressMonitor pm) {
                try {
                    provider.load(pm);
                } catch (InterruptedException e) {
                /*
						 * End user cancelled
						 */
                }
            }
        });
        if (provider.getDiscovery() != null) {
            DiscoveryWizard wizard = new DiscoveryWizard(provider);
            WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
            dialog.setMinimumPageSize(600, 400);
            dialog.open();
        }
    } catch (InvocationTargetException e1) {
        if (!(e1.getCause() instanceof OperationCanceledException)) {
            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e1.getMessage(), e1));
        }
    } catch (InterruptedException e1) {
    /*
			 * End user cancelled
			 */
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProgressService(org.eclipse.ui.progress.IProgressService) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) DiscoveryContentProvider(org.eclipse.amalgam.discovery.ui.viewer.DiscoveryContentProvider) DiscoveryWizard(org.eclipse.gemoc.gemoc_studio.branding.discovery.wizards.DiscoveryWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

IProgressService (org.eclipse.ui.progress.IProgressService)38 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)17 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)15 IStatus (org.eclipse.core.runtime.IStatus)11 IOException (java.io.IOException)7 Status (org.eclipse.core.runtime.Status)6 IWorkbench (org.eclipse.ui.IWorkbench)6 File (java.io.File)5 CoreException (org.eclipse.core.runtime.CoreException)5 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)4 IContext (org.talend.core.model.process.IContext)4 ProcessorException (org.talend.designer.runprocess.ProcessorException)4 MessageFormat (java.text.MessageFormat)3 Date (java.util.Date)3 IProject (org.eclipse.core.resources.IProject)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)3 IProcessor (org.talend.designer.runprocess.IProcessor)3 ClearPerformanceAction (org.talend.designer.runprocess.ui.actions.ClearPerformanceAction)3