Search in sources :

Example 1 with ISourceEditingTextTools

use of org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools in project webtools.sourceediting by eclipse.

the class BreakpointProviderBuilder method getBreakpointProviders.

/**
 * Returns an array of breakpoint providers for a specified content type
 * handler
 *
 * @param handler
 *            a content type handler
 * @param ext
 *            file extension
 * @return IBreakpointProvider[]
 */
public IBreakpointProvider[] getBreakpointProviders(IEditorPart editorpart, String contentTypeID, String ext) {
    initCache();
    // Get breakpoint providers for this content type handler
    IBreakpointProvider[] providers1 = new IBreakpointProvider[0];
    IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeID);
    List holdProviders = new ArrayList(2);
    while (contentType != null) {
        IBreakpointProvider[] providers = (IBreakpointProvider[]) map.get(contentType.getId());
        if (providers == null) {
            providers = createBreakpointProviders(ATT_CONTENT_TYPES, contentType.getId());
            if (providers != null) {
                map.put(contentType.getId(), providers);
            }
        }
        // providers were retrieved from cache or newly created
        if (providers != null) {
            holdProviders.addAll(Arrays.asList(providers));
        }
        contentType = contentType.getBaseType();
    }
    providers1 = (IBreakpointProvider[]) holdProviders.toArray(new IBreakpointProvider[holdProviders.size()]);
    // Get breakpoint providers for this extension
    IBreakpointProvider[] providers2 = new IBreakpointProvider[0];
    if (ext != null) {
        providers2 = (IBreakpointProvider[]) map.get(ext);
        if (providers2 == null) {
            providers2 = createBreakpointProviders(ATT_EXTENSIONS, ext);
            if (providers2 != null) {
                map.put(ext, providers2);
            }
        }
    }
    // create single hash set to remove duplication
    Set s = new HashSet();
    s.addAll(Arrays.asList(providers1));
    s.addAll(Arrays.asList(providers2));
    // create IBreakpointProvider[] to return
    IBreakpointProvider[] providers = new IBreakpointProvider[s.size()];
    Iterator itr = s.iterator();
    int i = 0;
    ISourceEditingTextTools tools = null;
    if (editorpart != null && itr.hasNext())
        tools = editorpart.getAdapter(ISourceEditingTextTools.class);
    while (itr.hasNext()) {
        providers[i] = (IBreakpointProvider) itr.next();
        providers[i].setSourceEditingTextTools(tools);
        i++;
    }
    return providers;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IContentType(org.eclipse.core.runtime.content.IContentType) ArrayList(java.util.ArrayList) List(java.util.List) ISourceEditingTextTools(org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools) IBreakpointProvider(org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider) HashSet(java.util.HashSet)

Example 2 with ISourceEditingTextTools

use of org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools in project webtools.sourceediting by eclipse.

the class AbstractDropAction method insert.

/*
	 * Replaces targetEditor's current selection by "text"
	 */
protected boolean insert(String text, IEditorPart targetEditor) {
    if (text == null || text.length() == 0) {
        return true;
    }
    ITextSelection textSelection = null;
    IDocument doc = null;
    ISelection selection = null;
    ISourceEditingTextTools tools = targetEditor.getAdapter(ISourceEditingTextTools.class);
    if (tools != null) {
        doc = tools.getDocument();
        selection = tools.getSelection();
    }
    ITextEditor textEditor = null;
    if (targetEditor instanceof ITextEditor) {
        textEditor = (ITextEditor) targetEditor;
    }
    if (textEditor == null) {
        textEditor = ((IAdaptable) targetEditor).getAdapter(ITextEditor.class);
    }
    if (textEditor == null && tools != null && tools.getEditorPart() instanceof ITextEditor) {
        textEditor = (ITextEditor) tools.getEditorPart();
    }
    if (textEditor == null && tools != null && tools.getEditorPart() != null) {
        textEditor = tools.getEditorPart().getAdapter(ITextEditor.class);
    }
    if (selection == null && textEditor != null) {
        selection = textEditor.getSelectionProvider().getSelection();
    }
    if (doc == null && textEditor != null) {
        doc = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
    }
    if (selection instanceof ITextSelection) {
        textSelection = (ITextSelection) selection;
        try {
            doc.replace(textSelection.getOffset(), textSelection.getLength(), text);
        } catch (BadLocationException e) {
            return false;
        }
    }
    if (textEditor != null && textSelection != null) {
        ISelectionProvider sp = textEditor.getSelectionProvider();
        ITextSelection sel = new TextSelection(textSelection.getOffset(), text.length());
        sp.setSelection(sel);
        textEditor.selectAndReveal(sel.getOffset(), sel.getLength());
    }
    return true;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TextSelection(org.eclipse.jface.text.TextSelection) ITextSelection(org.eclipse.jface.text.ITextSelection) ISelection(org.eclipse.jface.viewers.ISelection) ISourceEditingTextTools(org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools) ITextSelection(org.eclipse.jface.text.ITextSelection) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with ISourceEditingTextTools

use of org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method createSourceEditingTextTools.

/**
 * @return
 */
private ISourceEditingTextTools createSourceEditingTextTools() {
    ISourceEditingTextTools tools = null;
    ExtendedConfigurationBuilder builder = ExtendedConfigurationBuilder.getInstance();
    String[] ids = getConfigurationPoints();
    for (int i = 0; tools == null && i < ids.length; i++) {
        tools = (ISourceEditingTextTools) builder.getConfiguration(NullSourceEditingTextTools.ID, ids[i]);
    }
    if (tools == null) {
        tools = NullSourceEditingTextTools.getInstance();
        ((NullSourceEditingTextTools) tools).setTextEditor(this);
    }
    // $NON-NLS-1$
    Method method = null;
    try {
        // $NON-NLS-1$
        method = tools.getClass().getMethod("setTextEditor", new Class[] { StructuredTextEditor.class });
    } catch (NoSuchMethodException e) {
    }
    if (method == null) {
        try {
            // $NON-NLS-1$
            method = tools.getClass().getMethod("setTextEditor", new Class[] { ITextEditor.class });
        } catch (NoSuchMethodException e) {
        }
    }
    if (method == null) {
        try {
            // $NON-NLS-1$
            method = tools.getClass().getMethod("setTextEditor", new Class[] { IEditorPart.class });
        } catch (NoSuchMethodException e) {
        }
    }
    if (method != null) {
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
        try {
            method.invoke(tools, new Object[] { this });
        } catch (Exception e) {
            // $NON-NLS-1$
            Logger.logException("Problem creating ISourceEditingTextTools implementation", e);
        }
    }
    return tools;
}
Also used : NullSourceEditingTextTools(org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.NullSourceEditingTextTools) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Method(java.lang.reflect.Method) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) ExtendedConfigurationBuilder(org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder) ISourceEditingTextTools(org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools)

