diff options
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java new file mode 100644 index 0000000..140a3da --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java | |||
@@ -0,0 +1,101 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2013 Ken Gilmer, Intel Corporation | ||
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 | * Ken Gilmer - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.editors.bitbake; | ||
13 | |||
14 | import java.net.URI; | ||
15 | import java.net.URISyntaxException; | ||
16 | |||
17 | import org.eclipse.core.runtime.NullProgressMonitor; | ||
18 | import org.eclipse.jface.text.IDocument; | ||
19 | import org.eclipse.jface.text.IDocumentExtension3; | ||
20 | import org.eclipse.jface.text.IDocumentPartitioner; | ||
21 | import org.eclipse.jface.text.rules.FastPartitioner; | ||
22 | import org.eclipse.jface.text.rules.IPredicateRule; | ||
23 | import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; | ||
24 | import org.eclipse.jface.text.rules.SingleLineRule; | ||
25 | import org.eclipse.jface.text.rules.Token; | ||
26 | import org.eclipse.rse.core.model.IHost; | ||
27 | import org.eclipse.ui.IFileEditorInput; | ||
28 | import org.eclipse.ui.editors.text.FileDocumentProvider; | ||
29 | import org.yocto.remote.utils.RemoteHelper; | ||
30 | |||
31 | /** | ||
32 | * Document provider for BB recipe. | ||
33 | * @author kgilmer | ||
34 | * | ||
35 | */ | ||
36 | public class BitBakeDocumentProvider extends FileDocumentProvider { | ||
37 | /** | ||
38 | * The recipe partitioning. It contains two partition types: {@link #RECIPE_CODE} and | ||
39 | * {@link #RECIPE_COMMENT}. | ||
40 | */ | ||
41 | public static final String RECIPE_PARTITIONING= "org.recipeeditor.recipepartitioning"; //$NON-NLS-1$ | ||
42 | |||
43 | public static final String RECIPE_CODE= IDocument.DEFAULT_CONTENT_TYPE; | ||
44 | public static final String RECIPE_COMMENT= "RECIPE_COMMENT"; //$NON-NLS-1$ | ||
45 | |||
46 | private IHost connection; | ||
47 | |||
48 | private final BitBakeSourceViewerConfiguration viewerConfiguration; | ||
49 | |||
50 | private static final String[] CONTENT_TYPES= { | ||
51 | RECIPE_CODE, | ||
52 | RECIPE_COMMENT | ||
53 | }; | ||
54 | |||
55 | public BitBakeDocumentProvider(BitBakeSourceViewerConfiguration viewerConfiguration) { | ||
56 | this.viewerConfiguration = viewerConfiguration; | ||
57 | } | ||
58 | |||
59 | private IDocumentPartitioner createRecipePartitioner() { | ||
60 | IPredicateRule[] rules= { new SingleLineRule("#", null, new Token(RECIPE_COMMENT), (char) 0, true, false) }; //$NON-NLS-1$ | ||
61 | |||
62 | RuleBasedPartitionScanner scanner= new RuleBasedPartitionScanner(); | ||
63 | scanner.setPredicateRules(rules); | ||
64 | |||
65 | return new FastPartitioner(scanner, CONTENT_TYPES); | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | protected void setupDocument(Object element,IDocument document) { | ||
70 | if (document instanceof IDocumentExtension3) { | ||
71 | IDocumentExtension3 ext= (IDocumentExtension3) document; | ||
72 | IDocumentPartitioner partitioner= createRecipePartitioner(); | ||
73 | ext.setDocumentPartitioner(RECIPE_PARTITIONING, partitioner); | ||
74 | partitioner.connect(document); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | @Override | ||
79 | public boolean isDeleted(Object element) { | ||
80 | if (element instanceof IFileEditorInput) { | ||
81 | IFileEditorInput input= (IFileEditorInput) element; | ||
82 | |||
83 | URI root = viewerConfiguration.getBBSession().getProjInfoRoot(); | ||
84 | String relPath = input.getFile().getProjectRelativePath().toPortableString(); | ||
85 | try { | ||
86 | URI fileURI = new URI(root.getScheme(), root.getHost(), root.getPath() + "/" + relPath, root.getFragment()); | ||
87 | if (connection == null) | ||
88 | connection = viewerConfiguration.getBBSession().getProjectInfo().getConnection(); | ||
89 | return !RemoteHelper.fileExistsRemote(connection, new NullProgressMonitor(), fileURI.getPath()); | ||
90 | } catch (URISyntaxException e) { | ||
91 | e.printStackTrace(); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | return super.isDeleted(element); | ||
96 | } | ||
97 | |||
98 | public void setActiveConnection(IHost connection) { | ||
99 | this.connection = connection; | ||
100 | } | ||
101 | } | ||