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.files.*; 29 import org.openharmonise.vfs.*; 30 import org.openharmonise.vfs.context.*; 31 import org.openharmonise.vfs.gui.*; 32 33 34 41 public class ActionSynchronise extends AbstractHIMAction implements HIMAction { 42 43 public static String ACTION_NAME = "SYNC_FILE"; 44 45 48 private static final String WAIT_LABEL = "SYNC-ACTION"; 49 52 public ActionSynchronise() { 53 super(); 54 this.setup(); 55 } 56 57 60 public ActionSynchronise(VirtualFile vfFile) { 61 super(vfFile); 62 this.setup(); 63 } 64 65 69 private void setup() { 70 RuleGroup andGroup = new RuleGroup(); 71 SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_SYNC); 72 andGroup.addEnableRule(null); 73 IsLockedByOtherUser lockRule = new IsLockedByOtherUser(); 74 lockRule.setResultComparator(false); 75 andGroup.addEnableRule(lockRule); 76 super.addEnableRule(andGroup); 77 } 78 79 82 public void actionPerformed(ActionEvent ae) { 83 StateHandler.getInstance().addWait(WAIT_LABEL); 84 String sFileName = null; 85 86 try { 87 VirtualFile vfFile = ContextHandler.getInstance().getLastEvent(ContextType.CONTEXT_FILES).getVFS().getVirtualFile( ContextHandler.getInstance().getLastEvent(ContextType.CONTEXT_FILES).getPath() ).getResource(); 88 89 FilesSynchroniser filesSyncer = new FilesSynchroniser(); 90 boolean success = filesSyncer.syncFile(vfFile); 91 if(success){ 92 vfFile.unlock(); 93 } 94 } catch (Exception e) { 95 e.printStackTrace(); 96 } finally { 97 StateHandler.getInstance().removeWait(WAIT_LABEL); 98 } 99 } 100 101 104 public String getText() { 105 return "Submit Resource"; 106 } 107 108 111 public String getToolTip() { 112 return this.getDescription(); 113 } 114 115 118 public Icon getIcon() { 119 return IconManager.getInstance().getIcon("16-command-sync-all.gif"); 120 } 121 122 125 public String getMnemonic() { 126 return "S"; 127 } 128 129 132 public String getDescription() { 133 return "Submits the current resource to the server"; 134 } 135 136 139 public int getAcceleratorKeycode() { 140 return 0; 141 } 142 143 146 public int getAcceleratorMask() { 147 return 0; 148 } 149 150 153 public boolean isEnabled(ContextEvent ce) { 154 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_FILES) { 155 if(ce!=null && ce.getVFS()!=null && ce.getPath()!=null && ce.getVFS().getVirtualFile(ce.getPath())!=null && ce.getVFS().getVirtualFile(ce.getPath()).getResource().isChanged()) { 156 super.setEnabled(true); 157 return true; 158 } else { 159 super.setEnabled(false); 160 return false; 161 } 162 } else { 163 super.setEnabled(false); 164 return false; 165 } 166 } 167 168 } 169 | Popular Tags |