Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8d33a2f6a3258b94c2c79175f24745f12e996d6b (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
/*******************************************************************************
 * Copyright (c) 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.registry;

import org.eclipse.core.runtime.*;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.diff.IThreeWayDiff;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.internal.ui.TeamUIPlugin;

public class TeamDecoratorDescription {

	private static final String TAG_TEAM_DECORATOR = "teamDecorator"; //$NON-NLS-1$
	private static final String ATT_REPOSITORY_ID = "repositoryId"; //$NON-NLS-1$
	private static final String ATT_DECORATOR_ID = "decoratorId"; //$NON-NLS-1$
	private static final String ATT_DECORATED_DIRECTION_ID = "decoratedDirection"; //$NON-NLS-1$
	private static final String OUTGOING_FLAG = "OUTGOING"; //$NON-NLS-1$
	private static final String INCOMING_FLAG = "INCOMING"; //$NON-NLS-1$

	private String repositoryId;
	private String decoratorId;
	private int decoratedDirection;

	public TeamDecoratorDescription(IExtension extension) throws CoreException {
		readExtension(extension);
	}

	/**
	 * Initialize this descriptor based on the provided extension point.
	 */
	protected void readExtension(IExtension extension) throws CoreException {
		//read the extension
		String id = extension.getUniqueIdentifier(); // id not required
		IConfigurationElement[] elements = extension.getConfigurationElements();
		int count = elements.length;
		for (int i = 0; i < count; i++) {
			IConfigurationElement element = elements[i];
			String name = element.getName();
			if (name.equalsIgnoreCase(TAG_TEAM_DECORATOR)) {
				repositoryId = element.getAttribute(ATT_REPOSITORY_ID);
				decoratorId = element.getAttribute(ATT_DECORATOR_ID);
				String flags = element.getAttribute(ATT_DECORATED_DIRECTION_ID);
				if (flags == null) {
					decoratedDirection = IThreeWayDiff.INCOMING | IThreeWayDiff.OUTGOING;
				} else {
					if (flags.indexOf(INCOMING_FLAG) != -1) {
						decoratedDirection |= IThreeWayDiff.INCOMING;
					}
					if (flags.indexOf(OUTGOING_FLAG) != -1) {
						decoratedDirection |= IThreeWayDiff.OUTGOING;
					}
					if (decoratedDirection == 0) {
						decoratedDirection = IThreeWayDiff.INCOMING | IThreeWayDiff.OUTGOING;
					}
				}
			}
		}
		if (repositoryId == null)
			fail(NLS.bind(TeamUIMessages.TeamContentProviderDescriptor_1, new String[] { ATT_REPOSITORY_ID, TAG_TEAM_DECORATOR, id == null ? "" : id})); //$NON-NLS-1$
		if (repositoryId == null)
			fail(NLS.bind(TeamUIMessages.TeamContentProviderDescriptor_1, new String[] { ATT_DECORATOR_ID, TAG_TEAM_DECORATOR, id == null ? "" : id})); //$NON-NLS-1$
	}

	protected void fail(String reason) throws CoreException {
		throw new CoreException(new Status(IStatus.ERROR, TeamUIPlugin.ID, 0, reason, null));
	}

	public String getDecoratorId() {
		return decoratorId;
	}

	public String getRepositoryId() {
		return repositoryId;
	}

	public int getDecoratedDirectionFlags() {
		return decoratedDirection;
	}
}

Back to the top