1 19 package org.openharmonise.him.actions.file; 20 21 import java.awt.event.*; 22 23 import javax.swing.*; 24 25 import org.openharmonise.him.actions.*; 26 import org.openharmonise.him.actions.rules.*; 27 import org.openharmonise.him.context.StateHandler; 28 import org.openharmonise.him.window.messages.builders.*; 29 import org.openharmonise.him.window.session.*; 30 import org.openharmonise.vfs.*; 31 import org.openharmonise.vfs.context.*; 32 import org.openharmonise.vfs.gui.*; 33 import org.openharmonise.vfs.status.*; 34 35 36 43 public class ActionCreateCopy extends AbstractHIMAction implements HIMAction { 44 45 public static String ACTION_NAME = "CREATE_COPY"; 46 47 50 public ActionCreateCopy() { 51 super(); 52 this.setup(); 53 } 54 55 58 public ActionCreateCopy(VirtualFile vfFile) { 59 super(vfFile); 60 this.setup(); 61 } 62 63 67 private void setup() { 68 RuleGroup andGroup = new RuleGroup(); 69 andGroup.setGroupType(RuleGroup.GROUPTYPE_AND); 70 PathRule pathRule = new PathRule("/webdav/Archive/"); 71 pathRule.setResultComparator(false); 72 andGroup.addEnableRule(pathRule); 73 IsHistoricalRule histRule = new IsHistoricalRule(); 74 histRule.setResultComparator(false); 75 andGroup.addEnableRule(histRule); 76 SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_COPY); 77 andGroup.addEnableRule(secRule); 78 this.addEnableRule(andGroup); 79 } 80 81 84 public void actionPerformed(ActionEvent arg0) { 85 StateHandler.getInstance().addWait("COPY-ACTION"); 86 StatusData statusOverall = new VFSStatus(); 87 88 String sResourceTitle = null; 89 90 VirtualFile vfFile = this.getLastContextFile(); 91 if(vfFile.isVersionable() && vfFile.getState().equals(VirtualFile.STATE_PENDING) && ((VersionedVirtualFile)vfFile).getLiveVersionPath()!=null) { 92 vfFile = vfFile.getVFS().getVirtualFile( ((VersionedVirtualFile)vfFile).getLiveVersionPath() ).getResource(); 93 } 94 95 try { 96 StatusData status = vfFile.copy(vfFile.getFilePath(), "copy_of_" + vfFile.getFileName()); 97 statusOverall.addStatusData(status); 98 if( status.isOK() ) { 99 super.fireSessionEvent("Copy created", vfFile.getVFS(), vfFile.getFullPath(), SessionEventData.RESOURCE_COPIED); 100 } else { 101 102 } 103 104 sResourceTitle = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile); 105 } catch (Exception e) { 106 e.printStackTrace(System.err); 107 statusOverall.setStatusLevel(StatusData.LEVEL_ERROR); 108 } finally { 109 VFSMessageBuilder.getInstance().fireMessage(ActionCreateCopy.ACTION_NAME, statusOverall, sResourceTitle); 110 StateHandler.getInstance().removeWait("COPY-ACTION"); 111 } 112 113 } 114 115 118 public JMenuItem getMenuItem() { 119 JMenuItem menuItem = super.getMenuItem(); 120 menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) ); 121 122 return menuItem; 123 } 124 125 128 public String getDescription() { 129 return "Creates a copy of the resource in the current collection"; 130 } 131 132 135 public String getText() { 136 return "Create copy"; 137 } 138 139 142 public String getToolTip() { 143 return this.getDescription(); 144 } 145 146 149 public Icon getIcon() { 150 return IconManager.getInstance().getIcon("16-blank.gif"); 151 } 152 153 156 public int getAcceleratorKeycode() { 157 return KeyEvent.VK_C; 158 } 159 160 163 public String getMnemonic() { 164 return "C"; 165 } 166 167 170 public int getAcceleratorMask() { 171 return InputEvent.CTRL_MASK; 172 } 173 174 } 175 | Popular Tags |