Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog.

Prototype

public ProgressMonitorDialog(Shell parent) 

Source Link

Document

Creates a progress monitor dialog under the given shell.

Usage

From source file:es.bsc.servicess.ide.wizards.ServiceSsImportOrchestrationClassPage.java

License:Apache License

private boolean loadWarFile(final String selectedDirectory, final IFolder importFolder) {

    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(this.getShell());
    try {/*from   w  w  w .j  av a2 s.  c  om*/
        log.debug("Selected dir: " + selectedDirectory);

        final File warFile = new File(selectedDirectory);
        if (warFile.exists()) {
            dialog.run(false, true, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) throws InvocationTargetException {
                    try {
                        if (!importFolder.exists())
                            importFolder.create(true, true, monitor);
                        String name = PackagingUtils.getPackageName(warFile);
                        log.debug("Package name is " + name);
                        IFolder extractFolder = importFolder.getFolder(name);
                        if (!extractFolder.exists()) {
                            extractWar(warFile, extractFolder, monitor);
                            updateDeps(warPath, selectedDirectory, ProjectMetadata.WAR_DEP_TYPE, monitor);
                        } else
                            log.info("Package already exists. Not extracting");

                    } catch (Exception e) {
                        throw (new InvocationTargetException(e));
                    }
                }
            });
            return true;
        } else
            throw (new InvocationTargetException(new Exception("The selected file doesn't exists")));
    } catch (InvocationTargetException e) {
        log.error("Error loading package");
        ErrorDialog.openError(dialog.getShell(), "Error loading new package file",
                "Exception when loading package",
                new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
        return false;
    } catch (InterruptedException e) {
        log.error("Error loading package");
        ErrorDialog.openError(dialog.getShell(), "Package load interrumped", "Exception when loading package",
                new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
        return false;
    }
}

From source file:es.cv.gvcase.trmanager.internal.ui.pages.ShowTransformationResultsPage.java

License:Open Source License

public void performTransformation(TransformationExtraOperations transformationExtOperations) {

    this.resultMessages.clear();
    final RequestTransformationParametersPage parametersPage = (RequestTransformationParametersPage) this
            .getWizard()//ww w  .  j a  va 2  s .  co m
            .getPage(Messages.getString("ShowTransformationResultsPage.EnterTransformationParametersPageName"));
    final RequestConfigurationPage configurationPage = (RequestConfigurationPage) this.getWizard().getPage(
            Messages.getString("TransformationExecutionWizardDialog.SelectConfigurationModelPageName"));

    try {
        new ProgressMonitorDialog(this.getShell()).run(false, false,
                new ExecuteTransformationJob(parametersPage, configurationPage, transformationExtOperations));
    } catch (InvocationTargetException e) {
    } catch (InterruptedException e) {
    }

    this.setPageComplete(true);
    this.refreshPageInfo();
}

From source file:es.uah.aut.srg.micobs.libdesc.presentation.libdescEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * @generated//  w w  w . j  a  v a 2s .  c  o m
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        MICOBSPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:es.uah.aut.srg.micobs.library.ui.handlers.UpdateRemoteModelFile.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    if (!(HandlerUtil.getCurrentSelection(event) instanceof IStructuredSelection)) {
        return null;
    }/*  ww w  .j  a va2s . c  o m*/

    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);

    MCommonLibrary library = null;

    final Set<MCommonPackageVersionedItem> itemsToUpdate = new HashSet<MCommonPackageVersionedItem>();

    for (Iterator<?> i = selection.iterator(); i.hasNext();) {
        Object object = i.next();
        if (object instanceof MCommonLibrary) {
            itemsToUpdate.addAll(getVersionedItems((MCommonLibrary) object));
            library = (MCommonLibrary) object;
        } else if (object instanceof MCommonPackage) {
            itemsToUpdate.addAll(getVersionedItems((MCommonPackage) object));
            library = (MCommonLibrary) EcoreUtil.getRootContainer((EObject) object);
        } else if (object instanceof MCommonPackageItem) {
            MCommonPackageItem item = (MCommonPackageItem) object;
            itemsToUpdate.addAll(item.getVersionedItems());
            library = (MCommonLibrary) EcoreUtil.getRootContainer((EObject) object);
        } else if (object instanceof MCommonPackageVersionedItem) {
            itemsToUpdate.add((MCommonPackageVersionedItem) object);
            library = (MCommonLibrary) EcoreUtil.getRootContainer((EObject) object);
        }
    }

    final BasicDiagnostic diagnostics = new BasicDiagnostic(MICOBSPlugin.INSTANCE.getSymbolicName(), 0,
            "Updating Remote Files", null);

    String libraryID = LibraryAdapterFactory.getAdapterFactory().getLibraryID(library.eClass().getName());
    LibraryAdapter adapter = LibraryAdapterFactory.getAdapterFactory().getAdapter(libraryID);
    if (adapter == null) {
        CheckingDiagnostic diag = CheckingDiagnostic.createError(MICOBSPlugin.INSTANCE.getString(
                "_UI_UnknownLibraryError_message", new Object[] { library.eClass().getName() }), library);
        diagnostics.add(diag);

    }
    final ILibraryManager manager = (ILibraryManager) adapter.adapt(ILibraryManager.class);

    if (manager == null) {
        CheckingDiagnostic diag = CheckingDiagnostic.createError(MICOBSPlugin.INSTANCE.getString(
                "_UI_LibraryInstallError_message", new Object[] { library.eClass().getName() }), library);
        diagnostics.add(diag);
    }

    if (diagnostics.getSeverity() != Diagnostic.OK) {
        DiagnosticDialog.open(HandlerUtil.getActiveShell(event),
                MICOBSPlugin.INSTANCE.getString("_UI_updateRemoteModelFileError_Title"),
                MICOBSPlugin.INSTANCE.getString("_UI_updateRemoteModelFileError_Message"), diagnostics);
        return null;
    }

    try {
        new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)).run(true, true,
                new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {

                        monitor.beginTask("Updating Remote Files", 100); //$NON-NLS-1$   

                        int step = 100 / itemsToUpdate.size();

                        for (MCommonPackageVersionedItem versionedItem : itemsToUpdate) {
                            if (monitor.isCanceled()) {
                                break;
                            }
                            monitor.worked(step);

                            if (versionedItem.getRemoteModelURI() == null) {
                                continue;
                            }

                            MCommonPackageElement element;

                            try {
                                element = manager.getElement(versionedItem);
                            } catch (LibraryManagerException e) {
                                MICOBSPlugin.INSTANCE.log(e);
                                throw new InvocationTargetException(e);
                            }

                            String remoteModelURI = versionedItem.getRemoteModelURI();
                            String localModelURI = versionedItem.getLocalModelURI();
                            String modelFileExtension = remoteModelURI
                                    .substring(remoteModelURI.lastIndexOf(".") + 1, remoteModelURI.length());

                            File tmp = null;
                            try {
                                tmp = SVNUtil.loadRemoteFileOnTmp(remoteModelURI, "model",
                                        "." + modelFileExtension, monitor);
                            } catch (CoreException e) {
                                diagnostics.add(CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERROR_ModelElementLoading",
                                                new Object[] { remoteModelURI }),
                                        versionedItem));
                                continue;
                            } catch (IOException e) {
                                diagnostics.add(CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERROR_SavingTmp"), versionedItem));
                                continue;
                            }

                            File destFile = null;
                            String destString = null;

                            URI resourceURI = URI.createURI(localModelURI, true);

                            try {
                                destFile = FileConverter.platformPluginURItoFile(resourceURI);
                                destString = destFile.getAbsolutePath();
                                manager.removeElement(element.eClass(), element.getUri(), element.getVersion());
                            } catch (Throwable e) {
                                CheckingDiagnostic diag = CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERR_ResourceUnloadProblem"),
                                        versionedItem);
                                diagnostics.add(diag);
                                continue;
                            }

                            try {
                                if (destFile.isFile()) {
                                    destFile.setWritable(true);
                                    destFile.delete();
                                }
                                FileHelper.copyBinaryFile(tmp.getAbsolutePath(), destString);
                                destFile.setWritable(false);
                            } catch (IOException e) {
                                CheckingDiagnostic diag = CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERROR_CopyingFileToLibrary"),
                                        versionedItem);
                                diagnostics.add(diag);
                                continue;
                            }

                            MCommonPackageVersionedItem newVersionedItem = null;

                            try {
                                newVersionedItem = manager.putElement(resourceURI);
                            } catch (Throwable e) {
                                CheckingDiagnostic diag = CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERROR_CopyingFileToLibrary"),
                                        versionedItem);
                                diagnostics.add(diag);
                                continue;
                            }

                            for (Iterator<EStructuralFeature> f = versionedItem.eClass()
                                    .getEAllStructuralFeatures().iterator(); f.hasNext();) {
                                EStructuralFeature feature = f.next();
                                if (feature != commonPackage.eINSTANCE
                                        .getMCommonPackageVersionedItem_LocalModelURI()
                                        && versionedItem.eGet(feature) != null) {
                                    newVersionedItem.eSet(feature, versionedItem.eGet(feature));
                                }
                            }
                        }
                        try {
                            manager.saveLibrary();
                        } catch (IOException e) {
                            MICOBSPlugin.INSTANCE.log(e);
                            throw new InvocationTargetException(e);
                        }

                        monitor.done();

                    }
                });

    } catch (InvocationTargetException e) {
        MICOBSPlugin.INSTANCE.log(e);
        return false;
    } catch (InterruptedException e) {
        MICOBSPlugin.INSTANCE.log(e);
        return false;
    }

    if (diagnostics.getSeverity() != Diagnostic.OK) {
        DiagnosticDialog.open(HandlerUtil.getActiveShell(event),
                MICOBSPlugin.INSTANCE.getString("_UI_updateRemoteModelFileError_Title"),
                MICOBSPlugin.INSTANCE.getString("_UI_updateRemoteModelFileError_Message"), diagnostics);
    }

    return null;
}

