Search in sources :

Example 41 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.

the class ContentAssistTestUtilities method getProposals.

/**
 * <p>
 * Invoke content assist on the given editor at the given offset, for the given number of pages
 * and return the results of each page
 * </p>
 */
private static ICompletionProposal[][] getProposals(AbstractTextEditor editor, int offset, int pageCount) throws Exception {
    ICompletionProposal[][] pages = null;
    /* if JS editor
		 * else if HTML editor */
    if (editor instanceof JavaEditor) {
        // setup the viewer
        ISourceViewer viewer = ((JavaEditor) editor).getViewer();
        JavaScriptSourceViewerConfiguration configuration = new JavaScriptSourceViewerConfiguration(JavaScriptPlugin.getDefault().getJavaTextTools().getColorManager(), JavaScriptPlugin.getDefault().getCombinedPreferenceStore(), editor, IJavaScriptPartitions.JAVA_PARTITIONING);
        ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
        // get the processor
        String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
        IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
        // fire content assist session about to start
        Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionBeginEvent", new Class[] { boolean.class });
        privateFireSessionBeginEventMethod.setAccessible(true);
        privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] { Boolean.TRUE });
        // get content assist suggestions
        pages = new ICompletionProposal[pageCount][];
        for (int p = 0; p < pageCount; ++p) {
            pages[p] = processor.computeCompletionProposals(viewer, offset);
        }
        // fire content assist session ending
        Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
        privateFireSessionEndEventMethod.setAccessible(true);
        privateFireSessionEndEventMethod.invoke(contentAssistant, null);
    } else if (editor instanceof StructuredTextEditor) {
        // setup the viewer
        StructuredTextViewer viewer = ((StructuredTextEditor) editor).getTextViewer();
        StructuredTextViewerConfigurationHTML configuration = new StructuredTextViewerConfigurationHTML();
        ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
        viewer.configure(configuration);
        viewer.setSelectedRange(offset, 0);
        // get the processor
        String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
        IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
        // fire content assist session about to start
        Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionBeginEvent", new Class[] { boolean.class });
        privateFireSessionBeginEventMethod.setAccessible(true);
        privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] { Boolean.TRUE });
        // get content assist suggestions
        pages = new ICompletionProposal[pageCount][];
        for (int p = 0; p < pageCount; ++p) {
            pages[p] = processor.computeCompletionProposals(viewer, offset);
        }
        // fire content assist session ending
        Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
        privateFireSessionEndEventMethod.setAccessible(true);
        privateFireSessionEndEventMethod.invoke(contentAssistant, null);
    }
    return pages;
}
Also used : StructuredTextViewerConfigurationHTML(org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) Method(java.lang.reflect.Method) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) JavaEditor(org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) JavaScriptSourceViewerConfiguration(org.eclipse.wst.jsdt.ui.text.JavaScriptSourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 42 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.

the class NewDTDTemplatesWizardPage 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 StructuredTextViewerConfigurationDTD();

        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(ContentTypeIdForDTD.ContentTypeID_DTD);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument) StructuredTextViewerConfigurationDTD(org.eclipse.wst.dtd.ui.StructuredTextViewerConfigurationDTD)

Example 43 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.

the class ViewerTestXML 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 StructuredTextViewerConfigurationXML();
    // set up the viewer with a document & viewer config
    setupViewerForNew();
    setupViewerPreferences();
}
Also used : StructuredTextViewerConfigurationXML(org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IContributionManager(org.eclipse.jface.action.IContributionManager)

Example 44 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer 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();
            }
        });
    }
}
Also used : Action(org.eclipse.jface.action.Action) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) Separator(org.eclipse.jface.action.Separator)

Example 45 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer 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());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)62 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)21 IDocument (org.eclipse.jface.text.IDocument)19 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)18 IFile (org.eclipse.core.resources.IFile)14 SourceViewer (org.eclipse.jface.text.source.SourceViewer)14 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)14 Composite (org.eclipse.swt.widgets.Composite)13 Shell (org.eclipse.swt.widgets.Shell)13 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)12 StructuredTextViewerConfiguration (org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration)9 LineStyleProvider (org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider)8 ArrayList (java.util.ArrayList)7 BadLocationException (org.eclipse.jface.text.BadLocationException)6 Position (org.eclipse.jface.text.Position)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)6 List (java.util.List)5 Action (org.eclipse.jface.action.Action)4 IContributionManager (org.eclipse.jface.action.IContributionManager)4 Separator (org.eclipse.jface.action.Separator)4