List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement
public Object getFirstElement();
null
if the selection is empty. From source file:com.aptana.js.debug.ui.internal.actions.NewDetailFormatterAction.java
License:Open Source License
/** * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) *//* w w w . java2s . co m*/ public void run(IAction action) { IStructuredSelection selection = getCurrentSelection(); if (selection == null || selection.size() != 1) { return; } Object element = selection.getFirstElement(); String typeName; try { if (element instanceof IJSVariable) { typeName = ((IJSVariable) element).getReferenceTypeName(); } else { return; } } catch (DebugException e) { IdeLog.logError(JSDebugUIPlugin.getDefault(), e); return; } DebugOptionsManager detailFormattersManager = JSDebugPlugin.getDefault().getDebugOptionsManager(); DetailFormatter detailFormatter = new DetailFormatter(typeName, StringUtil.EMPTY, true); if (new DetailFormatterDialog(UIUtils.getActiveShell(), detailFormatter, null, true, false) .open() == Window.OK) { detailFormattersManager.setAssociatedDetailFormatter(detailFormatter); refreshCurrentSelection(); } }
From source file:com.aptana.js.debug.ui.internal.actions.NewWatchpointAction.java
License:Open Source License
public void run(IAction action) { IStructuredSelection selection = getCurrentSelection(); if (selection == null || selection.size() != 1) { return;/*from w ww. ja v a 2 s .c o m*/ } Object element = selection.getFirstElement(); try { if (element instanceof IJSVariable) { JSDebugModel.createWatchpoint((IJSVariable) element); refreshCurrentSelection(); } } catch (CoreException e) { IdeLog.logError(JSDebugUIPlugin.getDefault(), e); return; } }
From source file:com.aptana.js.debug.ui.internal.actions.OpenScriptSourceAction.java
License:Open Source License
/** * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection) */// ww w. j av a 2s. c om public void selectionChanged(IStructuredSelection selection) { if (selection.size() == 1) { Object element = selection.getFirstElement(); if (element instanceof IJSScriptElement) { scriptElement = (IJSScriptElement) element; URI location = scriptElement.getLocation(); if (location != null) { setEnabled(true); int lineNumber = scriptElement.getBaseLine(); Object sourceElement = DebugUITools.lookupSource(scriptElement, getSourceLocator(scriptElement)) .getSourceElement(); IEditorInput editorInput = SourceDisplayUtil.getEditorInput(sourceElement); if (editorInput != null) { IEditorPart editorPart = SourceDisplayUtil.findEditor(editorInput); if (editorPart != null) { SourceDisplayUtil.revealLineInEditor(editorPart, lineNumber); } } return; } } } else { scriptElement = null; } setEnabled(false); }
From source file:com.aptana.js.debug.ui.internal.actions.RemoveDetailFormatterAction.java
License:Open Source License
/** * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) *///from w w w. ja v a 2 s.com public void run(IAction action) { IStructuredSelection selection = getCurrentSelection(); if (selection == null || selection.size() != 1) { return; } Object element = selection.getFirstElement(); String typeName; try { if (element instanceof IJSVariable) { typeName = ((IJSVariable) element).getReferenceTypeName(); } else { return; } } catch (DebugException e) { IdeLog.logError(JSDebugUIPlugin.getDefault(), e); return; } DebugOptionsManager detailFormattersManager = JSDebugPlugin.getDefault().getDebugOptionsManager(); DetailFormatter detailFormatter = detailFormattersManager.getAssociatedDetailFormatter(typeName); detailFormattersManager.removeAssociatedDetailFormatter(detailFormatter); refreshCurrentSelection(); }
From source file:com.aptana.js.debug.ui.internal.preferences.JSDetailFormattersPreferencePage.java
License:Open Source License
private void updatePage(IStructuredSelection selection) { removeFormatterButton.setEnabled(!selection.isEmpty()); editFormatterButton.setEnabled(selection.size() == 1); sourceViewer.getDocument()//from w ww.java 2 s.c o m .set((selection.size() == 1) ? ((DetailFormatter) selection.getFirstElement()).getSnippet() : StringUtil.EMPTY); }
From source file:com.aptana.js.debug.ui.internal.preferences.JSDetailFormattersPreferencePage.java
License:Open Source License
@SuppressWarnings("unchecked") private void removeTypes() { Object[] list = formatters.toArray(); IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection(); Object first = selection.getFirstElement(); int index = -1; for (int i = 0; i < list.length; i++) { if (list[i].equals(first)) { index = i;/* w w w . j a va2s . co m*/ break; } } removeDetailFormatters( (DetailFormatter[]) selection.toList().toArray(new DetailFormatter[selection.size()])); list = formatters.toArray(); if (index > list.length - 1) { index = list.length - 1; } if (index >= 0) { listViewer.setSelection(new StructuredSelection(list[index])); } }
From source file:com.aptana.ruby.internal.debug.ui.breakpoints.AbstractDetailPane.java
License:Open Source License
public void display(IStructuredSelection selection) { // clear status line IStatusLineManager statusLine = getStatusLine(); if (statusLine != null) { statusLine.setErrorMessage(null); }/*from ww w.j av a 2 s . c o m*/ AbstractRubyBreakpointEditor editor = getEditor(); Object input = null; if (selection != null && selection.size() == 1) { input = selection.getFirstElement(); // update even if the same in case attributes have changed } try { editor.setInput(input); } catch (CoreException e) { IdeLog.logError(RubyDebugUIPlugin.getDefault(), e); } }
From source file:com.aptana.ruby.internal.debug.ui.breakpoints.BreakpointDetailPaneFactory.java
License:Open Source License
@SuppressWarnings("rawtypes") public Set getDetailPaneTypes(IStructuredSelection selection) { HashSet<String> set = new HashSet<String>(); if (selection.size() == 1) { IBreakpoint b = (IBreakpoint) selection.getFirstElement(); try {/*from w w w . ja v a2s. c o m*/ String type = b.getMarker().getType(); if (RubyLineBreakpoint.RUBY_LINE_BREAKPOINT.equals(type)) { set.add(LineBreakpointDetailPane.DETAIL_PANE_LINE_BREAKPOINT); } else { set.add(StandardBreakpointDetailPane.DETAIL_PANE_STANDARD); } } catch (CoreException e) { } } return set; }
From source file:com.aptana.ruby.internal.debug.ui.breakpoints.BreakpointDetailPaneFactory.java
License:Open Source License
public String getDefaultDetailPane(IStructuredSelection selection) { if (selection.size() == 1) { IBreakpoint b = (IBreakpoint) selection.getFirstElement(); try {/*from www . j av a 2s .c om*/ String type = b.getMarker().getType(); if (RubyLineBreakpoint.RUBY_LINE_BREAKPOINT.equals(type)) { return LineBreakpointDetailPane.DETAIL_PANE_LINE_BREAKPOINT; } return StandardBreakpointDetailPane.DETAIL_PANE_STANDARD; } catch (CoreException e) { } } return null; }
From source file:com.aptana.ruby.internal.rake.actions.RakeTasksContributionItem.java
License:Open Source License
private IResource getSelectedResource() { IEvaluationService evalService = (IEvaluationService) serviceLocator.getService(IEvaluationService.class); if (evalService != null) { IEvaluationContext context = evalService.getCurrentState(); IWorkbenchPart activePart = (IWorkbenchPart) context.getVariable(ISources.ACTIVE_PART_NAME); if (activePart instanceof IEditorPart) { IEditorInput input = (IEditorInput) context.getVariable(ISources.ACTIVE_EDITOR_INPUT_NAME); return (IResource) input.getAdapter(IResource.class); }//from w w w .j ava 2 s .c o m ISelection selection = (ISelection) context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); if (selection instanceof IStructuredSelection) { IStructuredSelection struct = (IStructuredSelection) selection; Object firstElement = struct.getFirstElement(); if (firstElement instanceof IResource) { return (IResource) firstElement; } else if (firstElement instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) firstElement; return (IResource) adaptable.getAdapter(IResource.class); } } } return null; }