Java Code Examples for org.eclipse.swt.program.Program#findProgram()

The following examples show how to use org.eclipse.swt.program.Program#findProgram() . 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: SearchSubsUtils.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
private static void launchURL(String s) {
	Program program = Program.findProgram(".html");
	if (program != null && program.getName().contains("Chrome")) {
		try {
			Field field = Program.class.getDeclaredField("command");
			field.setAccessible(true);
			String command = (String) field.get(program);
			command = command.replaceAll("%[1lL]", Matcher.quoteReplacement(s));
			command = command.replace(" --", "");
			PluginInitializer.getDefaultInterface().getUtilities().createProcess(command + " -incognito");
		} catch (Exception e1) {
			e1.printStackTrace();
			Utils.launch(s);
		}
	} else {
		Utils.launch(s);
	}
}
 
Example 2
Source File: UIFunctionsImpl.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean
isProgramInstalled(
	String extension,
	String name )
{
	if ( !extension.startsWith( "." )){

		extension = "." + extension;
	}

	Program program = Program.findProgram( extension );

	return( program == null ? false:(program.getName().toLowerCase(Locale.US)
		.contains(name.toLowerCase(Locale.US))));
}
 
Example 3
Source File: AuthorizationCodeInstalledAppTalend.java    From components with Apache License 2.0 6 votes vote down vote up
public static void browseWithProgramLauncher(String url) {
    Preconditions.checkNotNull(url);
    LOG.warn("Trying to open '{}'...", url);
    String osName = System.getProperty("os.name");
    String osNameMatch = osName.toLowerCase();
    if (osNameMatch.contains("linux")) {
        if (Program.findProgram("hmtl") == null) {
            try {
                Runtime.getRuntime().exec("xdg-open " + url);
                return;
            } catch (IOException e) {
                LOG.error("Failed to open url via xdg-open: {}.", e.getMessage());
            }
        }
    }
    Program.launch(url);
}
 
Example 4
Source File: ExternalLink.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public boolean doXRef(String refProvider, String refID){
	try {
		int r = refID.lastIndexOf('.');
		String ext = ""; //$NON-NLS-1$
		if (r != -1) {
			ext = refID.substring(r + 1);
		}
		Program proggie = Program.findProgram(ext);
		if (proggie != null) {
			proggie.execute(refID);
		} else {
			if (Program.launch(refID) == false) {
				Runtime.getRuntime().exec(refID);
			}
		}
	} catch (Exception ex) {
		ElexisStatus status =
			new ElexisStatus(ElexisStatus.ERROR, Hub.PLUGIN_ID, ElexisStatus.CODE_NONE,
				Messages.ExternalLink_CouldNotStartFile, ex);
		StatusManager.getManager().handle(status);
	}
	
	return true;
}
 
Example 5
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 6
Source File: ImportProjectWizardPage2.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Image getImage(Object element) {
	if (element instanceof ProjectResource) {
		ProjectResource proResource = (ProjectResource) element;
		String fileName = proResource.getLabel();
		if (proResource.isProject()) {
			return projectImg;
		} else if (proResource.isFolder()) {
			return folderImg;
		} else if (fileName.endsWith(".hsxliff")) {
			return hsXLiffImg;
		} else if (fileName.endsWith(".html")) {
			return htmlImg;
		} else {
			int index = fileName.lastIndexOf(".");
			if (index != -1) {
				String extension = fileName.substring(index, fileName.length());
				if (imgMap.containsKey(extension)) {
					return imgMap.get(extension);
				}
				Program program = Program.findProgram(extension);
				if (program != null) {
					ImageData imageData = program.getImageData();
					if (imageData != null) {
						Image img = new Image(getShell().getDisplay(), imageData);
						imgMap.put(extension, img);
						return img;
					}
				}
			}
		}
	}
	return defaultImg;
}
 
Example 7
Source File: ImportProjectWizardPage2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Image getImage(Object element) {
	if (element instanceof ProjectResource) {
		ProjectResource proResource = (ProjectResource) element;
		String fileName = proResource.getLabel();
		if (proResource.isProject()) {
			return projectImg;
		}else if (proResource.isFolder()) {
			return folderImg;
		}else if (fileName.endsWith(".hsxliff")) {
			return hsXLiffImg;
		}else if (fileName.endsWith(".html")) {
			return htmlImg;
		}else {
			int index = fileName.lastIndexOf(".");
			if (index != -1) {
				String extension = fileName.substring(index, fileName.length());
				if (imgMap.containsKey(extension)) {
					return imgMap.get(extension);
				}
				Program program = Program.findProgram(extension);
				if (program != null) {
					ImageData imageData = program.getImageData();
					if (imageData != null) {
						Image img = new Image(getShell().getDisplay(), imageData);
						imgMap.put(extension, img);
						return img;
					}
				}
			}
		}
	}
	return defaultImg;
}
 
