1 11 package org.eclipse.ui.views.properties; 12 13 import java.io.File ; 14 import org.eclipse.core.resources.IResource; 15 import org.eclipse.core.resources.ResourceAttributes; 16 import org.eclipse.core.runtime.Assert; 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.jface.viewers.IBasicPropertyConstants; 19 import org.eclipse.osgi.util.TextProcessor; 20 import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils; 21 import org.eclipse.ui.internal.views.properties.IDEPropertiesMessages; 22 23 26 public class ResourcePropertySource implements IPropertySource { 27 protected static String NOT_LOCAL_TEXT = IDEPropertiesMessages.PropertySource_notLocal; 28 29 protected static String FILE_NOT_FOUND = IDEPropertiesMessages.PropertySource_notFound; 30 31 protected static String UNDEFINED_PATH_VARIABLE = IDEPropertiesMessages.PropertySource_undefinedPathVariable; 32 33 protected static String FILE_NOT_EXIST_TEXT = IDEPropertiesMessages.PropertySource_fileNotExist; 34 35 protected IResource element; 37 38 protected String errorMessage = IDEPropertiesMessages.PropertySource_readOnly; 40 41 static protected IPropertyDescriptor[] propertyDescriptors = new IPropertyDescriptor[7]; 43 44 static protected IPropertyDescriptor[] propertyDescriptorsLinkVariable = new IPropertyDescriptor[8]; 45 static { 46 PropertyDescriptor descriptor; 47 48 descriptor = new PropertyDescriptor(IBasicPropertyConstants.P_TEXT, 50 IResourcePropertyConstants.P_LABEL_RES); 51 descriptor.setAlwaysIncompatible(true); 52 descriptor 53 .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY); 54 propertyDescriptors[0] = descriptor; 55 propertyDescriptorsLinkVariable[0] = descriptor; 56 57 descriptor = new PropertyDescriptor( 59 IResourcePropertyConstants.P_PATH_RES, 60 IResourcePropertyConstants.P_DISPLAYPATH_RES); 61 descriptor.setAlwaysIncompatible(true); 62 descriptor 63 .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY); 64 propertyDescriptors[1] = descriptor; 65 propertyDescriptorsLinkVariable[1] = descriptor; 66 67 descriptor = new PropertyDescriptor( 69 IResourcePropertyConstants.P_EDITABLE_RES, 70 IResourcePropertyConstants.P_DISPLAYEDITABLE_RES); 71 descriptor.setAlwaysIncompatible(true); 72 descriptor 73 .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY); 74 propertyDescriptors[2] = descriptor; 75 propertyDescriptorsLinkVariable[2] = descriptor; 76 77 descriptor = new PropertyDescriptor( 79 IResourcePropertyConstants.P_DERIVED_RES, 80 IResourcePropertyConstants.P_DISPLAYDERIVED_RES); 81 descriptor.setAlwaysIncompatible(true); 82 descriptor 83 .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY); 84 propertyDescriptors[3] = descriptor; 85 propertyDescriptorsLinkVariable[3] = descriptor; 86 87 descriptor = new PropertyDescriptor( 89 IResourcePropertyConstants.P_LAST_MODIFIED_RES, 90 IResourcePropertyConstants.P_DISPLAY_LAST_MODIFIED); 91 descriptor.setAlwaysIncompatible(true); 92 descriptor 93 .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY); 94 propertyDescriptors[4] = descriptor; 95 propertyDescriptorsLinkVariable[4] = descriptor; 96 97 descriptor = new PropertyDescriptor( 99 IResourcePropertyConstants.P_LINKED_RES, 100 IResourcePropertyConstants.P_DISPLAYLINKED_RES); 101 descriptor.setAlwaysIncompatible(true); 102 descriptor 103 .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY); 104 propertyDescriptors[5] = descriptor; 105 propertyDescriptorsLinkVariable[5] = descriptor; 106 107 descriptor = new PropertyDescriptor( 109 IResourcePropertyConstants.P_LOCATION_RES, 110 IResourcePropertyConstants.P_DISPLAYLOCATION_RES); 111 descriptor.setAlwaysIncompatible(true); 112 descriptor 113 .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY); 114 propertyDescriptors[6] = descriptor; 115 propertyDescriptorsLinkVariable[6] = descriptor; 116 117 descriptor = new PropertyDescriptor( 119 IResourcePropertyConstants.P_RESOLVED_LOCATION_RES, 120 IResourcePropertyConstants.P_DISPLAYRESOLVED_LOCATION_RES); 121 descriptor.setAlwaysIncompatible(true); 122 descriptor 123 .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY); 124 propertyDescriptorsLinkVariable[7] = descriptor; 125 126 } 127 128 133 public ResourcePropertySource(IResource res) { 134 Assert.isNotNull(res); 135 this.element = res; 136 } 137 138 141 public Object getEditableValue() { 142 return this; 143 } 144 145 148 public IPropertyDescriptor[] getPropertyDescriptors() { 149 if (isPathVariable(element)) { 150 return propertyDescriptorsLinkVariable; 151 } 152 return propertyDescriptors; 153 } 154 155 158 public Object getPropertyValue(Object name) { 159 if (name.equals(IBasicPropertyConstants.P_TEXT)) { 160 return element.getName(); 161 } 162 if (name.equals(IResourcePropertyConstants.P_PATH_RES)) { 163 return TextProcessor.process(element.getFullPath().toString()); 164 } 165 if (name.equals(IResourcePropertyConstants.P_LAST_MODIFIED_RES)) { 166 return IDEResourceInfoUtils.getDateStringValue(element); 167 } 168 if (name.equals(IResourcePropertyConstants.P_EDITABLE_RES)) { 169 final ResourceAttributes attributes = element.getResourceAttributes(); 170 if (attributes == null || attributes.isReadOnly()) { 171 return IDEPropertiesMessages.ResourceProperty_false; 172 } 173 return IDEPropertiesMessages.ResourceProperty_true; 174 } 175 if (name.equals(IResourcePropertyConstants.P_DERIVED_RES)) { 176 if (element.isDerived()) 177 return IDEPropertiesMessages.ResourceProperty_true; 178 return IDEPropertiesMessages.ResourceProperty_false; 179 } 180 if (name.equals(IResourcePropertyConstants.P_LINKED_RES)) { 181 if (element.isLinked()) 182 return IDEPropertiesMessages.ResourceProperty_true; 183 return IDEPropertiesMessages.ResourceProperty_false; 184 } 185 if (name.equals(IResourcePropertyConstants.P_LOCATION_RES)) { 186 return TextProcessor.process(IDEResourceInfoUtils.getLocationText(element)); 187 } 188 if (name.equals(IResourcePropertyConstants.P_RESOLVED_LOCATION_RES)) { 189 return TextProcessor.process(IDEResourceInfoUtils.getResolvedLocationText(element)); 190 } 191 return null; 192 } 193 194 204 private boolean isPathVariable(IResource resource) { 205 if (!resource.isLinked()) { 206 return false; 207 } 208 209 IPath resolvedLocation = resource.getLocation(); 210 if (resolvedLocation == null) { 211 return true; 213 } 214 IPath rawLocation = resource.getRawLocation(); 215 if (resolvedLocation.equals(rawLocation)) { 216 return false; 217 } 218 219 return true; 220 } 221 222 225 public boolean isPropertySet(Object property) { 226 return false; 227 } 228 229 234 public void resetPropertyValue(Object property) { 235 } 236 237 242 public void setPropertyValue(Object name, Object value) { 243 } 244 245 252 protected File getFile(IResource resource) { 253 IPath location = resource.getLocation(); 254 if (location == null) { 255 return null; 256 } 257 return location.toFile(); 258 } 259 260 } 261 | Popular Tags |