Java by API/org.eclipse.jface.dialogs/ErrorDialog

Материал из Java эксперт
Перейти к: навигация, поиск

ErrorDialog: openError(Shell shell, String arg1, String arg2, IStatus arg3)

   <source lang="java">

import org.eclipse.core.runtime.*; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.SWT; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class MainClass extends ApplicationWindow {

 public MainClass() {
   super(null);
 }
 public void run() {
   setBlockOnOpen(true);
   open();
   Display.getCurrent().dispose();
 }
 protected void configureShell(Shell shell) {
   super.configureShell(shell);
   shell.setText("Show Error");
   shell.setSize(400, 400);
 }
 protected Control createContents(Composite parent) {
   Composite composite = new Composite(parent, SWT.NONE);
   composite.setLayout(new GridLayout(1, false));
   final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
   text.setLayoutData(new GridData(GridData.FILL_BOTH));
   Button show = new Button(composite, SWT.PUSH);
   show.setText("Show Error");
   show.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent event) {
       Status status = new Status(IStatus.ERROR, "My Plug-in ID", 0,
           "Status Error Message", null);
       ErrorDialog.openError(Display.getCurrent().getActiveShell(),
           "JFace Error", text.getText(), status);
     }
   });
   return composite;
 }
 public static void main(String[] args) {
   new MainClass().run();
 }

}

      </source>