KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > view > FileAdapterPropertySource


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.pde.internal.ui.view;
12
13 import com.ibm.icu.text.DateFormat;
14 import java.util.Date JavaDoc;
15
16 import org.eclipse.pde.internal.core.FileAdapter;
17 import org.eclipse.ui.views.properties.IPropertyDescriptor;
18 import org.eclipse.ui.views.properties.IPropertySource;
19 import org.eclipse.ui.views.properties.PropertyDescriptor;
20
21 public class FileAdapterPropertySource implements IPropertySource {
22     private IPropertyDescriptor [] descriptors;
23     private FileAdapter adapter;
24
25     /**
26      * Constructor for FileAdapterPropertySource.
27      */

28     public FileAdapterPropertySource() {
29         super();
30     }
31     
32     public void setAdapter(FileAdapter adapter) {
33         this.adapter = adapter;
34     }
35
36     /**
37      * @see IPropertySource#getEditableValue()
38      */

39     public Object JavaDoc getEditableValue() {
40         return null;
41     }
42
43     /**
44      * @see IPropertySource#getPropertyDescriptors()
45      */

46     public IPropertyDescriptor[] getPropertyDescriptors() {
47         if (descriptors==null) {
48             descriptors = new IPropertyDescriptor[5];
49             descriptors[0] = new PropertyDescriptor("editable", "editable"); //$NON-NLS-1$ //$NON-NLS-2$
50
descriptors[1] = new PropertyDescriptor("last", "last modified"); //$NON-NLS-1$ //$NON-NLS-2$
51
descriptors[2] = new PropertyDescriptor("name", "name"); //$NON-NLS-1$ //$NON-NLS-2$
52
descriptors[3] = new PropertyDescriptor("path", "path"); //$NON-NLS-1$ //$NON-NLS-2$
53
descriptors[4] = new PropertyDescriptor("size", "size"); //$NON-NLS-1$ //$NON-NLS-2$
54
}
55         return descriptors;
56     }
57
58     /**
59      * @see IPropertySource#getPropertyValue(Object)
60      */

61     public Object JavaDoc getPropertyValue(Object JavaDoc id) {
62         String JavaDoc key = id.toString();
63         if (key.equals("editable")) //$NON-NLS-1$
64
return "false"; //$NON-NLS-1$
65
if (key.equals("last")) { //$NON-NLS-1$
66
Date JavaDoc date = new Date JavaDoc(adapter.getFile().lastModified());
67             return DateFormat.getInstance().format(date);
68         }
69         if (key.equals("name")) //$NON-NLS-1$
70
return adapter.getFile().getName();
71         if (key.equals("path")) //$NON-NLS-1$
72
return adapter.getFile().getAbsolutePath();
73         if (key.equals("size")) //$NON-NLS-1$
74
return ""+adapter.getFile().length(); //$NON-NLS-1$
75
return null;
76     }
77
78     /**
79      * @see IPropertySource#isPropertySet(Object)
80      */

81     public boolean isPropertySet(Object JavaDoc id) {
82         return false;
83     }
84
85     /**
86      * @see IPropertySource#resetPropertyValue(Object)
87      */

88     public void resetPropertyValue(Object JavaDoc id) {
89     }
90
91     /**
92      * @see IPropertySource#setPropertyValue(Object, Object)
93      */

94     public void setPropertyValue(Object JavaDoc id, Object JavaDoc value) {
95     }
96
97 }
98
Popular Tags