use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class XMLMultiPageEditorPart method connectDesignPage.
/**
* Connects the design viewer with the viewer selection manager. Should be
* done after createSourcePage() is done because we need to get the
* ViewerSelectionManager from the TextEditor. setModel is also done here
* because getModel() needs to reference the TextEditor.
*/
private void connectDesignPage() {
if (fDesignViewer != null) {
fDesignViewer.setDocument(getDocument());
}
/*
* Connect selection from the Design page to the selection provider
* for the XMLMultiPageEditorPart so that selection changes in the
* Design page will propagate across the workbench
*/
if (fDesignViewer.getSelectionProvider() instanceof IPostSelectionProvider) {
((IPostSelectionProvider) fDesignViewer.getSelectionProvider()).addPostSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (getActivePage() != fSourcePageIndex) {
((MultiPageSelectionProvider) getSite().getSelectionProvider()).firePostSelectionChanged(event);
}
}
});
}
fDesignViewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (getActivePage() != fSourcePageIndex) {
((MultiPageSelectionProvider) getSite().getSelectionProvider()).fireSelectionChanged(event);
}
}
});
fDesignViewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (getActivePage() != fSourcePageIndex) {
try {
updateStatusLine(event.getSelection());
} catch (Exception exception) {
Logger.logException(exception);
}
}
}
});
/*
* Handle double-click in the Design page by selecting the
* corresponding amount of text in the Source page.
*
* Warning: This implies more knowledge of the design viewer's underlying
* Control than expressed in the IDesignViewer interface
*/
fDesignViewer.getControl().addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
ISelection selection = fDesignViewer.getSelectionProvider().getSelection();
int start = -1;
int length = -1;
if (selection instanceof IStructuredSelection) {
/*
* selection goes from the start of the first object to
* the end of the last
*/
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object o = structuredSelection.getFirstElement();
Object o2 = null;
if (structuredSelection.size() > 1) {
o2 = structuredSelection.toArray()[structuredSelection.size() - 1];
} else {
o2 = o;
}
if (o instanceof IndexedRegion) {
start = ((IndexedRegion) o).getStartOffset();
length = ((IndexedRegion) o2).getEndOffset() - start;
} else if (o2 instanceof ITextRegion) {
start = ((ITextRegion) o).getStart();
length = ((ITextRegion) o2).getEnd() - start;
}
} else if (selection instanceof ITextSelection) {
start = ((ITextSelection) selection).getOffset();
length = ((ITextSelection) selection).getLength();
}
if ((start > -1) && (length > -1)) {
getTextEditor().selectAndReveal(start, length);
}
}
});
/*
* Connect selection from the Source page to the selection provider of
* the Design page so that selection in the Source page will drive
* selection in the Design page. Prefer post selection.
*/
ISelectionProvider provider = getTextEditor().getSelectionProvider();
if (fTextEditorSelectionListener == null) {
fTextEditorSelectionListener = new TextEditorPostSelectionAdapter();
}
if (provider instanceof IPostSelectionProvider) {
fTextEditorSelectionListener.forcePostSelection = false;
((IPostSelectionProvider) provider).addPostSelectionChangedListener(fTextEditorSelectionListener);
} else {
fTextEditorSelectionListener.forcePostSelection = true;
provider.addSelectionChangedListener(fTextEditorSelectionListener);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class TestStructuredModel method testGetNodeResource.
public void testGetNodeResource() throws IOException, CoreException {
IStructuredModel model = getTestModel();
IndexedRegion region = model.getIndexedRegion(0);
assertTrue("The region is not adaptable", region instanceof IAdaptable);
IResource resource = ((IAdaptable) region).getAdapter(IResource.class);
assertNotNull("A resource wasn't obtained from the model", resource);
assertEquals("The resource doesn't correspond to the model's base location", new Path("/" + fProjectName + "/files/simple.xml"), resource.getFullPath());
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class ViewerTestXML method followSelection.
/**
* Hooks up the viewer to follow the selection made in the active editor
*/
private void followSelection() {
ITextEditor editor = getActiveEditor();
if (editor != null) {
setupViewerForEditor(editor);
if (fHighlightRangeListener == null)
fHighlightRangeListener = new NodeRangeSelectionListener();
fContentOutlinePage = (editor.getAdapter(IContentOutlinePage.class));
if (fContentOutlinePage != null) {
fContentOutlinePage.addSelectionChangedListener(fHighlightRangeListener);
if (!fContentOutlinePage.getSelection().isEmpty() && fContentOutlinePage.getSelection() instanceof IStructuredSelection) {
fSourceViewer.resetVisibleRegion();
Object[] nodes = ((IStructuredSelection) fContentOutlinePage.getSelection()).toArray();
IndexedRegion startNode = (IndexedRegion) nodes[0];
IndexedRegion endNode = (IndexedRegion) nodes[nodes.length - 1];
if (startNode instanceof Attr)
startNode = (IndexedRegion) ((Attr) startNode).getOwnerElement();
if (endNode instanceof Attr)
endNode = (IndexedRegion) ((Attr) endNode).getOwnerElement();
int start = startNode.getStartOffset();
int end = endNode.getEndOffset();
fSourceViewer.setVisibleRegion(start, end - start);
fSourceViewer.setSelectedRange(start, 0);
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class OpenOnSelectionHelper method revealObject.
protected boolean revealObject(final XSDConcreteComponent component) {
if (component.getRootContainer().equals(xsdSchema)) {
Node element = component.getElement();
if (element instanceof IndexedRegion) {
IndexedRegion indexNode = (IndexedRegion) element;
textEditor.getTextViewer().setRangeIndication(indexNode.getStartOffset(), indexNode.getEndOffset() - indexNode.getStartOffset(), true);
return true;
}
return false;
} else {
lastResult = false;
if (component.getSchema() != null) {
String schemaLocation = URIHelper.removePlatformResourceProtocol(component.getSchema().getSchemaLocation());
IPath schemaPath = new Path(schemaLocation);
final IFile schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
Display.getDefault().syncExec(new Runnable() {
/**
* @see java.lang.Runnable#run()
*/
public void run() {
final IWorkbenchWindow workbenchWindow = XSDEditorPlugin.getPlugin().getWorkbench().getActiveWorkbenchWindow();
if (workbenchWindow != null) {
try {
IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), XSDEditorPlugin.PLUGIN_ID);
if (editorPart instanceof InternalXSDMultiPageEditor) {
((InternalXSDMultiPageEditor) editorPart).openOnGlobalReference(component);
lastResult = true;
}
} catch (PartInitException initEx) {
}
}
}
});
}
return lastResult;
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class StructuredSelectNextXMLHandler method getNewSelectionRegion.
protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
Region newRegion = null;
if (indexedRegion instanceof Node) {
Node cursorNode = (Node) indexedRegion;
// use parent node for empty text node
if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) {
cursorNode = cursorNode.getParentNode();
if (cursorNode instanceof IndexedRegion) {
indexedRegion = (IndexedRegion) cursorNode;
}
}
Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
int currentOffset = textSelection.getOffset();
int currentEndOffset = currentOffset + textSelection.getLength();
if ((cursorNodeRegion.getOffset() >= currentOffset) && (cursorNodeRegion.getOffset() <= currentEndOffset) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset) && (cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset)) {
newRegion = getNewSelectionRegion2(indexedRegion, textSelection);
} else {
newRegion = cursorNodeRegion;
}
}
return newRegion;
}
Aggregations