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

The following examples show how to use org.eclipse.swt.program.Program#launch() . 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: OpenBubbleChartHandler.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

	// get selection
	ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
	if (selection == null || !(selection instanceof IStructuredSelection)) {
		return null;
	}
	List<BubbleDataContainer> data = processSelectionData((IStructuredSelection) selection);

	boolean dataWrittenSuccessfully = false;
	try {
		// overwrite csv with new data
		dataWrittenSuccessfully = overwriteCSVFile(data);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	// open website in default browser
	if (dataWrittenSuccessfully) {
		Program.launch(Activator.getUrl() + "bubble.index.html");
	}

	return null;
}
 
Example 2
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 3
Source File: StartEditLocalDocumentHandler.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private void startEditLocal(Object object, ILocalDocumentService service, Shell parentShell){
	Optional<File> file = service.add(object, new IConflictHandler() {
		@Override
		public Result getResult(){
			if (MessageDialog.openQuestion(parentShell,
				Messages.StartEditLocalDocumentHandler_conflicttitle,
				Messages.StartEditLocalDocumentHandler_conflictmessage)) {
				return Result.KEEP;
			} else {
				return Result.OVERWRITE;
			}
		}
	});
	if (file.isPresent()) {
		Program.launch(file.get().getAbsolutePath());
	} else {
		MessageDialog.openError(parentShell, Messages.StartEditLocalDocumentHandler_errortitle,
			Messages.StartEditLocalDocumentHandler_errormessage);
	}
}
 
Example 4
Source File: TBXMakerDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private void displayHelp() {
	String curLang = CommonFunction.getSystemLanguage();
	StringBuffer sbHelp = new StringBuffer("help");
	if (Util.isWindows()) {
		sbHelp.append(File.separator).append("csv2tbxdoc").append(File.separator);
		if (curLang.equalsIgnoreCase("zh")) {
			sbHelp.append("tbxmaker_zh-cn.chm");
		} else {
			sbHelp.append("tbxmaker.chm");
		}
		Program.launch(PluginUtil.getConfigurationFilePath(sbHelp.toString()));
	} else {
		sbHelp.append(File.separator).append("csv2tbxdoc").append(File.separator);
		if (curLang.equalsIgnoreCase("zh")) {
			sbHelp.append("zh-cn");
		} else {
			sbHelp.append("en");
		}
		sbHelp.append(File.separator).append("toc.xml");
		PluginHelpDialog dialog = new PluginHelpDialog(getShell(), PluginUtil.getConfigurationFilePath(sbHelp.toString()),
				Messages.getString("dialog.TBXMakerDialog.helpDialogTitle"));
		dialog.open();
	}

}
 
Example 5
Source File: OpenCiteHandler.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

	// get selection
	ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
	if (selection == null || !(selection instanceof IStructuredSelection)) {
		return null;
	}
	Map<String, Integer> data = processSelectionData((IStructuredSelection) selection);

	boolean dataWrittenSuccessfully = false;
	try {
		// overwrite csv with new data
		dataWrittenSuccessfully = overwriteCSVFile(data);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	// call website on writen file
	if (dataWrittenSuccessfully) {
		Program.launch(Activator.getUrl() + "bar.index.html");
	}

	return null;
}
 
Example 6
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 7
Source File: HoverLocationListener.java    From typescript.java with MIT License 5 votes vote down vote up
private void handleHttpLink(URL url, Display display) {
	control.notifyDelayedInputChange(null);
	control.dispose(); // FIXME: should have protocol to hide,
						// rather than dispose

	// Open attached Javadoc links
	Program.launch(url.toExternalForm());
}
 
Example 8
Source File: LocationSelector.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private void showPath() {
    try{
        String path = VariableUtils.performStringSubstitution(getLocationTxt(), false);
        File f = new File(path);
        if (fileMode) {
            if (f.isFile()) {
                try {
                    ProcessBuilder builder = new ProcessBuilder(new String[] { 
                            "explorer.exe",  //$NON-NLS-1$
                            "/select,\"" + f.getCanonicalPath() + "\""});  //$NON-NLS-1$ //$NON-NLS-2$
                    builder.start();
                } catch (IOException exc) {
                    // Oops. can't show (or it is not windows?)
                    // Show in messagebox:
                    SWTFactory.ShowMessageBox(null, Messages.LocationSelector_SelectedFile, f.getCanonicalPath(), SWT.OK);
                }
            } else {
                MessageDialog.openWarning(text.getShell(), Messages.LocationSelector_SelectFile, Messages.LocationSelector_FileNotFound);
            }
        } else {
            if (f.isDirectory()) {
                Program.launch(f.getCanonicalPath());
            } else {
                MessageDialog.openWarning(text.getShell(), Messages.LocationSelector_OpenDir, Messages.LocationSelector_DirNotFound);
            }
        }
    } catch (Exception ex) {
        MessageDialog.openWarning(text.getShell(), Messages.LocationSelector_OpenLocation, Messages.LocationSelector_ErrorOccured + ": " + ex); //$NON-NLS-1$
    }
}
 
