Project

General

Profile

« Previous | Next » 

Revision 0c3e5a5d

Added by Patrick Plitzner about 6 years ago

ref #6925 Implement utility method to open links in external browser

View differences:

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/OpenExternalHelpHandler.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
9 9

  
10 10
package eu.etaxonomy.taxeditor;
11 11

  
12
import java.net.MalformedURLException;
12
import java.io.IOException;
13 13
import java.net.URL;
14 14

  
15 15
import org.apache.log4j.Logger;
16 16
import org.eclipse.core.commands.AbstractHandler;
17 17
import org.eclipse.core.commands.ExecutionEvent;
18 18
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.ui.PartInitException;
20
import org.eclipse.ui.PlatformUI;
21
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
19

  
20
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
22 21

  
23 22
/**
24 23
 * <p>OpenExternalHelpHandler class.</p>
......
30 29
public class OpenExternalHelpHandler extends AbstractHandler {
31 30
	private static final Logger logger = Logger.getLogger(OpenExternalHelpHandler.class);
32 31

  
33
	/* (non-Javadoc)
34
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
35
	 */
36 32
	/** {@inheritDoc} */
37
	public Object execute(ExecutionEvent event) throws ExecutionException {
33
	@Override
34
    public Object execute(ExecutionEvent event) throws ExecutionException {
38 35
		String url = "http://wp5.e-taxonomy.eu/download/taxeditor/stable/EDITTaxonomicEditor-UserManual.pdf";
39
	
36

  
40 37
		try {
41
			PlatformUI.getWorkbench().getBrowserSupport().createBrowser
42
						(IWorkbenchBrowserSupport.AS_EXTERNAL, "aCustomId", "url", "url").openURL(new URL(url));
43
		} catch (PartInitException e) {
44
			logger.error(e);
45
			throw new RuntimeException(e);
46
		} catch (MalformedURLException e) {
47
			logger.error(e);
48
			throw new RuntimeException(e);
49
		}
38
            WorkbenchUtility.openWebpage(new URL(url));
39
        } catch (IOException| RuntimeException e) {
40
            logger.error(e);
41
            throw new RuntimeException(e);
42
        }
50 43

  
51 44
		return null;
52 45
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.ui.element;
11 11

  
12
import java.net.MalformedURLException;
12
import java.io.IOException;
13 13
import java.net.URI;
14 14

  
15 15
import org.eclipse.core.runtime.IStatus;
......
19 19
import org.eclipse.swt.events.SelectionEvent;
20 20
import org.eclipse.swt.widgets.Button;
21 21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.ui.PartInitException;
23
import org.eclipse.ui.PlatformUI;
24 22

  
25 23
import eu.etaxonomy.taxeditor.l10n.Messages;
26 24
import eu.etaxonomy.taxeditor.model.ImageResources;
27 25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28 26
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
27
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
29 28

  
30 29
/**
31 30
 * @author n.hoffmann
......
73 72
                URI uri = parseText();
74 73
                if(uri!=null){
75 74
                    try {
76
                        PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri.toURL());
77
                    } catch (PartInitException pie) {
75
                        WorkbenchUtility.openWebpage(uri.toURL());
76
                    } catch (IOException pie) {
78 77
                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie));
79
                    } catch (MalformedURLException mue) {
80
                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, mue));
81 78
                    } catch (IllegalArgumentException iae) {
82 79
                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
83 80
                    }
......
94 91

  
95 92

  
96 93

  
94

  
97 95
    /**
98 96
     * {@inheritDoc}
99 97
     */
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/OpenExternalAboutPlatformHandler.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.workbench;
11 11

  
12
import java.net.MalformedURLException;
12
import java.io.IOException;
13 13
import java.net.URL;
14 14

  
15 15
import org.apache.log4j.Logger;
16 16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.ui.PartInitException;
18
import org.eclipse.ui.PlatformUI;
19
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
20 17

  
21 18
/**
22 19
 * @author p.ciardelli
......
29 26

  
30 27
	@Execute
31 28
	public Object execute() {
32
		String url = "http://wp5.e-taxonomy.eu/";
29
		String url = "https://cybertaxonomy.eu/";
33 30

  
34 31
		try {
35
			PlatformUI.getWorkbench().getBrowserSupport().createBrowser
36
					(IWorkbenchBrowserSupport.AS_EXTERNAL, "aCustomId", "url", "url").openURL(new URL(url));
37
		} catch (PartInitException e) {
38
			logger.error(e);
39
			throw new RuntimeException(e);
40
		} catch (MalformedURLException e) {
41
			logger.error(e);
42
			throw new RuntimeException(e);
43
		}
32
            WorkbenchUtility.openWebpage(new URL(url));
33
        } catch (IOException| RuntimeException e) {
34
            logger.error(e);
35
            throw new RuntimeException(e);
36
        }
44 37

  
45 38
		return null;
46 39
	}
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/OpenExternalParserHelpHandler.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.workbench;
11 11

  
12
import java.net.MalformedURLException;
12
import java.io.IOException;
13 13
import java.net.URL;
14 14

  
15 15
import org.apache.log4j.Logger;
16 16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.ui.PartInitException;
18
import org.eclipse.ui.PlatformUI;
19
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
20 17

  
21 18
/**
22 19
 * <p>OpenExternalParserHelpHandler class.</p>
......
34 31
		String url = "http://dev.e-taxonomy.eu/trac/wiki/NameParserDocumentation";
35 32

  
36 33
		try {
37
			PlatformUI.getWorkbench().getBrowserSupport().createBrowser
38
						(IWorkbenchBrowserSupport.AS_EXTERNAL, "aCustomId", "url", "url").openURL(new URL(url));
39
		} catch (PartInitException e) {
40
			logger.error(e);
41
			throw new RuntimeException(e);
42
		} catch (MalformedURLException e) {
34
            WorkbenchUtility.openWebpage(new URL(url));
35
		} catch (IOException| RuntimeException e) {
43 36
			logger.error(e);
44 37
			throw new RuntimeException(e);
45 38
		}
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/WorkbenchUtility.java
9 9
package eu.etaxonomy.taxeditor.workbench;
10 10

  
11 11
import java.io.File;
12
import java.net.URL;
12 13
import java.util.List;
13 14

  
14 15
import org.eclipse.core.runtime.Platform;
......
19 20
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement;
20 21
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
21 22
import org.eclipse.e4.ui.workbench.modeling.EModelService;
23
import org.eclipse.swt.program.Program;
22 24

  
23 25
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
24 26
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
......
97 99
        }
98 100
        return null;
99 101
    }
102

  
103
    public static boolean openWebpage(URL url){
104
        return Program.launch(url.toString());
105
    }
100 106
}

Also available in: Unified diff