1 package org.robsite.extension.rss;
2 import java.net.URL;
3 import oracle.ide.Ide;
4 import oracle.ide.addin.AbstractCommand;
5 import oracle.ide.addin.Command;
6 import oracle.ide.addin.Context;
7 import oracle.ide.net.URLFactory;
8 import oracle.ide.webbrowser.BrowserRunner;
9 import org.robsite.extension.rss.model.Channel;
10 import org.robsite.extension.rss.model.Item;
11
12 public class OpenInBrowserCommand extends AbstractCommand
13 {
14 public OpenInBrowserCommand()
15 {
16 super( Commands.id( Commands.OPEN_IN_BROWSER ),
17 Command.NO_CHANGE );
18 }
19
20 public int doit() throws Exception
21 {
22 Context context = getContext();
23 NewsDockableWindow window = (NewsDockableWindow) context.getView();
24
25 String url = null;
26
27 if ( context.getEvent().getSource() == window.getPanel().getChannelList() )
28 {
29 Channel channel = (Channel) window.getPanel().getSelectedChannel();
30 if ( channel != null )
31 {
32 url = channel.getLink();
33 }
34 }
35 else if ( context.getEvent().getSource() == window.getPanel().getItemTable() )
36 {
37 if ( context.getSelection() != null && context.getSelection().length == 1 )
38 {
39 Item item = (Item) context.getSelection()[0];
40 url = item.getLink();
41
42
43 Commands.getAction( Commands.MARK_AS_READ ).performAction( context );
44 }
45 }
46
47 if ( url != null )
48 {
49 URL theURL = URLFactory.newURL( url );
50 BrowserRunner.getBrowserRunner().runBrowserOnURL(
51 theURL, null, null
52 );
53 return OK;
54 }
55
56 return CANCEL;
57
58 }
59 }