Example 9
Source File: XSLTransformationDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void okPressed() {
	String strSourcePath = txtSource.getText();
	String strXSLPath = txtXSL.getText();
	String strTargetPath = txtTarget.getText();
	if (strSourcePath.equals("")) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
				Messages.getString("dialog.XSLTransformationDialog.msg1"));
		return;
	}
	if (strXSLPath.equals("")) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
				Messages.getString("dialog.XSLTransformationDialog.msg2"));
		return;
	}
	if (strTargetPath.equals("")) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
				Messages.getString("dialog.XSLTransformationDialog.msg3"));
		return;
	}

	try {
		transform(strSourcePath, strXSLPath, strTargetPath);
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
				Messages.getString("dialog.XSLTransformationDialog.msg4"));
		if (btnOpenFile.getSelection()) {
			if (!Program.launch(strTargetPath)) {
				MessageDialog.openInformation(getShell(),
						Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
						Messages.getString("dialog.XSLTransformationDialog.msg5"));
			}
		}
		close();
	} catch (Exception e) {
		LOGGER.error(Messages.getString("dialog.XSLTransformationDialog.logger1"), e);
	}
}
 
Example 10
Source File: SelfHelpDisplay.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Displays the specified url. The url can contain query parameters to
 * identify how help displays the document
 */
private void displayHelpURL(String helpURL, boolean forceExternal) {
	if (!BaseHelpSystem.ensureWebappRunning()) {
		return;
	}
	if (BaseHelpSystem.getMode() == BaseHelpSystem.MODE_STANDALONE) {
		// wait for Display to be created
		SelfDisplayUtils.waitForDisplay();
	}

	try {
		if (helpURL == null || helpURL.length() == 0) {
			helpURL = getHelpDisplay().getHelpHome( WebappManager.getHost(),  WebappManager.getPort(), null);
		} else if (helpURL.startsWith("tab=")) { //$NON-NLS-1$
			String tab = helpURL.substring("tab=".length()); //$NON-NLS-1$
			helpURL = getHelpDisplay().getHelpHome( WebappManager.getHost(),  WebappManager.getPort(), tab);	
		} else if (helpURL.startsWith("topic=")) { //$NON-NLS-1$
			String topic = helpURL.substring("topic=".length()); //$NON-NLS-1$
			helpURL = getHelpDisplay().getHelpForTopic( topic, WebappManager.getHost(),  WebappManager.getPort());	
		} 
		
		
		String systemname = System.getProperty("os.name").toUpperCase();
		if (systemname.contains("LINUX") || systemname.contains("MAC OS X")) { 
			Program.launch(helpURL);
		}else if (systemname.contains("WINDOW")) { 
			BaseHelpSystem.getHelpBrowser(forceExternal).displayURL(helpURL);
		} 
		
	} catch (Exception e) {
		HelpBasePlugin
				.logError(
						"An exception occurred while launching help.  Check the log at " + Platform.getLogFileLocation().toOSString(), e); //$NON-NLS-1$
		BaseHelpSystem.getDefaultErrorUtil()
				.displayError(
						NLS.bind(HelpBaseResources.HelpDisplay_exceptionMessage, Platform.getLogFileLocation().toOSString()));
	}
}
 
Example 11
Source File: XSLTransformationDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void okPressed() {
	String strSourcePath = txtSource.getText();
	String strXSLPath = txtXSL.getText();
	String strTargetPath = txtTarget.getText();
	if (strSourcePath.equals("")) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
				Messages.getString("dialog.XSLTransformationDialog.msg1"));
		return;
	}
	if (strXSLPath.equals("")) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
				Messages.getString("dialog.XSLTransformationDialog.msg2"));
		return;
	}
	if (strTargetPath.equals("")) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
				Messages.getString("dialog.XSLTransformationDialog.msg3"));
		return;
	}

	try {
		transform(strSourcePath, strXSLPath, strTargetPath);
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
				Messages.getString("dialog.XSLTransformationDialog.msg4"));
		if (btnOpenFile.getSelection()) {
			if (!Program.launch(strTargetPath)) {
				MessageDialog.openInformation(getShell(),
						Messages.getString("dialog.XSLTransformationDialog.msgTitle"),
						Messages.getString("dialog.XSLTransformationDialog.msg5"));
			}
		}
		close();
	} catch (Exception e) {
		LOGGER.error(Messages.getString("dialog.XSLTransformationDialog.logger1"), e);
	}
}
 
