use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project liferay-ide by liferay.
the class XmlSearchTestsUtils method getProposals.
private static ICompletionProposal[] getProposals(IFile file, int nodeType, String... nodeNames) throws Exception {
Node targetNode = null;
IDOMModel domModel = null;
final StructuredTextViewer viewer = getEditor(file).getTextViewer();
final SourceViewerConfiguration srcViewConf = getSourceViewerConfiguraionFromExtensionPoint(file);
viewer.refresh();
if (nodeType == Node.ELEMENT_NODE) {
String elementName = nodeNames[0];
domModel = getDOMModel(file, false);
targetNode = domModel.getDocument().getElementsByTagName(elementName).item(0);
} else if (nodeType == Node.ATTRIBUTE_NODE) {
String elementName = nodeNames[0];
String attrName = nodeNames[1];
domModel = getDOMModel(file, false);
NodeList elements = domModel.getDocument().getElementsByTagName(elementName);
Element element = getElementByAttr(elements, attrName);
targetNode = element.getAttributes().getNamedItem(attrName);
}
if (nodeType == Node.TEXT_NODE) {
String elementName = nodeNames[0];
domModel = getDOMModel(file, false);
targetNode = domModel.getDocument().getElementsByTagName(elementName).item(0).getFirstChild();
}
int offset = getRegion(targetNode).getOffset() + getRegion(targetNode).getLength();
final ContentAssistant contentAssistant = (ContentAssistant) srcViewConf.getContentAssistant(viewer);
// viewer.configure( srcViewConf );
// viewer.setSelectedRange( offset, 0 );
// get the processor
final String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
final IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
// get content assist suggestions
final ICompletionProposal[] proposals = processor.computeCompletionProposals(viewer, offset);
domModel.releaseFromRead();
return proposals;
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class ViewerTestHTML method createPartControl.
/**
* @see org.eclipse.ui.IWorkbenchPart#createPartControl(Composite)
*/
public void createPartControl(Composite parent) {
IContributionManager mgr = getViewSite().getActionBars().getMenuManager();
addActions(mgr);
// create source viewer & its content type-specific viewer
// configuration
fSourceViewer = new StructuredTextViewer(parent, null, null, false, SWT.NONE);
fConfig = new StructuredTextViewerConfigurationHTML();
// set up the viewer with a document & viewer config
setupViewerForNew();
setupViewerPreferences();
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class ViewerTestHTML method addActions.
protected void addActions(IContributionManager mgr) {
if (mgr != null) {
mgr.add(new Action() {
public String getText() {
return getToolTipText();
}
public String getToolTipText() {
return "New HTML";
}
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.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class TestHTMLContentAssistComputers method runProposalTest.
/**
* <p>Run a proposal test by opening the given file and invoking content assist for
* each expected proposal count at the given line number and line character
* offset and then compare the number of proposals for each invocation (pages) to the
* expected number of proposals.</p>
*
* @param fileName
* @param lineNum
* @param lineRelativeCharOffset
* @param expectedProposalCounts
* @throws Exception
*/
private static void runProposalTest(String fileName, int lineNum, int lineRelativeCharOffset, int[] expectedProposalCounts) throws Exception {
IFile file = getFile(fileName);
StructuredTextEditor editor = getEditor(file);
StructuredTextViewer viewer = editor.getTextViewer();
int offset = viewer.getDocument().getLineOffset(lineNum) + lineRelativeCharOffset;
ICompletionProposal[][] pages = getProposals(viewer, offset, expectedProposalCounts.length);
verifyProposalCounts(pages, expectedProposalCounts);
}
use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.
the class NewHTMLTemplatesWizardPage method createViewer.
/**
* Creates, configures and returns a source viewer to present the template
* pattern on the preference page. Clients may override to provide a
* custom source viewer featuring e.g. syntax coloring.
*
* @param parent
* the parent control
* @return a configured source viewer
*/
private SourceViewer createViewer(Composite parent) {
SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {
StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationHTML();
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
return baseConfiguration.getConfiguredContentTypes(sourceViewer);
}
public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
}
};
SourceViewer viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
// $NON-NLS-1$
viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForHTML.ContentTypeID_HTML);
IDocument document = scratchModel.getStructuredDocument();
viewer.configure(sourceViewerConfiguration);
viewer.setDocument(document);
return viewer;
}
Aggregations