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;
}
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;
}
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;
}
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;
}
Aggregations