use of org.eclipse.jface.action.IAction in project sling by apache.
the class ServersActionModeFiddlerActionDelegate method init.
@Override
public void init(IViewPart view) {
this.view = view;
actionBars = view.getViewSite().getActionBars();
initToolbarContributedActions();
for (ActionContributionItem actionContributionItem : prependedToolbarActions) {
// TODO - this looks wrong
IAction action = (IAction) actionContributionItem;
final ActionContributionItem contribution = new ActionContributionItem(action);
actionBars.getToolBarManager().add(contribution);
}
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class TextEditorActionContributor method doSetActiveEditor.
/**
* Internally sets the active editor to the actions provided by this contributor.
* Cannot be overridden by subclasses.
*
* @param part the editor
*/
private void doSetActiveEditor(final IEditorPart part) {
ITextEditor textEditor = null;
if (part instanceof ITextEditor)
textEditor = (ITextEditor) part;
/**
* The global actions to be connected with editor actions
*/
IActionBars actionBars = getActionBars();
actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId()));
actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId()));
IAction action = getAction(textEditor, ITextEditorActionConstants.NEXT);
actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, action);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, action);
action = getAction(textEditor, ITextEditorActionConstants.PREVIOUS);
actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, action);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, action);
action = getAction(textEditor, ITextEditorActionConstants.REFRESH);
actionBars.setGlobalActionHandler(ITextEditorActionConstants.REFRESH, action);
fChangeEncodingAction.setAction(getAction(textEditor, ITextEditorActionConstants.CHANGE_ENCODING));
IAction quickAssistAction = getAction(textEditor, ITextEditorActionConstants.QUICK_ASSIST);
fQuickAssistAction.setAction(quickAssistAction);
if (textEditor == null)
return;
// Update Quick Assist menu entry - for now don't show disabled entry
IMenuManager menuMgr = textEditor.getEditorSite().getActionBars().getMenuManager();
IMenuManager editMenu = menuMgr.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
if (editMenu != null) {
boolean isEnabled = quickAssistAction != null && quickAssistAction.isEnabled();
fQuickAssistMenuEntry.setVisible(isEnabled);
editMenu.update(true);
}
fRetargetShowInformationAction.setAction(getAction(textEditor, ITextEditorActionConstants.SHOW_INFORMATION));
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class GotoLineTest method goToLine.
private void goToLine(int line, int expectedResult) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
IEditorPart part = IDE.openEditor(page, fFile);
if (part instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) part;
IAction action = editor.getAction(ITextEditorActionConstants.GOTO_LINE);
Accessor accessor = new Accessor(action, GotoLineAction.class);
accessor.invoke("gotoLine", new Class[] { int.class }, new Integer[] { Integer.valueOf(line) });
Control control = part.getAdapter(Control.class);
if (control instanceof StyledText) {
int caretLine = -1;
StyledText styledText = (StyledText) control;
int caret = styledText.getCaretOffset();
try {
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
caretLine = document.getLineOfOffset(caret);
} catch (BadLocationException e1) {
fail();
}
assertEquals(expectedResult, caretLine);
} else
fail();
} else
fail();
} catch (PartInitException e) {
fail();
}
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class DefaultEncodingSupport method createStatusEncodingChangeControl.
/**
* Creates the control which allows to change the encoding.
* In case of encoding errors this control will be placed below
* the status of the status editor.
*
* @param parent the parent control
* @param status the status
* @since 3.1
*/
public void createStatusEncodingChangeControl(Composite parent, final IStatus status) {
final IAction action = fTextEditor.getAction(ITextEditorActionConstants.CHANGE_ENCODING);
if (action instanceof TextEditorAction)
((TextEditorAction) action).update();
if (action == null || !action.isEnabled())
return;
Shell shell = parent.getShell();
Display display = shell.getDisplay();
Color bgColor = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
Button button = new Button(parent, SWT.PUSH | SWT.FLAT);
button.setText(action.getText());
button.addSelectionListener(new SelectionAdapter() {
/*
* @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
action.run();
}
});
button.setFocus();
Label filler = new Label(parent, SWT.NONE);
filler.setLayoutData(new GridData(GridData.FILL_BOTH));
filler.setBackground(bgColor);
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class TextEditor method handlePreferenceStoreChanged.
@Override
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
if (event.getProperty().equals(SpellingService.PREFERENCE_SPELLING_ENABLED)) {
ISourceViewer viewer = getSourceViewer();
if (!(viewer instanceof ISourceViewerExtension2))
// cannot unconfigure - do nothing
return;
// XXX: this is pretty heavy-weight
((ISourceViewerExtension2) viewer).unconfigure();
viewer.configure(getSourceViewerConfiguration());
if (Boolean.FALSE.equals(event.getNewValue()))
SpellingProblem.removeAll(getSourceViewer(), null);
IAction quickAssistAction = getAction(ITextEditorActionConstants.QUICK_ASSIST);
if (quickAssistAction instanceof IUpdate)
((IUpdate) quickAssistAction).update();
return;
}
super.handlePreferenceStoreChanged(event);
}
Aggregations