Skip to main content
summaryrefslogtreecommitdiffstats
blob: c2ecdb74a4c4c0962692204a051a116952d49ae8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.wizards;

 
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.internal.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.team.internal.ccvs.core.CVSTag;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.client.Command;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.team.internal.ccvs.ui.operations.UpdateOperation;
import org.eclipse.team.internal.ccvs.ui.tags.*;
import org.eclipse.ui.IWorkbenchPart;

public class UpdateWizard extends ResizableWizard {

	private ResourceMapping[] mappers;
	private final IWorkbenchPart part;
	private TagSelectionWizardPage tagSelectionPage;
	
	public UpdateWizard(IWorkbenchPart part, ResourceMapping[] mappers) {
        super("UpdateWizard", CVSUIPlugin.getPlugin().getDialogSettings()); //$NON-NLS-1$
		this.part = part;
		this.mappers = mappers;
		setWindowTitle(CVSUIMessages.UpdateWizard_title); //$NON-NLS-1$
	}
	
    public static void run(IWorkbenchPart part, ResourceMapping[] mappers) {
        final UpdateWizard wizard = new UpdateWizard(part, mappers);
        open(part.getSite().getShell(), wizard);
    }
    
	public void addPages() {
		ImageDescriptor substImage = CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_CHECKOUT);
        tagSelectionPage = new TagSelectionWizardPage("tagPage", CVSUIMessages.UpdateWizard_0, substImage, CVSUIMessages.UpdateWizard_1, TagSource.create(mappers), TagSourceWorkbenchAdapter.INCLUDE_ALL_TAGS); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		tagSelectionPage.setAllowNoTag(true);
		tagSelectionPage.setHelpContxtId(IHelpContextIds.UPDATE_TAG_SELETION_PAGE);
		CVSTag tag = getInitialSelection();
		if (tag != null) {
			tagSelectionPage.setSelection(tag);
		}
		addPage(tagSelectionPage);
	}
	
	/**
     * @return
     */
    private CVSTag getInitialSelection() {
        try {
            for (int i = 0; i < mappers.length; i++) {
                ResourceMapping mapper = mappers[i];
                IProject[] projects = mapper.getProjects();
                for (int k = 0; k < projects.length; k++) {
                    IProject project = projects[k];
                    ICVSFolder folder = CVSWorkspaceRoot.getCVSFolderFor(project);
                    FolderSyncInfo info = folder.getFolderSyncInfo();
                    if (info != null) {
                        return info.getTag();
                    }
                }
            }
        } catch (CoreException e) {
            CVSUIPlugin.log(e);
        }
        return null;
    }

	/*
	 * @see IWizard#performFinish()
	 */
	public boolean performFinish() {
		try {
			new UpdateOperation(part, mappers, Command.NO_LOCAL_OPTIONS, tagSelectionPage.getSelectedTag()).run();
		} catch (InvocationTargetException e) {
			CVSUIPlugin.openError(getShell(), null, null, e);
			return false;
		} catch (InterruptedException e) {
			return false;
		}

		return super.performFinish();
	}
}

Back to the top