Пример #1
0
  public void run(IAction action) {
    FastStringBuffer buf = new FastStringBuffer();
    try {
      PyEdit pyEdit = getPyEdit();

      PySelection pySelection = new PySelection(pyEdit);

      IPythonNature nature = pyEdit.getPythonNature();
      File editorFile = pyEdit.getEditorFile();

      if (editorFile != null) {
        if (nature != null) {
          String mod = nature.resolveModule(editorFile);
          if (mod != null) {
            buf.append(mod);

          } else {
            // Support for external files (not in PYTHONPATH).
            buf.append(FullRepIterable.getFirstPart(editorFile.getName()));
          }
        } else {
          buf.append(FullRepIterable.getFirstPart(editorFile.getName()));
        }
      }

      List<stmtType> path =
          FastParser.parseToKnowGloballyAccessiblePath(
              pySelection.getDoc(), pySelection.getStartLineIndex());
      for (stmtType stmtType : path) {
        if (buf.length() > 0) {
          buf.append('.');
        }
        buf.append(NodeUtils.getRepresentationString(stmtType));
      }

    } catch (MisconfigurationException e1) {
      Log.log(e1);
      return;
    }

    Transfer[] dataTypes = new Transfer[] {TextTransfer.getInstance()};
    Object[] data = new Object[] {buf.toString()};

    Clipboard clipboard = new Clipboard(EditorUtils.getShell().getDisplay());
    try {
      clipboard.setContents(data, dataTypes);
    } catch (SWTError e) {
      if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
        throw e;
      }
      MessageDialog.openError(
          EditorUtils.getShell(), "Error copying to clipboard.", e.getMessage());
    } finally {
      clipboard.dispose();
    }
  }
Пример #2
0
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(2, true));

    final Browser browser;
    try {
      browser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
      System.out.println("Could not instantiate Browser: " + e.getMessage());
      display.dispose();
      return;
    }
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    browser.setLayoutData(data);

    Button headersButton = new Button(shell, SWT.PUSH);
    headersButton.setText("Send custom headers");
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    headersButton.setLayoutData(data);
    headersButton.addListener(
        SWT.Selection,
        event ->
            browser.setUrl(
                "http://www.ericgiguere.com/tools/http-header-viewer.html",
                null,
                new String[] {"User-agent: SWT Browser", "Custom-header: this is just a demo"}));
    Button postDataButton = new Button(shell, SWT.PUSH);
    postDataButton.setText("Send post data");
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    postDataButton.setLayoutData(data);
    postDataButton.addListener(
        SWT.Selection,
        event ->
            browser.setUrl(
                "https://bugs.eclipse.org/bugs/buglist.cgi",
                "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW&email1=platform-swt-inbox&emailtype1=substring",
                null));

    shell.setBounds(10, 10, 600, 600);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Пример #3
