use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class TestOpenEditorXML method testOpenOnLocalFileStore.
public void testOpenOnLocalFileStore() throws Exception {
// filebuffers for local files have a location
IPath stateLocation = XMLUITestsPlugin.getDefault().getStateLocation();
File file = stateLocation.append(FILE_NAME).toFile();
FileOutputStream fileOutputStream = new FileOutputStream(file);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
InputStream contents = fFile.getContents();
if (contents != null) {
int c;
byte[] bytes = new byte[2048];
try {
while ((c = contents.read(bytes)) >= 0) {
buffer.write(bytes, 0, c);
}
contents.close();
} catch (IOException ioe) {
// no cleanup can be done
}
}
fileOutputStream.write(buffer.toByteArray());
URI uri = URIUtil.toURI(new Path(file.getAbsolutePath()));
IFileStore store = EFS.getStore(uri);
FileStoreEditorInput input = new FileStoreEditorInput(store);
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
IEditorPart editor = IDE.openEditor(page, input, "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart");
page.closeEditor(editor, false);
assertTrue("Unable to open structured text editor " + fEditor, (fEditor instanceof XMLMultiPageEditorPart) || (fEditor instanceof StructuredTextEditor));
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class TestOpenEditorXML method setUp.
protected void setUp() throws Exception {
// only create project and file once
if (!fIsSetup) {
// create project
createProject(PROJECT_NAME);
fFile = getOrCreateFile(PROJECT_NAME + "/" + FILE_NAME);
fIsSetup = true;
}
assertTrue("Input file not accessible: " + fFile.getFullPath(), fFile.isAccessible());
// editor is opened each time
if (fIsSetup && fEditor == null) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
fEditor = IDE.openEditor(page, fFile, true, true);
assertTrue("Unable to open structured text editor " + fEditor, (fEditor instanceof XMLMultiPageEditorPart) || (fEditor instanceof StructuredTextEditor));
}
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class ViewerTestXML method addActions.
protected void addActions(IContributionManager mgr) {
if (mgr != null) {
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "New XML";
}
public void run() {
super.run();
BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {
public void run() {
setupViewerForNew();
fSourceViewer.setEditable(true);
}
});
}
});
mgr.add(new Separator());
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "Change Visibility";
}
public void run() {
super.run();
NumberInputDialog dlg = new NumberInputDialog(fSourceViewer.getControl().getShell());
int proceed = dlg.open();
if (proceed == Window.CANCEL)
return;
fSourceViewer.resetVisibleRegion();
fSourceViewer.setVisibleRegion(dlg.startValue, dlg.lengthValue);
}
});
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "Show All";
}
public void run() {
super.run();
fSourceViewer.resetVisibleRegion();
}
});
mgr.add(new Separator());
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "Change Visibility in Editor";
}
public void run() {
super.run();
StructuredTextViewer sourceViewer = null;
IEditorPart part = getViewSite().getWorkbenchWindow().getActivePage().getActiveEditor();
if (part != null && part instanceof StructuredTextEditor) {
sourceViewer = ((StructuredTextEditor) part).getTextViewer();
}
if (sourceViewer != null) {
NumberInputDialog dlg = new NumberInputDialog(sourceViewer.getControl().getShell());
int proceed = dlg.open();
if (proceed == Window.CANCEL)
return;
sourceViewer.resetVisibleRegion();
sourceViewer.setVisibleRegion(dlg.startValue, dlg.lengthValue);
}
}
});
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "Show All in Editor";
}
public void run() {
super.run();
StructuredTextViewer sourceViewer = null;
IEditorPart part = getViewSite().getWorkbenchWindow().getActivePage().getActiveEditor();
if (part != null && part instanceof StructuredTextEditor) {
sourceViewer = ((StructuredTextEditor) part).getTextViewer();
}
if (sourceViewer != null) {
sourceViewer.resetVisibleRegion();
}
}
});
mgr.add(new Separator());
// no longer able to set input to NULL
// mgr.add(new Action() {
// public String getText() {
// return getToolTipText();
// }
//
// public String getToolTipText() {
// return "Set Input to NULL";
// }
// public void run() {
// super.run();
// viewer.setInput(null);
// }
// });
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "Take Input from Active Editor";
}
public void run() {
super.run();
ITextEditor textEditor = getActiveEditor();
if (textEditor != null) {
setupViewerForEditor(textEditor);
fSourceViewer.setEditable(true);
}
}
});
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "Take Input and Follow Selection";
}
public void run() {
super.run();
followSelection();
fSourceViewer.setEditable(true);
}
});
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "Take Input and Follow Selection As ReadOnly";
}
public void run() {
super.run();
followSelection();
fSourceViewer.setEditable(false);
}
});
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "Stop Following Selection";
}
public void run() {
super.run();
stopFollowSelection();
}
});
}
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class XMLCodeFoldingTest method testAddNode.
/**
* <p><b>TEST:</b> that folding annotations are updated after node is added</p>
*/
public void testAddNode() throws Exception {
IFile file = getFile("XMLFoldingTest2.xml");
StructuredTextEditor editor = getEditor(file);
try {
StructuredTextViewer viewer = editor.getTextViewer();
IDocument doc = viewer.getDocument();
doc.replace(149, 0, "\n<addMe>\n\n\n</addMe>");
editor.doSave(null);
List expectedPositions = new ArrayList();
expectedPositions.add(new Position(150, 18));
expectedPositions.add(new Position(62, 126));
expectedPositions.add(new Position(47, 13));
expectedPositions.add(new Position(39, 198));
expectedPositions.add(new Position(192, 36));
expectedPositions.add(new Position(71, 13));
expectedPositions.add(new Position(142, 35));
expectedPositions.add(new Position(87, 49));
waitForReconcileThenVerify(viewer, expectedPositions);
} catch (BadLocationException e) {
fail("Test is broken, add location has become invalid.\n" + e.getMessage());
}
}
use of org.eclipse.wst.sse.ui.StructuredTextEditor in project webtools.sourceediting by eclipse.
the class XMLCodeFoldingTest method testInitFolding.
/**
* <p><b>TEST:</b> the initially placed folding annotations</p>
*/
public void testInitFolding() throws Exception {
IFile file = getFile("XMLFoldingTest1.xml");
StructuredTextEditor editor = getEditor(file);
// expected for single-character line delimiter
List expectedPositions = new ArrayList();
expectedPositions.add(new Position(142, 16));
expectedPositions.add(new Position(173, 36));
expectedPositions.add(new Position(39, 179));
expectedPositions.add(new Position(71, 13));
expectedPositions.add(new Position(62, 107));
expectedPositions.add(new Position(47, 13));
expectedPositions.add(new Position(87, 49));
waitForReconcileThenVerify(editor.getTextViewer(), expectedPositions);
}
Aggregations