1 19 package org.openharmonise.him.actions.file; 20 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.InputEvent ; 23 import java.awt.event.KeyEvent ; 24 25 import javax.swing.Icon ; 26 import javax.swing.JMenuItem ; 27 import javax.swing.KeyStroke ; 28 29 import org.openharmonise.him.actions.*; 30 import org.openharmonise.him.actions.rules.*; 31 import org.openharmonise.him.context.StateHandler; 32 import org.openharmonise.him.editors.*; 33 import org.openharmonise.him.harmonise.*; 34 import org.openharmonise.him.window.messages.builders.*; 35 import org.openharmonise.vfs.*; 36 import org.openharmonise.vfs.context.*; 37 import org.openharmonise.vfs.gui.*; 38 import org.openharmonise.vfs.status.*; 39 40 41 48 public class ActionOpen extends AbstractHIMAction implements HIMAction { 49 50 public static String ACTION_NAME = "OPEN"; 51 52 55 public ActionOpen() { 56 super(); 57 this.setup(); 58 } 59 60 63 public ActionOpen(VirtualFile vfFile) { 64 super(vfFile); 65 this.setup(); 66 } 67 68 72 private void setup() { 73 RuleGroup andGroup = new RuleGroup(); 74 andGroup.setGroupType(RuleGroup.GROUPTYPE_AND); 75 IsLockedByOtherUser lockRule = new IsLockedByOtherUser(); 76 lockRule.setResultComparator(false); 77 andGroup.addEnableRule(lockRule); 78 IsHistoricalRule histRule = new IsHistoricalRule(); 79 histRule.setResultComparator(false); 80 andGroup.addEnableRule(histRule); 81 EnableRule rule = new IsDirectoryRule(); 82 rule.setResultComparator(false); 83 andGroup.addEnableRule( rule ); 84 TabRule tabRule = new TabRule("Search"); 85 tabRule.setResultComparator(false); 86 andGroup.addEnableRule( tabRule ); 87 PathRule pathRule = new PathRule(HarmonisePaths.PATH_REPORTS_OUTPUT); 88 pathRule.setResultComparator(false); 89 andGroup.addEnableRule(pathRule); 90 this.addEnableRule(andGroup); 91 } 92 93 96 public void actionPerformed(ActionEvent arg0) { 97 StatusData statusOverall = new VFSStatus(); 98 VirtualFile vfFile = this.getLastContextFile(); 99 String sFileName = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile); 100 StateHandler.getInstance().addWait("OPEN-ACTION", "Opening editor..."); 101 try { 102 StatusData status = EditorController.getInstance().open(vfFile.getFullPath(), vfFile.getVFS()); 103 statusOverall.addStatusData(status); 104 } catch (Exception e) { 105 statusOverall.setStatusLevel(StatusData.LEVEL_ERROR); 106 e.printStackTrace(System.err); 107 } finally { 108 StateHandler.getInstance().removeWait("OPEN-ACTION"); 109 VFSMessageBuilder.getInstance().fireMessage(ActionOpen.ACTION_NAME, statusOverall, sFileName); 110 } 111 } 112 113 116 public JMenuItem getMenuItem() { 117 JMenuItem menuItem = super.getMenuItem(); 118 menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) ); 119 120 return menuItem; 121 } 122 123 126 public String getDescription() { 127 return "Opens the currently selected resource"; 128 } 129 130 133 public String getText() { 134 return "Open"; 135 } 136 137 140 public String getToolTip() { 141 return this.getDescription(); 142 } 143 144 147 public Icon getIcon() { 148 return IconManager.getInstance().getIcon("16-command-edit.gif"); 149 } 150 151 154 public int getAcceleratorKeycode() { 155 return KeyEvent.VK_O; 156 } 157 158 161 public String getMnemonic() { 162 return "O"; 163 } 164 165 168 public int getAcceleratorMask() { 169 return InputEvent.CTRL_MASK; 170 } 171 172 } 173 | Popular Tags |