0
 /**
  * Create this dialog's drop-down list component.
  *
  * @param parent the parent composite
  * @return the drop-down list component
  */
 protected void createDropDownText(Composite parent) {
   // create the list
   text = new Text(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
   // print the stacktrace in the text field
   try {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream ps = new PrintStream(baos);
     detail.printStackTrace(ps);
     if ((detail instanceof SWTError) && (((SWTError) detail).throwable != null)) {
       ps.println("\n*** Stack trace of contained exception ***"); // $NON-NLS-1$
       ((SWTError) detail).throwable.printStackTrace(ps);
     } else if ((detail instanceof SWTException) && (((SWTException) detail).throwable != null)) {
       ps.println("\n*** Stack trace of contained exception ***"); // $NON-NLS-1$
       ((SWTException) detail).throwable.printStackTrace(ps);
     }
     ps.flush();
     baos.flush();
     text.setText(baos.toString());
   } catch (IOException e) {
   }
   GridData data =
       new GridData(
           GridData.HORIZONTAL_ALIGN_FILL
               | GridData.GRAB_HORIZONTAL
               | GridData.VERTICAL_ALIGN_FILL
               | GridData.GRAB_VERTICAL);
   data.heightHint = text.getLineHeight() * TEXT_LINE_COUNT;
   text.setLayoutData(data);
 }
Пример #4
0
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setLayout(new FillLayout());
   shell.setText("Mozilla");
   final Browser browser;
   try {
     browser = new Browser(shell, SWT.MOZILLA);
   } catch (SWTError e) {
     System.out.println("Could not instantiate Browser: " + e.getMessage());
     display.dispose();
     return;
   }
   shell.open();
   browser.setUrl("http://mozilla.org");
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
Пример #5
0
  /** *************************************************************** */
  private void creaContenidos() {
    display = new Display();
    shell = new Shell();

    // EN CASO DE NO RECUPERAR BIEN TOD0 EL CODIGO CNO browser.getText(); lo hacemos con el DOM
    // mediante JAVASCRIPT
    // System.out.println( (String)brw.evaluate("return document.forms[0].innerHTML;") );
    //
    // if ((Boolean)brw.evaluate("return raise('SelectFare', new SelectFareEventArgs(1, 1, 'G'));"))
    // System.out.println("raise() EJEC CORRECMT");;

    final String html =
        "<html><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></html>";
    // final String jsSelecValladolid = "var i=0; while(Stations[i]!=null){; i++;}";

    // Ej de jQuery que funciona: Devuelve el valor del listbox de "Origen Vuelo" selecionado
    final String jQueryRyan = "var orig=$(\"select[@id*='Origin1']\").val(); alert(orig);";
    // "$(\"select[@id*='Origin1']\")[posicion].attr('selected', 'true');";

    /** *** VARIABLES !!!VENTANA¡¡¡ **** */

    // SYSTEM TRAY
    Image image = null;
    try {
      // image = new Image(display, /*rutaActual*/"C:\\"+"fr.ico");
      image = new Image(display, rutaActual + "fr.ico");
    } catch (Exception e) {
      e.getMessage();
    }
    final Tray tray = display.getSystemTray();
    if (tray == null) {
      System.out.println("El system tray no está disponible");
    } else {
      final TrayItem item = new TrayItem(tray, SWT.NONE);
      item.setToolTipText("Ryanair Inspector v2");
      item.setImage(image);
      // Click simple en en icono
      item.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event event) {
              // System.out.println("selection");
            }
          });
      // Doble click en en icono
      item.addListener(
          SWT.DefaultSelection,
          new Listener() {
            public void handleEvent(Event event) {
              // System.out.println("default selection");
              // mio
              if (shell.getVisible()) shell.setVisible(false);
              else shell.setVisible(true);
              // shell.setMinimized(false);
              // shell.setMinimized(true);
            }
          });
    }

    // SHELL
    shell.setSize(1054, 727);
    // shell.setLayout(new FillLayout());
    shell.setText("Ryanair checker");
    shell.setImage(image);
    // Con esto al agrandar y empequeñecer se reorganizan los componentes
    // shell.setLayout(new FillLayout());

    // CREAMOS CONTENEDOR
    /** ************************************************************************ */
    compIzq = new Composite(shell, SWT.NONE);
    compIzq.setBounds(0, 0, 765, 691);
    final FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
    fillLayout.marginWidth = 200;
    fillLayout.marginHeight = 200;
    // comp.setLayout(fillLayout);
    // comp.setSize(200, 200);

    compDer = new Composite(shell, SWT.NONE);
    compDer.setBounds(771, 0, 267, 691);

    // CREAMOS CAJA TEXTO Y BOTON PARA HTML OBTENIDO
    /** ************************************************************************ */
    final Text txtGetHTML = new Text(compDer, SWT.MULTI);
    txtGetHTML.setBounds(0, 0, 251, 198);

    // RyanairInspector2.class.getResource("RyanairInspector2.class").getPath();
    // System.getProperty("user.dir")+"\\bin\\calculadora\\";
    txtGetHTML.setText(
        RyanairInspector2.class.getResource("RyanairInspector2.class").getPath()
            + "\n"
            + System.getProperty("user.dir"));

    final Button button = new Button(compDer, SWT.NONE);
    button.setText("button");

    // TABS
    /** ************************************************************************ */
    tabFolder = new TabFolder(compIzq, SWT.BORDER);
    itemT1 = new TabItem(tabFolder, SWT.NONE);
    itemT2 = new TabItem(tabFolder, SWT.NONE);
    itemT3 = new TabItem(tabFolder, SWT.NONE);
    itemT1.setText("Resultado");
    itemT2.setText("Debugger");
    itemT3.setText("Hilos");

    // TABLE CON DOS COLUMNAS
    /** ************************************************************************ */
    table = new Table(tabFolder, SWT.VIRTUAL);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    final TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.setText("Origen");
    column1.setWidth(200);
    final TableColumn column2 = new TableColumn(table, SWT.NONE);
    column2.setText("Destino");
    column2.setWidth(200);
    final TableColumn column3 = new TableColumn(table, SWT.NONE);
    column3.setText("Fecha");
    column3.setWidth(200);
    final TableColumn column4 = new TableColumn(table, SWT.NONE);
    column4.setText("Precio");
    column4.setWidth(150);

    /* Metemos elementos en la tabla
    TableItem fila = new TableItem(table, SWT.NONE);
    fila.setText(new String[] { "a", "b", "c", "d" });
    */

    // METEMOS EL TABLE EN LA TAB2
    itemT1.setControl(table);
    tabFolder.setBounds(0, 0, 700, 691);
    tabFolder.pack();

    // CREAMOS BROWSER
    /** ************************************************************************ */
    try {
    } catch (SWTError e) {
      System.out.println("Could not instantiate Browser: " + e.getMessage());
      return;
    }
    // CREAMOS BROWSER (2)
    /** ************************************************************************ */
    // FUNCIONA BIEN SIN TABS: browser = new Browser(compIzq, SWT.BORDER);

    // El Normal
    navegadores.add(new Navegador(tabFolder, SWT.BORDER));
    // El Mozilla (hay q ejecutar el xulrunner.exe --register-global)
    // browser = new Browser(tabFolder, SWT.MOZILLA);
    // browser.setSize(1000, 800);
    navegadores.get(0).setBounds(0, 0, 787, 691);
    // browser.setLocation(500, 900);
    /*final FillLayout fillLayoutB = new FillLayout(SWT.VERTICAL);
    fillLayoutB.marginWidth = 200;
    fillLayoutB.marginHeight = 200;
    browser.setLayout(fillLayoutB);
     */

    // METEMOS EL BROWSER EN LA TAB1
    itemT2.setControl(navegadores.get(0)); // prueba18-6-09
    // browser.setVisible(false);

    tabFolder.setBounds(0, 0, 766, 691);
    tabFolder.pack();

    navegadores.add(new Navegador(tabFolder, SWT.BORDER));
    navegadores.get(1).setBounds(0, 0, 787, 691);
    itemT3.setControl(navegadores.get(1));

    // CADA VEZ!!! QUE TERMINE DE CARGAR
    navegadores
        .get(0)
        .addProgressListener(
            new ProgressAdapter() {
              public void completed(ProgressEvent event) {
                if (!postSubmit(navegadores.get(0), table)) {
                  System.out.println(
                      "ERROR: Problema al ejecutar la gestion de los datos, finalizar la carga de la pagina.");
                }
              }
            });

    // CADA VEZ!!! QUE TERMINE DE CARGAR
    navegadores
        .get(1)
        .addProgressListener(
            new ProgressAdapter() {
              public void completed(ProgressEvent event) {
                if (!postSubmit(navegadores.get(1), table)) {
                  System.out.println(
                      "ERROR: Problema al ejecutar la gestion de los datos, finalizar la carga de la pagina.");
                }
              }
            });

    // BOTON OBTENER HTML
    /** ************************************************************************ */
    final Button btnGetHTML = new Button(compDer, SWT.PUSH);
    btnGetHTML.setBounds(0, 204, 151, 30);
    btnGetHTML.setText("Obtener codigo html");
    btnGetHTML.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {

            addBrowser();

            String result = navegadores.get(0).getText();
            txtGetHTML.setText(result);
          }
        });

    // CREAMOS CAJA TEXTO PARA EJECUTAR JS
    /** ************************************************************************ */
    /*final Text txtJS = new Text(compDer, SWT.MULTI);
    txtJS.setText("var newNode = document.createElement('P'); \r\n"+
    		"var text = document.createTextNode('At least when I am around');\r\n"+
    		"newNode.appendChild(text);\r\n"+
    		"document.getElementById('myid').appendChild(newNode);\r\n"+
    		"document.bgColor='yellow';\r\n"+
    		"\r\n"+
    		"document.getElementById('AvailabilitySearchInputFRSearchView_OneWay').checked = true;\r\n"+
    		"document.getElementById('AvailabilitySearchInputFRSearchView_ButtonSubmit').click();\r\n"+
    		"document.getElementById('AvailabilitySearchInputFRSearchView_DropDownListMarketOrigin1')[2].selected=true;\r\n"+
    		"Destination1");
    */

    // BOTON LANZAMOS RYANAIR
    /** ************************************************************************ */
    /*final Button btnCargarRyan = new Button(compDer, SWT.PUSH);
    btnCargarRyan.setText("Cargar RYANAIR");
    btnCargarRyan.addListener(SWT.Selection, new Listener() {
    	public void handleEvent(Event event) {
    		//boolean result = browser.execute(text.getText());
    		boolean result = browser.setUrl("http://www.bookryanair.com/SkySales/FRSearch.aspx?culture=ES-ES&pos=HEAD");
    		if (!result) {
    			// Script may fail or may not be supported on certain platforms.
    			System.out.println("Script was not executed.");
    		}
    	}
    });
    */

    // BOTON EJECUTAMOS JAVASCRIPT
    /** ************************************************************************ */
    final Button btnEjeJS = new Button(compDer, SWT.PUSH);
    btnEjeJS.setBounds(0, 266, 151, 30);
    btnEjeJS.setText("Ejecutar JAVASCRIPT");
    btnEjeJS.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {}
        });

    // image.dispose(); //con esto no funciona el shell.setImage(image)

  }
