org.eclipse.ui.internal.browser.IBrowserDescriptor Java Examples

The following examples show how to use org.eclipse.ui.internal.browser.IBrowserDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeJSDebugLauncher.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private boolean foundValidBrowser(String browserName){
	BrowserManager bm = BrowserManager.getInstance();
       if (bm != null){
        List<IBrowserDescriptor> browserList = bm.getWebBrowsers();
        if (browserList != null){
	        
	        int len = browserList.size();
	        
	        for (int i=0;i<len;i++){
	        	IBrowserDescriptor tempBrowser = browserList.get(i);
	        	if (tempBrowser != null && tempBrowser.getLocation() != null && 
	        			!tempBrowser.getLocation().trim().equals("")){ //$NON-NLS-1$
	        		// The location is not empty
	        		String name = tempBrowser.getName();
	        		if (name != null && name.equalsIgnoreCase(browserName)){
	        			return true;
	        		}
	        	}
	        }
        }
       }
       return false;
}
 
Example #2
Source File: BrowserUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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;
}
 
Example #3
Source File: BrowserUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #4
Source File: BrowserUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: ChromeExecutableTab.java    From wildwebdeveloper with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
	try {
		String browserLocation = configuration.getAttribute(ChromeRunDAPDebugDelegate.RUNTIME_EXECUTABLE, "");
		if (browserLocation.isEmpty()) {
			browserToUse.setSelection(new StructuredSelection(browserLocation));
		} else {
			Optional<IBrowserDescriptor> desc = proposals.stream() //
					.filter(IBrowserDescriptor.class::isInstance) //
					.map(IBrowserDescriptor.class::cast) //
					.filter(it -> browserLocation.equals(it.getLocation())) //
					.findFirst();
			if (desc.isPresent()) {
				desc.ifPresent(it -> browserToUse.setSelection(new StructuredSelection(it)));
			} else {
				if (!proposals.contains(browserLocation)) {
					proposals.add(browserLocation);
				}
				browserToUse.refresh();
				browserToUse.setSelection(new StructuredSelection(browserLocation));
			}
		}
	} catch (CoreException ex) {
		Activator.getDefault().getLog().log(ex.getStatus());
	}
}
 
Example #6
Source File: ChromeExecutableTab.java    From wildwebdeveloper with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
	Object selectedBrowser = ((IStructuredSelection)browserToUse.getSelection()).getFirstElement();
	if (selectedBrowser instanceof IBrowserDescriptor) {
		configuration.setAttribute(ChromeRunDAPDebugDelegate.RUNTIME_EXECUTABLE, ((IBrowserDescriptor)selectedBrowser).getLocation());
	} else if (selectedBrowser instanceof String) {
		configuration.setAttribute(ChromeRunDAPDebugDelegate.RUNTIME_EXECUTABLE, selectedBrowser);
	}
}
 
Example #7
Source File: ChromeExecutableTab.java    From wildwebdeveloper with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getText(Object element) {
	if (element instanceof IBrowserDescriptor) {
		IBrowserDescriptor browser = (IBrowserDescriptor)element;
		return browser.getName();
	}
	if ("".equals(element)) {
		return "[Default]";
	}
	return super.getText(element);
}
 
Example #8
Source File: BrowserUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #9
Source File: BrowserUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: BrowserUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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();
  }
}
 
Example #11
Source File: BrowserSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: BrowserSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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});
  }
}
 
Example #13
Source File: BrowserSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@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);
  }
}
 
Example #14
Source File: BrowserManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example #15
Source File: BrowserManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public BrowserInfo getCurrentWebBrowser()
{
	IBrowserDescriptor currentWebBrowser = org.eclipse.ui.internal.browser.BrowserManager.getInstance()
			.getCurrentWebBrowser();
	return new BrowserInfo(currentWebBrowser.getName(), currentWebBrowser.getLocation());
}
 
Example #16
Source File: BrowserSelectionBlock.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private void setBrowserText(IBrowserDescriptor browser) {
  setText(browser != null ? browser.getName() : "");
}
 
