2 * Copyright (c) 2003-2004 Christopher Lenz and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Christopher Lenz - initial API and implementation
11 * $Id: CssRulePropertySource.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.ui.internal.properties;
16 import java.util.ArrayList;
17 import java.util.List;
19 import net.sourceforge.phpeclipse.core.model.ISourceReference;
20 import net.sourceforge.phpeclipse.css.core.CssCore;
21 import net.sourceforge.phpeclipse.css.core.model.IDeclaration;
22 import net.sourceforge.phpeclipse.css.core.model.IPropertyInfo;
23 import net.sourceforge.phpeclipse.css.core.model.IRule;
24 import net.sourceforge.phpeclipse.css.core.profiles.IProfile;
25 import net.sourceforge.phpeclipse.css.core.profiles.IProfileManager;
26 import net.sourceforge.phpeclipse.css.ui.CssUI;
28 import org.eclipse.jface.viewers.LabelProvider;
29 import org.eclipse.swt.graphics.Image;
30 import org.eclipse.ui.views.properties.IPropertyDescriptor;
31 import org.eclipse.ui.views.properties.IPropertySource;
32 import org.eclipse.ui.views.properties.PropertyDescriptor;
37 public class CssRulePropertySource implements IPropertySource {
39 // Inner Classes -----------------------------------------------------------
42 * Extended label provider that decorates the property values with specific
43 * icons when a priority is set.
45 private static class DeclarationLabelProvider extends LabelProvider {
48 * The CSS declaration for which a label should be provided.
50 private IDeclaration declaration;
55 * @param declaration the declaration for which to provide a label
57 public DeclarationLabelProvider(IDeclaration declaration) {
58 this.declaration = declaration;
62 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
64 public Image getImage(Object element) {
65 if (this.declaration.getPriority() != null) {
66 CssUI plugin = CssUI.getDefault();
67 return plugin.getImageRegistry().get(
68 CssUI.ICON_IMPORTANT);
74 * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
76 public String getText(Object element) {
77 return this.declaration.getValue().getSource();
82 // Instance Variables ------------------------------------------------------
85 * The CSS rule for which properties should be provided.
90 * Cached list of property descriptors (<code>IPropertyDescriptor</code>).
92 private List descriptors;
94 // Constructors ------------------------------------------------------------
99 * @param styleRule the style rule for which to provide properties
101 public CssRulePropertySource(IRule styleRule) {
102 this.rule = styleRule;
105 // IPropertySource Implementation ------------------------------------------
108 * @see IPropertySource#getEditableValue()
110 public Object getEditableValue() {
115 * @see IPropertySource#getPropertyDescriptors()
117 public IPropertyDescriptor[] getPropertyDescriptors() {
118 if (this.descriptors == null) {
119 IProfileManager mgr = CssCore.getDefault().getProfileManager();
120 IProfile profile = mgr.getProfile(null);
121 this.descriptors = new ArrayList();
122 for (int i = 0; i < this.rule.getDeclarations().length; i++) {
123 IDeclaration declaration = this.rule.getDeclarations()[i];
124 String property = declaration.getProperty().getSource();
125 PropertyDescriptor descriptor = new PropertyDescriptor(
126 new Integer(i), property);
127 descriptor.setLabelProvider(
128 new DeclarationLabelProvider(declaration));
129 IPropertyInfo info = profile.getPropertyInfo(property);
131 descriptor.setCategory(info.getCategory());
133 this.descriptors.add(descriptor);
136 return (IPropertyDescriptor[]) this.descriptors.toArray(
137 new IPropertyDescriptor[this.descriptors.size()]);
141 * @see IPropertySource#getPropertyValue(Object)
143 public Object getPropertyValue(Object id) {
144 int i = ((Integer) id).intValue();
145 ISourceReference propertyValue =
146 this.rule.getDeclarations()[i].getValue();
147 return propertyValue.getSource();
151 * @see IPropertySource#isPropertySet(Object)
153 public boolean isPropertySet(Object id) {
154 // read-only property
159 * @see IPropertySource#resetPropertyValue(Object)
161 public void resetPropertyValue(Object id) {
162 // read-only property
166 * @see IPropertySource#setPropertyValue(Object, Object)
168 public void setPropertyValue(Object id, Object value) {
169 // read-only property