Пример #6
0
  private void initSkin(Class<? extends BrowserSimSkin> skinClass, Point location) {
    try {
      skin = skinClass.newInstance(); // new AppleIPhone3Skin();//new NativeSkin();
    } catch (InstantiationException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (IllegalAccessException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    skin.setBrowserFactory(new WebKitBrowserFactory());

    Display display = Display.getDefault();

    try {
      skin.createControls(display, location);
      currentLocation = location;
    } catch (SWTError e) {
      e.printStackTrace();
      ExceptionNotifier.showWebKitLoadError(new Shell(display), e);
      display.dispose();
      return;
    }

    final Shell shell = skin.getShell();
    resizableSkinSizeAdvisor =
        new ResizableSkinSizeAdvisorImpl(commonPreferences, specificPreferences, shell);
    shell.addControlListener(
        new ControlAdapter() {
          @Override
          public void controlMoved(ControlEvent e) {
            currentLocation = shell.getLocation();
            super.controlMoved(e);
          }
        });

    shell.addListener(
        SWT.Close,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            instances.remove(BrowserSim.this);
            specificPreferences.setLocation(currentLocation);
            SpecificPreferencesStorage.INSTANCE.save(specificPreferences);
            if (instances.isEmpty()) {
              CommonPreferencesStorage.INSTANCE.save(commonPreferences);
            }
            commonPreferences.deleteObserver(commonPreferencesObserver);
          }
        });

    shell.addListener(
        SWT.Close,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            for (ExitListener e : exitListenerList) {
              e.exit();
            }
          }
        });

    final BrowserSimBrowser browser = getBrowser();
    controlHandler = createControlHandler(browser, homeUrl, specificPreferences);
    final BrowserSimMenuCreator menuCreator =
        createMenuCreator(skin, commonPreferences, specificPreferences, controlHandler, homeUrl);

    shell.addShellListener(
        new ShellListener() {
          @Override
          public void shellIconified(ShellEvent e) {}

          @Override
          public void shellDeiconified(ShellEvent e) {}

          @Override
          public void shellDeactivated(ShellEvent e) {}

          @Override
          public void shellClosed(ShellEvent e) {}

          @Override
          public void shellActivated(ShellEvent e) {
            // adding menu on activation to make it working properly on every sync window
            menuCreator.addMenuBar();
          }
        });
    menuCreator.addMenuBar();
    setShellAttibutes();

    skin.setControlHandler(controlHandler);

    Menu contextMenu = new Menu(shell);
    skin.setContextMenu(contextMenu);
    menuCreator.createMenuItemsForContextMenu(contextMenu);

    progressListener =
        new ProgressListener() {
          public void changed(ProgressEvent event) {
            int ratio;
            if (event.current == event.total || event.total == 0) {
              ratio = -1;
            } else {
              ratio = event.current * 100 / event.total;
            }
            skin.progressChanged(ratio);
          }

          public void completed(ProgressEvent event) {
            skin.progressChanged(-1);
          }
        };
    browser.addProgressListener(progressListener);

    browser.addStatusTextListener(
        new StatusTextListener() {
          public void changed(StatusTextEvent event) {
            skin.statusTextChanged(event.text);
          }
        });
    browser.addLocationListener(
        new LocationListener() {
          public void changed(LocationEvent event) {
            if (event.top) {
              BrowserSimBrowser browser = (BrowserSimBrowser) event.widget;
              skin.locationChanged(
                  event.location, browser.isBackEnabled(), browser.isForwardEnabled());
            }
          }

          public void changing(LocationEvent event) {}
        });

    browser.addLocationListener(
        new LocationAdapter() {
          public void changed(LocationEvent event) {
            initOrientation(specificPreferences.getOrientationAngle());
            WebSqlLoader.initWebSql(skin.getBrowser());
          }
        });

    // JBIDE-12191 - custom scrollbars work satisfactorily on windows only
    if (PlatformUtil.OS_WIN32.equals(PlatformUtil.getOs())) {
      browser.addLocationListener(
          new LocationAdapter() {
            @Override
            public void changed(LocationEvent event) {
              Browser browser = (Browser) event.widget;
              setCustomScrollbarStyles(browser);
            }

            @SuppressWarnings("nls")
            private void setCustomScrollbarStyles(Browser browser) {

              browser.execute(
                  "if (window._browserSim_customScrollBarStylesSetter === undefined) {"
                      + "window._browserSim_customScrollBarStylesSetter = function () {"
                      + "document.removeEventListener('DOMSubtreeModified', window._browserSim_customScrollBarStylesSetter, false);"
                      + "var head = document.head;"
                      + "var style = document.createElement('style');"
                      + "style.type = 'text/css';"
                      + "style.id='browserSimStyles';"
                      + "head.appendChild(style);"
                      + "style.innerText='"
                      // The following two rules fix a problem with showing scrollbars in Google
                      // Mail and similar,
                      // but autohiding of navigation bar stops to work with it. That is why they
                      // are commented.
                      // +	"html {"
                      // +		"overflow: hidden;"
                      // +	"}"
                      // +	"body {"
                      // +		"position: absolute;"
                      // +		"top: 0px;"
                      // +		"left: 0px;"
                      // +		"bottom: 0px;"
                      // +		"right: 0px;"
                      // +		"margin: 0px;"
                      // +		"overflow-y: auto;"
                      // +		"overflow-x: auto;"
                      // +	"}"
                      + "::-webkit-scrollbar {"
                      + "width: 5px;"
                      + "height: 5px;"
                      + "}"
                      + "::-webkit-scrollbar-thumb {"
                      + "background: rgba(0,0,0,0.4); "
                      + "}"
                      + "::-webkit-scrollbar-corner, ::-webkit-scrollbar-thumb:window-inactive {"
                      + "background: rgba(0,0,0,0.0);"
                      + "};"
                      + "';"
                      + "};"
                      + "document.addEventListener('DOMSubtreeModified', window._browserSim_customScrollBarStylesSetter, false);"
                      + "}");
            }
          });
    }
    ;

    browser.addOpenWindowListener(
        new OpenWindowListener() {
          public void open(WindowEvent event) {
            if (FireBugLiteLoader.isFireBugPopUp(event)) {
              FireBugLiteLoader.processFireBugPopUp(event);
            } else {
              event.browser = browser;
            }
          }
        });

    browser.addLocationListener(
        new LocationListener() {
          private BrowserFunction scrollListener = null;

          @SuppressWarnings("nls")
          public void changed(LocationEvent event) {
            if (scrollListener != null) {
              scrollListener.dispose();
            }
            scrollListener =
                new BrowserFunction(((Browser) event.widget), "_browserSim_scrollListener") {
                  public Object function(Object[] arguments) {
                    double pageYOffset = (Double) arguments[0];
                    if (pageYOffset > 0.0) {
                      skin.getShell()
                          .getDisplay()
                          .asyncExec(
                              new Runnable() {
                                public void run() {
                                  if (skin != null
                                      && skin.getShell() != null
                                      && !skin.getShell().isDisposed()) {
                                    skin.setAddressBarVisible(false);
                                  }
                                }
                              });
                    }
                    return null;
                  }
                };

            Browser browser = (Browser) event.widget;
            browser.execute(
                "(function() {"
                    + "var scrollListener = function(e){"
                    + "window._browserSim_scrollListener(window.pageYOffset)"
                    + "};"
                    + "window.addEventListener('scroll', scrollListener);"
                    + "window.addEventListener('beforeunload', function(e){"
                    + "window.removeEventListener('scroll', scrollListener);"
                    + "delete window._browserSim_scrollListener;"
                    + "})"
                    + "})();");
          }

          public void changing(LocationEvent event) {
            skin.setAddressBarVisible(true);
          }
        });

    browser.addLocationListener(
        new LocationAdapter() {
          @Override
          public void changed(LocationEvent event) {
            if (getBrowser().equals(Display.getDefault().getFocusControl()) && event.top) {
              for (BrowserSim bs : instances) {
                if (bs.skin != skin) {
                  bs.skin.getBrowser().setUrl(event.location);
                }
              }
            }
          }
        });

    browser.addTitleListener(
        new TitleListener() {
          @Override
          public void changed(TitleEvent event) {
            skin.pageTitleChanged(event.title);
          }
        });
  }
