KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jface.resource.ImageDescriptor;
15 import org.eclipse.team.internal.ui.TeamUIPlugin;
16 import org.eclipse.team.ui.synchronize.ISynchronizeParticipantDescriptor;
17
18 public class SynchronizeParticipantDescriptor implements ISynchronizeParticipantDescriptor {
19     public static final String JavaDoc ATT_ID = "id"; //$NON-NLS-1$
20
public static final String JavaDoc ATT_NAME = "name"; //$NON-NLS-1$
21
public static final String JavaDoc ATT_ICON = "icon"; //$NON-NLS-1$
22
public static final String JavaDoc ATT_CLASS = "class"; //$NON-NLS-1$
23
private static final String JavaDoc ATT_PERSISTENT = "persistent"; //$NON-NLS-1$
24

25     private String JavaDoc label;
26     private String JavaDoc className;
27     private String JavaDoc id;
28     private boolean persistent;
29     private ImageDescriptor imageDescriptor;
30     private String JavaDoc description;
31     
32     private IConfigurationElement configElement;
33
34     /**
35      * Create a new ViewDescriptor for an extension.
36      */

37     public SynchronizeParticipantDescriptor(IConfigurationElement e, String JavaDoc desc) throws CoreException {
38         configElement = e;
39         description = desc;
40         loadFromExtension();
41     }
42
43     public IConfigurationElement getConfigurationElement() {
44         return configElement;
45     }
46
47     /**
48      * Returns this view's description. This is the value of its <code>"description"</code>
49      * attribute.
50      *
51      * @return the description
52      */

53     public String JavaDoc getDescription() {
54         return description;
55     }
56     
57     public String JavaDoc getId() {
58         return id;
59     }
60     
61     public ImageDescriptor getImageDescriptor() {
62         if (imageDescriptor != null)
63             return imageDescriptor;
64         String JavaDoc iconName = configElement.getAttribute(ATT_ICON);
65         if (iconName == null)
66             return null;
67         imageDescriptor = TeamUIPlugin.getImageDescriptorFromExtension(configElement.getDeclaringExtension(), iconName);
68         return imageDescriptor;
69     }
70
71     public String JavaDoc getName() {
72         return label;
73     }
74     
75     /* (non-Javadoc)
76      * @see org.eclipse.team.ui.synchronize.ISynchronizeParticipantDescriptor#isPersistent()
77      */

78     public boolean isPersistent() {
79         return persistent;
80     }
81     
82     /**
83      * load a view descriptor from the registry.
84      */

85     private void loadFromExtension() throws CoreException {
86         String JavaDoc identifier = configElement.getAttribute(ATT_ID);
87         label = configElement.getAttribute(ATT_NAME);
88         className = configElement.getAttribute(ATT_CLASS);
89         String JavaDoc persistentString = configElement.getAttribute(ATT_PERSISTENT);
90         if(persistentString == null) {
91             persistent = true;
92         } else {
93             persistent = Boolean.valueOf(persistentString).booleanValue();
94         }
95         // Sanity check.
96
if ((label == null) || (className == null) || (identifier == null)) {
97             throw new CoreException(new Status(IStatus.ERROR, configElement.getNamespace(), 0, "Invalid extension (missing label or class name): " + identifier, //$NON-NLS-1$
98
null));
99         }
100         id = identifier;
101     }
102
103     /**
104      * Returns a string representation of this descriptor. For debugging
105      * purposes only.
106      */

107     public String JavaDoc toString() {
108         return "Synchronize Participant(" + getId() + ")"; //$NON-NLS-2$//$NON-NLS-1$
109
}
110 }
111
Popular Tags