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.themes;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IConfigurationElement;
014: import org.eclipse.ui.IPluginContribution;
015: import org.eclipse.ui.internal.WorkbenchPlugin;
016: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
017: import org.eclipse.ui.themes.IThemePreview;
018:
019: /**
020: * @since 3.0
021: */
022: public class ThemeElementCategory implements IPluginContribution,
023: IThemeElementDefinition {
024:
025: private String description;
026:
027: private IConfigurationElement element;
028:
029: private String id;
030:
031: private String parentId;
032:
033: private String label;
034:
035: private String pluginId;
036:
037: /**
038: *
039: * @param label
040: * @param id
041: * @param parentId
042: * @param description
043: * @param pluginId
044: * @param element
045: */
046: public ThemeElementCategory(String label, String id,
047: String parentId, String description, String pluginId,
048: IConfigurationElement element) {
049:
050: this .label = label;
051: this .id = id;
052: this .parentId = parentId;
053: this .description = description;
054: this .pluginId = pluginId;
055: this .element = element;
056: }
057:
058: /**
059: * @return Returns the <code>IColorExample</code> for this category. If one
060: * is not available, <code>null</code> is returned.
061: * @throws CoreException thrown if there is a problem instantiating the preview
062: */
063: public IThemePreview createPreview() throws CoreException {
064: String classString = element
065: .getAttribute(IWorkbenchRegistryConstants.ATT_CLASS);
066: if (classString == null || "".equals(classString)) { //$NON-NLS-1$
067: return null;
068: }
069: return (IThemePreview) WorkbenchPlugin.createExtension(element,
070: IWorkbenchRegistryConstants.ATT_CLASS);
071: }
072:
073: /**
074: * @return Returns the description.
075: */
076: public String getDescription() {
077: return description;
078: }
079:
080: /**
081: * @return Returns the element.
082: */
083: public IConfigurationElement getElement() {
084: return element;
085: }
086:
087: /* (non-Javadoc)
088: * @see org.eclipse.ui.internal.themes.IThemeElementDefinition#getId()
089: */
090: public String getId() {
091: return id;
092: }
093:
094: /* (non-Javadoc)
095: * @see org.eclipse.ui.internal.themes.IThemeElementDefinition#getLabel()
096: */
097: public String getName() {
098: return label;
099: }
100:
101: /* (non-Javadoc)
102: * @see org.eclipse.ui.IPluginContribution#getLocalId()
103: */
104: public String getLocalId() {
105: return id;
106: }
107:
108: /* (non-Javadoc)
109: * @see org.eclipse.ui.IPluginContribution#getPluginId()
110: */
111: public String getPluginId() {
112: return pluginId;
113: }
114:
115: /**
116: * @return Returns the parentId. May be <code>null</code>.
117: */
118: public String getParentId() {
119: return parentId;
120: }
121:
122: /* (non-Javadoc)
123: * @see java.lang.Object#equals(java.lang.Object)
124: */
125: public boolean equals(Object obj) {
126: if (obj instanceof ThemeElementCategory) {
127: return getId().equals(((ThemeElementCategory) obj).getId());
128: }
129: return false;
130: }
131:
132: /* (non-Javadoc)
133: * @see java.lang.Object#hashCode()
134: */
135: public int hashCode() {
136: return id.hashCode();
137: }
138: }
|