Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dc2abf5afae18dc8d4559535aa18acfdedb07b35 (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
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ui.dialogs;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.team.core.mapping.ISynchronizationContext;
import org.eclipse.team.core.mapping.ISynchronizationScope;
import org.eclipse.team.internal.ui.mapping.TeamViewerSorter;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.mapping.ITeamContentProviderManager;
import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.navigator.CommonViewerSorter;
import org.eclipse.ui.navigator.INavigatorContentExtension;
import org.eclipse.ui.navigator.INavigatorContentServiceListener;

public class ResourceMappingHierarchyArea extends DialogArea implements INavigatorContentServiceListener {
	private static final String TEAM_NAVIGATOR_CONTENT = "org.eclipse.team.ui.navigatorViewer"; //$NON-NLS-1$
	private String description;
    private CommonViewer viewer;
	private final ISynchronizationScope scope;
	private final ISynchronizationContext context;


    public static ResourceMappingHierarchyArea create(ISynchronizationScope scope, ISynchronizationContext context) {
        return new ResourceMappingHierarchyArea(scope, context);
    }

	private ResourceMappingHierarchyArea(ISynchronizationScope scope, ISynchronizationContext context) {
		this.scope = scope;
		this.context = context;
	}

	@Override
	public void createArea(Composite parent) {
        Composite composite = new Composite(parent, SWT.NULL);
        GridLayout layout = new GridLayout(1, false);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        composite.setLayout(layout);
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));

        if (description != null)
            createWrappingLabel(composite, description, 1);

        viewer = new CommonViewer(TEAM_NAVIGATOR_CONTENT, composite, SWT.BORDER);
        viewer.setSorter(new CommonViewerSorter());
        viewer.setSorter(new TeamViewerSorter((CommonViewerSorter)viewer.getSorter()));
        viewer.getNavigatorContentService().bindExtensions(TeamUI.getTeamContentProviderManager().getContentProviderIds(scope), true);
        viewer.getNavigatorContentService().getActivationService().activateExtensions(TeamUI.getTeamContentProviderManager().getContentProviderIds(scope), true);
        GridData data = new GridData(GridData.FILL_BOTH);
        data.heightHint = 100;
        data.widthHint = 300;
        viewer.getControl().setLayoutData(data);
        viewer.getNavigatorContentService().addListener(this);
        viewer.setInput(getInitialInput());
        viewer.refresh();
        Object[] objects = getRootModelObjects();
        viewer.setSelection(new StructuredSelection(objects), true);
    }

	private Object getInitialInput() {
		if (context != null)
			return context;
		return scope;
	}

	private Object[] getRootModelObjects() {
		if (scope == null)
			return new Object[0];
		ResourceMapping[] mappings = scope.getMappings();
		List<Object> result = new ArrayList<>();
		for (int i = 0; i < mappings.length; i++) {
			ResourceMapping mapping = mappings[i];
			result.add(mapping.getModelObject());
		}
		return result.toArray(new Object[result.size()]);
	}

	public void setDescription(String string) {
        description = string;
    }

	@Override
	public void onLoad(INavigatorContentExtension anExtension) {
		anExtension.getStateModel().setProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_SCOPE, scope);
		if (context != null) {
			anExtension.getStateModel().setProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT, context);
		}
	}
}

Back to the top