Source Code Cross Referenced for WorkbenchResource.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » internal » ide » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui ide » org.eclipse.ui.internal.ide.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.ide.model;
011:
012:        import org.eclipse.core.resources.IFile;
013:        import org.eclipse.core.resources.IProject;
014:        import org.eclipse.core.resources.IResource;
015:        import org.eclipse.core.runtime.CoreException;
016:        import org.eclipse.core.runtime.IAdaptable;
017:        import org.eclipse.core.runtime.QualifiedName;
018:        import org.eclipse.core.runtime.content.IContentDescription;
019:        import org.eclipse.core.runtime.content.IContentType;
020:        import org.eclipse.jface.resource.ImageDescriptor;
021:        import org.eclipse.ui.IResourceActionFilter;
022:        import org.eclipse.ui.actions.SimpleWildcardTester;
023:        import org.eclipse.ui.model.WorkbenchAdapter;
024:
025:        /**
026:         * An IWorkbenchAdapter that represents IResources.
027:         */
028:        public abstract class WorkbenchResource extends WorkbenchAdapter
029:                implements  IResourceActionFilter {
030:
031:            /**
032:             *	Answer the appropriate base image to use for the resource.
033:             */
034:            protected abstract ImageDescriptor getBaseImage(IResource resource);
035:
036:            /**
037:             * Returns an image descriptor for this object.
038:             */
039:            public ImageDescriptor getImageDescriptor(Object o) {
040:                IResource resource = getResource(o);
041:                return resource == null ? null : getBaseImage(resource);
042:            }
043:
044:            /**
045:             * getLabel method comment.
046:             */
047:            public String getLabel(Object o) {
048:                IResource resource = getResource(o);
049:                return resource == null ? null : resource.getName();
050:            }
051:
052:            /**
053:             * Returns the parent of the given object.  Returns null if the
054:             * parent is not available.
055:             */
056:            public Object getParent(Object o) {
057:                IResource resource = getResource(o);
058:                return resource == null ? null : resource.getParent();
059:            }
060:
061:            /**
062:             * Returns the resource corresponding to this object,
063:             * or null if there is none.
064:             */
065:            protected IResource getResource(Object o) {
066:                if (o instanceof  IResource) {
067:                    return (IResource) o;
068:                }
069:                if (o instanceof  IAdaptable) {
070:                    return (IResource) ((IAdaptable) o)
071:                            .getAdapter(IResource.class);
072:                }
073:                return null;
074:            }
075:
076:            /**
077:             * Returns whether the specific attribute matches the state of the target
078:             * object.
079:             *
080:             * @param target the target object
081:             * @param name the attribute name
082:             * @param value the attribute value
083:             * @return <code>true</code> if the attribute matches; <code>false</code> otherwise
084:             */
085:            public boolean testAttribute(Object target, String name,
086:                    String value) {
087:                if (!(target instanceof  IResource)) {
088:                    return false;
089:                }
090:                IResource res = (IResource) target;
091:                if (name.equals(NAME)) {
092:                    return SimpleWildcardTester.testWildcardIgnoreCase(value,
093:                            res.getName());
094:                } else if (name.equals(PATH)) {
095:                    return SimpleWildcardTester.testWildcardIgnoreCase(value,
096:                            res.getFullPath().toString());
097:                } else if (name.equals(EXTENSION)) {
098:                    return SimpleWildcardTester.testWildcardIgnoreCase(value,
099:                            res.getFileExtension());
100:                } else if (name.equals(READ_ONLY)) {
101:                    return (res.isReadOnly() == value.equalsIgnoreCase("true"));//$NON-NLS-1$
102:                } else if (name.equals(PROJECT_NATURE)) {
103:                    try {
104:                        IProject proj = res.getProject();
105:                        return proj.isAccessible() && proj.hasNature(value);
106:                    } catch (CoreException e) {
107:                        return false;
108:                    }
109:                } else if (name.equals(PERSISTENT_PROPERTY)) {
110:                    return testProperty(res, true, false, value);
111:                } else if (name.equals(PROJECT_PERSISTENT_PROPERTY)) {
112:                    return testProperty(res, true, true, value);
113:                } else if (name.equals(SESSION_PROPERTY)) {
114:                    return testProperty(res, false, false, value);
115:                } else if (name.equals(PROJECT_SESSION_PROPERTY)) {
116:                    return testProperty(res, false, true, value);
117:                } else if (name.equals(CONTENT_TYPE_ID)) {
118:                    return testContentTypeProperty(res, value);
119:                }
120:                return false;
121:            }
122:
123:            /**
124:             * Tests whether the content type for <code>resource</code> matches the
125:             * <code>contentTypeId</code>. It is possible that this method call could
126:             * cause the resource to be read. It is also possible (through poor plug-in
127:             * design) for this method to load plug-ins.
128:             * 
129:             * @param resource
130:             *            The resource for which the content type should be determined;
131:             *            must not be <code>null</code>.
132:             * @param contentTypeId
133:             *            The expected content type; must not be <code>null</code>.
134:             * @return <code>true</code> iff the best matching content type has an
135:             *         identifier that matches <code>contentTypeId</code>;
136:             *         <code>false</code> otherwise.
137:             */
138:            private final boolean testContentTypeProperty(
139:                    final IResource resource, final String contentTypeId) {
140:                final String expectedValue = contentTypeId.trim();
141:
142:                if (!(resource instanceof  IFile)) {
143:                    return false;
144:                }
145:
146:                final IFile file = (IFile) resource;
147:                String actualValue = null;
148:
149:                try {
150:                    final IContentDescription contentDescription = file
151:                            .getContentDescription();
152:
153:                    if (contentDescription != null) {
154:                        final IContentType contentType = contentDescription
155:                                .getContentType();
156:                        actualValue = contentType.getId();
157:                    }
158:                } catch (CoreException e) {
159:                    //ignore - this just means the file does not exist or is not accessible
160:                }
161:
162:                return expectedValue == null
163:                        || expectedValue.equals(actualValue);
164:            }
165:
166:            /**
167:             * Tests whether a session or persistent property on the resource or its project
168:             * matches the given value.
169:             * 
170:             * @param resource
171:             *            the resource to check
172:             * @param persistentFlag
173:             *            <code>true</code> for a persistent property, <code>false</code>
174:             *            for a session property
175:             * @param projectFlag
176:             *            <code>true</code> to check the resource's project,
177:             *            <code>false</code> to check the resource itself
178:             * @param value
179:             *            the attribute value, which has either the form "propertyName" or
180:             *            "propertyName=propertyValue"
181:             * @return whether there is a match
182:             */
183:            private boolean testProperty(IResource resource,
184:                    boolean persistentFlag, boolean projectFlag, String value) {
185:                String propertyName;
186:                String expectedVal;
187:                int i = value.indexOf('=');
188:                if (i != -1) {
189:                    propertyName = value.substring(0, i).trim();
190:                    expectedVal = value.substring(i + 1).trim();
191:                } else {
192:                    propertyName = value.trim();
193:                    expectedVal = null;
194:                }
195:                try {
196:                    QualifiedName key;
197:                    int dot = propertyName.lastIndexOf('.');
198:                    if (dot != -1) {
199:                        key = new QualifiedName(propertyName.substring(0, dot),
200:                                propertyName.substring(dot + 1));
201:                    } else {
202:                        key = new QualifiedName(null, propertyName);
203:                    }
204:                    IResource resToCheck = projectFlag ? resource.getProject()
205:                            : resource;
206:                    // getProject() on workspace root can be null
207:                    if (resToCheck == null) {
208:                        return false;
209:                    }
210:                    if (persistentFlag) {
211:                        String actualVal = resToCheck
212:                                .getPersistentProperty(key);
213:                        if (actualVal == null) {
214:                            return false;
215:                        }
216:                        return expectedVal == null
217:                                || expectedVal.equals(actualVal);
218:                    }
219:
220:                    Object actualVal = resToCheck.getSessionProperty(key);
221:                    if (actualVal == null) {
222:                        return false;
223:                    }
224:
225:                    return expectedVal == null
226:                            || expectedVal.equals(actualVal.toString());
227:
228:                } catch (CoreException e) {
229:                    // ignore
230:                }
231:                return false;
232:            }
233:
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.