Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6f3d734817c52e009096cf8eb82ee602a12b5439 (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package org.eclipse.papyrus.infra.core.sasheditor.tests.texteditor;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.part.FileEditorInput;

/**
 * A fake {@link IEditorInput} suitable for creating TextEditor.
 * This IEditorInput allows to carry the {@link ISashWindowsContentProvider} to the created Editor.
 * 
 * 
 * @copy Copied from org.eclipse.ui.internal.part.NullEditorInput v3.8 
 */
public class FakeEditorInput extends FileEditorInput implements IEditorInput {

	protected ISashWindowsContentProvider contentProvider;
	
	static int count =0;
	
	/**
	 * Create a temporary file to pass to the texteditor.
	 * @return
	 */
	static IFile createIFile() {
		// the name used is no important as nothing is created.
		IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.papyrus.tests.tmp");
		IFile model1File = p.getFile("tmp/model" + count++ +".txt");
//		System.err.println("file: " + model1File.getName());
		return model1File;
	}
	
	/**
	 * Creates a <code>FakeEditorInput</code>.
	 */
	public FakeEditorInput() {
		super(createIFile());
	}

	/**
	 * Constructor.
	 * Carry the contentProvider to the created editor.
	 * 
	 * @param contentProvider
	 */
	public FakeEditorInput(ISashWindowsContentProvider contentProvider) {
		super(createIFile());
		this.contentProvider = contentProvider;
	}

	/**
	 * 
	 * @return
	 */
	public ISashWindowsContentProvider getContentProvider() {
		return contentProvider;
	}

	/**
	 * 
	 * @param contentProvider
	 */
	public void setContentProvider(ISashWindowsContentProvider contentProvider) {
		this.contentProvider = contentProvider;
	}

	/* (non-Javadoc)
     * @see org.eclipse.ui.IEditorInput#exists()
     */
    public boolean exists() {
        return false;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
     */
    public ImageDescriptor getImageDescriptor() {
        return ImageDescriptor.getMissingImageDescriptor();
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.IEditorInput#getName()
     */
//    public String getName() {
//		String result = null;
//        return ""; //$NON-NLS-1$
//    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.IEditorInput#getPersistable()
     */
    public IPersistableElement getPersistable() {
        return null;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.IEditorInput#getToolTipText()
     */
    public String getToolTipText() {
       return ""; //$NON-NLS-1$
    }

    /* (non-Javadoc)
     * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
     */
    public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
        return null;
    }

}

Back to the top