001: /*******************************************************************************
002: * Copyright (c) 2007 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.tests.views.properties.tabbed.dynamic.model;
011:
012: import java.util.ArrayList;
013: import java.util.List;
014:
015: import org.eclipse.core.runtime.Assert;
016: import org.eclipse.swt.graphics.Image;
017: import org.eclipse.ui.tests.views.properties.tabbed.Activator;
018: import org.eclipse.ui.tests.views.properties.tabbed.dynamic.views.DynamicTestsView;
019: import org.eclipse.ui.views.properties.IPropertyDescriptor;
020: import org.eclipse.ui.views.properties.IPropertySource;
021: import org.eclipse.ui.views.properties.PropertyDescriptor;
022: import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
023:
024: /**
025: * An element for the dynamic tests view. We build an element for one of the
026: * icons. For example, "icons/blue_circle.gif" becomes a "Blue Circle" element.
027: *
028: * @author Anthony Hunter
029: */
030: public class DynamicTestsElement implements
031: ITabbedPropertySheetPageContributor, IPropertySource {
032:
033: public static String ADVANCED_CATEGORY = "Advanced"; //$NON-NLS-1$
034:
035: public static String DEFAULT_CATEGORY = "Default"; //$NON-NLS-1$
036:
037: public static String ID_COLOR = "Color"; //$NON-NLS-1$
038:
039: public static String ID_IMAGE = "Image"; //$NON-NLS-1$
040:
041: public static String ID_NAME = "Name"; //$NON-NLS-1$
042:
043: public static String ID_SHAPE = "Shape"; //$NON-NLS-1$
044:
045: private DynamicTestsColor dynamicTestsColor;
046:
047: private Image image;
048:
049: private String name;
050:
051: private String path;
052:
053: private List propertyDescriptors = new ArrayList();
054:
055: private DynamicTestsShape shape;
056:
057: private DynamicTestsView view;
058:
059: public DynamicTestsElement(DynamicTestsView aView, String aPath) {
060: super ();
061: this .view = aView;
062: this .path = aPath;
063: int slash = path.indexOf('/');
064: Assert.isTrue(slash > 0);
065: int underscore = path.indexOf('_');
066: Assert.isTrue(underscore > 0);
067: int dot = path.indexOf('.');
068: Assert.isTrue(dot > 0);
069: this .shape = DynamicTestsShape.getShape(path.substring(
070: underscore + 1, dot));
071: this .dynamicTestsColor = DynamicTestsColor.getColor(path
072: .substring(slash + 1, underscore));
073: this .image = Activator.getImageDescriptor(path).createImage();
074: StringBuffer nameBuffer = new StringBuffer(path);
075: nameBuffer.replace(slash + 1, slash + 2, path.substring(
076: slash + 1, slash + 2).toUpperCase());
077: nameBuffer.replace(underscore + 1, underscore + 2, path
078: .substring(underscore + 1, underscore + 2)
079: .toUpperCase());
080: nameBuffer.replace(underscore, underscore + 1, " ");//$NON-NLS-1$
081: name = nameBuffer.substring(slash + 1, dot).toString();
082: PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
083: ID_NAME, ID_NAME);
084: propertyDescriptor.setCategory(DEFAULT_CATEGORY);
085: propertyDescriptors.add(propertyDescriptor);
086: propertyDescriptor = new PropertyDescriptor(ID_COLOR, ID_COLOR);
087: propertyDescriptor.setCategory(DEFAULT_CATEGORY);
088: propertyDescriptors.add(propertyDescriptor);
089: propertyDescriptor = new PropertyDescriptor(ID_SHAPE, ID_SHAPE);
090: propertyDescriptor.setCategory(DEFAULT_CATEGORY);
091: propertyDescriptors.add(propertyDescriptor);
092: propertyDescriptor = new PropertyDescriptor(ID_IMAGE, ID_IMAGE);
093: propertyDescriptor.setCategory(ADVANCED_CATEGORY);
094: propertyDescriptors.add(propertyDescriptor);
095: }
096:
097: public String getContributorId() {
098: return view.getContributorId();
099: }
100:
101: public Object getEditableValue() {
102: return this ;
103: }
104:
105: /**
106: * @return the image
107: */
108: public Image getImage() {
109: return image;
110: }
111:
112: /**
113: * @return the name
114: */
115: public String getName() {
116: return name;
117: }
118:
119: public IPropertyDescriptor[] getPropertyDescriptors() {
120: return (IPropertyDescriptor[]) propertyDescriptors
121: .toArray(new IPropertyDescriptor[0]);
122: }
123:
124: public Object getPropertyValue(Object id) {
125: if (id.equals(ID_COLOR)) {
126: return dynamicTestsColor;
127: } else if (id.equals(ID_SHAPE)) {
128: return shape;
129: } else if (id.equals(ID_NAME)) {
130: return name;
131: } else if (id.equals(ID_IMAGE)) {
132: return path;
133: }
134: return null;
135: }
136:
137: public boolean isPropertySet(Object id) {
138: return true;
139: }
140:
141: public void resetPropertyValue(Object id) {
142: // Not implemented, read only properties
143: }
144:
145: public void setPropertyValue(Object id, Object value) {
146: // Not implemented, read only properties
147: }
148: }
|