001: package net.refractions.udig.catalog.ui;
002:
003: import net.refractions.udig.catalog.ui.ConnectionFactoryManager.Descriptor;
004:
005: import org.eclipse.core.runtime.CoreException;
006: import org.eclipse.jface.resource.ImageDescriptor;
007: import org.eclipse.ui.plugin.AbstractUIPlugin;
008:
009: /**
010: * Descriptor for net.refractions.udig.catalog.ui.connectionFactory extensions.
011: *
012: * @author Justin Deoliveira,Refractions Research Inc.,jdeolive@refractions.net
013: *
014: */
015: public class UDIGConnectionFactoryDescriptor {
016: UDIGConnectionFactory factory;
017: private Descriptor<UDIGConnectionPage> wizardPage;
018:
019: public UDIGConnectionFactoryDescriptor(
020: Descriptor<UDIGConnectionFactory> factoryDescriptor)
021: throws CoreException {
022: factory = factoryDescriptor.getConcreteInstance();
023: factory.setDescriptor(this );
024: wizardPage = ConnectionFactoryManager.instance()
025: .getPageDescriptor(factoryDescriptor);
026: }
027:
028: public UDIGConnectionFactory getConnectionFactory() {
029: return factory;
030: }
031:
032: public UDIGConnectionPage createConnectionPage()
033: throws CoreException {
034: UDIGConnectionPage page = wizardPage.getConcreteInstance();
035:
036: page.setTitle(getLabel());
037: page.setDescription(getDescription());
038: page.setImageDescriptor(getDescriptionImage());
039:
040: return page;
041: }
042:
043: public String getLabel() {
044: return wizardPage.getConfigurationElement()
045: .getAttribute("name"); //$NON-NLS-1$
046: }
047:
048: public String getDescription() {
049: String desc = wizardPage.getConfigurationElement()
050: .getAttribute("description"); //$NON-NLS-1$
051: if (desc == null)
052: return ""; //$NON-NLS-1$
053:
054: return desc.trim();
055: }
056:
057: public String getId() {
058: return wizardPage.getConfigurationElement().getAttribute("id"); //$NON-NLS-1$
059: }
060:
061: public ImageDescriptor getImage() {
062: String ns = wizardPage.getConfigurationElement().getNamespace();
063: String banner = wizardPage.getConfigurationElement()
064: .getAttribute("icon"); //$NON-NLS-1$
065:
066: if (banner == null)
067: return null;
068:
069: return AbstractUIPlugin.imageDescriptorFromPlugin(ns, banner);
070: }
071:
072: public ImageDescriptor getDescriptionImage() {
073: String ns = wizardPage.getConfigurationElement().getNamespace();
074: String banner = wizardPage.getConfigurationElement()
075: .getAttribute("banner"); //$NON-NLS-1$
076:
077: if (banner == null)
078: return null;
079:
080: return AbstractUIPlugin.imageDescriptorFromPlugin(ns, banner);
081: }
082:
083: public String getServiceType() {
084: return wizardPage.getConfigurationElement()
085: .getAttribute("type"); //$NON-NLS-1$
086: }
087:
088: @Override
089: public boolean equals(Object obj) {
090: if (this == obj)
091: return true;
092:
093: if (obj instanceof UDIGConnectionFactoryDescriptor) {
094: UDIGConnectionFactoryDescriptor descriptor = (UDIGConnectionFactoryDescriptor) obj;
095:
096: return getId() != null
097: && getId().equals(descriptor.getId());
098: }
099:
100: return false;
101: }
102:
103: @Override
104: public int hashCode() {
105: if (getId() == null)
106: return "".hashCode(); //$NON-NLS-1$
107: return getId().hashCode();
108: }
109: }
|