Example 4 with ISourceEditingTextTools

use of org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools in project webtools.sourceediting by eclipse.

the class ToggleBreakpointAction method createBreakpoints.

protected boolean createBreakpoints(int lineNumber) {
    /*
		 * Note: we'll always allow processing to continue, even for a "read
		 * only" IStorageEditorInput, for the ActiveScript debugger. But this
		 * means sometimes the ActiveScript provider might get an input from
		 * CVS or something that is not related to debugging.
		 */
    ITextEditor editor = getTextEditor();
    IEditorInput input = editor.getEditorInput();
    IDocument document = editor.getDocumentProvider().getDocument(input);
    if (document == null)
        return false;
    String contentType = getContentType(document);
    IBreakpointProvider[] providers = BreakpointProviderBuilder.getInstance().getBreakpointProviders(editor, contentType, getFileExtension(input));
    int pos = -1;
    ISourceEditingTextTools tools = editor.getAdapter(ISourceEditingTextTools.class);
    if (tools != null) {
        pos = tools.getCaretOffset();
    }
    final int n = providers.length;
    List<IStatus> errors = new ArrayList<>(0);
    for (int i = 0; i < n; i++) {
        try {
            if (Debug.debugBreakpoints)
                // $NON-NLS-1$
                System.out.println(providers[i].getClass().getName() + " adding breakpoint to line " + lineNumber);
            IStatus status = providers[i].addBreakpoint(document, input, lineNumber, pos);
            if (status != null && !status.isOK()) {
                errors.add(status);
            }
        } catch (CoreException e) {
            errors.add(e.getStatus());
        } catch (Exception t) {
            // $NON-NLS-1$
            Logger.logException("exception while adding breakpoint", t);
        }
    }
    IStatus status = null;
    if (errors.size() > 0) {
        Shell shell = editor.getSite().getShell();
        if (errors.size() > 1) {
            // $NON-NLS-1$
            status = new MultiStatus(SSEUIPlugin.ID, IStatus.OK, errors.toArray(new IStatus[0]), SSEUIMessages.ManageBreakpoints_error_adding_message1, null);
        } else {
            status = errors.get(0);
        }
        if ((status.getSeverity() > IStatus.INFO) || (Platform.inDebugMode() && !status.isOK())) {
            Platform.getLog(SSEUIPlugin.getDefault().getBundle()).log(status);
        }
        /*
			 * Show for conditions more severe than INFO or when no
			 * breakpoints were created
			 */
        if (status.getSeverity() > IStatus.INFO && getBreakpoints(getMarkers()).length < 1) {
            // $NON-NLS-1$ //$NON-NLS-2$
            ErrorDialog.openError(shell, SSEUIMessages.ManageBreakpoints_error_adding_title1, status.getMessage(), status);
            return false;
        }
    }
    /*
		 * Although no errors were reported, no breakpoints exist on this line
		 * after having run the existing providers. Run the fallback action.
		 */
    if ((status == null || status.getSeverity() < IStatus.WARNING) && fFallbackAction != null && !hasMarkers()) {
        if (fFallbackAction instanceof ISelectionListener) {
            ((ISelectionListener) fFallbackAction).selectionChanged(null, null);
        }
        fFallbackAction.run();
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) CoreException(org.eclipse.core.runtime.CoreException) ISelectionListener(org.eclipse.ui.ISelectionListener) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) ISourceEditingTextTools(org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools) IBreakpointProvider(org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ISourceEditingTextTools (org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools)4 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)3 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IDocument (org.eclipse.jface.text.IDocument)2 IBreakpointProvider (org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 IContentType (org.eclipse.core.runtime.content.IContentType)1 IBreakpoint (org.eclipse.debug.core.model.IBreakpoint)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 TextSelection (org.eclipse.jface.text.TextSelection)1