From source file:es.uah.aut.srg.micobs.mesp.library.mesplibrary.presentation.mesplibraryEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * @generated/*from   w w  w  .  j a  v a2  s  .c o m*/
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        MESPPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:es.uah.aut.srg.micobs.pdl.library.pdllibrary.presentation.pdllibraryEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * @generated/*from w ww  .  j a  v  a  2  s.c om*/
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        PDLPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:es.uah.aut.srg.micobs.ui.handlers.UpdateRemoteFilesHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection instanceof IStructuredSelection) {
        final Object object = ((IStructuredSelection) selection).getFirstElement();
        if (object instanceof IResource) {
            shell = HandlerUtil.getActiveShell(event);
            final IRunnableContext context = new ProgressMonitorDialog(shell);
            final Exception except[] = new Exception[1];

            // First we obtain the model folder
            final IContainer modelFolder = ((IResource) object).getParent();

            final IContainer rootFolder = modelFolder.getParent();

            ResourceSet resourceSet = new ResourceSetImpl();
            Resource resource = resourceSet.getResource(
                    URI.createPlatformResourceURI(((IResource) object).getFullPath().toString(), true), true);

            final EObject model = resource.getContents().get(0);

            if (model.eClass() != getModelEClass()) {
                MessageDialog.openError(shell,
                        MICOBSPlugin.INSTANCE
                                .getString("_UI_GenerateFileHandler_ModelClassMismatch_dialogTitle"),
                        getModelClassErrorMessage());
                return null;
            }/*from  ww  w . j a  v  a  2s  .com*/

            Diagnostic diagnostic = MICOBSUtilProvider.getMICOBSUtil().validateResource(resource,
                    getItemProviderAdapterFactory());

            if (diagnostic.getSeverity() != Diagnostic.OK) {
                handleDiagnostic(diagnostic);
                return null;
            }

            if (getModelFolderName(model) != null && !modelFolder.getName().equals(getModelFolderName(model))) {
                MessageDialog.openError(shell,
                        MICOBSPlugin.INSTANCE
                                .getString("_UI_GenerateFileHandler_ModelFolderNameMismatch_dialogTitle"),
                        getModelFolderErrorMessage());
                return null;
            }

            if (!MessageDialog.openQuestion(shell,
                    MICOBSPlugin.INSTANCE.getString("_UI_GenerateFileHandler_ConfirmOperation_dialogTitle"),
                    getConfirmDialogMessage())) {
                return null;
            }

            shell.getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {

                    try {
                        context.run(false, false, new IRunnableWithProgress() {

                            @Override
                            public void run(IProgressMonitor monitor)
                                    throws InvocationTargetException, InterruptedException {

                                monitor.beginTask(MICOBSPlugin.INSTANCE
                                        .getString("_UI_GenerateFileHandler_ErasingTask_message"), 100);

                                try {
                                    List<IResource> resources = getResourcesToErase(rootFolder, model);

                                    for (Iterator<IResource> res = resources.iterator(); res.hasNext();) {
                                        IResource resource = res.next();

                                        if (resource.exists()) {
                                            res.remove();
                                            resource.delete(true, new NullProgressMonitor());
                                        }
                                    }

                                } catch (CoreException e) {
                                    throw new InvocationTargetException(e);
                                }

                                monitor.done();

                            }
                        });
                    } catch (InvocationTargetException e) {
                        except[0] = e;
                    } catch (InterruptedException e) {
                        except[0] = e;
                    }
                }
            });

            if (except[0] != null) {
                except[0].printStackTrace();
                return null;
            }

            // Now we have to link the new stuff and update

            shell.getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {

                    try {
                        context.run(false, false, new IRunnableWithProgress() {
                            public void run(IProgressMonitor monitor)
                                    throws InvocationTargetException, InterruptedException {

                                monitor.beginTask(MICOBSPlugin.INSTANCE
                                        .getString("_UI_GenerateFileHandler_FileGeneration_message"), 100);

                                List<RemoteFileToCopy> remoteFiles = getRemoteFilesToCopy(model, rootFolder,
                                        monitor);

                                for (RemoteFileToCopy remoteFileToCopy : remoteFiles) {
                                    if (remoteFileToCopy.getDestination() == null
                                            || remoteFileToCopy.getUrl() == null) {
                                        continue;
                                    }
                                    IContainer destination = remoteFileToCopy.getDestination();
                                    String url = remoteFileToCopy.getUrl();
                                    String remoteFilename = "";

                                    for (int i = 0; i < url.length(); i++) {
                                        String partialPath = url.substring(0, i + 1);
                                        if (partialPath.endsWith("/")) {
                                            remoteFilename = url.substring(i + 1, url.length());
                                        }
                                    }
                                    if (remoteFilename.length() == 0) {
                                        continue;
                                    }
                                    IFile localFile = destination.getFile(new Path(remoteFilename));

                                    try {
                                        ISVNRepositoryLocation location = SVNProviderPlugin.getPlugin()
                                                .getRepository(url);
                                        RemoteFile remoteFile = null;

                                        remoteFile = new RemoteFile(location, new SVNUrl(url),
                                                SVNRevision.HEAD);
                                        remoteFile.fetchContents(new NullProgressMonitor());
                                        InputStream remoteFileIS = remoteFile
                                                .getStorage(new NullProgressMonitor()).getContents();

                                        if (localFile.exists() == true) {
                                            if (FileHelper.compare(localFile.getContents(),
                                                    remoteFileIS) == false) {
                                                localFile.setContents(remoteFileIS, true, true, monitor);
                                            }
                                        } else {
                                            localFile.create(remoteFileIS, true, monitor);
                                        }
                                    } catch (CoreException e) {
                                        e.printStackTrace();
                                        throw new InvocationTargetException(e);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                        throw new InvocationTargetException(e);
                                    }
                                }

                                monitor.done();

                            }
                        });
                    } catch (InvocationTargetException e) {
                        except[0] = e;
                    } catch (InterruptedException e) {
                        except[0] = e;
                    }
                }
            });

            if (except[0] != null) {
                except[0].printStackTrace();
                return null;
            }

            try {
                ((IResource) object).getProject().refreshLocal(IProject.DEPTH_INFINITE,
                        new NullProgressMonitor());
            } catch (CoreException e) {
                e.printStackTrace();
            }
        }
    }

    return null;
}

