KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > propertiesfileeditor > PropertiesFileDocumentProvider


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
12 package org.eclipse.jdt.internal.ui.propertiesfileeditor;
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.Platform;
16 import org.eclipse.core.runtime.content.IContentDescription;
17 import org.eclipse.core.runtime.content.IContentType;
18
19 import org.eclipse.core.resources.IFile;
20
21 import org.eclipse.jface.text.IDocument;
22
23 import org.eclipse.ui.editors.text.ForwardingDocumentProvider;
24 import org.eclipse.ui.editors.text.TextFileDocumentProvider;
25
26 import org.eclipse.ui.IFileEditorInput;
27 import org.eclipse.ui.texteditor.IDocumentProvider;
28
29
30 /**
31  * Shared properties file document provider specialized for Java properties files.
32  *
33  * @since 3.1
34  */

35 public class PropertiesFileDocumentProvider extends TextFileDocumentProvider {
36
37
38     private static final IContentType JAVA_PROPERTIES_FILE_CONTENT_TYPE= Platform.getContentTypeManager().getContentType("org.eclipse.jdt.core.javaProperties"); //$NON-NLS-1$
39

40
41     /**
42      * Creates a new properties file document provider and
43      * sets up the parent chain.
44      */

45     public PropertiesFileDocumentProvider() {
46         IDocumentProvider provider= new TextFileDocumentProvider();
47         provider= new ForwardingDocumentProvider(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, new PropertiesFileDocumentSetupParticipant(), provider);
48         setParentDocumentProvider(provider);
49     }
50
51     /*
52      * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
53      */

54     protected FileInfo createFileInfo(Object JavaDoc element) throws CoreException {
55         if (JAVA_PROPERTIES_FILE_CONTENT_TYPE == null || !(element instanceof IFileEditorInput))
56             return null;
57
58         IFileEditorInput input= (IFileEditorInput)element;
59
60         IFile file= input.getFile();
61         if (file == null || !file.isAccessible())
62             return null;
63
64         IContentDescription description= file.getContentDescription();
65         if (description == null || description.getContentType() == null || !description.getContentType().isKindOf(JAVA_PROPERTIES_FILE_CONTENT_TYPE))
66             return null;
67
68         return super.createFileInfo(element);
69     }
70
71     /*
72      * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
73      * @since 3.1
74      */

75     protected DocumentProviderOperation createSaveOperation(final Object JavaDoc element, final IDocument document, final boolean overwrite) throws CoreException {
76         if (getFileInfo(element) == null)
77             return null;
78
79         return super.createSaveOperation(element, document, overwrite);
80     }
81 }
82
Popular Tags