Search in sources :

Example 1 with TextEditorAction

use of org.eclipse.ui.texteditor.TextEditorAction 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);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IAction(org.eclipse.jface.action.IAction) Button(org.eclipse.swt.widgets.Button) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) TextEditorAction(org.eclipse.ui.texteditor.TextEditorAction) Display(org.eclipse.swt.widgets.Display)

Aggregations

IAction (org.eclipse.jface.action.IAction)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Color (org.eclipse.swt.graphics.Color)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 Display (org.eclipse.swt.widgets.Display)1 Label (org.eclipse.swt.widgets.Label)1 Shell (org.eclipse.swt.widgets.Shell)1 TextEditorAction (org.eclipse.ui.texteditor.TextEditorAction)1