Example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

Introduction

In this page you can find the example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress.

Prototype

IRunnableWithProgress

Source Link

Usage

From source file:com.codenvy.eclipse.ui.wizard.importer.pages.ProjectWizardPage.java

License:Open Source License

/**
 * Method used to load the workspace projects asynchronously when the workspace is selected.
 *///from   ww  w . j ava2 s  .  co m
private void loadWorkspaceProjects(final WorkspaceReference workspaceRef) {
    try {

        projectTableViewer.setInput(null);
        validatePage();

        getContainer().run(true, false, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                final CredentialsProviderWizard wizard = getWizard();

                try {

                    monitor.beginTask("Fetch workspace projects from Codenvy", UNKNOWN);

                    Display.getDefault().syncExec(new Runnable() {
                        @Override
                        public void run() {
                            final String platformURL = wizard.getUrl();
                            final String username = wizard.getUsername();
                            final String password = wizard.getPassword();
                            final boolean isStoreUserCredentials = wizard.isStoreUserCredentials();
                            final Credentials credentials = CodenvyAPI.getClient().newCredentialsBuilder()
                                    .withUsername(username).withPassword(password)
                                    .storeOnlyToken(!isStoreUserCredentials).build();

                            final Codenvy codenvy = CodenvyPlugin.getDefault()
                                    .getCodenvyBuilder(platformURL, username).withCredentials(credentials)
                                    .build();

                            final List<ProjectReference> projects = codenvy.project()
                                    .getWorkspaceProjects(workspaceRef.id()).execute();

                            projectTableViewer.setInput(projects);

                            final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                            for (ProjectReference oneProject : projects) {
                                final IProject workspaceProject = workspaceRoot.getProject(oneProject.name());
                                projectTableViewer.setGrayed(oneProject, workspaceProject.exists());
                            }

                            projectTableViewer.refresh();
                        }
                    });

                } finally {
                    monitor.done();
                }
            }
        });

    } catch (InvocationTargetException | InterruptedException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.codesourcery.internal.installer.ui.InstallWizard.java

License:Open Source License

/**
 * Performs the uninstallation.//www.  j  av a2 s . c  om
 *
 * @return Status
 * @throws CoreException on failure
 */
private IStatus uninstall() {
    Throwable error = null;
    final IStatus[] status = new IStatus[] { Status.OK_STATUS };

    final IInstallProduct[] products = productsPage.getSelectedProducts();

    // Install
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    // Remove products
                    getInstallManager().uninstall(products, monitor);

                    if (monitor.isCanceled())
                        status[0] = Status.CANCEL_STATUS;
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (Exception e) {
        error = e;
    }

    // Install operation failed
    if (error != null) {
        status[0] = new Status(IStatus.ERROR, Installer.ID, 0, InstallMessages.UninstallationFailed, error);
    }

    return status[0];
}

From source file:com.codesourcery.internal.installer.ui.InstallWizard.java

License:Open Source License

/**
 * Performs the installation/*from   ww w . ja  v  a  2s  .  c o  m*/
 * 
 * @param data Install data
 * @return Status
 * @throws CoreException on failure
 */
private IStatus install(IInstallData data) {
    final IStatus[] status = new IStatus[] { Status.OK_STATUS };
    try {
        // Install
        getContainer().run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    getInstallManager().install(installData, monitor);

                    if (monitor.isCanceled()) {
                        status[0] = Status.CANCEL_STATUS;
                    }
                } catch (CoreException e) {
                    Installer.log(e);
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (Exception e) {
        status[0] = new Status(IStatus.ERROR, Installer.ID, 0, "", e);
    }

    return status[0];
}

From source file:com.collabnet.ccf.migration.wizards.MigrateLandscapeWizard.java

License:Open Source License

@Override
public boolean performFinish() {

    saveSelections();/*from w w w  .  ja v  a 2 s.c  o m*/

    participantConfigs = null;
    landscapeConfigs = null;
    directionConfigs = null;
    migrationResults = new ArrayList<MigrationResult>();
    exception = null;
    canceled = false;
    showMigrationResults = true;

    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            String taskName = "Migrating landscape";
            monitor.setTaskName(taskName);
            int taskCount = 25 + (mappingPage.getSelectedProjectMappings().length * 2)
                    + mappingPage.getSelectedRepositoryMappings().length;
            monitor.beginTask(taskName, taskCount);
            try {
                projectMappings = mappingPage.getSelectedProjectMappings();
                if (projectMappings == null) {
                    projectMappings = getProjectMappings(monitor);
                } else {
                    projectIds = mappingPage.getSelectedProjectIds();
                }
                boolean resumedMappingSelected = false;
                for (SynchronizationStatus projectMapping : projectMappings) {
                    if (!projectMapping.isPaused()) {
                        resumedMappingSelected = true;
                        break;
                    }
                }
                if (resumedMappingSelected) {
                    Display.getDefault().syncExec(new Runnable() {
                        public void run() {
                            if (!MessageDialog.openConfirm(Display.getDefault().getActiveShell(),
                                    "Migrate Landscape to CCF 2.x",
                                    "Before migration starts, all selected CCF 1.x project mappings will be paused.  This is to prevent situation where CCF 1.x and CCF 2.x are trying to synchronize the same entities which might result in conflicts and duplicate artifacts. After the migration has been finished, please resume the repository mapping directions in CCF 2.x again and make sure that they are not resumed again in CCF 1.x. The reason this migrator does not automatically delete CCF 1.x project mappings after successful migration is that you should still have the chance to fall back to CCF 1.x if you are not satisfied with the migration result.\n\nPause selected CCF 1.x project mappings and continue with migration?")) {
                                canceled = true;
                                showMigrationResults = false;
                            }
                        }
                    });
                    if (canceled == true) {
                        return;
                    }
                    monitor.subTask("Pausing CCF 1.x project mappings");
                    for (SynchronizationStatus projectMapping : projectMappings) {
                        if (!projectMapping.isPaused()) {
                            getCcfDataProvider().pauseSynchronization(projectMapping);
                        }
                    }
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                if (projectMappingMap == null) {
                    projectMappingMap = getProjectMappingMap(monitor);
                }

                teamForgeClient.getConnection().login();
                if (!teamForgeClient.getConnection().supports54()) {
                    exception = new Exception("TeamForge 5.4 or higher is required to migrate landscape.");
                    return;
                }

                UserDO userDO = teamForgeClient.getConnection().getTeamForgeClient()
                        .getUserData(ccfMasterPage.getCcfMasterUser());
                if (!userDO.getSuperUser()) {
                    exception = new Exception(
                            "TeamForge site admin privileges are required to migrate landscape.");
                    return;
                }

                monitor.worked(1);
                monitor.subTask("Checking for existing CCF Master participants");
                String otherType;
                if (landscape.getType1().equals("TF")) {
                    otherType = landscape.getType2();
                } else {
                    otherType = landscape.getType1();
                }

                Participant[] participants = getCcfMasterClient().getParticipants();
                Participant teamForgeParticipant = null;
                Participant otherParticipant = null;
                for (Participant participant : participants) {
                    if (participant.getSystemKind().equals("TF")) {
                        teamForgeParticipant = participant;
                        migrationResults.add(
                                new MigrationResult("TeamForge participant already exists in CCF Master."));
                    } else {
                        otherParticipant = participant;
                        migrationResults.add(new MigrationResult(getParticipantDescription(otherType)
                                + " participant already exists in CCF Master."));
                    }
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                boolean teamForgeParticipantAlreadyExists = teamForgeParticipant != null;
                if (teamForgeParticipant == null) {
                    monitor.subTask("Creating CCF Master TeamForge participant");
                    teamForgeParticipant = new Participant();
                    teamForgeParticipant.setSystemId("TeamForge");
                    teamForgeParticipant.setDescription("TeamForge");
                    teamForgeParticipant.setSystemKind("TF");
                    if (landscape.getType2().equals("TF")) {
                        teamForgeParticipant.setTimezone(landscape.getTimezone2());
                    } else {
                        teamForgeParticipant.setTimezone(landscape.getTimezone1());
                    }
                    teamForgeParticipant = getCcfMasterClient().createParticipant(teamForgeParticipant);
                    migrationResults.add(new MigrationResult("TeamForge participant created in CCF Master."));
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                ParticipantConfig teamForgeParticipantConfig = new ParticipantConfig();
                teamForgeParticipantConfig.setName(ParticipantConfig.TF_URL);
                if (landscape.getType2().equals("TF")) {
                    teamForgeParticipantConfig.setVal(landscape.getUrl(2));
                } else {
                    teamForgeParticipantConfig.setVal(landscape.getUrl(1));
                }
                teamForgeParticipantConfig.setParticipant(teamForgeParticipant);
                if (createOrUpdateParticipantConfig(getCcfMasterClient(), teamForgeParticipant,
                        teamForgeParticipantAlreadyExists, teamForgeParticipantConfig)) {
                    migrationResults
                            .add(new MigrationResult("TeamForge participant properties set in CCF Master."));
                } else {
                    String message = "CCF Master landscape already exists and refers to a different TeamForge site.";
                    migrationResults
                            .add(new MigrationResult(message, MigrationResult.ERROR, new Exception(message)));
                    return;
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                boolean otherParticipantAlreadyExists = otherParticipant != null;
                if (otherParticipant == null) {
                    String otherDescription = getParticipantDescription(otherType);
                    monitor.subTask("Creating CCF Master " + otherDescription + " participant");
                    otherParticipant = new Participant();
                    if (otherType.equals("QC")) {
                        otherParticipant.setSystemId("Quality Center");
                    } else {
                        otherParticipant.setSystemId(otherType);
                    }
                    otherParticipant.setDescription(otherDescription);
                    otherParticipant.setSystemKind(otherType);
                    if (landscape.getType2().equals("TF")) {
                        otherParticipant.setTimezone(landscape.getTimezone1());
                    } else {
                        otherParticipant.setTimezone(landscape.getTimezone2());
                    }
                    otherParticipant = getCcfMasterClient().createParticipant(otherParticipant);
                    migrationResults.add(new MigrationResult(
                            getParticipantDescription(otherType) + " participant created in CCF Master."));
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                ParticipantConfig otherParticipantConfig = new ParticipantConfig();
                if (otherType.equals("SWP")) {
                    otherParticipantConfig.setName(ParticipantConfig.SWP_URL);
                } else {
                    otherParticipantConfig.setName(ParticipantConfig.QC_URL);
                }
                if (landscape.getType2().equals("TF")) {
                    otherParticipantConfig.setVal(landscape.getUrl(1));
                } else {
                    otherParticipantConfig.setVal(landscape.getUrl(2));
                }
                otherParticipantConfig.setParticipant(otherParticipant);
                if (createOrUpdateParticipantConfig(getCcfMasterClient(), otherParticipant,
                        otherParticipantAlreadyExists, otherParticipantConfig)) {
                    migrationResults.add(new MigrationResult(getParticipantDescription(otherType)
                            + " participant properties set in CCF Master."));
                } else {
                    String participantDescription;
                    if (otherType.equals("SWP")) {
                        participantDescription = "ScrumWorks Pro";
                    } else {
                        participantDescription = "Quality Center";
                    }
                    String message = "CCF Master landscape already exists and refers to a different "
                            + participantDescription + " site.";
                    migrationResults
                            .add(new MigrationResult(message, MigrationResult.ERROR, new Exception(message)));
                    return;
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                monitor.subTask("Checking for existing CCF Master landscape");
                com.collabnet.ccf.api.model.Landscape ccfMasterLandscape = null;
                com.collabnet.ccf.api.model.Landscape[] landscapes = getCcfMasterClient().getLandscapes(true);
                for (com.collabnet.ccf.api.model.Landscape landscape : landscapes) {
                    ccfMasterLandscape = landscape;
                    migrationResults.add(new MigrationResult(
                            "Landscape " + ccfMasterLandscape.getName() + " already exists in CCF Master."));
                    break;
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                boolean landscapeAlreadyExists = ccfMasterLandscape != null;

                if (ccfMasterLandscape == null) {
                    monitor.subTask("Creating CCF Master landscape");
                    ccfMasterLandscape = new com.collabnet.ccf.api.model.Landscape();
                    ccfMasterLandscape.setName(landscape.getDescription());
                    ccfMasterLandscape.setParticipant(otherParticipant);
                    ccfMasterLandscape.setTeamForge(teamForgeParticipant);
                    ccfMasterLandscape = getCcfMasterClient().createLandscape(ccfMasterLandscape);
                    migrationResults.add(new MigrationResult(
                            "Landscape " + ccfMasterLandscape.getName() + " created in CCF Master."));
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                String teamForgeUsername = null;
                String teamForgePassword = null;
                String otherUsername = null;
                String otherPassword = null;
                String swpResyncUsername = null;
                String swpResyncPassword = null;
                if (landscape.getType2().equals("TF")) {
                    teamForgeUsername = landscape.getProperties2().getProperty(Activator.PROPERTIES_SFEE_USER,
                            "");
                    teamForgePassword = landscape.getProperties2()
                            .getProperty(Activator.PROPERTIES_SFEE_PASSWORD, "");
                    if (otherType.equals("QC")) {
                        otherUsername = landscape.getProperties1().getProperty(Activator.PROPERTIES_QC_USER,
                                "");
                        otherPassword = landscape.getProperties1().getProperty(Activator.PROPERTIES_QC_PASSWORD,
                                "");
                    } else if (otherType.equals("SWP")) {
                        otherUsername = landscape.getProperties1().getProperty(Activator.PROPERTIES_SW_USER,
                                "");
                        otherPassword = landscape.getProperties1().getProperty(Activator.PROPERTIES_SW_PASSWORD,
                                "");
                        swpResyncUsername = landscape.getProperties1()
                                .getProperty(Activator.PROPERTIES_SW_RESYNC_USER, "");
                        swpResyncPassword = landscape.getProperties1()
                                .getProperty(Activator.PROPERTIES_SW_RESYNC_PASSWORD, "");
                    }
                } else {
                    teamForgeUsername = landscape.getProperties1().getProperty(Activator.PROPERTIES_SFEE_USER,
                            "");
                    teamForgePassword = landscape.getProperties1()
                            .getProperty(Activator.PROPERTIES_SFEE_PASSWORD, "");
                    if (otherType.equals("QC")) {
                        otherUsername = landscape.getProperties2().getProperty(Activator.PROPERTIES_QC_USER,
                                "");
                        otherPassword = landscape.getProperties2().getProperty(Activator.PROPERTIES_QC_PASSWORD,
                                "");
                    } else if (otherType.equals("SWP")) {
                        otherUsername = landscape.getProperties2().getProperty(Activator.PROPERTIES_SW_USER,
                                "");
                        otherPassword = landscape.getProperties2().getProperty(Activator.PROPERTIES_SW_PASSWORD,
                                "");
                        swpResyncUsername = landscape.getProperties2()
                                .getProperty(Activator.PROPERTIES_SW_RESYNC_USER, "");
                        swpResyncPassword = landscape.getProperties2()
                                .getProperty(Activator.PROPERTIES_SW_RESYNC_PASSWORD, "");
                    }
                }

                LandscapeConfig landscapeConfig = new LandscapeConfig();
                landscapeConfig.setLandscape(ccfMasterLandscape);
                landscapeConfig.setName(LandscapeConfig.TF_USERNAME);
                landscapeConfig.setVal(teamForgeUsername);
                createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape, landscapeAlreadyExists,
                        landscapeConfig);
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                landscapeConfig.setName(LandscapeConfig.TF_PASSWORD);
                landscapeConfig.setVal(obfuscatePassword(teamForgePassword));
                createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape, landscapeAlreadyExists,
                        landscapeConfig);
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                if (otherUsername != null) {
                    if (otherType.equals("SWP")) {
                        landscapeConfig.setName(LandscapeConfig.SWP_USERNAME);
                    } else {
                        landscapeConfig.setName(LandscapeConfig.QC_USERNAME);
                    }
                    landscapeConfig.setVal(otherUsername);
                    createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape,
                            landscapeAlreadyExists, landscapeConfig);
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                if (otherPassword != null) {
                    if (otherType.equals("SWP")) {
                        landscapeConfig.setName(LandscapeConfig.SWP_PASSWORD);
                    } else {
                        landscapeConfig.setName(LandscapeConfig.QC_PASSWORD);
                    }
                    landscapeConfig.setVal(obfuscatePassword(otherPassword));
                    createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape,
                            landscapeAlreadyExists, landscapeConfig);
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                if (swpResyncUsername != null) {
                    landscapeConfig.setName(LandscapeConfig.SWP_RESYNC_USERNAME);
                    landscapeConfig.setVal(swpResyncUsername);
                    createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape,
                            landscapeAlreadyExists, landscapeConfig);
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                if (swpResyncPassword != null) {
                    landscapeConfig.setName(LandscapeConfig.SWP_RESYNC_PASSWORD);
                    landscapeConfig.setVal(obfuscatePassword(swpResyncPassword));
                    createOrUpdateLandscapeConfig(getCcfMasterClient(), ccfMasterLandscape,
                            landscapeAlreadyExists, landscapeConfig);
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                migrationResults.add(new MigrationResult(
                        "Landscape " + ccfMasterLandscape.getName() + " properties set in CCF Master."));

                Direction forward = null;
                Direction reverse = null;
                if (landscapeAlreadyExists) {
                    monitor.subTask("Checking for existing CCF Master directions");
                    Direction[] directions = getCcfMasterClient().getDirections(ccfMasterLandscape, null, true);
                    for (Direction direction : directions) {
                        if (direction.getLandscape().getId() == ccfMasterLandscape.getId()) {
                            if (direction.getDirections().equals(Directions.FORWARD)) {
                                forward = direction;
                                migrationResults.add(new MigrationResult("Direction " + forward.getDescription()
                                        + " (FORWARD) already exists in CCF Master."));
                            } else if (direction.getDirections().equals(Directions.REVERSE)) {
                                reverse = direction;
                                migrationResults.add(new MigrationResult("Direction " + reverse.getDescription()
                                        + " (REVERSE) already exists in CCF Master."));
                            }
                            if (forward != null && reverse != null) {
                                break;
                            }
                        }
                    }
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                if (forward == null || reverse == null) {
                    monitor.subTask("Creating CCF Master directions");
                }

                if (forward == null) {
                    forward = new Direction();
                    forward.setLandscape(ccfMasterLandscape);
                    forward.setDirections(Directions.FORWARD);
                    if (landscape.getType1().equals("TF")) {
                        forward.setDescription(landscape.getType1() + landscape.getType2());
                    } else {
                        forward.setDescription(landscape.getType2() + landscape.getType1());
                    }
                    forward.setShouldStartAutomatically(Boolean.valueOf(false));
                    forward = getCcfMasterClient().createDirection(forward);
                    migrationResults.add(new MigrationResult(
                            "Direction " + forward.getDescription() + " (FORWARD) created in CCF Master."));
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                DirectionConfig forwardConfig = new DirectionConfig();
                String teamForgeMaxAttachmentSize = null;
                String otherMaxAttachmentSize = null;
                if (landscape.getType1().equals("TF")) {
                    forwardConfig.setVal(landscape.getLogMessageTemplate1());
                    teamForgeMaxAttachmentSize = landscape.getProperties1()
                            .getProperty(Activator.PROPERTIES_SFEE_ATTACHMENT_SIZE, "10485760");
                    if (otherType.equals("SWP")) {
                        otherMaxAttachmentSize = landscape.getProperties2()
                                .getProperty(Activator.PROPERTIES_SW_ATTACHMENT_SIZE, "10485760");
                    } else {
                        otherMaxAttachmentSize = landscape.getProperties2()
                                .getProperty(Activator.PROPERTIES_QC_ATTACHMENT_SIZE, "10485760");
                    }
                } else {
                    forwardConfig.setVal(landscape.getLogMessageTemplate2());
                    teamForgeMaxAttachmentSize = landscape.getProperties2()
                            .getProperty(Activator.PROPERTIES_SFEE_ATTACHMENT_SIZE, "10485760");
                    if (otherType.equals("SWP")) {
                        otherMaxAttachmentSize = landscape.getProperties1()
                                .getProperty(Activator.PROPERTIES_SW_ATTACHMENT_SIZE, "10485760");
                    } else {
                        otherMaxAttachmentSize = landscape.getProperties1()
                                .getProperty(Activator.PROPERTIES_QC_ATTACHMENT_SIZE, "10485760");
                    }
                }
                forwardConfig.setDirection(forward);
                forwardConfig.setName(DirectionConfig.LOG_MESSAGE_TEMPLATE);
                createOrUpdateDirectionConfig(getCcfMasterClient(), forward, forwardConfig);
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                if (teamForgeMaxAttachmentSize != null) {
                    forwardConfig.setName(DirectionConfig.TF_MAX_ATTACHMENT_SIZE);
                    forwardConfig.setVal(teamForgeMaxAttachmentSize);
                    createOrUpdateDirectionConfig(getCcfMasterClient(), forward, forwardConfig);
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                migrationResults.add(new MigrationResult(
                        "Direction " + forward.getDescription() + " (FORWARD) properties set in CCF Master."));

                if (reverse == null) {
                    reverse = new Direction();
                    reverse.setLandscape(ccfMasterLandscape);
                    reverse.setDirections(Directions.REVERSE);
                    if (landscape.getType1().equals("TF")) {
                        reverse.setDescription(landscape.getType2() + landscape.getType1());
                    } else {
                        reverse.setDescription(landscape.getType1() + landscape.getType2());
                    }
                    reverse.setShouldStartAutomatically(Boolean.valueOf(false));
                    reverse = getCcfMasterClient().createDirection(reverse);
                    migrationResults.add(new MigrationResult(
                            "Direction " + reverse.getDescription() + " (REVERSE) created in CCF Master."));

                    // Null out existing direction configs because next time we check them we want them to be retrieved again since creating
                    // the reverse direction will have resulted in more configs being created automatically.
                    directionConfigs = null;
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                DirectionConfig reverseConfig = new DirectionConfig();
                teamForgeMaxAttachmentSize = null;
                otherMaxAttachmentSize = null;
                if (landscape.getType1().equals("TF")) {
                    reverseConfig.setVal(landscape.getLogMessageTemplate2());
                    teamForgeMaxAttachmentSize = landscape.getProperties1()
                            .getProperty(Activator.PROPERTIES_SFEE_ATTACHMENT_SIZE, "10485760");
                    if (otherType.equals("SWP")) {
                        otherMaxAttachmentSize = landscape.getProperties2()
                                .getProperty(Activator.PROPERTIES_SW_ATTACHMENT_SIZE, "10485760");
                    } else {
                        otherMaxAttachmentSize = landscape.getProperties2()
                                .getProperty(Activator.PROPERTIES_QC_ATTACHMENT_SIZE, "10485760");
                    }
                } else {
                    reverseConfig.setVal(landscape.getLogMessageTemplate1());
                    teamForgeMaxAttachmentSize = landscape.getProperties2()
                            .getProperty(Activator.PROPERTIES_SFEE_ATTACHMENT_SIZE, "10485760");
                    if (otherType.equals("SWP")) {
                        otherMaxAttachmentSize = landscape.getProperties1()
                                .getProperty(Activator.PROPERTIES_SW_ATTACHMENT_SIZE, "10485760");
                    } else {
                        otherMaxAttachmentSize = landscape.getProperties1()
                                .getProperty(Activator.PROPERTIES_QC_ATTACHMENT_SIZE, "10485760");
                    }
                }
                reverseConfig.setDirection(reverse);
                reverseConfig.setName(DirectionConfig.LOG_MESSAGE_TEMPLATE);
                createOrUpdateDirectionConfig(getCcfMasterClient(), reverse, reverseConfig);
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                if (otherMaxAttachmentSize != null) {
                    if (otherType.equals("SWP")) {
                        reverseConfig.setName(DirectionConfig.SWP_MAX_ATTACHMENT_SIZE);
                    } else {
                        reverseConfig.setName(DirectionConfig.QC_MAX_ATTACHMENT_SIZE);
                    }
                    reverseConfig.setVal(otherMaxAttachmentSize);
                    createOrUpdateDirectionConfig(getCcfMasterClient(), reverse, reverseConfig);
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                migrationResults.add(new MigrationResult(
                        "Direction " + reverse.getDescription() + " (REVERSE) properties set in CCF Master."));

                Map<String, ExternalApp> externalAppMap = new HashMap<String, ExternalApp>();
                monitor.subTask("Creating CCF Master external applications:");
                ExternalApp[] externalApps = getCcfMasterClient().getExternalApps(ccfMasterLandscape, true);
                for (String project : projectIds) {
                    ProjectDO projectDO = projectMap.get(project);
                    ExternalApp externalApp = new ExternalApp();
                    externalApp.setProjectPath(projectDO.getPath());
                    externalApp.setProjectTitle(projectDO.getTitle());
                    externalApp.setLandscape(ccfMasterLandscape);
                    ExternalApp existingApp = getExternalApp(externalApp, externalApps);
                    if (existingApp != null) {
                        externalApp = existingApp;
                        migrationResults
                                .add(new MigrationResult("External application " + externalApp.getLinkId()
                                        + " (" + project + ") already exists in CCF Master."));
                    } else {
                        monitor.subTask(
                                "Creating CCF Master external applications: " + externalApp.getProjectTitle());
                        externalApp = getCcfMasterClient().createExternalApp(externalApp);
                        migrationResults.add(new MigrationResult("External application "
                                + externalApp.getLinkId() + " (" + project + ") created in CCF Master."));
                    }
                    externalAppMap.put(project, externalApp);
                    if (monitor.isCanceled()) {
                        canceled = true;
                        return;
                    }
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }

                monitor.subTask("Creating CCF Master repository mappings:");
                List<String> repositoryMappingList = new ArrayList<String>();
                RepositoryMapping[] repositoryMappings = getCcfMasterClient().getRepositoryMappings(true);
                for (SynchronizationStatus projectMapping : projectMappings) {
                    String projectId = projectMappingMap.get(projectMapping);
                    if (projectId != null) {
                        ExternalApp externalApp = externalAppMap.get(projectId);
                        if (externalApp != null) {
                            String teamForgeRepositoryId = null;
                            String participantRepositoryId = null;
                            if (projectMapping.getSourceSystemKind().startsWith("TF")) {
                                teamForgeRepositoryId = projectMapping.getSourceRepositoryId();
                                participantRepositoryId = projectMapping.getTargetRepositoryId();
                            } else if (projectMapping.getTargetSystemKind().startsWith("TF")) {
                                teamForgeRepositoryId = projectMapping.getTargetRepositoryId();
                                participantRepositoryId = projectMapping.getSourceRepositoryId();
                            }
                            if (teamForgeRepositoryId != null) {
                                if (!repositoryMappingList.contains(
                                        projectId + teamForgeRepositoryId + participantRepositoryId)) {
                                    RepositoryMapping repositoryMapping = new RepositoryMapping();
                                    String description = null;
                                    if (otherType.equals("SWP")) {
                                        int index = participantRepositoryId.lastIndexOf("-");
                                        if (index != -1) {
                                            description = participantRepositoryId.substring(index + 1);
                                        }
                                    }
                                    if (description == null) {
                                        description = teamForgeRepositoryId + " " + "\u21D4" + " "
                                                + participantRepositoryId;
                                    }
                                    repositoryMapping.setDescription(description);
                                    repositoryMapping.setExternalApp(externalApp);
                                    repositoryMapping.setParticipantRepositoryId(participantRepositoryId);
                                    repositoryMapping.setTeamForgeRepositoryId(teamForgeRepositoryId);
                                    RepositoryMapping checkMapping = getRepositoryMapping(repositoryMapping,
                                            repositoryMappings);
                                    if (checkMapping == null) {
                                        monitor.subTask("Creating CCF Master repository mappings: "
                                                + repositoryMapping.getDescription());
                                        repositoryMapping = getCcfMasterClient()
                                                .createRepositoryMapping(repositoryMapping);
                                        migrationResults.add(new MigrationResult(
                                                "Repository mapping " + repositoryMapping.getDescription()
                                                        + " created in CCF Master."));
                                    } else {
                                        repositoryMapping = checkMapping;
                                        migrationResults.add(new MigrationResult(
                                                "Repository mapping " + repositoryMapping.getDescription()
                                                        + " already exists in CCF Master."));
                                    }
                                    repositoryMappingList
                                            .add(projectId + teamForgeRepositoryId + participantRepositoryId);
                                }
                            }
                        }
                        if (monitor.isCanceled()) {
                            canceled = true;
                            return;
                        }
                    }
                    monitor.worked(1);
                    if (monitor.isCanceled()) {
                        canceled = true;
                        return;
                    }
                }

                monitor.subTask("Creating CCF Master repository mapping directions:");
                repositoryMappings = getCcfMasterClient().getRepositoryMappings(ccfMasterLandscape, true);
                RepositoryMappingDirection[] repositoryMappingDirections = getCcfMasterClient()
                        .getRepositoryMappingDirections(ccfMasterLandscape, true);
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
                for (SynchronizationStatus projectMapping : projectMappings) {
                    if (projectMapping.getSourceSystemKind().startsWith("TF")
                            || projectMapping.getTargetSystemKind().startsWith("TF")) {
                        RepositoryMappingDirection repositoryMappingDirection = new RepositoryMappingDirection();
                        if (projectMapping.getTargetSystemKind().startsWith("TF")) {
                            repositoryMappingDirection.setDirection(Directions.REVERSE);
                        } else {
                            repositoryMappingDirection.setDirection(Directions.FORWARD);
                        }
                        repositoryMappingDirection
                                .setRepositoryMapping(getRepositoryMapping(projectMapping, repositoryMappings));
                        if (projectMapping.isPaused()) {
                            repositoryMappingDirection.setStatus(RepositoryMappingDirectionStatus.PAUSED);
                        } else {
                            repositoryMappingDirection.setStatus(RepositoryMappingDirectionStatus.RUNNING);
                        }
                        repositoryMappingDirection.setLastSourceArtifactModificationDate(
                                projectMapping.getSourceLastModificationTime());
                        repositoryMappingDirection
                                .setLastSourceArtifactVersion(projectMapping.getSourceLastArtifactVersion());
                        repositoryMappingDirection
                                .setLastSourceArtifactId(projectMapping.getSourceLastArtifactId());
                        String conflictResolutionPolicy = projectMapping.getConflictResolutionPriority();
                        if (conflictResolutionPolicy.equals(ConflictResolutionPolicy.alwaysIgnore.toString())) {
                            repositoryMappingDirection
                                    .setConflictResolutionPolicy(ConflictResolutionPolicy.alwaysIgnore);
                        } else if (conflictResolutionPolicy
                                .equals(ConflictResolutionPolicy.quarantineArtifact.toString())) {
                            repositoryMappingDirection
                                    .setConflictResolutionPolicy(ConflictResolutionPolicy.quarantineArtifact);
                        } else if (conflictResolutionPolicy
                                .equals(ConflictResolutionPolicy.alwaysOverrideAndIgnoreLocks.toString())) {
                            repositoryMappingDirection.setConflictResolutionPolicy(
                                    ConflictResolutionPolicy.alwaysOverrideAndIgnoreLocks);
                        } else {
                            repositoryMappingDirection
                                    .setConflictResolutionPolicy(ConflictResolutionPolicy.alwaysOverride);
                        }
                        RepositoryMappingDirection checkRepositoryMappingDirection = getRepositoryMappingDirection(
                                repositoryMappingDirection, repositoryMappingDirections);
                        if (checkRepositoryMappingDirection == null) {
                            monitor.subTask("Creating CCF Master repository mapping directions: "
                                    + repositoryMappingDirection.getRepositoryMapping().getDescription() + " ("
                                    + repositoryMappingDirection.getDirection() + ")");
                            repositoryMappingDirection = getCcfMasterClient()
                                    .createRepositoryMappingDirection(repositoryMappingDirection);
                            migrationResults.add(new MigrationResult("Repository mapping direction "
                                    + repositoryMappingDirection.getRepositoryMapping().getDescription() + " ("
                                    + repositoryMappingDirection.getDirection() + ") created in CCF Master."));
                            if (projectMapping.getSourceRepositoryKind().contains("Template")) {
                                FieldMapping fieldMapping = new FieldMapping();
                                fieldMapping.setParent(repositoryMappingDirection);
                                fieldMapping.setScope(FieldMappingScope.CCF_CORE);
                                String fieldMappingName;
                                int index = projectMapping.getSourceRepositoryKind().indexOf(".xsl");
                                if (index == -1) {
                                    fieldMappingName = projectMapping.getSourceRepositoryKind();
                                } else {
                                    fieldMappingName = projectMapping.getSourceRepositoryKind().substring(0,
                                            index);
                                }
                                fieldMapping.setName(fieldMappingName);
                                fieldMapping.setKind(FieldMappingKind.CUSTOM_XSLT);
                                fieldMapping = getCcfMasterClient().createFieldMapping(fieldMapping);
                                repositoryMappingDirection.setActiveFieldMapping(fieldMapping);
                                repositoryMappingDirection = getCcfMasterClient()
                                        .updateRepositoryMappingDirection(repositoryMappingDirection);
                            } else if (projectMapping.getSourceRepositoryKind().contains(".xsl")) {
                                List<FieldMappingRule> fieldMappingRules = new ArrayList<FieldMappingRule>();
                                File preFile = projectMapping.getGenericArtifactToSourceRepositorySchemaFile();
                                File postFile = projectMapping.getTargetRepositorySchemaToGenericArtifactFile();
                                File mfdFile = projectMapping.getMappingFile(projectMapping.getMFDFileName());
                                File mainFile = projectMapping.getGraphicalXslFile();
                                File sourceRepositorySchemaFile = projectMapping
                                        .getSourceRepositorySchemaFile();
                                File targetRepositorySchemaFile = projectMapping
                                        .getTargetRepositorySchemaFile();
                                FieldMapping fieldMapping = new FieldMapping();
                                fieldMapping.setParent(repositoryMappingDirection);
                                fieldMapping.setScope(FieldMappingScope.REPOSITORY_MAPPING_DIRECTION);
                                fieldMapping.setKind(FieldMappingKind.MAPFORCE);
                                fieldMapping.setName(FieldMappingKind.MAPFORCE.toString());
                                if (sourceRepositorySchemaFile.exists()) {
                                    fieldMappingRules.add(
                                            getFieldMappingRule(FieldMappingRuleType.SOURCE_REPOSITORY_LAYOUT,
                                                    sourceRepositorySchemaFile));
                                }
                                if (targetRepositorySchemaFile.exists()) {
                                    fieldMappingRules.add(
                                            getFieldMappingRule(FieldMappingRuleType.TARGET_REPOSITORY_LAYOUT,
                                                    targetRepositorySchemaFile));
                                }
                                if (preFile.exists()) {
                                    fieldMappingRules.add(
                                            getFieldMappingRule(FieldMappingRuleType.MAPFORCE_PRE, preFile));
                                }
                                if (mainFile.exists()) {
                                    fieldMappingRules.add(
                                            getFieldMappingRule(FieldMappingRuleType.MAPFORCE_MAIN, mainFile));
                                }
                                if (postFile.exists()) {
                                    fieldMappingRules.add(
                                            getFieldMappingRule(FieldMappingRuleType.MAPFORCE_POST, postFile));
                                }
                                if (mfdFile.exists()) {
                                    XSLTInitialMFDGeneratorScriptGenerator generator = new XSLTInitialMFDGeneratorScriptGenerator();
                                    Document mfdDocument = generator.generateCreateInitialMFDScript(
                                            mfdFile.getAbsolutePath(),
                                            projectMapping.getSourceRepositorySchemaFileName(),
                                            projectMapping.getTargetRepositorySchemaFileName()); //$NON-NLS-1$ //$NON-NLS-2$
                                    FieldMappingRule mfdFieldMappingRule = getFieldMappingRule(
                                            FieldMappingRuleType.MAPFORCE_MFD, mfdFile);
                                    mfdFieldMappingRule.setXmlContent(mfdDocument.asXML());
                                    fieldMappingRules.add(mfdFieldMappingRule);
                                }
                                fieldMapping.setRules(fieldMappingRules);
                                fieldMapping = getCcfMasterClient().createFieldMapping(fieldMapping);
                                repositoryMappingDirection.setActiveFieldMapping(fieldMapping);
                                repositoryMappingDirection = getCcfMasterClient()
                                        .updateRepositoryMappingDirection(repositoryMappingDirection);
                            } else {
                                FieldMapping fieldMapping = new FieldMapping();
                                fieldMapping.setParent(repositoryMappingDirection);
                                fieldMapping.setScope(FieldMappingScope.REPOSITORY_MAPPING_DIRECTION);
                                fieldMapping.setKind(FieldMappingKind.CUSTOM_XSLT);
                                fieldMapping.setName(FieldMappingKind.CUSTOM_XSLT.toString());
                                FieldMappingRule fieldMappingRule = new FieldMappingRule();
                                fieldMappingRule.setType(FieldMappingRuleType.CUSTOM_XSLT_DOCUMENT);
                                fieldMappingRule.setSource("source");
                                fieldMappingRule.setSourceIsTopLevelAttribute(Boolean.valueOf(false));
                                fieldMappingRule.setTarget("target");
                                fieldMappingRule.setTargetIsTopLevelAttribute(Boolean.valueOf(false));
                                File xslFile = projectMapping.getXslFile();
                                if (!xslFile.exists()) {
                                    xslFile = projectMapping.getSampleXslFile();
                                }
                                fieldMappingRule.setXmlContent(CcfMasterClient.readFile(xslFile));
                                List<FieldMappingRule> fieldMappingRules = new ArrayList<FieldMappingRule>();
                                fieldMappingRules.add(fieldMappingRule);
                                fieldMapping.setRules(fieldMappingRules);
                                fieldMapping = getCcfMasterClient().createFieldMapping(fieldMapping);
                                repositoryMappingDirection.setActiveFieldMapping(fieldMapping);
                                repositoryMappingDirection = getCcfMasterClient()
                                        .updateRepositoryMappingDirection(repositoryMappingDirection);
                            }

                        } else {
                            repositoryMappingDirection = checkRepositoryMappingDirection;
                            migrationResults.add(new MigrationResult("Repository mapping direction "
                                    + repositoryMappingDirection.getRepositoryMapping().getDescription() + " ("
                                    + repositoryMappingDirection.getDirection()
                                    + ") already exists in CCF Master."));
                        }
                        if (monitor.isCanceled()) {
                            canceled = true;
                            return;
                        }
                    }
                    monitor.worked(1);
                    if (monitor.isCanceled()) {
                        canceled = true;
                        return;
                    }
                }
                repositoryMappingDirections = getCcfMasterClient()
                        .getRepositoryMappingDirections(ccfMasterLandscape, true);

                monitor.subTask("Creating CCF Master identity mappings:");

                createdCount = 0;
                notCreatedCount = 0;
                alreadyExistedCount = 0;

                for (RepositoryMapping repositoryMapping : mappingPage.getSelectedRepositoryMappings()) {

                    List<String> identityMappingList = new ArrayList<String>();

                    Filter forwardSourceRepositoryFilter = new Filter(
                            CcfDataProvider.IDENTITY_MAPPING_SOURCE_REPOSITORY_ID,
                            repositoryMapping.getTeamForgeRepositoryId(), true);
                    Filter forwardTargetRepositoryFilter = new Filter(
                            CcfDataProvider.IDENTITY_MAPPING_TARGET_REPOSITORY_ID,
                            repositoryMapping.getParticipantRepositoryId(), true);
                    Filter[] forwardFilter = { forwardSourceRepositoryFilter, forwardTargetRepositoryFilter };
                    Filter reverseSourceRepositoryFilter = new Filter(
                            CcfDataProvider.IDENTITY_MAPPING_SOURCE_REPOSITORY_ID,
                            repositoryMapping.getParticipantRepositoryId(), true);
                    Filter reverseTargetRepositoryFilter = new Filter(
                            CcfDataProvider.IDENTITY_MAPPING_TARGET_REPOSITORY_ID,
                            repositoryMapping.getTeamForgeRepositoryId(), true);
                    Filter[] reverseFilter = { reverseSourceRepositoryFilter, reverseTargetRepositoryFilter };
                    Filter[][] filter = { forwardFilter, reverseFilter };

                    IdentityMapping[] identityMappings = getCcfDataProvider().getIdentityMappings(landscape,
                            filter);

                    // First select source = TF, version != -1
                    for (IdentityMapping mapping : identityMappings) {
                        if (mapping.getSourceSystemKind().startsWith("TF")
                                && !mapping.getArtifactType().equals("attachment")
                                && !"-1".equals(mapping.getSourceArtifactVersion())
                                && !"-1".equals(mapping.getTargetArtifactVersion())) {
                            com.collabnet.ccf.api.model.IdentityMapping identityMapping = getIdentityMapping(
                                    mapping);
                            if (!identityMappingList.contains(identityMapping.getSourceArtifactId()
                                    + identityMapping.getArtifactType())) {
                                identityMapping.setRepositoryMapping(
                                        getRepositoryMapping(mapping, repositoryMappings));
                                try {
                                    getCcfMasterClient().createIdentityMapping(identityMapping);
                                    createdCount++;
                                } catch (Exception e) {
                                    handleIdentityMappingMigrationError(mapping, e);
                                }
                                identityMappingList.add(identityMapping.getSourceArtifactId()
                                        + identityMapping.getArtifactType());
                                monitor.subTask(
                                        "Creating CCF Master identity mappings: " + getStatusMessage(""));
                            }
                            if (monitor.isCanceled()) {
                                if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) {
                                    migrationResults
                                            .add(new MigrationResult(getStatusMessage("identity mappings")));
                                }
                                canceled = true;
                                return;
                            }
                        }
                    }

                    // Next, target = TF, version != -1 (and attachments)
                    for (IdentityMapping mapping : identityMappings) {
                        if (mapping.getTargetSystemKind().startsWith("TF")
                                && (mapping.getArtifactType().equals("attachment")
                                        || (!"-1".equals(mapping.getSourceArtifactVersion())
                                                && !"-1".equals(mapping.getTargetArtifactVersion())))) {
                            com.collabnet.ccf.api.model.IdentityMapping identityMapping = getIdentityMapping(
                                    mapping);
                            if (!identityMappingList.contains(identityMapping.getSourceArtifactId()
                                    + identityMapping.getArtifactType())) {
                                identityMapping.setRepositoryMapping(
                                        getRepositoryMapping(mapping, repositoryMappings));
                                try {
                                    getCcfMasterClient().createIdentityMapping(identityMapping);
                                    createdCount++;
                                } catch (Exception e) {
                                    handleIdentityMappingMigrationError(mapping, e);
                                }
                                identityMappingList.add(identityMapping.getSourceArtifactId()
                                        + identityMapping.getArtifactType());
                                monitor.subTask(
                                        "Creating CCF Master identity mappings: " + getStatusMessage(""));
                            }
                            if (monitor.isCanceled()) {
                                if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) {
                                    migrationResults
                                            .add(new MigrationResult(getStatusMessage("identity mappings")));
                                }
                                canceled = true;
                                return;
                            }
                        }
                    }

                    // Next source = TF, version = -1
                    for (IdentityMapping mapping : identityMappings) {
                        if (mapping.getSourceSystemKind().startsWith("TF")
                                && !mapping.getArtifactType().equals("attachment")
                                && ("-1".equals(mapping.getSourceArtifactVersion())
                                        || "-1".equals(mapping.getTargetArtifactVersion()))) {
                            com.collabnet.ccf.api.model.IdentityMapping identityMapping = getIdentityMapping(
                                    mapping);
                            if (!identityMappingList.contains(identityMapping.getSourceArtifactId()
                                    + identityMapping.getArtifactType())) {
                                identityMapping.setRepositoryMapping(
                                        getRepositoryMapping(mapping, repositoryMappings));
                                try {
                                    getCcfMasterClient().createIdentityMapping(identityMapping);
                                    createdCount++;
                                } catch (Exception e) {
                                    handleIdentityMappingMigrationError(mapping, e);
                                }
                                identityMappingList.add(identityMapping.getSourceArtifactId()
                                        + identityMapping.getArtifactType());
                                monitor.subTask(
                                        "Creating CCF Master identity mappings: " + getStatusMessage(""));
                            }
                            if (monitor.isCanceled()) {
                                if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) {
                                    migrationResults
                                            .add(new MigrationResult(getStatusMessage("identity mappings")));
                                }
                                canceled = true;
                                return;
                            }
                        }
                    }

                    // Finally target = TF, version = -1
                    for (IdentityMapping mapping : identityMappings) {
                        if (mapping.getTargetSystemKind().startsWith("TF")
                                && !mapping.getArtifactType().equals("attachment")
                                && ("-1".equals(mapping.getSourceArtifactVersion())
                                        || "-1".equals(mapping.getTargetArtifactVersion()))) {
                            com.collabnet.ccf.api.model.IdentityMapping identityMapping = getIdentityMapping(
                                    mapping);
                            if (!identityMappingList.contains(identityMapping.getSourceArtifactId()
                                    + identityMapping.getArtifactType())) {
                                identityMapping.setRepositoryMapping(
                                        getRepositoryMapping(mapping, repositoryMappings));
                                try {
                                    getCcfMasterClient().createIdentityMapping(identityMapping);
                                    createdCount++;
                                } catch (Exception e) {
                                    handleIdentityMappingMigrationError(mapping, e);
                                }
                                identityMappingList.add(identityMapping.getSourceArtifactId()
                                        + identityMapping.getArtifactType());
                                monitor.subTask(
                                        "Creating CCF Master identity mappings: " + getStatusMessage(""));
                            }
                            if (monitor.isCanceled()) {
                                if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) {
                                    migrationResults
                                            .add(new MigrationResult(getStatusMessage("identity mappings")));
                                }
                                canceled = true;
                                return;
                            }
                        }
                    }
                    monitor.worked(1);
                }

                if (createdCount > 0 || notCreatedCount > 0 || alreadyExistedCount > 0) {
                    migrationResults.add(new MigrationResult(getStatusMessage("identity mappings")));
                }
                if (monitor.isCanceled()) {
                    canceled = true;
                    return;
                }
            } catch (Exception e) {
                exception = e;
                return;
            } finally {
                monitor.done();
            }
        }
    };

    try {
        getContainer().run(true, true, runnable);
    } catch (Exception e) {
        Activator.handleError(e);
        if (e.getMessage() != null && e.getMessage().contains("<html>")) {
            MigrateLandscapeErrorDialog dialog = new MigrateLandscapeErrorDialog(getShell(), e);
            dialog.open();
        } else {
            ExceptionDetailsErrorDialog.openError(getShell(), "Migrate Landscape to CCF 2.x", e.getMessage(),
                    new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e));
        }
        migrationResults.add(new MigrationResult(e));
        return false;
    }

    if (exception != null) {
        Activator.handleError(exception);
        if (exception.getMessage() != null && exception.getMessage().contains("<html>")) {
            MigrateLandscapeErrorDialog dialog = new MigrateLandscapeErrorDialog(getShell(), exception);
            dialog.open();
        } else {
            ExceptionDetailsErrorDialog.openError(getShell(), "Migrate Landscape to CCF 2.x",
                    exception.getMessage(),
                    new Status(IStatus.ERROR, Activator.PLUGIN_ID, exception.getLocalizedMessage(), exception));
        }
        migrationResults.add(new MigrationResult(exception));
    }

    if (showMigrationResults) {
        if (canceled) {
            migrationResults.add(new MigrationResult(new Exception("Migration canceled by user.")));
        }

        MigrationResult[] migrationResultArray = new MigrationResult[migrationResults.size()];
        migrationResults.toArray(migrationResultArray);
        MigrateLandscapeResultsDialog dialog = new MigrateLandscapeResultsDialog(getShell(),
                migrationResultArray);
        if (dialog.open() == MigrateLandscapeResultsDialog.CANCEL) {
            return false;
        }
    }

    return exception == null && !canceled;
}

From source file:com.collabnet.ccf.migration.wizards.MigrateLandscapeWizardMappingSelectionPage.java

License:Open Source License

@SuppressWarnings("deprecation")
@Override//  w w w.  j  av a 2  s  . c  om
public void setVisible(boolean visible) {
    setErrorMessage(null);
    exception = null;
    if (visible && projectMappings == null) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    projectMappings = ((MigrateLandscapeWizard) getWizard()).getProjectMappings(monitor);
                    projectMappingMap = ((MigrateLandscapeWizard) getWizard()).getProjectMappingMap(monitor);
                    projectMap = ((MigrateLandscapeWizard) getWizard()).getProjectMap();
                    trackerMap = ((MigrateLandscapeWizard) getWizard()).getTrackerMap();
                } catch (Exception e) {
                    exception = e;
                }
            }
        };
        try {
            getContainer().run(true, false, runnable);
        } catch (Exception e) {
            exception = e;
        }
        if (exception == null) {
            treeViewer.setInput(MigrateLandscapeWizardMappingSelectionPage.this);
            treeViewer.expandAll();
            treeViewer.setAllChecked(true);
            updateSelectedProjectMappings();
            if (projectMappings == null || projectMappings.length == 0) {
                setErrorMessage("There are no unmigrated project mappings to migrate.");
            } else {
                setPageComplete(true);
            }
        }
    }
    ;
    if (exception != null) {
        Activator.handleError(exception);
        setErrorMessage(exception.getMessage());
    }
    super.setVisible(visible);
}

From source file:com.collabnet.subversion.merge.wizards.MergeWizardAdvancedPage.java

License:Open Source License

private void initializeLocations() {
    combosInitialized = true;//from  www  .j a  v a  2s .c  o m
    MergeWizard wizard = (MergeWizard) getWizard();
    resource = wizard.getResource();
    resources = wizard.getResources();
    svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
    mergeInfoPaths = null;
    repositoryLocation = svnResource.getRepository().getLocation();
    if (((MergeWizard) getWizard()).suggestMergeSources()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.setTaskName(Messages.MergeWizardStandardPage_retrievingMergeSourceInfo);
                monitor.beginTask(Messages.MergeWizardStandardPage_retrievingMergeSourceInfo,
                        IProgressMonitor.UNKNOWN);
                monitor.subTask(""); //$NON-NLS-1$
                ISVNClientAdapter svnClient = null;
                try {
                    svnClient = svnResource.getRepository().getSVNClient();
                    try {
                        mergeInfoPaths = svnClient.suggestMergeSources(new SVNUrl(commonRoot),
                                SVNRevision.HEAD);
                    } catch (Exception e1) {
                    }
                } catch (Exception e) {
                    Activator.handleError(e);
                } finally {
                    svnResource.getRepository().returnSVNClient(svnClient);
                }
                monitor.done();
            }
        };
        try {
            getContainer().run(true, false, runnable);
        } catch (Exception e2) {
            Activator.handleError(e2);
        }
    }
    boolean valueAdded = false;
    List<String> fromUrls = new ArrayList<String>();
    if (mergeInfoPaths != null) {
        for (int i = 0; i < mergeInfoPaths.length; i++) {
            String url = mergeInfoPaths[i].substring(repositoryLocation.length());
            if (!fromUrls.contains(url))
                fromUrls.add(url);
            valueAdded = true;
        }
    }
    String previousFromUrls = null;
    String previousFromUrl = null;
    try {
        previousFromUrls = Activator.getDefault().getDialogSettings().get("mergeFromUrls_" + commonRoot);
    } catch (Exception e) {
    }
    if (previousFromUrls != null) {
        String[] urls = previousFromUrls.split("\\,");
        for (String url : urls) {
            if (!fromUrls.contains(url))
                fromUrls.add(url);
            valueAdded = true;
        }
        if (urls.length > 0)
            previousFromUrl = urls[0];
    }

    if (!valueAdded && commonRoot != null) {
        fromUrls.add(commonRoot.substring(repositoryLocation.length()));
    }

    for (String url : fromUrls) {
        fromCombo.add(url);
        toCombo.add(url);
    }

    if (previousFromUrl != null)
        fromCombo.setText(previousFromUrl);
    else if (fromCombo.getItemCount() > 0)
        fromCombo.setText(fromCombo.getItem(0));
    if (fromCombo.getText() != null && fromCombo.getText().length() > 0) {
        try {
            String previousToUrl = Activator.getDefault().getDialogSettings()
                    .get("mergeToUrl_" + fromCombo.getText());
            if (previousToUrl != null) {
                if (toCombo.indexOf(previousToUrl) == -1) {
                    toCombo.add(previousToUrl);
                }
                try {
                    boolean useFromDeselected = Activator.getDefault().getDialogSettings()
                            .getBoolean("mergeUseFromDeselected_" + fromCombo.getText());
                    if (useFromDeselected) {
                        useFromButton.setSelection(false);
                    }
                } catch (Exception e) {
                }
                if (!useFromButton.getSelection()) {
                    toCombo.setVisible(true);
                    toCombo.setText(previousToUrl);
                }
            }
        } catch (Exception e) {
        }
    }
}

From source file:com.collabnet.subversion.merge.wizards.MergeWizardBestPracticesPage.java

License:Open Source License

public void performChecks(boolean refreshPage) {
    try {//from  w  w  w .  j av a  2s  . co m
        getContainer().run(true, true, new IRunnableWithProgress() {

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

                needsChecks = false;
                localMods = false;
                switchedChildren = false;
                mixedRevisions = false;
                incompleteWorkingCopy = false;
                localModsList = new ArrayList();
                switchedChildrenList = new ArrayList();
                mixedRevisionsList = new ArrayList();
                incompleteList = new ArrayList();
                IResource[] resources = ((MergeWizard) getWizard()).getResources();

                if (resources == null)
                    return;

                monitor.beginTask(Messages.MergeWizardBestPracticesPage_0, resources.length);

                for (int i = 0; i < resources.length; i++) {
                    monitor.subTask(resources[i].getName());
                    ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
                    ISVNClientAdapter svnClient = null;
                    try {
                        svnClient = svnResource.getRepository().getSVNClient();

                        File fileProject = new File(resources[i].getLocation().toString());

                        List incompleteInfoList = new ArrayList();

                        ISVNInfo[] infos = svnClient.getInfo(fileProject, true);
                        for (int j = 0; j < infos.length; j++) {
                            if (infos[j].getDepth() != Depth.infinity && infos[j].getDepth() != Depth.unknown) {
                                incompleteWorkingCopy = true;
                                incompleteInfoList.add(infos[j].getUrl().toString());
                            }
                        }
                        File file = new File(resources[i].getLocation().toString());
                        ISVNStatus status = svnClient.getSingleStatus(file);

                        highestRevision = status.getRevision().getNumber();

                        ISVNStatus[] statuses = svnClient.getStatus(file, true, true, false, true);
                        for (int j = 0; j < statuses.length; j++) {
                            if (statuses[j].getUrl() != null
                                    && incompleteInfoList.contains(statuses[j].getUrl().toString())) {
                                incompleteList.add(SVNWorkspaceRoot.getResourceFor(resources[i], statuses[j]));
                            }
                            if (statuses[j].getTextStatus().equals(SVNStatusKind.MODIFIED)
                                    | statuses[j].getPropStatus().equals(SVNStatusKind.MODIFIED)) {
                                localMods = true;
                                localModsList.add(SVNWorkspaceRoot.getResourceFor(resources[i], statuses[j]));
                            }
                            if (statuses[j].isSwitched()) {
                                switchedChildren = true;
                                switchedChildrenList
                                        .add(SVNWorkspaceRoot.getResourceFor(resources[i], statuses[j]));
                            }
                            if (!statuses[j].getTextStatus().equals(SVNStatusKind.EXTERNAL)
                                    && statuses[j].getRevision() != null) {
                                if (!statuses[j].getRevision().equals(status.getRevision())) {
                                    mixedRevisions = true;
                                    if (!mixedRevisionsList.contains(resources[i]))
                                        mixedRevisionsList.add(resources[i]);
                                    if (statuses[j].getRevision().getNumber() > highestRevision) {
                                        highestRevision = statuses[j].getRevision().getNumber();
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        Activator.handleError(e);
                    } finally {
                        svnResource.getRepository().returnSVNClient(svnClient);
                    }
                    monitor.worked(1);
                }
                monitor.done();
            }

        });
    } catch (Exception e) {
        Activator.handleError(e);
    }

    if (refreshPage)
        refreshPage(true, false);
    if (localMods || switchedChildren || mixedRevisions || incompleteWorkingCopy) {
        setMessage(Messages.MergeWizardBestPracticesPage_notReady);
        setPageComplete(false);
    } else {
        setMessage(Messages.MergeWizardBestPracticesPage_ready);
        setPageComplete(true);
    }
}

From source file:com.collabnet.subversion.merge.wizards.MergeWizardRevisionsPage.java

License:Open Source License

private void refresh() {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.setTaskName(Messages.MergeWizardRevisionsPage_retrievingRemoteResource);
                monitor.beginTask(Messages.MergeWizardRevisionsPage_retrievingRemoteResource,
                        IProgressMonitor.UNKNOWN);
                monitor.worked(1);//from   w w w  .  j  av a2s .  c  o m
                remoteResource = repositoryLocation.getRemoteFile(new SVNUrl(getUrl()));
                monitor.done();
            } catch (Exception e) {
                Activator.handleError(e);
            }
        }
    };
    setPageComplete(false);
    setErrorMessage(null);
    fromUrl = standardPage.getFromUrl();
    remoteResource = null;
    try {
        getContainer().run(true, false, runnable);
        if (remoteResource == null) {
            setErrorMessage(Messages.MergeWizardRevisionsPage_errorRetrievingRemoteResource);
            entries = new ILogEntry[0];
        } else {
            getLogEntries(false, false);
            if (noEligibleEntries) {
                setErrorMessage(Messages.MergeWizardRevisionsPage_noEligibleRevisions);
            }
        }
    } catch (Exception e) {
        Activator.handleError(e);
        setErrorMessage(e.getMessage());
        entries = new ILogEntry[0];
    }
    if (tableHistoryViewer.getInput() == null)
        tableHistoryViewer.setInput(getUrl());
    else
        tableHistoryViewer.refresh();
}

From source file:com.collabnet.subversion.merge.wizards.MergeWizardRevisionsPage.java

License:Open Source License

private void getLogEntries(final boolean getAll, final boolean getNext) {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.setTaskName(Messages.MergeWizardRevisionsPage_retrievingRevisionLogInfo);
                monitor.beginTask(Messages.MergeWizardRevisionsPage_retrievingRevisionLogInfo, 5);
                if (SVNUIPlugin.getPlugin().getPreferenceStore()
                        .getBoolean(ISVNUIConstants.PREF_SHOW_TAGS_IN_REMOTE))
                    tagManager = new AliasManager(remoteResource.getUrl());
                monitor.worked(1);//from   w  w w . j  a va 2 s  . c o  m
                noEligibleEntries = false;
                entries = getEligibleLogEntries(monitor);
                monitor.worked(1);
                if (entries == null || entries.length == 0)
                    noEligibleEntries = true;
                monitor.worked(1);
            } catch (Exception e) {
                Activator.handleError(e);
                Display.getDefault().asyncExec(new Runnable() {
                    public void run() {
                        setErrorMessage(Messages.MergeWizardChangeSetRevisionsPage_errorRetrievingLogEntries);
                    }
                });
                entries = new ILogEntry[0];
            }
            monitor.worked(1);
            monitor.done();
        }
    };

    try {
        getContainer().run(true, false, runnable);
    } catch (Exception e1) {
        Activator.handleError(e1);
    }
}

