KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > registry > TeamDecoratorDescription


1 /*******************************************************************************
2  * Copyright (c) 2006 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.registry;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.osgi.util.NLS;
15 import org.eclipse.team.core.diff.IThreeWayDiff;
16 import org.eclipse.team.internal.ui.TeamUIMessages;
17 import org.eclipse.team.internal.ui.TeamUIPlugin;
18
19 public class TeamDecoratorDescription {
20
21     private static final String JavaDoc TAG_TEAM_DECORATOR = "teamDecorator"; //$NON-NLS-1$
22
private static final String JavaDoc ATT_REPOSITORY_ID = "repositoryId"; //$NON-NLS-1$
23
private static final String JavaDoc ATT_DECORATOR_ID = "decoratorId"; //$NON-NLS-1$
24
private static final String JavaDoc ATT_DECORATED_DIRECTION_ID = "decoratedDirection"; //$NON-NLS-1$
25
private static final String JavaDoc OUTGOING_FLAG = "OUTGOING"; //$NON-NLS-1$
26
private static final String JavaDoc INCOMING_FLAG = "INCOMING"; //$NON-NLS-1$
27

28     private String JavaDoc repositoryId;
29     private String JavaDoc decoratorId;
30     private int decoratedDirection;
31     
32     public TeamDecoratorDescription(IExtension extension) throws CoreException {
33         readExtension(extension);
34     }
35
36     /**
37      * Initialize this descriptor based on the provided extension point.
38      */

39     protected void readExtension(IExtension extension) throws CoreException {
40         //read the extension
41
String JavaDoc id = extension.getUniqueIdentifier(); // id not required
42
IConfigurationElement[] elements = extension.getConfigurationElements();
43         int count = elements.length;
44         for (int i = 0; i < count; i++) {
45             IConfigurationElement element = elements[i];
46             String JavaDoc name = element.getName();
47             if (name.equalsIgnoreCase(TAG_TEAM_DECORATOR)) {
48                 repositoryId = element.getAttribute(ATT_REPOSITORY_ID);
49                 decoratorId = element.getAttribute(ATT_DECORATOR_ID);
50                 String JavaDoc flags = element.getAttribute(ATT_DECORATED_DIRECTION_ID);
51                 if (flags == null) {
52                     decoratedDirection = IThreeWayDiff.INCOMING | IThreeWayDiff.OUTGOING;
53                 } else {
54                     if (flags.indexOf(INCOMING_FLAG) != -1) {
55                         decoratedDirection |= IThreeWayDiff.INCOMING;
56                     }
57                     if (flags.indexOf(OUTGOING_FLAG) != -1) {
58                         decoratedDirection |= IThreeWayDiff.OUTGOING;
59                     }
60                     if (decoratedDirection == 0) {
61                         decoratedDirection = IThreeWayDiff.INCOMING | IThreeWayDiff.OUTGOING;
62                     }
63                 }
64             }
65         }
66         if (repositoryId == null)
67             fail(NLS.bind(TeamUIMessages.TeamContentProviderDescriptor_1, new String JavaDoc[] { ATT_REPOSITORY_ID, TAG_TEAM_DECORATOR, id == null ? "" : id})); //$NON-NLS-1$
68
if (repositoryId == null)
69             fail(NLS.bind(TeamUIMessages.TeamContentProviderDescriptor_1, new String JavaDoc[] { ATT_DECORATOR_ID, TAG_TEAM_DECORATOR, id == null ? "" : id})); //$NON-NLS-1$
70
}
71     
72     protected void fail(String JavaDoc reason) throws CoreException {
73         throw new CoreException(new Status(IStatus.ERROR, TeamUIPlugin.ID, 0, reason, null));
74     }
75
76     public String JavaDoc getDecoratorId() {
77         return decoratorId;
78     }
79
80     public String JavaDoc getRepositoryId() {
81         return repositoryId;
82     }
83
84     public int getDecoratedDirectionFlags() {
85         return decoratedDirection;
86     }
87 }
88
Popular Tags