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 ActionUnlock extends AbstractHIMAction implements HIMAction { 44 45 public static String ACTION_NAME = "UNLOCK"; 46 47 50 private static final String WAIT_LABEL = "UNLOCK-ACTION"; 51 54 public ActionUnlock() { 55 super(); 56 this.setup(); 57 } 58 59 62 public ActionUnlock(VirtualFile vfFile) { 63 super(vfFile); 64 this.setup(); 65 } 66 67 71 private void setup() { 72 RuleGroup andGroup = new RuleGroup(); 73 andGroup.setGroupType(RuleGroup.GROUPTYPE_AND); 74 PathRule pathRule = new PathRule("/webdav/Archive/"); 75 pathRule.setResultComparator(false); 76 andGroup.addEnableRule(pathRule); 77 IsHistoricalRule histRule = new IsHistoricalRule(); 78 histRule.setResultComparator(false); 79 andGroup.addEnableRule(histRule); 80 SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_UNLOCK); 81 andGroup.addEnableRule(secRule); 82 this.addEnableRule(andGroup); 83 } 84 85 88 public void actionPerformed(ActionEvent arg0) { 89 StateHandler.getInstance().addWait(WAIT_LABEL); 90 StatusData statusOverall = new VFSStatus(); 91 92 String sFileName = null; 93 String sLockUser = null; 94 try { 95 if(this.getLastContextFile().isLocked()) { 96 sLockUser = this.getLastContextFile().getLockOwner(); 97 } 98 sFileName = this.getLastContextFile().getVFS().getVirtualFileSystemView().getDisplayName(this.getLastContextFile()); 99 StatusData status = this.getLastContextFile().unlock(); 100 statusOverall.addStatusData(status); 101 102 if(status.isOK()) { 103 super.fireSessionEvent("Unlocked", this.getLastContextFile().getVFS(), this.getLastContextFile().getFullPath(), SessionEventData.RESOURCE_UNLOCKED); 104 } else { 105 106 } 107 } catch (Exception e) { 108 e.printStackTrace(System.err); 109 statusOverall.setStatusLevel(StatusData.LEVEL_ERROR); 110 } finally { 111 VFSMessageBuilder.getInstance().fireMessage(ActionUnlock.ACTION_NAME, statusOverall, sFileName, sLockUser); 112 StateHandler.getInstance().removeWait(WAIT_LABEL); 113 } 114 } 115 116 119 public JMenuItem getMenuItem() { 120 JMenuItem menuItem = super.getMenuItem(); 121 menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) ); 122 123 return menuItem; 124 } 125 126 129 public String getDescription() { 130 return "Unlocks the currently selected resource to allow others to edit it"; 131 } 132 133 136 public String getText() { 137 return "Unlock"; 138 } 139 140 143 public String getToolTip() { 144 return this.getDescription(); 145 } 146 147 150 public Icon getIcon() { 151 return IconManager.getInstance().getIcon("16-blank.gif"); 152 } 153 154 157 public int getAcceleratorKeycode() { 158 return KeyEvent.VK_U; 159 } 160 161 164 public String getMnemonic() { 165 return "U"; 166 } 167 168 171 public int getAcceleratorMask() { 172 return InputEvent.CTRL_MASK; 173 } 174 175 178 public boolean isEnabled(ContextEvent ce) { 179 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_FILES && super.isEnabled(ce)) { 180 VirtualFile vfFile = ce.getVFS().getVirtualFile(ce.getPath()).getResource(); 181 if(vfFile!=null) { 182 this.setEnabled(vfFile.isLocked()); 183 return vfFile.isLocked(); 184 } else { 185 return false; 186 } 187 } else { 188 this.setEnabled(false); 189 return false; 190 } 191 } 192 } 193 | Popular Tags |