aboutsummaryrefslogtreecommitdiffstats
path: root/org.openembedded.bc.ui/src/org/openembedded/bc/ui/editors/bitbake/BitBakeFileEditor.java
blob: 2e48c97ca1991a329dd3973f6a66f7f0dd05e67b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*****************************************************************************
 * Copyright (c) 2009 Ken Gilmer
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Ken Gilmer - initial API and implementation
 *******************************************************************************/
package org.openembedded.bc.ui.editors.bitbake;

import java.util.ResourceBundle;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
import org.eclipse.ui.texteditor.ContentAssistAction;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.openembedded.bc.ui.Activator;
import org.openembedded.bc.ui.builder.BitbakeCommanderNature;


/**
 * Editor for BB Recipe
 * 
 * @author kgilmer
 * 
 */
public class BitBakeFileEditor extends AbstractDecoratedTextEditor {

	public static final String EDITOR_ID = "org.openembedded.bc.ui.editors.BitBakeFileEditor";
	static final String CONTENT_ASSIST = "ContentAssist";
	private BitBakeSourceViewerConfiguration viewerConfiguration;
	private String targetFilePath;

	public BitBakeFileEditor() {
		super();
		viewerConfiguration = new BitBakeSourceViewerConfiguration(getSharedColors(), getPreferenceStore());
		setSourceViewerConfiguration(viewerConfiguration);
		setDocumentProvider(new BitBakeDocumentProvider());
	}

	@Override
	protected void createActions() {
		super.createActions();

		ResourceBundle bundle = RecipeEditorMessages.getBundle();
		ContentAssistAction action = new ContentAssistAction(bundle, "contentAssist.", this); //$NON-NLS-1$
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
		setAction(CONTENT_ASSIST, action);
	}

	@Override
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {

		if (input instanceof FileEditorInput) {
			IProject p = ((FileEditorInput) input).getFile().getProject();
			try {
				if (p != null && p.isOpen() && p.hasNature(BitbakeCommanderNature.NATURE_ID)) {
					targetFilePath = ((FileEditorInput) input).getFile().getLocationURI().getPath();
					viewerConfiguration.setTargetFilePath(targetFilePath);
					viewerConfiguration.setBBSession(Activator.getBBSession(p.getLocationURI().getPath()));
				}
			} catch (Exception e) {
				throw new PartInitException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "On " + input.getClass().getName() + " input, nable to load editor.", e));
			}
		} else if (input instanceof FileStoreEditorInput) {
			targetFilePath = ((FileStoreEditorInput)input).getURI().getPath();
			System.out.println("Target path:" + targetFilePath);
		} else {
			if (input == null) {
				System.out.println("The input is null!");
			}
			System.out.println("The input is not a FileEditorInput: " + input.getClass().getName());
		}
		
		super.init(site, input);
	}
}