KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > history > RefactoringPropertyPageTester


1 /*******************************************************************************
2  * Copyright (c) 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.ltk.internal.ui.refactoring.history;
12
13 import java.net.URI JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IPath;
18
19 import org.eclipse.core.expressions.PropertyTester;
20
21 import org.eclipse.core.filesystem.EFS;
22 import org.eclipse.core.filesystem.IFileStore;
23
24 import org.eclipse.core.resources.IProject;
25 import org.eclipse.core.resources.IResource;
26
27 import org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin;
28 import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService;
29
30 /**
31  * Property tester for the 'refactoringPropertiesEnabled' property.
32  *
33  * @since 3.3
34  */

35 public final class RefactoringPropertyPageTester extends PropertyTester {
36
37     /** The property name */
38     public static final String JavaDoc PROPERTY_NAME= "refactoringPropertiesEnabled"; //$NON-NLS-1$
39

40     private IFileStore getHistoryStore(final IProject project) {
41         final IPath location= RefactoringCorePlugin.getDefault().getStateLocation();
42         final IFileStore store= EFS.getLocalFileSystem().getStore(location).getChild(RefactoringHistoryService.NAME_HISTORY_FOLDER);
43         try {
44             if (project.isAccessible()) {
45                 if (RefactoringHistoryService.hasSharedRefactoringHistory(project)) {
46                     final URI JavaDoc uri= project.getLocationURI();
47                     if (uri != null)
48                         return EFS.getStore(uri).getChild(RefactoringHistoryService.NAME_HISTORY_FOLDER);
49                 } else
50                     return store.getChild(project.getName());
51             }
52         } catch (CoreException exception) {
53             // Do nothing
54
}
55         return null;
56     }
57
58     /**
59      * {@inheritDoc}
60      */

61     public boolean test(final Object JavaDoc receiver, final String JavaDoc property, final Object JavaDoc[] arguments, final Object JavaDoc expected) {
62         if (PROPERTY_NAME.equals(property)) {
63             if (receiver instanceof IAdaptable) {
64                 final IAdaptable adaptable= (IAdaptable) receiver;
65                 final IResource resource= (IResource) adaptable.getAdapter(IResource.class);
66                 if (resource instanceof IProject) {
67                     final IProject project= (IProject) resource;
68                     final IFileStore store= getHistoryStore(project);
69                     if (store != null)
70                         return store.fetchInfo().exists();
71                 }
72             }
73         }
74         return false;
75     }
76 }
Popular Tags