001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal;
011:
012: import java.net.URL;
013:
014: import org.eclipse.core.runtime.IBundleGroup;
015: import org.eclipse.jface.resource.ImageDescriptor;
016: import org.eclipse.ui.branding.IBundleGroupConstants;
017:
018: /**
019: * A class that converts the strings returned by
020: * <code>org.eclipse.core.runtime.IBundleGroup.getProperty</code> to the
021: * appropriate class. This implementation is tightly bound to the properties
022: * provided in IBundleGroupConstants. Clients adding their own properties could
023: * choose to subclass this.
024: *
025: * @see org.eclipse.ui.branding.IBundleGroupConstants
026: * @since 3.0
027: */
028: public class BundleGroupProperties extends BrandingProperties implements
029: IBundleGroupConstants {
030:
031: private final IBundleGroup bundleGroup;
032:
033: private ImageDescriptor featureImageDescriptor;
034:
035: private URL featureImageUrl;
036:
037: private String tipsAndTricksHref;
038:
039: private URL welcomePageUrl;
040:
041: private String welcomePerspective;
042:
043: private URL licenseUrl;
044:
045: private String featureLabel;
046:
047: private String featureId;
048:
049: private String providerName;
050:
051: private String versionId;
052:
053: /**
054: * This instance will return properties from the given bundle group. The properties are
055: * retrieved in a lazy fashion and cached for later retrieval.
056: * @param bundleGroup must not be null
057: */
058: public BundleGroupProperties(IBundleGroup bundleGroup) {
059: if (bundleGroup == null) {
060: throw new IllegalArgumentException();
061: }
062: this .bundleGroup = bundleGroup;
063: }
064:
065: /**
066: * An image which can be shown in an "about features" dialog (32x32).
067: */
068: public ImageDescriptor getFeatureImage() {
069: if (featureImageDescriptor == null) {
070: featureImageDescriptor = getFeatureImage(bundleGroup);
071: }
072: return featureImageDescriptor;
073: }
074:
075: /**
076: * The URL to an image which can be shown in an "about features" dialog (32x32).
077: */
078: public URL getFeatureImageUrl() {
079: if (featureImageUrl == null) {
080: featureImageUrl = getFeatureImageUrl(bundleGroup);
081: }
082: return featureImageUrl;
083: }
084:
085: /**
086: * A help reference for the feature's tips and tricks page (optional).
087: */
088: public String getTipsAndTricksHref() {
089: if (tipsAndTricksHref == null) {
090: tipsAndTricksHref = getTipsAndTricksHref(bundleGroup);
091: }
092: return tipsAndTricksHref;
093: }
094:
095: /**
096: * A URL for the feature's welcome page (special XML-based format) ($nl$/
097: * prefix to permit locale-specific translations of entire file). Products
098: * designed to run "headless" typically would not have such a page.
099: */
100: public URL getWelcomePageUrl() {
101: if (welcomePageUrl == null) {
102: welcomePageUrl = getWelcomePageUrl(bundleGroup);
103: }
104: return welcomePageUrl;
105: }
106:
107: /**
108: * The id of a perspective in which to show the welcome page (optional).
109: */
110: public String getWelcomePerspective() {
111: if (welcomePerspective == null) {
112: welcomePerspective = getWelcomePerspective(bundleGroup);
113: }
114: return welcomePerspective;
115: }
116:
117: /**
118: * A URL for the feature's license page.
119: */
120: public URL getLicenseUrl() {
121: if (licenseUrl == null) {
122: licenseUrl = getLicenseUrl(bundleGroup);
123: }
124: return licenseUrl;
125: }
126:
127: /**
128: * Returns a label for the feature plugn, or <code>null</code>.
129: */
130: public String getFeatureLabel() {
131: if (featureLabel == null) {
132: featureLabel = getFeatureLabel(bundleGroup);
133: }
134: return featureLabel;
135: }
136:
137: /**
138: * Returns the id for this bundleGroup.
139: */
140: public String getFeatureId() {
141: if (featureId == null) {
142: featureId = getFeatureId(bundleGroup);
143: }
144: return featureId;
145: }
146:
147: /**
148: * Returns the provider name.
149: */
150: public String getProviderName() {
151: if (providerName == null) {
152: providerName = getProviderName(bundleGroup);
153: }
154: return providerName;
155: }
156:
157: /**
158: * Returns the feature version id.
159: */
160: public String getFeatureVersion() {
161: if (versionId == null) {
162: versionId = getFeatureVersion(bundleGroup);
163: }
164: return versionId;
165: }
166:
167: /**
168: * An image which can be shown in an "about features" dialog (32x32).
169: */
170: public static ImageDescriptor getFeatureImage(
171: IBundleGroup bundleGroup) {
172: return getImage(bundleGroup.getProperty(FEATURE_IMAGE), null);
173: }
174:
175: /**
176: * The URL to an image which can be shown in an "about features" dialog (32x32).
177: */
178: public static URL getFeatureImageUrl(IBundleGroup bundleGroup) {
179: return getUrl(bundleGroup.getProperty(FEATURE_IMAGE), null);
180: }
181:
182: /**
183: * A help reference for the feature's tips and tricks page (optional).
184: */
185: public static String getTipsAndTricksHref(IBundleGroup bundleGroup) {
186: return bundleGroup.getProperty(TIPS_AND_TRICKS_HREF);
187: }
188:
189: /**
190: * A URL for the feature's welcome page (special XML-based format) ($nl$/
191: * prefix to permit locale-specific translations of entire file). Products
192: * designed to run "headless" typically would not have such a page.
193: */
194: public static URL getWelcomePageUrl(IBundleGroup bundleGroup) {
195: return getUrl(bundleGroup.getProperty(WELCOME_PAGE), null);
196: }
197:
198: /**
199: * The id of a perspective in which to show the welcome page (optional).
200: */
201: public static String getWelcomePerspective(IBundleGroup bundleGroup) {
202: String property = bundleGroup.getProperty(WELCOME_PERSPECTIVE);
203: return property == null ? null : property;
204: }
205:
206: /**
207: * A URL for the feature's license page.
208: */
209: public static URL getLicenseUrl(IBundleGroup bundleGroup) {
210: return getUrl(bundleGroup.getProperty(LICENSE_HREF), null);
211: }
212:
213: /**
214: * Returns a label for the feature plugn, or <code>null</code>.
215: */
216: public static String getFeatureLabel(IBundleGroup bundleGroup) {
217: return bundleGroup.getName();
218: }
219:
220: /**
221: * Returns the id for this bundleGroup.
222: */
223: public static String getFeatureId(IBundleGroup bundleGroup) {
224: return bundleGroup.getIdentifier();
225: }
226:
227: /**
228: * Returns the provider name.
229: */
230: public static String getProviderName(IBundleGroup bundleGroup) {
231: return bundleGroup.getProviderName();
232: }
233:
234: /**
235: * Returns the feature version id.
236: */
237: public static String getFeatureVersion(IBundleGroup bundleGroup) {
238: return bundleGroup.getVersion();
239: }
240: }
|