Пример #7
0
  public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    shell.setLayout(gridLayout);
    ToolBar toolbar = new ToolBar(shell, SWT.NONE);
    ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
    itemBack.setText("Back");
    ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
    itemForward.setText("Forward");
    ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
    itemStop.setText("Stop");
    ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
    itemRefresh.setText("Refresh");
    ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
    itemGo.setText("Go");

    GridData data = new GridData();
    data.horizontalSpan = 3;
    toolbar.setLayoutData(data);

    Label labelAddress = new Label(shell, SWT.NONE);
    labelAddress.setText("Address");

    final Text location = new Text(shell, SWT.BORDER);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    data.grabExcessHorizontalSpace = true;
    location.setLayoutData(data);

    final Browser browser;
    try {
      browser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
      System.out.println("Could not instantiate Browser: " + e.getMessage());
      display.dispose();
      return;
    }
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    data.horizontalSpan = 3;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    browser.setLayoutData(data);

    final Label status = new Label(shell, SWT.NONE);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    status.setLayoutData(data);

    final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE);
    data = new GridData();
    data.horizontalAlignment = GridData.END;
    progressBar.setLayoutData(data);

    /* event handling */
    Listener listener =
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            ToolItem item = (ToolItem) event.widget;
            String string = item.getText();
            if (string.equals("Back")) browser.back();
            else if (string.equals("Forward")) browser.forward();
            else if (string.equals("Stop")) browser.stop();
            else if (string.equals("Refresh")) browser.refresh();
            else if (string.equals("Go")) browser.setUrl(location.getText());
          }
        };
    browser.addProgressListener(
        new ProgressListener() {
          @Override
          public void changed(ProgressEvent event) {
            if (event.total == 0) return;
            int ratio = event.current * 100 / event.total;
            progressBar.setSelection(ratio);
          }

          @Override
          public void completed(ProgressEvent event) {
            progressBar.setSelection(0);
          }
        });
    browser.addStatusTextListener(
        new StatusTextListener() {
          @Override
          public void changed(StatusTextEvent event) {
            status.setText(event.text);
          }
        });
    browser.addLocationListener(
        new LocationListener() {
          @Override
          public void changed(LocationEvent event) {
            if (event.top) location.setText(event.location);
          }

          @Override
          public void changing(LocationEvent event) {}
        });
    itemBack.addListener(SWT.Selection, listener);
    itemForward.addListener(SWT.Selection, listener);
    itemStop.addListener(SWT.Selection, listener);
    itemRefresh.addListener(SWT.Selection, listener);
    itemGo.addListener(SWT.Selection, listener);
    location.addListener(
        SWT.DefaultSelection,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            browser.setUrl(location.getText());
          }
        });

    shell.open();
    browser.setUrl("http://eclipse.org");

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }