]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2008 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 | * @param document the document | |
36 | * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument) | |
37 | */ | |
38 | public static void setupDocument(IDocument document) { | |
39 | IDocumentPartitioner partitioner= createDocumentPartitioner(); | |
40 | if (document instanceof IDocumentExtension3) { | |
41 | IDocumentExtension3 extension3= (IDocumentExtension3) document; | |
42 | extension3.setDocumentPartitioner(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, partitioner); | |
43 | } else { | |
44 | document.setDocumentPartitioner(partitioner); | |
45 | } | |
46 | partitioner.connect(document); | |
47 | } | |
48 | ||
49 | /** | |
50 | * Factory method for creating a properties file document specific document | |
51 | * partitioner. | |
52 | * | |
53 | * @return a newly created properties file document partitioner | |
54 | */ | |
55 | private static IDocumentPartitioner createDocumentPartitioner() { | |
56 | return new FastPartitioner(new PropertiesFilePartitionScanner(), IPropertiesFilePartitions.PARTITIONS); | |
57 | } | |
58 | } |