Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c347ecc4ddbf0c4703e26fcd7056c68310b02afc (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*******************************************************************************
 * Copyright (c) 2006, 2017 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.examples.filesystem.ui;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.IContentChangeNotifier;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.core.resources.mapping.ModelProvider;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.*;
import org.eclipse.team.core.mapping.IMergeContext;
import org.eclipse.team.internal.ui.Policy;
import org.eclipse.team.ui.PageSaveablePart;
import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
import org.eclipse.team.ui.mapping.ISynchronizationCompareInput;


/**
 * This class is the compare container used by the {@link NonSyncModelMergeOperation}
 * to show a manual merge.
 */
public class NonSyncMergePart extends PageSaveablePart {
	
	private final NonSyncModelMergePage page;

	protected NonSyncMergePart(Shell shell, CompareConfiguration compareConfiguration, NonSyncModelMergePage page) {
		super(shell, compareConfiguration);
		this.page = page;
	}

	protected Control createPage(Composite parent, ToolBarManager toolBarManager) {
		page.createControl(parent);
		return page.getControl();
	}

	protected ISelectionProvider getSelectionProvider() {
		return page.getViewer();
	}

	protected ICompareInput getCompareInput(ISelection selection) {
		ICompareInput compareInput = super.getCompareInput(selection);
		if (compareInput != null)
			return compareInput;
		Object element = ((IStructuredSelection)selection).getFirstElement();
		ISynchronizationCompareAdapter compareAdapter = getCompareAdapter(element);
		if (element instanceof ResourceMapping) {
			element = ((ResourceMapping) element).getModelObject();
		}
		if (compareAdapter != null){
			return compareAdapter.asCompareInput(page.getContext(), element);
		}
		return null;
	}
	
	protected static ISynchronizationCompareAdapter getCompareAdapter(Object element) {
		if (element instanceof ResourceMapping) {
			ResourceMapping mapping = (ResourceMapping) element;
			ModelProvider provider = mapping.getModelProvider();
			Object adapter = provider.getAdapter(ISynchronizationCompareAdapter.class);
			if (adapter instanceof ISynchronizationCompareAdapter) {
				return (ISynchronizationCompareAdapter) adapter;
			}
		}
		return null;
	}

	protected void prepareInput(ICompareInput input,
			CompareConfiguration configuration, IProgressMonitor monitor)
			throws InvocationTargetException {
		try {
			ISynchronizationCompareInput adapter = asSynchronizationCompareInput(input);
			if (adapter != null) {
				adapter.prepareInput(configuration, Policy.subMonitorFor(monitor, 90));
			}
		} catch (CoreException e) {
			throw new InvocationTargetException(e);
		}
	}

	/*
	 * Convert the compare input to a synchronize compare input.
	 */
	private ISynchronizationCompareInput asSynchronizationCompareInput(ICompareInput input) {
		return Adapters.adapt(input, ISynchronizationCompareInput.class);
	}

	public void contentChanged(IContentChangeNotifier source) {
		// TODO Auto-generated method stub

	}

	public String getTitle() {
		return "File System Provider Merge";
	}

	public Image getTitleImage() {
		return null;
	}

	public IMergeContext getContext() {
		return page.getContext();
	}

}

Back to the top