KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > properties > FilePropertySource


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  *******************************************************************************/

11 package org.eclipse.ui.views.properties;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.jface.viewers.IBasicPropertyConstants;
15 import org.eclipse.osgi.util.TextProcessor;
16 import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
17
18 /**
19  * The FilePropertySource gives the extra information that is shown for files
20  */

21 public class FilePropertySource extends ResourcePropertySource {
22
23     private static PropertyDescriptor fileDescriptor;
24     static {
25         fileDescriptor = new PropertyDescriptor(
26                 IResourcePropertyConstants.P_SIZE_RES,
27                 IResourcePropertyConstants.P_DISPLAY_SIZE);
28         fileDescriptor.setAlwaysIncompatible(true);
29         fileDescriptor
30                 .setCategory(IResourcePropertyConstants.P_FILE_SYSTEM_CATEGORY);
31     }
32
33     /**
34      * Creates an property source for a file resource.
35      * @param file the file resource
36      */

37     public FilePropertySource(IFile file) {
38         super(file);
39     }
40
41     /**
42      * Get a PropertyDescriptor that defines the size property
43      * @return the PropertyDescriptor
44      */

45     private static PropertyDescriptor getInitialPropertyDescriptor() {
46         return fileDescriptor;
47     }
48
49     /* (non-Javadoc)
50      * Method declared on IPropertySource.
51      */

52     public IPropertyDescriptor[] getPropertyDescriptors() {
53         IPropertyDescriptor[] superDescriptors = super.getPropertyDescriptors();
54         int superLength = superDescriptors.length;
55         IPropertyDescriptor[] fileDescriptors = new IPropertyDescriptor[superLength + 1];
56         System.arraycopy(superDescriptors, 0, fileDescriptors, 0, superLength);
57         fileDescriptors[superLength] = getInitialPropertyDescriptor();
58
59         return fileDescriptors;
60     }
61
62     /* (non-Javadoc)
63      * Method declared on IPropertySource.
64      */

65     public Object JavaDoc getPropertyValue(Object JavaDoc key) {
66         Object JavaDoc returnValue = (key.equals(IBasicPropertyConstants.P_TEXT)) ? TextProcessor
67                 .process(element.getName())
68                 : super.getPropertyValue(key);
69
70         if (returnValue != null) {
71             return returnValue;
72         }
73
74         if (key.equals(IResourcePropertyConstants.P_SIZE_RES)) {
75             return IDEResourceInfoUtils.getSizeString((IFile) element);
76         }
77         return null;
78     }
79 }
80
Popular Tags