From source file:es.uah.aut.srg.micobs.ui.handlers.UpdateRemoteFoldersHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection instanceof IStructuredSelection) {
        final Object object = ((IStructuredSelection) selection).getFirstElement();
        if (object instanceof IResource) {
            shell = HandlerUtil.getActiveShell(event);
            final IRunnableContext context = new ProgressMonitorDialog(shell);
            final Exception except[] = new Exception[1];

            // First we obtain the model folder
            final IContainer modelFolder = ((IResource) object).getParent();

            if (!modelFolder.getName().equals(getModelFolderName())) {
                MessageDialog.openError(shell,
                        MICOBSPlugin.INSTANCE
                                .getString("_UI_UpdateResourcesHandler_ModelFolderNameMismatch_dialogTitle"),
                        getModelFolderErrorMessage());
                return null;
            }/*from  w w  w .  j  av  a2  s  .c om*/

            final IContainer rootFolder = modelFolder.getParent();

            ResourceSet resourceSet = new ResourceSetImpl();
            Resource resource = resourceSet.getResource(
                    URI.createPlatformResourceURI(((IResource) object).getFullPath().toString(), true), true);

            final EObject model = resource.getContents().get(0);

            if (model.eClass() != getModelEClass()) {
                MessageDialog.openError(shell,
                        MICOBSPlugin.INSTANCE
                                .getString("_UI_UpdateResourcesHandler_ModelClassMismatch_dialogTitle"),
                        getModelClassErrorMessage());
                return null;
            }

            Diagnostic diagnostic = MICOBSUtilProvider.getMICOBSUtil().validateResource(resource,
                    getItemProviderAdapterFactory());

            if (diagnostic.getSeverity() != Diagnostic.OK) {
                handleDiagnostic(diagnostic);
                return null;
            }

            if (!MessageDialog.openQuestion(shell,
                    MICOBSPlugin.INSTANCE.getString("_UI_UpdateResourcesHandler_ConfirmOperation_dialogTitle"),
                    getConfirmDialogMessage())) {
                return null;
            }

            final BasicDiagnostic runningDiagnostics = new BasicDiagnostic(
                    MICOBSPlugin.INSTANCE.getSymbolicName(), 0, "Update Resources Handler", null);

            // Now that we have the OK and the model is fine, we can start
            // the action!

            shell.getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {

                    try {
                        context.run(false, true, new IRunnableWithProgress() {

                            @Override
                            public void run(IProgressMonitor monitor)
                                    throws InvocationTargetException, InterruptedException {

                                monitor.beginTask(MICOBSPlugin.INSTANCE
                                        .getString("_UI_UpdateResourcesHandler_Task_message"), 100);

                                IFolder[] folders = getFoldersToUnlink(rootFolder, model);
                                List<Map<String, String>> itemList = new ArrayList<Map<String, String>>();
                                Diagnostic diag = getNewMappingLists(rootFolder, model, itemList);
                                if (diag != null) {
                                    runningDiagnostics.add(diag);
                                }
                                if (runningDiagnostics.getSeverity() != Diagnostic.OK) {
                                    return;
                                }

                                if (folders.length == 0 || itemList.size() == 0) {
                                    return;
                                }

                                int step = (100 + folders.length - 1) / folders.length;

                                for (int i = 0; i < folders.length; i++) {
                                    monitor.subTask(MICOBSPlugin.INSTANCE.getString(
                                            "_UI_UpdateResourcesHandler_UpdatingFolderSubTask_message",
                                            new Object[] { folders[i].getName() }));
                                    if (folders[i].exists() == false) {
                                        runningDiagnostics.add(CheckingDiagnostic.createError(
                                                "Folder " + folders[i].getName() + " does not exist"));
                                        continue;
                                    }
                                    Collection<String> foldersToErase = new HashSet<String>();
                                    Map<String, String> oldItems = SVNUtil.getExternalItems(folders[i]);
                                    for (Iterator<String> m = oldItems.keySet().iterator(); m.hasNext();) {
                                        String key = m.next();
                                        if (!itemList.get(i).containsKey(key)) {
                                            // This means that it was a
                                            // linked resource that is no more
                                            foldersToErase.add(key);
                                        }
                                    }

                                    // Now we have to clean the externals
                                    SVNUtil.setExternalItems(folders[i], itemList.get(i));
                                    SVNUtil.updateResources(new IResource[] { folders[i] });
                                    monitor.worked(step / 2);

                                    // Now it's cleaned.. we have to erase
                                    // foldersToErase
                                    monitor.subTask(MICOBSPlugin.INSTANCE
                                            .getString("_UI_UpdateResourcesHandler_ErasingSubTask_message"));
                                    for (Iterator<String> f = foldersToErase.iterator(); f.hasNext();) {
                                        String erase = f.next();
                                        IFolder eraseFolder = folders[i].getFolder(new Path(erase));
                                        if (eraseFolder.exists()) {
                                            try {
                                                eraseFolder.delete(true, new NullProgressMonitor());
                                            } catch (CoreException e) {
                                                throw new InvocationTargetException(e);
                                            }
                                        }
                                    }
                                    monitor.worked(step / 2);
                                    if (monitor.isCanceled()) {
                                        return;
                                    }
                                }

                                try {
                                    ((IResource) object).getProject().refreshLocal(IProject.DEPTH_INFINITE,
                                            new NullProgressMonitor());
                                } catch (CoreException e) {
                                    throw new InvocationTargetException(e);
                                }

                                monitor.done();

                            }
                        });
                    } catch (InvocationTargetException e) {
                        except[0] = e;
                    } catch (InterruptedException e) {
                        except[0] = e;
                    }
                }
            });

            if (except[0] != null) {
                MICOBSPlugin.INSTANCE.log(except[0]);
                return null;
            }

            if (runningDiagnostics.getSeverity() != Diagnostic.OK) {
                handleDiagnostic(runningDiagnostics);
                return null;
            }
        }
    }
    return null;
}

