Java 类org.eclipse.ui.internal.browser.IBrowserDescriptor 实例源码

项目:gwt-eclipse-plugin    文件:BrowserUtilities.java   
/**
 * Computes the full command-line that can be passed directly to {@link ProcessBuilder}.
 */
public static List<String> computeCommandLine(IBrowserDescriptor browser, String url) {
  String params = browser.getParameters();
  if (params == null) {
    params = "";
  }

  boolean paramsHasUrlVariable = params.contains("%URL%");
  if (paramsHasUrlVariable) {
    // Quote the URL in case it has spaces
    params = params.replaceAll("%URL%", '"' + url + '"');
  }

  final List<String> command = LaunchConfigurationProcessorUtilities.parseArgs(params);
  command.add(0, browser.getLocation());
  if (!paramsHasUrlVariable) {
    // Cover the case where the user forgot the %URL%
    command.add(url);
  }

  return command;
}
项目:gwt-eclipse-plugin    文件:BrowserUtilities.java   
/**
 * Creates and saves a browser model object.
 *
 * @param browserName
 *          the name of the browser
 * @param browserLocation
 *          the location, unescaped
 * @return the new object
 */
public static IBrowserDescriptor createBrowserDescriptor(String browserName, String browserLocation) {
  assert browserName != null;
  assert browserLocation != null;

  IBrowserDescriptorWorkingCopy browserWc = BrowserManager.getInstance().createExternalWebBrowser();
  browserWc.setName(browserName);

  if (Platform.OS_MACOSX.equals(Platform.getOS())) {
    // Special handling necessary to get smooth launches on Mac
    browserWc.setLocation("/usr/bin/open");
    browserWc.setParameters("-a \"" + browserLocation + "\" %URL%");
  } else {
    browserWc.setLocation(browserLocation);
    browserWc.setParameters("%URL%");
  }

  return browserWc.save();
}
项目:gwt-eclipse-plugin    文件:BrowserUtilities.java   
/**
 * @return a browser that looks like Chrome, or null
 * @see #findChromeBrowserName()
 */
@SuppressWarnings("unchecked")
public static IBrowserDescriptor findChromeBrowser() {
  BrowserManager browserManager = BrowserManager.getInstance();
  List<IBrowserDescriptor> browsers = new ArrayList<IBrowserDescriptor>(browserManager.getWebBrowsers());

  // Give the default web browser the highest priority
  IBrowserDescriptor currentWebBrowser = browserManager.getCurrentWebBrowser();
  if (currentWebBrowser != null) {
    browsers.remove(currentWebBrowser);
    browsers.add(0, currentWebBrowser);
  }

  for (IBrowserDescriptor browser : browsers) {
    if (containsChromeRelatedString(browser.getName()) || containsChromeRelatedString(browser.getLocation())) {
      return browser;
    }
  }

  return null;
}
项目:gwt-eclipse-plugin    文件:BrowserUtilities.java   
@SuppressWarnings("unchecked")
public static IBrowserDescriptor findBrowser(String browserName) {
  List<IBrowserDescriptor> browsers = BrowserManager.getInstance().getWebBrowsers();
  for (IBrowserDescriptor browser : browsers) {
    if (browser.getName().equals(browserName)) {
      return browser;
    }
  }

  return null;
}
项目:gwt-eclipse-plugin    文件:BrowserUtilities.java   
public static List<String> getBrowserNames() {
  List<String> browserNames = new ArrayList<String>();
  for (Object browserObj : BrowserManager.getInstance().getWebBrowsers()) {
    IBrowserDescriptor browser = (IBrowserDescriptor) browserObj;
    browserNames.add(browser.getName());
  }
  return browserNames;
}
项目:gwt-eclipse-plugin    文件:BrowserUtilities.java   
/**
 * Launches the browser with the given name. This method does not use the Eclipse browser methods to launch the
 * browser since they do not properly pass quoted strings as a single argument.
 */
public static void launchBrowser(String browserName, String url) throws CoreException, IOException {
  IBrowserDescriptor browser = findBrowser(browserName);
  if (browser == null) {
    throw new CoreException(
        StatusUtilities.newErrorStatus("Could not find browser \"" + browserName + "\".", CorePlugin.PLUGIN_ID));
  }

  // SystemBrowserDescriptors have no info in them...
  if (browser instanceof SystemBrowserDescriptor) {
    Program p = Program.findProgram("html");
    boolean launched = false;
    if (p != null) {
      launched = p.execute(url);
    }

    if (!launched) {
      String msg = "Could not launch the default " + "browser, please configure a browser in "
          + "Preferences -> General -> Web Browsers";
      MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell());
      mb.setMessage(msg);
      mb.open();
      throw new CoreException(StatusUtilities.newErrorStatus(msg, CorePlugin.PLUGIN_ID));
    }
  } else {
    List<String> command = computeCommandLine(browser, url);
    new ProcessBuilder(command).start();
  }
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionDialog.java   
/**
 * Opens the dialog for the user to choose a browser.
 * 
 * @param initialSelection optional
 * @return the selected browser, or <code>null</code> if the dialog was
 *         canceled
 */
