View | Details | Raw Unified | Return to bug 300215 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ui/TeamUIMessages.java (+7 lines)
Lines 718-723 Link Here
718
	public static String PatchParsedPage_description;
718
	public static String PatchParsedPage_description;
719
	public static String PatchParsedPage_clickFinishToGoToSynchronizeView;
719
	public static String PatchParsedPage_clickFinishToGoToSynchronizeView;
720
720
721
	public static String PatchInaccessibleProjectsPage_title;
722
	public static String PatchInaccessibleProjectsPage_message;
723
	public static String PatchInaccessibleProjectsPage_projectDoesNotExistInWorkspace;
724
	public static String PatchInaccessibleProjectsPage_selectExisting;
725
	public static String PatchInaccessibleProjectsPage_deselectAll;
726
	public static String PatchInaccessibleProjectsPage_openingProjects;
727
721
	public static String NotFound;
728
	public static String NotFound;
722
729
723
}
730
}
(-)src/org/eclipse/team/internal/ui/messages.properties (-1 / +10 lines)
Lines 575-578 Link Here
575
#
575
#
576
PatchParsedPage_title=Patch Parsed
576
PatchParsedPage_title=Patch Parsed
577
PatchParsedPage_description=The patch has been processed.
577
PatchParsedPage_description=The patch has been processed.
578
PatchParsedPage_clickFinishToGoToSynchronizeView=Click finish button to go to Synchronize view.
578
PatchParsedPage_clickFinishToGoToSynchronizeView=Click finish button to go to Synchronize view.
579
#
580
# PatchInaccessibleProjectsPage
581
#
582
PatchInaccessibleProjectsPage_title=Inaccessible Projects
583
PatchInaccessibleProjectsPage_message=Select projects to open for applying the patch. Inaccessbile projects will not appear in the Synchronize View.
584
PatchInaccessibleProjectsPage_projectDoesNotExistInWorkspace={0} (Project does not exist in workspace)
585
PatchInaccessibleProjectsPage_selectExisting=Select Existing
586
PatchInaccessibleProjectsPage_deselectAll=Deselect All
587
PatchInaccessibleProjectsPage_openingProjects=Opening projects
(-)src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriber.java (-5 / +13 lines)
Lines 101-121 Link Here
101
	}
101
	}