From source file:com.collabnet.subversion.merge.wizards.MergeWizardStandardPage.java

License:Open Source License

private void initializeLocations() {
    MergeWizard wizard = (MergeWizard) getWizard();
    resource = wizard.getResource();/*  ww  w.j a  v  a2 s .  c o  m*/
    resources = wizard.getResources();
    svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
    mergeInfoPaths = null;
    try {
        fromUrl = svnResource.getStatus().getUrlString();
    } catch (Exception e) {
        Activator.handleError(e);
    }
    repositoryLocation = svnResource.getRepository().getLocation();
    if (((MergeWizard) getWizard()).suggestMergeSources()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.setTaskName(Messages.MergeWizardStandardPage_retrievingMergeSourceInfo);
                monitor.beginTask(Messages.MergeWizardStandardPage_retrievingMergeSourceInfo,
                        IProgressMonitor.UNKNOWN);
                monitor.subTask(""); //$NON-NLS-1$
                ISVNClientAdapter svnClient = null;
                try {
                    svnClient = svnResource.getRepository().getSVNClient();
                    try {
                        if (unblock) {
                            try {
                                mergeInfo = svnClient.getMergeInfo(new SVNUrl(commonRoot), SVNRevision.HEAD);
                            } catch (Exception e) {
                            }
                            if (mergeInfo != null)
                                mergeInfoPaths = mergeInfo.getPaths();
                            if (mergeInfoPaths == null || mergeInfoPaths.length == 0) {
                                Display.getDefault().asyncExec(new Runnable() {
                                    public void run() {
                                        setErrorMessage(Messages.MergeWizardStandardPage_noRevisionsToUnblock);
                                    }
                                });
                            }
                        } else {
                            mergeInfoPaths = svnClient.suggestMergeSources(new SVNUrl(commonRoot),
                                    SVNRevision.HEAD);
                        }
                    } catch (Exception e1) {
                    }
                } catch (Exception e) {
                    Activator.handleError(e);
                } finally {
                    svnResource.getRepository().returnSVNClient(svnClient);
                }
                monitor.done();
            }
        };
        try {
            getContainer().run(true, false, runnable);
        } catch (Exception e2) {
            Activator.handleError(e2);
        }
    }
    boolean valueAdded = false;
    List<String> fromUrls = new ArrayList<String>();
    if (mergeInfoPaths != null) {
        for (int i = 0; i < mergeInfoPaths.length; i++) {
            String url = mergeInfoPaths[i].substring(repositoryLocation.length());
            if (!fromUrls.contains(url))
                fromUrls.add(url);
            valueAdded = true;
        }
    }
    String previousFromUrls = null;
    String previousFromUrl = null;
    try {
        previousFromUrls = Activator.getDefault().getDialogSettings().get("mergeFromUrls_" + commonRoot);
    } catch (Exception e) {
    }
    if (previousFromUrls != null) {
        String[] urls = previousFromUrls.split("\\,");
        for (String url : urls) {
            if (!fromUrls.contains(url))
                fromUrls.add(url);
            valueAdded = true;
        }
        if (urls.length > 0)
            previousFromUrl = urls[0];
    }

    if (!valueAdded && !unblock && commonRoot != null) {
        fromUrls.add(commonRoot.substring(repositoryLocation.length()));
    }

    for (String url : fromUrls) {
        fromCombo.add(url);
    }

    if (previousFromUrl != null)
        fromCombo.setText(previousFromUrl);
    else if (fromCombo.getItemCount() > 0)
        fromCombo.setText(fromCombo.getItem(0));
}