Example 8
Source File: OpenUIDLogCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final Optional<File> logFile = UIDesignerServerManager.getInstance().getLogFile();
    if (logFile.isPresent() && logFile.get().exists()) {
        try {
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(logFile.get().toURI());
            final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR);
            final long fileSize = localFile.length();
            if (fileSize < MAX_FILE_SIZE) {
                IDE.openEditorOnFileStore(page, fileStore);
            } else {
                Program textEditor = Program.findProgram("log");
                if (textEditor == null) {
                    textEditor = Program.findProgram("txt");
                }
                if (textEditor == null || !textEditor.execute(localFile.getAbsolutePath())) {
                    showWarningMessage(localFile);
                }
            }
            return true;
        } catch (final Exception e) {
            BonitaStudioLog.error(e);
            return false;
        }
    }
    MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            Messages.unableTofindLogTitle, Messages.unableTofindLogMessage);
    return false;
}
 
Example 9
Source File: OpenEngineLogCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final File logFile = BOSWebServerManager.getInstance().getBonitaLogFile();
    if (logFile != null && logFile.exists()) {
        IFileStore fileStore;
        try {
            fileStore = EFS.getLocalFileSystem().getStore(logFile.toURI());
            final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR);
            final long fileSize = localFile.length();
            if (fileSize < MAX_FILE_SIZE) {
                IDE.openEditorOnFileStore(page, fileStore);
            } else {
                Program textEditor = Program.findProgram("log");
                if (textEditor == null) {
                    textEditor = Program.findProgram("txt");
                }
                if (textEditor != null) {
                    final boolean success = textEditor.execute(localFile.getAbsolutePath());
                    if (!success) {
                        showWarningMessage(localFile);
                    }
                } else {
                    showWarningMessage(localFile);
                }
            }

            return Boolean.TRUE;
        } catch (final Exception e) {
            BonitaStudioLog.error(e);
            return Boolean.FALSE;
        }
    } else {
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.unableTofindLogTitle, Messages.unableTofindLogMessage);
        return Boolean.FALSE;
    }
}
 
Example 10
Source File: DisplayLabDokumenteDialog.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Opens a document in a system viewer
 * 
 * @param document
 */
private void openDocument(String docName){
	Patient patient = ElexisEventDispatcher.getSelectedPatient();
	try {
		if (this.docManager != null) {
			java.util.List<IOpaqueDocument> documentList =
				this.docManager.listDocuments(patient, null, docName, null, new TimeSpan(
					this.date, this.date), null);
			if (documentList == null || documentList.size() == 0) {
				throw new IOException(MessageFormat.format("Dokument {0} nicht vorhanden!",
					docName));
			}
			int counter = 0;
			for (IOpaqueDocument document : documentList) {
				String fileExtension = null; 
				try {
					MimeType docMimeType = new MimeType(document.getMimeType());
					fileExtension = MimeTool.getExtension(docMimeType.toString());
				}
				catch(MimeTypeParseException mpe) {
					fileExtension = FileTool.getExtension(document.getMimeType());
					
					if(fileExtension == null) {
						fileExtension = FileTool.getExtension(docName);
					}
				}
				
				if(fileExtension == null) {
					fileExtension = "";
				}
				
				File temp = File.createTempFile("lab" + counter, "doc." + fileExtension); //$NON-NLS-1$ //$NON-NLS-2$
				temp.deleteOnExit();
				byte[] b = document.getContentsAsBytes();
				if (b == null) {
					throw new IOException("Dokument ist leer!");
				}
				FileOutputStream fos = new FileOutputStream(temp);
				fos.write(b);
				fos.close();
				
				Program proggie = Program.findProgram(FileTool.getExtension(fileExtension));
				if (proggie != null) {
					proggie.execute(temp.getAbsolutePath());
				} else {
					if (Program.launch(temp.getAbsolutePath()) == false) {
						Runtime.getRuntime().exec(temp.getAbsolutePath());
					}
				}
				counter++;
			}
		}
	} catch (Exception ex) {
		SWTHelper.showError("Fehler beim Öffnen des Dokumentes", ex.getMessage());
	}
}