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.vfs.*; 30 import org.openharmonise.vfs.context.*; 31 import org.openharmonise.vfs.gui.*; 32 import org.openharmonise.vfs.status.*; 33 34 35 42 public class ActionLock extends AbstractHIMAction implements HIMAction { 43 44 public static String ACTION_NAME = "LOCK"; 45 46 49 public ActionLock() { 50 super(); 51 this.setup(); 52 } 53 54 57 public ActionLock(VirtualFile vfFile) { 58 super(vfFile); 59 this.setup(); 60 } 61 62 66 private void setup() { 67 RuleGroup andGroup = new RuleGroup(); 68 andGroup.setGroupType(RuleGroup.GROUPTYPE_AND); 69 PathRule pathRule = new PathRule("/webdav/Archive/"); 70 pathRule.setResultComparator(false); 71 andGroup.addEnableRule(pathRule); 72 IsHistoricalRule histRule = new IsHistoricalRule(); 73 histRule.setResultComparator(false); 74 andGroup.addEnableRule(histRule); 75 SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_LOCK); 76 andGroup.addEnableRule(secRule); 77 this.addEnableRule(andGroup); 78 } 79 80 83 public void actionPerformed(ActionEvent arg0) { 84 StateHandler.getInstance().addWait("LOCK-ACTION"); 85 StatusData statusOverall = new VFSStatus(); 86 87 String sFileName = null; 88 String sLockUser = null; 89 try { 90 if(this.getLastContextFile().isLocked()) { 91 sLockUser = this.getLastContextFile().getLockOwner(); 92 } 93 sFileName = this.getLastContextFile().getVFS().getVirtualFileSystemView().getDisplayName(this.getLastContextFile()); 94 StatusData status = this.getLastContextFile().lock(); 95 statusOverall.addStatusData(status); 96 97 if(status.isOK()) { 98 } else { 100 } 101 } catch (Exception e) { 102 e.printStackTrace(System.err); 103 statusOverall.setStatusLevel(StatusData.LEVEL_ERROR); 104 } finally { 105 VFSMessageBuilder.getInstance().fireMessage(ActionLock.ACTION_NAME, statusOverall, sFileName, sLockUser); 106 StateHandler.getInstance().removeWait("LOCK-ACTION"); 107 } 108 } 109 110 113 public JMenuItem getMenuItem() { 114 JMenuItem menuItem = super.getMenuItem(); 115 menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) ); 116 117 return menuItem; 118 } 119 120 123 public String getDescription() { 124 return "Locks the currently selected resource so that others cannot edit it"; 125 } 126 127 130 public String getText() { 131 return "Lock"; 132 } 133 134 137 public String getToolTip() { 138 return this.getDescription(); 139 } 140 141 144 public Icon getIcon() { 145 return IconManager.getInstance().getIcon("16-command-lock.gif"); 146 } 147 148 151 public int getAcceleratorKeycode() { 152 return KeyEvent.VK_L; 153 } 154 155 158 public String getMnemonic() { 159 return "L"; 160 } 161 162 165 public int getAcceleratorMask() { 166 return InputEvent.CTRL_MASK; 167 } 168 169 170 171 174 public boolean isEnabled(ContextEvent ce) { 175 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_FILES && super.isEnabled(ce)) { 176 VirtualFile vfFile = ce.getVFS().getVirtualFile(ce.getPath()).getResource(); 177 if(vfFile!=null) { 178 this.setEnabled(!vfFile.isLocked()); 179 return !vfFile.isLocked(); 180 } else { 181 return false; 182 } 183 } else { 184 this.setEnabled(false); 185 return false; 186 } 187 } 188 189 } 190 | Popular Tags |