blob: 6d12a6f548a0b2647a30107ee26c8d8226b3111d (
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
|
/*******************************************************************************
* Copyright (c) 2016 Red Hat Inc. and others
* 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:
* Sopot Cela (Red Hat Inc.)
*******************************************************************************/
package org.eclipse.ui.genericeditor.tests;
import java.io.ByteArrayInputStream;
import org.junit.After;
import org.junit.Before;
import org.eclipse.swt.widgets.Display;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor;
import org.eclipse.ui.intro.IIntroPart;
import org.eclipse.ui.part.FileEditorInput;
/**
* Closes intro, create {@link #project}, create {@link #file} and open {@link #editor}; and clean up.
* Also contains additional utility methods
* @since 1.0
*/
public class AbstratGenericEditorTest {
protected IProject project;
protected IFile file;
protected ExtensionBasedTextEditor editor;
/**
* Closes intro, create {@link #project}, create {@link #file} and open {@link #editor}
* @throws Exception ex
*/
@Before
public void setUp() throws Exception {
closeIntro();
project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis());
project.create(null);
project.open(null);
file = project.getFile("foo.txt");
file.create(new ByteArrayInputStream("bar 'bar'".getBytes()), true, null);
editor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().openEditor(new FileEditorInput(this.file), "org.eclipse.ui.genericeditor.GenericEditor");
}
@After
public void tearDown() throws Exception {
if (file != null) {
file.delete(true, null);
}
if (project != null) {
project.delete(true, null);
}
}
private static void closeIntro() {
IIntroPart intro = PlatformUI.getWorkbench().getIntroManager().getIntro();
if (intro != null) {
PlatformUI.getWorkbench().getIntroManager().closeIntro(intro);
}
}
public static void waitAndDispatch(long milliseconds) {
long timeout = milliseconds; //ms
long start = System.currentTimeMillis();
while (start + timeout > System.currentTimeMillis()) {
Display.getDefault().readAndDispatch();
}
}
}
|