Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d5bda6837a9951057fcb80bdb6b5627a639ac896 (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
/*******************************************************************************
 * Copyright (c) 2010 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.ui.mapping;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.team.core.diff.provider.DiffTree;
import org.eclipse.team.internal.core.subscribers.SubscriberDiffTreeEventHandler;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.internal.ui.synchronize.patch.*;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;

public class IgnoreLeadingPathSegmentsAction extends Action {

	private ISynchronizePageConfiguration configuration;
	private ApplyPatchModelSynchronizeParticipant participant;
	private ApplyPatchSubscriberMergeContext context;
	private ApplyPatchSubscriber subscriber;
	private int maxValue;

	public IgnoreLeadingPathSegmentsAction(
			ISynchronizePageConfiguration configuration) {
		this.configuration = configuration;
		participant = (ApplyPatchModelSynchronizeParticipant) configuration
				.getParticipant();
		context = (ApplyPatchSubscriberMergeContext) participant.getContext();
		subscriber = (ApplyPatchSubscriber) context.getSubscriber();
	}

	@Override
	public boolean isEnabled() {
		return !subscriber.getPatcher().isWorkspacePatch();
	}

	@Override
	public void run() {
		int oldValue = subscriber.getPatcher().getStripPrefixSegments();
		maxValue = subscriber.getPatcher().calculatePrefixSegmentCount() - 1;

		InputDialog dlg = new InputDialog(
				Display.getCurrent().getActiveShell(),
				TeamUIMessages.IgnoreLeadingPathSegmentsDialog_title, NLS.bind(
						TeamUIMessages.IgnoreLeadingPathSegmentsDialog_message,
						new Integer(maxValue)), new Integer(oldValue)
						.toString(), new IInputValidator() {
					@Override
					public String isValid(String input) {
						try {
							int i = Integer.parseInt(input);
							if (i < 0 || i > maxValue)
								return TeamUIMessages.IgnoreLeadingPathSegmentsDialog_numberOutOfRange;
						} catch (NumberFormatException x) {
							return TeamUIMessages.IgnoreLeadingPathSegmentsDialog_notANumber;
						}
						return null;
					}
				});

		if (dlg.open() == Window.OK) {
			String input = dlg.getValue();
			int newValue = Integer.parseInt(input);
			if (newValue != oldValue) {
				DiffTree tree = (DiffTree)context.getDiffTree();
				tree.clear();
				SubscriberDiffTreeEventHandler handler = (SubscriberDiffTreeEventHandler) context
						.getAdapter(SubscriberDiffTreeEventHandler.class);
				handler.reset();
				subscriber.getPatcher().setStripPrefixSegments(newValue);
				participant.refresh(configuration.getSite().getWorkbenchSite(),
						context.getScope().getMappings());
			}
		}
	}
}

Back to the top