01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.views.properties;
11:
12: import org.eclipse.core.resources.IFile;
13: import org.eclipse.jface.viewers.IBasicPropertyConstants;
14: import org.eclipse.osgi.util.TextProcessor;
15: import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
16:
17: /**
18: * The FilePropertySource gives the extra information that is shown for files
19: */
20: public class FilePropertySource extends ResourcePropertySource {
21:
22: private static PropertyDescriptor fileDescriptor;
23: static {
24: fileDescriptor = new PropertyDescriptor(
25: IResourcePropertyConstants.P_SIZE_RES,
26: IResourcePropertyConstants.P_DISPLAY_SIZE);
27: fileDescriptor.setAlwaysIncompatible(true);
28: fileDescriptor
29: .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY);
30: }
31:
32: /**
33: * Creates an property source for a file resource.
34: * @param file the file resource
35: */
36: public FilePropertySource(IFile file) {
37: super (file);
38: }
39:
40: /**
41: * Get a PropertyDescriptor that defines the size property
42: * @return the PropertyDescriptor
43: */
44: private static PropertyDescriptor getInitialPropertyDescriptor() {
45: return fileDescriptor;
46: }
47:
48: /* (non-Javadoc)
49: * Method declared on IPropertySource.
50: */
51: public IPropertyDescriptor[] getPropertyDescriptors() {
52: IPropertyDescriptor[] super Descriptors = super
53: .getPropertyDescriptors();
54: int super Length = super Descriptors.length;
55: IPropertyDescriptor[] fileDescriptors = new IPropertyDescriptor[super Length + 1];
56: System.arraycopy(super Descriptors, 0, fileDescriptors, 0,
57: super Length);
58: fileDescriptors[super Length] = getInitialPropertyDescriptor();
59:
60: return fileDescriptors;
61: }
62:
63: /* (non-Javadoc)
64: * Method declared on IPropertySource.
65: */
66: public Object getPropertyValue(Object key) {
67: Object returnValue = (key
68: .equals(IBasicPropertyConstants.P_TEXT)) ? TextProcessor
69: .process(element.getName())
70: : super .getPropertyValue(key);
71:
72: if (returnValue != null) {
73: return returnValue;
74: }
75:
76: if (key.equals(IResourcePropertyConstants.P_SIZE_RES)) {
77: return IDEResourceInfoUtils.getSizeString((IFile) element);
78: }
79: return null;
80: }
81: }
|