1 19 20 package org.netbeans.modules.subversion.ui.status; 21 22 import org.netbeans.modules.subversion.util.*; 23 import org.openide.util.NbBundle; 24 import org.openide.nodes.Node; 25 import org.openide.cookies.*; 26 import org.openide.filesystems.FileObject; 27 import org.openide.filesystems.FileUtil; 28 import org.openide.loaders.DataObject; 29 import org.openide.loaders.DataObjectNotFoundException; 30 31 import javax.swing.*; 32 import java.awt.event.ActionEvent ; 33 import java.io.File ; 34 35 40 public class OpenInEditorAction extends AbstractAction { 41 42 public OpenInEditorAction() { 43 super(NbBundle.getBundle(OpenInEditorAction.class).getString("CTL_Synchronize_Popup_OpenInEditor")); 44 setEnabled(isActionEnabled()); 45 } 46 47 private boolean isActionEnabled() { 48 File [] files = SvnUtils.getCurrentContext(null).getFiles(); 49 for (File file : files) { 50 if (file.canRead()) return true; 51 } 52 return false; 53 } 54 55 public void actionPerformed(ActionEvent e) { 56 File [] files = SvnUtils.getCurrentContext(null).getFiles(); 57 for (File file : files) { 58 FileObject fo = FileUtil.toFileObject(file); 59 if (fo != null) { 60 try { 61 openDataObjectByCookie(DataObject.find(fo)); 62 } catch (DataObjectNotFoundException ex) { 63 } 65 } 66 } 67 } 68 69 private final boolean openDataObjectByCookie(DataObject dataObject) { 70 Node.Cookie cookie; 71 Class cookieClass; 72 if ((((cookie = dataObject.getCookie(cookieClass = EditorCookie.Observable.class)) != null 73 || (cookie = dataObject.getCookie(cookieClass = EditorCookie.class)) != null)) 74 || (cookie = dataObject.getCookie(cookieClass = OpenCookie.class)) != null 75 || (cookie = dataObject.getCookie(cookieClass = EditCookie.class)) != null 76 || (cookie = dataObject.getCookie(cookieClass = ViewCookie.class)) != null) { 77 return openByCookie(cookie, cookieClass); 78 } 79 return false; 80 } 81 82 private boolean openByCookie(Node.Cookie cookie, Class cookieClass) { 83 if ((cookieClass == EditorCookie.class) 84 || (cookieClass == EditorCookie.Observable.class)) { 85 ((EditorCookie) cookie).open(); 86 } else if (cookieClass == OpenCookie.class) { 87 ((OpenCookie) cookie).open(); 88 } else if (cookieClass == EditCookie.class) { 89 ((EditCookie) cookie).edit(); 90 } else if (cookieClass == ViewCookie.class) { 91 ((ViewCookie) cookie).view(); 92 } else { 93 throw new IllegalArgumentException ("Reopen #58766: " + cookieClass); } 95 return true; 96 } 97 } 98 | Popular Tags |