1 19 package org.openharmonise.him.actions.publish; 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.window.messages.builders.*; 34 import org.openharmonise.vfs.*; 35 import org.openharmonise.vfs.context.*; 36 import org.openharmonise.vfs.gui.*; 37 import org.openharmonise.vfs.status.*; 38 39 40 47 public class ActionPreview extends AbstractHIMAction implements HIMAction { 48 49 public static String ACTION_NAME = "PREVIEW"; 50 51 54 public ActionPreview() { 55 super(); 56 this.setup(); 57 } 58 59 62 public ActionPreview(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 75 EnableRule rule = new IsDirectoryRule(); 76 rule.setResultComparator(false); 77 andGroup.addEnableRule( rule ); 78 79 RuleGroup orGroup = new RuleGroup(); 80 orGroup.setGroupType(RuleGroup.GROUPTYPE_OR); 81 82 orGroup.addEnableRule(new PathRule("/webdav/Content/Documents")); 83 orGroup.addEnableRule(new PathRule("/webdav/Website/Page Definition")); 84 orGroup.addEnableRule(new PathRule( 85 "/webdav/Website/Composition/Page Templates")); 86 orGroup.addEnableRule(new PathRule("/webdav/Content/Assets")); 87 orGroup.addEnableRule(new PathRule("/webdav/Document")); 88 orGroup.addEnableRule(new PathRule("/webdav/Webpage")); 89 orGroup.addEnableRule(new PathRule("/webdav/XMLResource")); 90 orGroup.addEnableRule(new PathRule("/webdav/Assets")); 91 92 andGroup.addEnableRule(orGroup); 93 94 super.addEnableRule(andGroup); 95 } 96 97 102 public void actionPerformed(ActionEvent arg0) { 103 StatusData statusOverall = new VFSStatus(); 104 VirtualFile vfFile = this.getLastContextFile(); 105 StateHandler.getInstance().addWait("PREVIEW-ACTION", 106 "Opening previewer..."); 107 String sFileName = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile); 108 try { 109 StatusData status = EditorController.getInstance().preview(vfFile.getFullPath(), 110 vfFile.getVFS()); 111 statusOverall.addStatusData(status); 112 } catch (Exception e) { 113 e.printStackTrace(System.err); 114 statusOverall.setStatusLevel(StatusData.LEVEL_ERROR); 115 } finally { 116 StateHandler.getInstance().removeWait("PREVIEW-ACTION"); 117 VFSMessageBuilder.getInstance().fireMessage(ActionPreview.ACTION_NAME, statusOverall, sFileName); 118 } 119 } 120 121 126 public JMenuItem getMenuItem() { 127 JMenuItem menuItem = super.getMenuItem(); 128 menuItem.setAccelerator(KeyStroke.getKeyStroke(this 129 .getAcceleratorKeycode(), this.getAcceleratorMask())); 130 131 return menuItem; 132 } 133 134 139 public String getDescription() { 140 return "Previews the currently selected resource"; 141 } 142 143 148 public String getText() { 149 return "Preview"; 150 } 151 152 157 public String getToolTip() { 158 return this.getDescription(); 159 } 160 161 166 public Icon getIcon() { 167 return IconManager.getInstance().getIcon("16-command-preview.gif"); 168 } 169 170 175 public int getAcceleratorKeycode() { 176 return KeyEvent.VK_V; 177 } 178 179 184 public String getMnemonic() { 185 return "v"; 186 } 187 188 193 public int getAcceleratorMask() { 194 return InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK; 195 } 196 197 } | Popular Tags |