001: /*******************************************************************************
002: * Copyright (c) 2000, 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.examples.propertysheet;
011:
012: import java.util.Vector;
013:
014: import org.eclipse.core.runtime.IAdaptable;
015: import org.eclipse.jface.resource.ImageDescriptor;
016: import org.eclipse.jface.viewers.IBasicPropertyConstants;
017: import org.eclipse.ui.model.IWorkbenchAdapter;
018: import org.eclipse.ui.views.properties.IPropertyDescriptor;
019: import org.eclipse.ui.views.properties.IPropertySource;
020: import org.eclipse.ui.views.properties.PropertyDescriptor;
021: import org.eclipse.ui.views.properties.TextPropertyDescriptor;
022:
023: /**
024: * An Organization Element
025: */
026: public abstract class OrganizationElement implements IAdaptable,
027: IPropertySource, IWorkbenchAdapter {
028: //
029: private GroupElement parent;
030:
031: private String name;
032:
033: private ImageDescriptor imageDescriptor;
034:
035: //
036: private static Vector descriptors;
037: static {
038: descriptors = new Vector();
039: PropertyDescriptor name = new TextPropertyDescriptor(
040: IBasicPropertyConstants.P_TEXT, MessageUtil
041: .getString("name")); //$NON-NLS-1$
042: descriptors.addElement(name);
043: }
044:
045: /**
046: * Constructor.
047: * Creates a new OrganizationElement within the passed parent GroupElement,
048: *
049: * @param name the name
050: * @param parent the parent
051: */
052: OrganizationElement(String name, GroupElement parent) {
053: this .name = name;
054: this .parent = parent;
055: }
056:
057: /**
058: * Deletes this OrganizationElement from its parentGroup
059: */
060: public void delete() {
061: parent.delete(this );
062: }
063:
064: /* (non-Javadoc)
065: * Method declared on IAdaptable
066: */
067: public Object getAdapter(Class adapter) {
068: if (adapter == IPropertySource.class) {
069: return this ;
070: }
071: if (adapter == IWorkbenchAdapter.class) {
072: return this ;
073: }
074: return null;
075: }
076:
077: /**
078: * Returns the descriptors
079: */
080: static Vector getDescriptors() {
081: return descriptors;
082: }
083:
084: /* (non-Javadoc)
085: * Method declared on IPropertySource
086: */
087: public Object getEditableValue() {
088: return this ;
089: }
090:
091: /* (non-Javadoc)
092: * Method declared on IWorkbenchAdapter
093: */
094: public ImageDescriptor getImageDescriptor(Object object) {
095: return imageDescriptor;
096: }
097:
098: /* (non-Javadoc)
099: * Method declared on IWorkbenchAdapter
100: */
101: public String getLabel(Object o) {
102: return getName();
103: }
104:
105: /**
106: * Returns the name
107: */
108: String getName() {
109: return name;
110: }
111:
112: /**
113: * Returns the parent
114: */
115: public Object getParent(Object o) {
116: return parent;
117: }
118:
119: /* (non-Javadoc)
120: * Method declared on IPropertySource
121: */
122: public IPropertyDescriptor[] getPropertyDescriptors() {
123: return (IPropertyDescriptor[]) getDescriptors().toArray(
124: new IPropertyDescriptor[getDescriptors().size()]);
125: }
126:
127: /**
128: * The <code>OrganizationElement</code> implementation of this
129: * <code>IPropertySource</code> method returns the following properties
130: *
131: * 1) P_NAME returns String, name of this element
132: * this property key is defined in <code>IBasicPropertyConstants</code>
133: */
134: public Object getPropertyValue(Object propKey) {
135: if (propKey.equals(IBasicPropertyConstants.P_TEXT))
136: return getName();
137: return null;
138: }
139:
140: /**
141: * Hook. Implemented by <code>GroupElement</code> for use instead of instanceof
142: * @return boolean
143: */
144: public boolean isGroup() {
145: return false;
146: }
147:
148: /* (non-Javadoc)
149: * Method declared on IPropertySource
150: */
151: public boolean isPropertySet(Object property) {
152: return false;
153: }
154:
155: /**
156: * Hook. Implemented by <code>UserElement</code> for use instead of instanceof
157: * @return boolean
158: */
159: public boolean isUser() {
160: return false;
161: }
162:
163: /* (non-Javadoc)
164: * Method declared on IPropertySource
165: */
166: public void resetPropertyValue(Object property) {
167: }
168:
169: /**
170: * Sets the image descriptor
171: */
172: void setImageDescriptor(ImageDescriptor desc) {
173: imageDescriptor = desc;
174: }
175:
176: /**
177: * Sets the name
178: */
179: void setName(String newName) {
180: name = newName;
181: }
182:
183: /**
184: * Sets this instance's parent back pointer.
185: */
186: void setParent(GroupElement newParent) {
187: parent = newParent;
188: }
189:
190: /**
191: * The <code>OrganizationElement</code> implementation of this
192: * <code>IPropertySource</code> method returns the following properties
193: * defines the following Setable properties
194: *
195: * 1) P_NAME, expects String, sets the name of this OrganizationElement
196: */
197: public void setPropertyValue(Object name, Object value) {
198: if (name.equals(IBasicPropertyConstants.P_TEXT)) {
199: setName((String) value);
200: return;
201: }
202: }
203: }
|