public static IBrowserDescriptor chooseBrowser(Shell shell,
    IBrowserDescriptor initialSelection) {

  ElementListSelectionDialog dialog = new BrowserSelectionDialog(shell,
      initialSelection);

  if (dialog.open() == Window.OK) {
    return (IBrowserDescriptor) dialog.getFirstResult();
  }

  return null;
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionDialog.java   
private BrowserSelectionDialog(Shell parent,
    IBrowserDescriptor initialSelection) {
  super(parent, new BrowserLabelProvider());
  setTitle("Browser Selection");
  setMessage("Choose a browser:");
  List<IBrowserDescriptor> browers = getBrowsers();
  setElements(browers.toArray(new IBrowserDescriptor[browers.size()]));
  setHelpAvailable(false);
  if (initialSelection != null) {
    setInitialSelections(new Object[] {initialSelection});
  }
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionDialog.java   
@Override
protected void buttonPressed(int buttonId) {
  super.buttonPressed(buttonId);

  if (buttonId == ADD_BROWSER_ID) {
    new AddBrowserDialog(getShell()).open();
    IBrowserDescriptor[] elements = getBrowsers().toArray(
        new IBrowserDescriptor[0]);
    setElements(elements);
    setListElements(elements);
  }
}
项目:gwt-eclipse-plugin    文件:BrowserUtilities.java   
/**
 * @return the name for a Chrome browser or empty string
 * @see #findChromeBrowser()
 */
public static String findChromeBrowserName() {
  IBrowserDescriptor browser = findChromeBrowser();
  return browser != null ? browser.getName() : "";
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionDialog.java   
public String getText(Object element) {
  IBrowserDescriptor browser = (IBrowserDescriptor) element;
  return browser.getName();
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionDialog.java   
@SuppressWarnings("unchecked")
private static List<IBrowserDescriptor> getBrowsers() {
  return BrowserManager.getInstance().getWebBrowsers();
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionBlock.java   
public BrowserSelectionBlock(IBrowserDescriptor browser, Listener listener) {
  super("Browser:", "&Browse...");

  this.browser = browser;
  this.listener = listener;
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionBlock.java   
public IBrowserDescriptor getBrowser() {
  return browser;
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionBlock.java   
@Override
protected String onButtonClicked() {
  IBrowserDescriptor selectedBrowser = BrowserSelectionDialog.chooseBrowser(
      getShell(), browser);
  return selectedBrowser != null ? selectedBrowser.getName() : null;
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionBlock.java   
private void setBrowserText(IBrowserDescriptor browser) {
  setText(browser != null ? browser.getName() : "");
}
项目:APICloud-Studio    文件:BrowserManager.java   
public Collection<BrowserInfo> searchMoreBrowsers()
{
    org.eclipse.ui.internal.browser.BrowserManager eclipseBrowserManager = org.eclipse.ui.internal.browser.BrowserManager
            .getInstance();
    List<IBrowserDescriptor> webBrowsers = eclipseBrowserManager.getWebBrowsers();
    Set<String> currentBrowsers = new HashSet<String>();
    for (IBrowserDescriptor iBrowserDescriptor : webBrowsers)
    {
        String path = getRealPath(iBrowserDescriptor.getLocation());
        if (path == null)
        {
            continue;
        }
        currentBrowsers.add(path);
    }

    Collection<BrowserInfo> browsersFound = new ArrayList<BrowserInfo>();

    List<BrowserInfo> discoverInstalledBrowsers = BrowserUtil.discoverInstalledBrowsers();
    boolean needSave = false;
    for (BrowserInfo browserInfo : discoverInstalledBrowsers)
    {
        String browserLocation = getRealPath(browserInfo.getLocation());
        if (browserLocation != null && !currentBrowsers.contains(browserLocation))
        {
            currentBrowsers.add(browserLocation);
            BrowserDescriptorWorkingCopy workingCopy = new BrowserDescriptorWorkingCopy();
            workingCopy.setName(browserInfo.getName());
            workingCopy.setLocation(browserInfo.getLocation());
            workingCopy.save();
            browsersFound.add(browserInfo);
            needSave = true;
        }
    }
    if (needSave)
    {
        // forces a save on the new list of browsers
        eclipseBrowserManager.setCurrentWebBrowser(eclipseBrowserManager.getCurrentWebBrowser());
    }
    return browsersFound;
}
项目:APICloud-Studio    文件:BrowserManager.java   
public BrowserInfo getCurrentWebBrowser()
{
    IBrowserDescriptor currentWebBrowser = org.eclipse.ui.internal.browser.BrowserManager.getInstance()
            .getCurrentWebBrowser();
    return new BrowserInfo(currentWebBrowser.getName(), currentWebBrowser.getLocation());
}
项目:gwt-eclipse-plugin    文件:BrowserSelectionBlock.java   
void browserSelected(IBrowserDescriptor browserDescriptor, IStatus status);