From source file:es.uah.aut.srg.micobs.ui.wizards.EmptyMICOBSProjectWizard.java

License:Open Source License

@Override
public void addPages() {

    projectCreationPage = addProjectCreationPage(selection);
    if (projectCreationPage == null) {
        return;/* w w w  .j a va2 s. co  m*/
    }
    addPage(projectCreationPage);

    ImageDescriptor sharingImage = SVNUIPlugin.getPlugin().getImageDescriptor(ISVNUIConstants.IMG_WIZBAN_SHARE);

    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            locations = SVNUIPlugin.getPlugin().getRepositoryManager().getKnownRepositoryLocations(monitor);
        }
    };
    try {
        new ProgressMonitorDialog(getShell()).run(true, false, runnable);
    } catch (Exception e) {
        SVNUIPlugin.openError(getShell(), null, null, e, SVNUIPlugin.LOG_TEAM_EXCEPTIONS);
    }
    if (locations.length > 0) {
        locationPage = new RepositorySelectionPage("importPage", Policy.bind("SharingWizard.importTitle"), //$NON-NLS-1$//$NON-NLS-2$
                sharingImage);
        locationPage.setDescription(Policy.bind("SharingWizard.importTitleDescription")); //$NON-NLS-1$
        addPage(locationPage);
    }
    createLocationPage = new ConfigurationWizardMainPage("createLocationPage", //$NON-NLS-1$
            Policy.bind("SharingWizard.enterInformation"), sharingImage); //$NON-NLS-1$
    createLocationPage.setDescription(Policy.bind("SharingWizard.enterInformationDescription")); //$NON-NLS-1$
    addPage(createLocationPage);
    createLocationPage.setDialogSettings(getDialogSettings());
    ISVNRepositoryLocationProvider repositoryLocationProvider = new ISVNRepositoryLocationProvider() {
        public ISVNRepositoryLocation getLocation() throws TeamException {
            return EmptyMICOBSProjectWizard.this.getLocation();
        }

        public IProject getProject() {
            return EmptyMICOBSProjectWizard.this.newProject;
        }
    };
    directoryPage = new GenDirectorySelectionPage("modulePage", Policy.bind("SharingWizard.enterModuleName"), //$NON-NLS-1$//$NON-NLS-2$
            sharingImage, repositoryLocationProvider, this);
    directoryPage.setDescription(Policy.bind("SharingWizard.enterModuleNameDescription")); //$NON-NLS-1$
    addPage(directoryPage);

}

From source file:eu.aniketos.wp1.ststool.diagram.sheet.ThreatEventPropertySection.java

License:Open Source License

/**
 * @generated NOT/*from w  w  w.j av  a  2  s.c  o  m*/
 */
private void loadThreatRepositoryPlugin() {

    try {
        new ProgressMonitorDialog(container.getShell()).run(true, false, new ConnectionInitiationHandler());

    } catch (Exception ex) {
        // This is nothing to tell the user about just yet as it should be done in the background
        MessageDialog.openError(container.getShell(), "Threat Repository connection failed",
                ex.getCause().getMessage());
    }
}