Example 12
Source File: SelfHelpDisplay.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Displays the specified url. The url can contain query parameters to
 * identify how help displays the document
 */
private void displayHelpURL(String helpURL, boolean forceExternal) {
	if (!BaseHelpSystem.ensureWebappRunning()) {
		return;
	}
	if (BaseHelpSystem.getMode() == BaseHelpSystem.MODE_STANDALONE) {
		// wait for Display to be created
		SelfDisplayUtils.waitForDisplay();
	}

	try {
		if (helpURL == null || helpURL.length() == 0) {
			helpURL = getHelpDisplay().getHelpHome( WebappManager.getHost(),  WebappManager.getPort(), null);
		} else if (helpURL.startsWith("tab=")) { //$NON-NLS-1$
			String tab = helpURL.substring("tab=".length()); //$NON-NLS-1$
			helpURL = getHelpDisplay().getHelpHome( WebappManager.getHost(),  WebappManager.getPort(), tab);	
		} else if (helpURL.startsWith("topic=")) { //$NON-NLS-1$
			String topic = helpURL.substring("topic=".length()); //$NON-NLS-1$
			helpURL = getHelpDisplay().getHelpForTopic( topic, WebappManager.getHost(),  WebappManager.getPort());	
		} 
		
		
		String systemname = System.getProperty("os.name").toUpperCase();
		if (systemname.contains("LINUX") || systemname.contains("MAC OS X")) { 
			Program.launch(helpURL);
		}else if (systemname.contains("WINDOW")) { 
			BaseHelpSystem.getHelpBrowser(forceExternal).displayURL(helpURL);
		} 
		
	} catch (Exception e) {
		HelpBasePlugin
				.logError(
						"An exception occurred while launching help.  Check the log at " + Platform.getLogFileLocation().toOSString(), e); //$NON-NLS-1$
		BaseHelpSystem.getDefaultErrorUtil()
				.displayError(
						NLS.bind(HelpBaseResources.HelpDisplay_exceptionMessage, Platform.getLogFileLocation().toOSString()));
	}
}
 
Example 13
Source File: LoginServiceUi.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public VerificationCodeHolder obtainVerificationCodeFromExternalUserInteraction(String message) {
  LocalServerReceiver codeReceiver = createLocalServerReceiver();

  try {
    String redirectUrl = codeReceiver.getRedirectUri();
    if (!Program.launch(GoogleLoginService.getGoogleLoginUrl(redirectUrl))) {
      showErrorDialogHelper(
          Messages.getString("LOGIN_ERROR_DIALOG_TITLE"),
          Messages.getString("LOGIN_ERROR_CANNOT_OPEN_BROWSER"));
      return null;
    }

    String authorizationCode = showProgressDialogAndWaitForCode(codeReceiver);
    if (authorizationCode != null) {
      AnalyticsPingManager.getInstance().sendPingOnShell(shellProvider.getShell(),
          AnalyticsEvents.LOGIN_SUCCESS);

      return new VerificationCodeHolder(authorizationCode, redirectUrl);
    }
    return null;

  } catch (IOException ioe) {
    showErrorDialogHelper(Messages.getString("LOGIN_ERROR_DIALOG_TITLE"),
        Messages.getString("LOGIN_ERROR_LOCAL_SERVER_RUN", ioe.getLocalizedMessage()));
    return null;
  } finally {
    stopLocalServerReceiver(codeReceiver);
  }
}
 
Example 14
Source File: SWTApplication.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void openUrl(URL url) {
	Program.launch(url.toExternalForm());
}
 
Example 15
Source File: GiveFeedbackHandler.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Program.launch(URL);
    return null;
}
 
Example 16
Source File: EclipseGuiCallback.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean showDocument(URL u) {
    return Program.launch(u.toExternalForm());
}
 
