use of org.eclipse.ui.IWorkbench in project eclipse.platform.text by eclipse.
the class EncodingChangeTests method testChangeEncodingViaFile.
@Test
public void testChangeEncodingViaFile() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
fFile.setCharset(NON_DEFAULT_ENCODING, null);
} catch (CoreException ex) {
fail();
}
try {
fEditor = IDE.openEditor(page, fFile);
if (fEditor instanceof TextEditor) {
TextEditor editor = (TextEditor) fEditor;
Accessor accessor = new Accessor(editor, StatusTextEditor.class);
while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
}
ScrolledComposite composite = (ScrolledComposite) accessor.get("fStatusControl");
assertNull(composite);
DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
assertEquals(NON_DEFAULT_ENCODING, encodingSupport.getEncoding());
} else
fail();
} catch (PartInitException e) {
fail();
}
}
use of org.eclipse.ui.IWorkbench in project eclipse.platform.text by eclipse.
the class EncodingChangeTests method testChangeEncodingViaEncodingSupport.
@Test
public void testChangeEncodingViaEncodingSupport() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
fEditor = IDE.openEditor(page, fFile);
if (fEditor instanceof TextEditor) {
TextEditor editor = (TextEditor) fEditor;
while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
}
DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
encodingSupport.setEncoding(NON_DEFAULT_ENCODING);
Accessor accessor = new Accessor(editor, StatusTextEditor.class);
while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
}
ScrolledComposite composite = (ScrolledComposite) accessor.get("fStatusControl");
assertNull(composite);
String actual = null;
try {
actual = fFile.getCharset(false);
} catch (CoreException e1) {
fail();
}
assertEquals(NON_DEFAULT_ENCODING, actual);
} else
fail();
} catch (PartInitException e) {
fail();
}
}
use of org.eclipse.ui.IWorkbench in project eclipse.platform.text by eclipse.
the class EncodingChangeTests method testAInvalidEncoding.
@Test
public void testAInvalidEncoding() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
fFile.setCharset("nonexistent", null);
} catch (CoreException e2) {
fail();
}
try {
fEditor = IDE.openEditor(page, fFile);
if (fEditor instanceof TextEditor) {
TextEditor editor = (TextEditor) fEditor;
Accessor accessor = new Accessor(editor, StatusTextEditor.class);
while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
}
ITextFileBuffer fileBuffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
String expected = encodingSupport.getStatusMessage(fileBuffer.getStatus());
Composite composite = (Composite) accessor.get("fStatusControl");
ScrolledComposite scrolledComposite = (ScrolledComposite) composite.getChildren()[0];
StyledText statusText = (StyledText) ((Composite) scrolledComposite.getContent()).getChildren()[5];
String actual = statusText.getText();
assertEquals(expected, actual);
} else
fail();
} catch (PartInitException e) {
fail();
}
}
use of org.eclipse.ui.IWorkbench in project eclipse.platform.text by eclipse.
the class LockJob method setUp.
@Before
public void setUp() throws Exception {
IFolder folder = ResourceHelper.createFolder("FileDocumentProviderTestProject/test");
file = (File) ResourceHelper.createFile(folder, "file.txt", "");
assertTrue(file.exists());
fsManager = file.getLocalManager();
assertTrue(fsManager.fastIsSynchronized(file));
stopLockingFlag = new AtomicBoolean(false);
stoppedByTest = new AtomicBoolean(false);
fileProvider = new FileDocumentProviderMock();
lockJob = new LockJob("Locking workspace", file, stopLockingFlag, stoppedByTest);
// We need the editor only to get the default editor status line manager
IWorkbench workbench = PlatformUI.getWorkbench();
page = workbench.getActiveWorkbenchWindow().getActivePage();
editor = IDE.openEditor(page, file);
TestUtil.runEventLoop();
IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
// This is default monitor which almost all editors are using
IProgressMonitor progressMonitor = statusLineManager.getProgressMonitor();
assertNotNull(progressMonitor);
assertFalse(progressMonitor instanceof NullProgressMonitor);
assertFalse(progressMonitor instanceof EventLoopProgressMonitor);
assertTrue(progressMonitor instanceof IProgressMonitorWithBlocking);
// Because this monitor is not EventLoopProgressMonitor, it will not
// process UI events while waiting on workspace lock
fileProvider.setProgressMonitor(progressMonitor);
TestUtil.waitForJobs(500, 5000);
Job[] jobs = Job.getJobManager().find(null);
String jobsList = Arrays.toString(jobs);
System.out.println("Still running jobs: " + jobsList);
if (!Job.getJobManager().isIdle()) {
jobs = Job.getJobManager().find(null);
for (Job job : jobs) {
System.out.println("Going to cancel: " + job.getName() + " / " + job);
job.cancel();
}
}
}
use of org.eclipse.ui.IWorkbench in project eclipse.platform.text by eclipse.
the class GotoLineTest method goToLine.
private void goToLine(int line, int expectedResult) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
IEditorPart part = IDE.openEditor(page, fFile);
if (part instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) part;
IAction action = editor.getAction(ITextEditorActionConstants.GOTO_LINE);
Accessor accessor = new Accessor(action, GotoLineAction.class);
accessor.invoke("gotoLine", new Class[] { int.class }, new Integer[] { Integer.valueOf(line) });
Control control = part.getAdapter(Control.class);
if (control instanceof StyledText) {
int caretLine = -1;
StyledText styledText = (StyledText) control;
int caret = styledText.getCaretOffset();
try {
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
caretLine = document.getLineOfOffset(caret);
} catch (BadLocationException e1) {
fail();
}
assertEquals(expectedResult, caretLine);
} else
fail();
} else
fail();
} catch (PartInitException e) {
fail();
}
}
Aggregations