1 19 package org.netbeans.modules.versioning.system.cvss.ui.history; 20 21 import org.netbeans.modules.versioning.spi.VCSContext; 22 import org.netbeans.modules.versioning.util.Utils; 23 import org.netbeans.modules.versioning.system.cvss.VersionsCache; 24 import org.openide.util.NbBundle; 25 import org.openide.util.HelpCtx; 26 import org.openide.DialogDescriptor; 27 import org.openide.DialogDisplayer; 28 import org.openide.cookies.EditorCookie; 29 import org.openide.loaders.DataObject; 30 import org.openide.loaders.DataObjectNotFoundException; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 34 import javax.swing.*; 35 import java.io.*; 36 import java.awt.event.ActionEvent ; 37 import java.awt.Dialog ; 38 39 44 public class ViewRevisionAction extends AbstractAction implements Runnable { 45 46 private final VCSContext ctx; 47 private ViewRevisionPanel settings; 48 49 public ViewRevisionAction(VCSContext ctx) { 50 this(Utils.getActionName(ViewRevisionAction.class, "CTL_MenuItem_ViewRevision", ctx), ctx); 51 } 52 53 public ViewRevisionAction(String name, VCSContext ctx) { 54 super(name); 55 this.ctx = ctx; 56 } 57 58 public boolean isEnabled() { 59 return ctx.getRootFiles().size() > 0; 60 } 61 62 public void actionPerformed(ActionEvent e) { 63 64 String title = NbBundle.getMessage(ViewRevisionAction.class, "CTL_ViewRevisionDialog_Title", Utils.getContextDisplayName(ctx)); 66 settings = new ViewRevisionPanel(ctx); 67 68 JButton view = new JButton(NbBundle.getMessage(ViewRevisionAction.class, "CTL_ViewRevisionDialog_Action_View")); settings.putClientProperty("OKButton", view); settings.refreshComponents(); 71 view.setToolTipText(NbBundle.getMessage(ViewRevisionAction.class, "TT_ViewRevisionDialog_Action_View")); DialogDescriptor descriptor = new DialogDescriptor( 73 settings, 74 title, 75 true, 76 new Object [] { view, DialogDescriptor.CANCEL_OPTION }, 77 view, 78 DialogDescriptor.DEFAULT_ALIGN, 79 new HelpCtx(ViewRevisionAction.class), 80 null); 81 descriptor.setClosingOptions(null); 82 Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor); 83 dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ViewRevisionAction.class, "ACSD_ViewRevisionDialog")); dialog.setVisible(true); 85 if (descriptor.getValue() != view) return; 86 87 settings.saveSettings(); 88 Utils.createTask(this).schedule(0); 89 } 90 91 public void run() { 92 final String revision = settings.getRevision(); 93 File tempFolder = Utils.getTempFolder(); 94 tempFolder.deleteOnExit(); 95 for (File file : ctx.getRootFiles()) { 96 if (file.isDirectory()) continue; 97 try { 98 File original = VersionsCache.getInstance().getRemoteFile(file, revision, null); 99 File daoFile = new File(tempFolder, file.getName()); 100 Utils.copyStreamsCloseAll(new FileOutputStream(daoFile), new FileInputStream(original)); 101 daoFile.deleteOnExit(); 102 final FileObject fo = FileUtil.toFileObject(daoFile); 103 try { 104 DataObject dao = DataObject.find(fo); 105 final EditorCookie ec = dao.getCookie(EditorCookie.class); 106 if (ec != null) { 107 SwingUtilities.invokeLater(new Runnable () { 108 public void run() { 109 Utils.openFile(fo, revision); 110 } 111 }); 112 } 113 } catch (DataObjectNotFoundException e) { 114 } 116 } catch (Exception e) { 117 } 119 } 120 } 121 122 } 123 | Popular Tags |