KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.ui.propertiesfileeditor;
12
13 import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
14
15 import org.eclipse.jface.text.IDocument;
16 import org.eclipse.jface.text.IDocumentExtension3;
17 import org.eclipse.jface.text.IDocumentPartitioner;
18 import org.eclipse.jface.text.rules.FastPartitioner;
19
20 /**
21  * The document setup participant for a properties file document.
22  *
23  * @since 3.1
24  */

25 public class PropertiesFileDocumentSetupParticipant implements IDocumentSetupParticipant {
26
27     /*
28      * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
29      */

30     public void setup(IDocument document) {
31         setupDocument(document);
32     }
33
34     /**
35      * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
36      */

37     public static void setupDocument(IDocument document) {
38         IDocumentPartitioner partitioner= createDocumentPartitioner();
39         if (document instanceof IDocumentExtension3) {
40             IDocumentExtension3 extension3= (IDocumentExtension3) document;
41             extension3.setDocumentPartitioner(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, partitioner);
42         } else {
43             document.setDocumentPartitioner(partitioner);
44         }
45         partitioner.connect(document);
46     }
47
48     /**
49      * Factory method for creating a properties file document specific document
50      * partitioner.
51      *
52      * @return a newly created properties file document partitioner
53      */

54     private static IDocumentPartitioner createDocumentPartitioner() {
55         return new FastPartitioner(new PropertiesFilePartitionScanner(), IPropertiesFilePartitions.PARTITIONS);
56     }
57 }
58
Popular Tags