102
102
103
	public IResource[] members(IResource resource) throws TeamException {
103
	public IResource[] members(IResource resource) throws TeamException {
104
		//XXX: what if there is an addition in the patch that needs to add 3 subfolders?
104
		try {
105
		try {
105
			if(resource.getType() == IResource.FILE)
106
			if(resource.getType() == IResource.FILE)
106
				// file has no IResource members
107
				// file has no IResource members
107
				return new IResource[0];
108
				return new IResource[0];
108
			IContainer container = (IContainer) resource;
109
			IContainer container = (IContainer) resource;
109
110
			
110
			// workspace container members
111
			// workspace container members
111
			List existingChildren = new ArrayList(Arrays.asList(container.members()));
112
			List existingChildren = new ArrayList();
113
114
			if (container.isAccessible())
115
				existingChildren.addAll(Arrays.asList(container.members()));
112
116
113
			// patch members, subscriber location
117
			// patch members, subscriber location
114
			FilePatch2[] diffs = getPatcher().getDiffs();
118
			FilePatch2[] diffs = getPatcher().getDiffs();
115
			for (int i = 0; i < diffs.length; i++) {
119
			for (int i = 0; i < diffs.length; i++) {
116
				IResource file = PatchModelProvider.getFile(diffs[i], getPatcher());
120
				IResource file = PatchModelProvider.getFile(diffs[i], getPatcher());
117
				if (!container.exists(file.getProjectRelativePath())) {
121
				if (container.getFullPath().isPrefixOf(file.getFullPath())) {
118
					existingChildren.add(file);
122
					// XXX: check segments
123
					if (!container.exists(file.getProjectRelativePath())) {
124
						existingChildren.add(file);
125
					}
119
				}
126
				}
120
			}
127
			}
121
			return (IResource[]) existingChildren.toArray(new IResource[existingChildren.size()]);
128
			return (IResource[]) existingChildren.toArray(new IResource[existingChildren.size()]);
Lines 146-152 Link Here
146
				// return array of projects from the patch
153
				// return array of projects from the patch
147
				DiffProject diffProject = ((PatchProjectDiffNode)children[i]).getDiffProject();
154
				DiffProject diffProject = ((PatchProjectDiffNode)children[i]).getDiffProject();
148
				IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(diffProject.getName());
155
				IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(diffProject.getName());
149
				roots.add(project);
156
				if (project.isAccessible())
157
					roots.add(project);
150
			}
158
			}
151
		} else {
159
		} else {
152
			roots.add(getPatcher().getTarget());
160
			roots.add(getPatcher().getTarget());
(-)src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSynchronizationWizard.java (-2 / +70 lines)
Lines 11-23 Link Here
11
package org.eclipse.team.internal.ui.synchronize.patch;
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
12
13
import org.eclipse.compare.CompareConfiguration;
13
import org.eclipse.compare.CompareConfiguration;
14
import org.eclipse.compare.internal.core.patch.DiffProject;
14
import org.eclipse.compare.internal.patch.*;
15
import org.eclipse.compare.internal.patch.*;
15
import org.eclipse.core.resources.*;
16
import org.eclipse.core.resources.*;
16
import org.eclipse.core.resources.mapping.ResourceMapping;
17
import org.eclipse.core.resources.mapping.ResourceMapping;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.jobs.Job;
17
import org.eclipse.jface.wizard.IWizardPage;
20
import org.eclipse.jface.wizard.IWizardPage;
18
import org.eclipse.team.core.subscribers.SubscriberMergeContext;
21
import org.eclipse.team.core.subscribers.SubscriberMergeContext;
19
import org.eclipse.team.core.subscribers.SubscriberScopeManager;
22
import org.eclipse.team.core.subscribers.SubscriberScopeManager;
20
import org.eclipse.team.internal.ui.Utils;
23
import org.eclipse.team.internal.ui.*;
24
import org.eclipse.team.internal.ui.wizards.PatchInaccessibleProjectsPage;
21
import org.eclipse.team.ui.IConfigurationWizard;
25
import org.eclipse.team.ui.IConfigurationWizard;
22
import org.eclipse.team.ui.TeamUI;
26
import org.eclipse.team.ui.TeamUI;
23
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
27
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
Lines 27-32 Link Here
27
public class ApplyPatchSynchronizationWizard extends PatchWizard implements
31
public class ApplyPatchSynchronizationWizard extends PatchWizard implements
28
		IConfigurationWizard {
32
		IConfigurationWizard {
29
33
34
	private PatchInaccessibleProjectsPage fPatchInaccessibleProjectsPage;
35
30
	public ApplyPatchSynchronizationWizard() {
36
	public ApplyPatchSynchronizationWizard() {
31
		// TODO: get selection, available when launched from toolbar or main
37
		// TODO: get selection, available when launched from toolbar or main
32
		// menu
38
		// menu
Lines 34-39 Link Here
34
	}
40
	}
35
41
36
	public boolean performFinish() {
42
	public boolean performFinish() {
43
		if (fPatchInaccessibleProjectsPage != null) {
44
			IProject[] projects = fPatchInaccessibleProjectsPage
45
					.getSelectedProjects();
46
			if (projects != null && projects.length != 0)
47
				openSelectedProjects(projects);
48
		}
49
37
		ApplyPatchSubscriber subscriber = new ApplyPatchSubscriber(getPatcher());
50
		ApplyPatchSubscriber subscriber = new ApplyPatchSubscriber(getPatcher());
38
51
39
		// Get ResourceMappings for root resources from the patch.
52
		// Get ResourceMappings for root resources from the patch.
Lines 72-83 Link Here
72
		if (getPatch() == null)
85
		if (getPatch() == null)
73
			addPage(fPatchWizardPage = new InputPatchPage(this));
86
			addPage(fPatchWizardPage = new InputPatchPage(this));
74
		if (getPatch() == null || !getPatcher().isWorkspacePatch())
87
		if (getPatch() == null || !getPatcher().isWorkspacePatch())
75
			addPage(fPatchTargetPage = new PatchTargetPage(getPatcher()));
88
			addPage(fPatchTargetPage = new PatchTargetPage(getPatcher()) {
89
				public IWizardPage getNextPage() {
90
					if (!isTargetingInaccessibleProjects())
91
						return super.getNextPage().getNextPage();
92
					return super.getNextPage();
93
				}
94
			});
95
		if (getPatch() == null || isTargetingInaccessibleProjects())
96
			addPage(fPatchInaccessibleProjectsPage = new PatchInaccessibleProjectsPage(
97
					getPatcher()));
76
		addPage(new PatchParsedPage());
98
		addPage(new PatchParsedPage());
77
	}
99
	}
78
100
101
	private boolean isTargetingInaccessibleProjects() {
102
		DiffProject[] diffProjects = getPatcher().getDiffProjects();
103
		if (diffProjects != null) {
104
			for (int i = 0; i < diffProjects.length; i++) {
105
				IProject project = ResourcesPlugin.getWorkspace().getRoot()
106
						.getProject(diffProjects[i].getName());
107
				if (!project.isAccessible())
108
					return true;
109
			}
110
		}
111
		return false;
112
	}
113
79
	public boolean canFinish() {
114
	public boolean canFinish() {
80
		IWizardPage currentPage = getContainer().getCurrentPage();
115
		IWizardPage currentPage = getContainer().getCurrentPage();
116
		if (currentPage.getName().equals(
117
				PatchInaccessibleProjectsPage.PATCH_INACCESSIBLE_PROJECTS_NAME)) {
118
			return currentPage.isPageComplete();
119
		}
81
		if (currentPage.getName()
120
		if (currentPage.getName()
82
				.equals(PatchParsedPage.PATCH_PARSED_PAGE_NAME)) {
121
				.equals(PatchParsedPage.PATCH_PARSED_PAGE_NAME)) {
83
			return currentPage.isPageComplete();
122
			return currentPage.isPageComplete();
Lines 89-92 Link Here
89
		// make the patcher available to other classes in the package
128
		// make the patcher available to other classes in the package
90
		return super.getPatcher();
129
		return super.getPatcher();
91
	}
130
	}
131
132
	private void openSelectedProjects(final IProject projects[]) {
133
		Job openProjectsJob = new Job(
134
				TeamUIMessages.PatchInaccessibleProjectsPage_openingProjects) {
135
			protected IStatus run(IProgressMonitor monitor) {
136
				monitor.beginTask(
137
						TeamUIMessages.PatchInaccessibleProjectsPage_openingProjects,
138
						projects.length);
139
				MultiStatus errorStatus = new MultiStatus(
140
						TeamUIPlugin.ID,
141
						IStatus.ERROR,
142
						TeamUIMessages.PatchInaccessibleProjectsPage_openingProjects,
143
						null);
144
				for (int i = 0; i < projects.length; i++) {
145
					IProject project = (IProject) projects[i];
146
					try {
147
						project.open(new SubProgressMonitor(monitor, 1));
148
					} catch (CoreException e) {
149
						errorStatus.add(e.getStatus());
150
					}
151
				}
152
				monitor.done();
153
				return errorStatus;
154
			}
155
		};
156
		openProjectsJob.setUser(true);
157
		openProjectsJob.schedule();
158
	}
159
92
}
160
}
(-)src/org/eclipse/team/internal/ui/wizards/PatchInaccessibleProjectsPage.java (+173 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.wizards;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.compare.internal.core.patch.DiffProject;
17
import org.eclipse.compare.internal.patch.WorkspacePatcher;
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.jface.viewers.*;
21
import org.eclipse.jface.wizard.IWizardPage;
22
import org.eclipse.jface.wizard.WizardPage;
23
import org.eclipse.osgi.util.NLS;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.SelectionAdapter;
26
import org.eclipse.swt.events.SelectionEvent;
27
import org.eclipse.swt.graphics.Color;
28
import org.eclipse.swt.graphics.Font;
29
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.widgets.*;
32
import org.eclipse.team.internal.ui.TeamUIMessages;
33
import org.eclipse.ui.model.WorkbenchLabelProvider;
34
import org.eclipse.ui.views.navigator.ResourceComparator;
35
36
public class PatchInaccessibleProjectsPage extends WizardPage {
37
38
	private CheckboxTableViewer checkList;
39
	private Button checkAllButton;
40
	private Button uncheckAllButton;
41
42
	private WorkspacePatcher fPatcher;
43
44
	public final static String PATCH_INACCESSIBLE_PROJECTS_NAME = "PatchInaccessibleProjectsPage"; //$NON-NLS-1$
45
46
	public PatchInaccessibleProjectsPage(WorkspacePatcher patcher) {
47
		super(PATCH_INACCESSIBLE_PROJECTS_NAME,
48
				TeamUIMessages.PatchInaccessibleProjectsPage_title, null);
49
		setMessage(TeamUIMessages.PatchInaccessibleProjectsPage_message);
50
		fPatcher = patcher;
51
	}
52
53
	public void createControl(Composite parent) {
54
		initializeDialogUnits(parent);
55
56
		Composite composite = new Composite(parent, SWT.NULL);
57
		composite.setLayout(new GridLayout(3, false));
58
		composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL
59
				| GridData.HORIZONTAL_ALIGN_FILL));
60
		setControl(composite);
61
		Font parentFont = composite.getFont();
62
63
		checkList = CheckboxTableViewer.newCheckList(composite, SWT.H_SCROLL
64
				| SWT.V_SCROLL | SWT.BORDER);
65
		checkList.setContentProvider(new ArrayContentProvider());
66
		checkList.setLabelProvider(new WorkbenchLabelProvider() {
67
			public Color getForeground(Object element) {
68
				if (element instanceof IProject
69
						&& !((IProject) element).exists())
70
					return Display.getCurrent().getSystemColor(
71
							SWT.COLOR_WIDGET_NORMAL_SHADOW);
72
				return super.getForeground(element);
73
			}
74
75
			protected String decorateText(String input, Object element) {
76
				if (element instanceof IProject
77
						&& !((IProject) element).exists())
78
					return input
79
							+ NLS.bind(
80
									TeamUIMessages.PatchInaccessibleProjectsPage_projectDoesNotExistInWorkspace,
81
									""); //$NON-NLS-1$
82
				return input;
83
			}
84
		});
85
		checkList.addCheckStateListener(new ICheckStateListener() {
86
			public void checkStateChanged(CheckStateChangedEvent event) {
87
				IProject project = (IProject) event.getElement();
88
				if (event.getChecked() && !project.exists())
89
					checkList.setChecked(project, false);
90
			}
91
		});
92
		checkList
93
				.setComparator(new ResourceComparator(ResourceComparator.NAME));
94
95
		Table table = checkList.getTable();
96
		GridData data = new GridData(GridData.VERTICAL_ALIGN_FILL
97
				| GridData.HORIZONTAL_ALIGN_FILL);
98
		data.horizontalSpan = 3;
99
		data.grabExcessHorizontalSpace = true;
100
		data.grabExcessVerticalSpace = true;
101
		table.setLayoutData(data);
102
103
		checkAllButton = new Button(composite, SWT.NONE);
104
		checkAllButton
105
				.setText(TeamUIMessages.PatchInaccessibleProjectsPage_selectExisting);
106
		checkAllButton.addSelectionListener(new SelectionAdapter() {
107
			public void widgetSelected(SelectionEvent e) {
108
				setAllChecked(true);
109
			}
110
		});
111
		checkAllButton.setFont(parentFont);
112
		setButtonLayoutData(checkAllButton);
113
114
		uncheckAllButton = new Button(composite, SWT.NONE);
115
		uncheckAllButton
116
				.setText(TeamUIMessages.PatchInaccessibleProjectsPage_deselectAll);
117
		uncheckAllButton.addSelectionListener(new SelectionAdapter() {
118
			public void widgetSelected(SelectionEvent e) {
119
				setAllChecked(false);
120
			}
121
		});
122
		uncheckAllButton.setFont(parentFont);
123
		setButtonLayoutData(uncheckAllButton);
124
125
		updateControls();
126
	}
127
128
	private void updateControls() {
129
		DiffProject[] diffProjects = fPatcher.getDiffProjects();
130
		List projects = new ArrayList();
131
		if (diffProjects != null) {
132
			for (int i = 0; i < diffProjects.length; i++) {
133
				IProject project = ResourcesPlugin.getWorkspace().getRoot()
134
						.getProject(diffProjects[i].getName());
135
				if (!project.isAccessible())
136
					projects.add(project);
137
			}
138
		}
139
		checkList.setInput(projects.toArray(new IProject[] {}));
140
	}
141
142
	public void setVisible(boolean visible) {
143
		super.setVisible(visible);
144
		if (visible)
145
			updateControls();
146
	}
147
148
	public IWizardPage getNextPage() {
149
		Object input = checkList.getInput();
150
		// Skipping the patch parsed page in case this one is displayed
151
		if (input instanceof IProject[] && ((IProject[]) input).length > 0)
152
			return null;
153
		return super.getNextPage();
154
	}
155
156
	public IProject[] getSelectedProjects() {
157
		Object elements[] = checkList.getCheckedElements();
158
		List projects = new ArrayList();
159
		for (int i = 0; i < elements.length; i++)
160
			projects.add(elements[i]);
161
		return (IProject[]) projects.toArray(new IProject[] {});
162
	}
163
164
	private void setAllChecked(boolean checked) {
165
		int count = checkList.getTable().getItemCount();
166
		for (int i = 0; i < count; i++) {
167
			IProject project = (IProject) checkList.getElementAt(i);
168
			if (project.exists())
169
				checkList.setChecked(project, checked);
170
		}
171
	}
172
173
}

Return to bug 300215