Example #17
Source File: BrowserSelectionBlock.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected String onButtonClicked() {
  IBrowserDescriptor selectedBrowser = BrowserSelectionDialog.chooseBrowser(
      getShell(), browser);
  return selectedBrowser != null ? selectedBrowser.getName() : null;
}
 
Example #18
Source File: BrowserSelectionBlock.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public IBrowserDescriptor getBrowser() {
  return browser;
}
 
Example #19
Source File: BrowserSelectionBlock.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public BrowserSelectionBlock(IBrowserDescriptor browser, Listener listener) {
  super("Browser:", "&Browse...");

  this.browser = browser;
  this.listener = listener;
}
 
Example #20
Source File: BrowserSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static List<IBrowserDescriptor> getBrowsers() {
  return BrowserManager.getInstance().getWebBrowsers();
}
 
Example #21
Source File: BrowserSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public String getText(Object element) {
  IBrowserDescriptor browser = (IBrowserDescriptor) element;
  return browser.getName();
}
 
Example #22
Source File: BrowserUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @return the name for a Chrome browser or empty string
 * @see #findChromeBrowser()
 */
public static String findChromeBrowserName() {
  IBrowserDescriptor browser = findChromeBrowser();
  return browser != null ? browser.getName() : "";
}
 
Example #23
Source File: ChromeExecutableTab.java    From wildwebdeveloper with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean isChrome(IBrowserDescriptor desc) {
	return desc != null && (desc.getName().toLowerCase().contains("chrom") || (desc.getLocation() != null && desc.getLocation().toLowerCase().contains("chrom")));
}
 
Example #24
Source File: ChromeExecutableTab.java    From wildwebdeveloper with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void createControl(Composite parent) {
	Composite res = new Composite(parent, SWT.NONE);
	res.setLayout(new GridLayout(2, false));

	new Label(res, SWT.NONE).setText(Messages.ChromeAttachTab_runWith);
	browserToUse = new ComboViewer(res, SWT.VERTICAL | SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
	browserToUse.setContentProvider(new ArrayContentProvider());
	browserToUse.setLabelProvider(new BrowserLabelProvider());
	proposals = new LinkedList<>();
	proposals.add(""); //$NON-NLS-1$
	proposals.addAll(BrowserManager.getInstance().getWebBrowsers().stream().filter(ChromeExecutableTab::isChrome).collect(Collectors.toList()));
	browserToUse.setInput(proposals);
	browserToUse.addPostSelectionChangedListener(e -> {
		setDirty(true);
		updateLaunchConfigurationDialog();
	});

	Link link = new Link(res, SWT.NONE);
	link.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1));
	link.setText(Messages.ChromeAttachTab_browserPreferences);
	link.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
		Dialog dialog = PreferencesUtil.createPreferenceDialogOn(link.getShell(), "org.eclipse.ui.browser.preferencePage", null, null); //$NON-NLS-1$
		dialog.open();
		List<IBrowserDescriptor> previous = proposals.stream().filter(IBrowserDescriptor.class::isInstance).map(IBrowserDescriptor.class::cast).collect(Collectors.toList());
		List<IBrowserDescriptor> next = BrowserManager.getInstance().getWebBrowsers();
		List<IBrowserDescriptor> toRemove = new LinkedList<>(previous);
		toRemove.removeAll(next);
		proposals.removeAll(toRemove);
		List<IBrowserDescriptor> toAdd = new LinkedList<>(next);
		toAdd.removeAll(previous);
		toAdd.removeIf(browser -> !isChrome(browser));
		proposals.addAll(toAdd);
		if (!(toAdd.isEmpty() && toRemove.isEmpty())) {
			browserToUse.refresh();
			if (browserToUse.getSelection().isEmpty()) {
				browserToUse.setSelection(new StructuredSelection("")); //$NON-NLS-1$
			}
		}
	}));
	
	setControl(res);
}
 
Example #25
Source File: BrowserSelectionBlock.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 votes vote down vote up
void browserSelected(IBrowserDescriptor browserDescriptor, IStatus status);