david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2001, 2004 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | * Jens Lukowski/Innoopract - initial renaming/restructuring |
| 11 | * |
| 12 | *******************************************************************************/ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 13 | package org.eclipse.wst.dtd.ui.internal.views.properties; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 14 | |
| 15 | import java.util.Stack; |
| 16 | |
| 17 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
| 18 | import org.eclipse.ui.views.properties.IPropertySource; |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 19 | import org.eclipse.wst.dtd.core.internal.DTDNode; |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 20 | import org.eclipse.wst.dtd.ui.internal.DTDUIMessages; |
david_williams | 4ad020f | 2005-04-18 08:00:30 +0000 | [diff] [blame] | 21 | import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; |
| 22 | import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; |
nitind | bca2663 | 2005-03-30 18:13:32 +0000 | [diff] [blame] | 23 | import org.eclipse.wst.sse.ui.internal.properties.CustomPropertyDescriptor; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 24 | |
| 25 | |
| 26 | /** |
| 27 | * An IPropertySource implementation for a JFace viewer used to display |
| 28 | * properties of DOM nodes. Requires an adapter factory to create JFace |
| 29 | * adapters for the nodes in the tree. |
| 30 | */ |
| 31 | public class DTDPropertySourceAdapter implements INodeAdapter, IPropertySource { |
| 32 | protected final static String CATEGORY_ATTRIBUTES = "Attributes"; //$NON-NLS-1$ |
| 33 | |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 34 | private static final String ID_NAME = DTDUIMessages.DTDPropertySourceAdapter_0; //$NON-NLS-1$ |
| 35 | private static final String ID_TEXT = DTDUIMessages.DTDPropertySourceAdapter_1; //$NON-NLS-1$ |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 36 | |
| 37 | protected IPropertyDescriptor[] fDescriptors = null; |
| 38 | protected INodeNotifier fNode = null; |
| 39 | |
| 40 | protected Stack fValuesBeingSet = new Stack(); |
| 41 | |
| 42 | public DTDPropertySourceAdapter(INodeNotifier target) { |
| 43 | super(); |
| 44 | fNode = target; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @return |
| 49 | */ |
| 50 | private IPropertyDescriptor[] createPropertyDescriptors() { |
| 51 | CustomPropertyDescriptor nameDescriptor = new CustomPropertyDescriptor(ID_NAME, ID_NAME, null); |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 52 | nameDescriptor.setCategory(DTDUIMessages.DTDPropertySourceAdapter_2); //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 53 | // CustomPropertyDescriptor contentDescriptor = new |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 54 | // CustomPropertyDescriptor(ID_TEXT, ID_TEXT, null); |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 55 | // contentDescriptor.setCategory("Attributes"); |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 56 | return new IPropertyDescriptor[]{nameDescriptor}; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns a value for this Node that can be editted in a property sheet. |
| 61 | * |
| 62 | * @return a value that can be editted |
| 63 | */ |
| 64 | public Object getEditableValue() { |
| 65 | return null; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the current collection of property descriptors. |
| 70 | * |
| 71 | * @return all valid descriptors. |
| 72 | */ |
| 73 | public IPropertyDescriptor[] getPropertyDescriptors() { |
| 74 | if (fDescriptors == null || fDescriptors.length == 0) { |
| 75 | fDescriptors = createPropertyDescriptors(); |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 76 | } |
| 77 | else { |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 78 | updatePropertyDescriptors(); |
| 79 | } |
| 80 | return fDescriptors; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) |
| 85 | */ |
| 86 | public Object getPropertyValue(Object id) { |
| 87 | Object value = null; |
| 88 | if (id.equals(ID_NAME) && fNode instanceof DTDNode) { |
| 89 | value = ((DTDNode) fNode).getName(); |
| 90 | } |
| 91 | if (id.equals(ID_TEXT) && fNode instanceof DTDNode) { |
| 92 | value = ((DTDNode) fNode).getFullNodeText(); |
| 93 | } |
| 94 | return value; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Allowing the INodeAdapter to compare itself against the type allows it |
| 99 | * to return true in more than one case. |
| 100 | */ |
| 101 | public boolean isAdapterForType(Object type) { |
| 102 | return type == IPropertySource.class; |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * (non-Javadoc) |
| 107 | * |
| 108 | * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object) |
| 109 | */ |
| 110 | public boolean isPropertySet(Object id) { |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * (non-Javadoc) |
| 119 | * |
| 120 | * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object) |
| 121 | */ |
| 122 | public void resetPropertyValue(Object id) { |
| 123 | } |
| 124 | |
| 125 | public void setPropertyValue(Object nameObject, Object value) { |
| 126 | } |
| 127 | |
| 128 | protected void updatePropertyDescriptors() { |
| 129 | } |
| 130 | } |