Example 17
Source File: TextView.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public boolean openDocument(Brief doc){
	if (actBrief != null) {
		LocalLockServiceHolder.get().releaseLock(actBrief);
		actBrief.save(txt.getPlugin().storeToByteArray(), txt.getPlugin().getMimeType());
	}
	if (doc == null) {
		return false;
	} else {
		// test lock and set read only before opening the Brief
		LockResponse result = LocalLockServiceHolder.get().acquireLock(doc);
		if (result.isOk()) {
			txt.getPlugin().setParameter(null);
		} else {
			LockResponseHelper.showInfo(result, doc, log);
			txt.getPlugin().setParameter(Parameter.READ_ONLY);
		}
	}
	if (txt.open(doc) == true) {
		log.debug("TextView.openDocument: "); //$NON-NLS-1$
		actBrief = doc;
		setName();
		return true;
	} else {
		actBrief = null;
		LocalLockServiceHolder.get().releaseLock(doc);
		if (CoreHub.localCfg.get(Preferences.P_TEXT_SUPPORT_LEGACY, false) == true) {
			setName();
			String ext = MimeTool.getExtension(doc.getMimeType());
			if (ext.length() == 0) {
				log.warn("TextView.openDocument no extension found for mime type: " + doc.getMimeType()); //$NON-NLS-1$
				ext = "odt"; //$NON-NLS-1$
			}
			try {
				File tmp = File.createTempFile("elexis", "brief." + ext); //$NON-NLS-1$ //$NON-NLS-2$
				log.debug("TextView.openDocument createTempFile: " + tmp.getAbsolutePath() + " mime " + doc.getMimeType()); //$NON-NLS-1$ //$NON-NLS-2$
				tmp.deleteOnExit();
				byte[] buffer = doc.loadBinary();
				if (buffer == null) {
					log.warn("TextView.openDocument createTempFile [{}] -> loadBinary returned null array", doc.getId());
					return false;
				}
				try (ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
						FileOutputStream fos = new FileOutputStream(tmp);) {
					FileTool.copyStreams(bais, fos);
				}
				File file = new File(tmp.getAbsolutePath());
				file.setReadable(true);
				file.setExecutable(false);
				file.setWritable(false);
				return Program.launch(tmp.getAbsolutePath());
			} catch (IOException e) {
				ExHandler.handle(e);
			}
			return false;
		} else {
			log.warn("TextView.openDocument: Preferences do not allow alternative method of documents created with legacy text-plugins"); //$NON-NLS-1$
			// Do not show a message box, as this happens often when you load a document
			// with an invalid content. Eg. with demoDB and Rezept of Absolut Erfunden
			return false;
		}
	}
}
 
Example 18
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());
	}
}
 
Example 19
Source File: OpenFileWithValidAction.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Opens an editor on the given file resource.
 * @param file
 *            the file resource
 */
void openFile1(IFile file) throws Exception{
	try {
		boolean activate = OpenStrategy.activateOnOpen();
		if (editorDescriptor == null) {
			// 如果是nattble打开的,就验证其是否已经被打开
			if (!validIsopened(file)) {
				return;
			}
			String filePath = file.getFullPath().toOSString();
			// Bug #2519
			if (CommonFunction.validXlfExtensionByFileName(file.getName())
					|| (filePath.startsWith(File.separator + file.getProject().getName() + File.separator
							+ "Intermediate" + File.separator + "Report") && file.getName().endsWith(".html"))) {
				// 之前的这块验证 xliff 文件的代码是放在 nattable 打开时,现在改为在调用 nattable 打开之前
				// html 是不会验证路径的
				if (!file.getFullPath().getFileExtension().equals("html")) {
					if (XLFValidator.validateXliffFile(file)) {
						IDE.openEditor(page, file, activate);
					}
				}else {
					IDE.openEditor(page, file, activate);
				}
			} else {
				boolean openReult = Program.launch(file.getLocation().toOSString());
				if (!openReult) {
					MessageDialog.openWarning(page.getWorkbenchWindow().getShell(), WorkbenchNavigatorMessages.navigator_all_dialog_warning,
							MessageFormat.format(WorkbenchNavigatorMessages.actions_OpenFileWithValidAction_notFindProgram, new Object[]{file.getLocation().getFileExtension()}));
				}
			}
		} else {
			if (ensureFileLocal(file)) {
				if (!file.getFullPath().getFileExtension().equals("html")) {
					if (XLFValidator.validateXliffFile(file)) {
						page.openEditor(new FileEditorInput(file), editorDescriptor.getId(), activate);
					}
				}else {
					page.openEditor(new FileEditorInput(file), editorDescriptor.getId(), activate);
				}
			}
		}
	} catch (PartInitException e) {
		DialogUtil.openError(page.getWorkbenchWindow().getShell(),
				IDEWorkbenchMessages.OpenFileAction_openFileShellTitle, e.getMessage(), e);
	}
}
 
Example 20
Source File: BugReportCommandHandler.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  Program.launch(formatReportUrl());
  return null;
}