1 19 package org.openharmonise.him.actions.publish; 20 21 import java.awt.event.*; 22 import java.util.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.him.actions.*; 27 import org.openharmonise.him.actions.rules.*; 28 import org.openharmonise.him.context.StateHandler; 29 import org.openharmonise.him.harmonise.*; 30 import org.openharmonise.him.window.messages.*; 31 import org.openharmonise.him.window.messages.builders.*; 32 import org.openharmonise.him.window.session.*; 33 import org.openharmonise.vfs.*; 34 import org.openharmonise.vfs.context.*; 35 import org.openharmonise.vfs.event.*; 36 import org.openharmonise.vfs.gui.*; 37 import org.openharmonise.vfs.status.*; 38 39 40 47 public class ActionArchive extends AbstractHIMAction implements HIMAction { 48 49 public static String ACTION_NAME = "ARCHIVE"; 50 51 54 private static final String WAIT_LABEL = "ARCHIVE-ACTION"; 55 56 59 public ActionArchive() { 60 super(); 61 this.setup(); 62 } 63 64 67 public ActionArchive(VirtualFile vfFile) { 68 super(vfFile); 69 this.setup(); 70 } 71 72 76 private void setup() { 77 RuleGroup andGroup = new RuleGroup(); 78 andGroup.setGroupType(RuleGroup.GROUPTYPE_AND); 79 PathRule pathRule = new PathRule("/webdav/Archive/"); 80 pathRule.setResultComparator(false); 81 andGroup.addEnableRule(pathRule); 82 PathEquals pathEqualsRule = new PathEquals(HarmonisePaths.PATH_USERS_ADMIN + "/super"); 83 pathEqualsRule.setResultComparator(false); 84 andGroup.addEnableRule(pathEqualsRule); 85 PathEquals pathEqualsRule2 = new PathEquals(HarmonisePaths.PATH_REPORTS_QUERIES + "/LinkChecker"); 86 pathEqualsRule2.setResultComparator(false); 87 andGroup.addEnableRule(pathEqualsRule2); 88 IsHistoricalRule histRule = new IsHistoricalRule(); 89 histRule.setResultComparator(false); 90 andGroup.addEnableRule(histRule); 91 SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_DELETE); 92 andGroup.addEnableRule(secRule); 93 ParentPathEquals ppathRule = new ParentPathEquals(HarmonisePaths.PATH_ASSETS); 94 ppathRule.setResultComparator(false); 95 andGroup.addEnableRule(ppathRule); 96 this.addEnableRule(andGroup); 97 } 98 99 102 public void actionPerformed(ActionEvent ae) { 103 StateHandler.getInstance().addWait(WAIT_LABEL); 104 StatusData statusOverall = new VFSStatus(); 105 106 String sFileName = null; 107 boolean bFound = false; 108 try { 109 VirtualFile vfFile = this.getLastContextFile(); 110 111 if(vfFile.isDirectory()) { 112 Iterator itor = vfFile.getChildren().iterator(); 113 while (itor.hasNext()) { 114 String sPath = (String ) itor.next(); 115 VirtualFile vfChild = vfFile.getVFS().getVirtualFile(sPath).getResource(); 116 if(vfChild.getState()==VirtualFile.STATE_LIVE) { 117 bFound = true; 118 break; 119 } 120 } 121 } 122 if(bFound) { 123 MessageHandler.getInstance().fireMessageEvent("This collection has published children, you must delete those first.", MessageHandler.TYPE_ERROR); 124 } else { 125 sFileName = vfFile.getVFS().getVirtualFileSystemView().getDisplayName(vfFile); 126 String sMessage = null; 127 StatusData status = vfFile.delete(); 128 statusOverall.addStatusData(status); 129 if( status.isOK() ) { 130 this.getLastContextDirectory().removeChild(vfFile.getFullPath()); 131 this.getLastContextDirectory().refreshChildren(); 132 this.getLastContextDirectory().fireVirtualFileEvent(VirtualFileEvent.FILE_MEMBERS_CHANGED); 133 super.fireSessionEvent("Archived", vfFile.getVFS(), vfFile.getFullPath().replaceAll("webdav", "webdav/Archive"), SessionEventData.RESOURCE_ARCHIVED); 134 } else { 135 } 136 } 137 138 139 } catch (Exception e) { 140 e.printStackTrace(System.err); 141 statusOverall.setStatusLevel(StatusData.LEVEL_ERROR); 142 } finally { 143 if(!bFound) { 144 VFSMessageBuilder.getInstance().fireMessage(ActionArchive.ACTION_NAME, statusOverall, sFileName); 145 } 146 StateHandler.getInstance().removeWait(WAIT_LABEL); 147 } 148 } 149 150 153 public JMenuItem getMenuItem() { 154 JMenuItem menuItem = super.getMenuItem(); 155 menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) ); 156 157 return menuItem; 158 } 159 160 163 public String getDescription() { 164 return "Archives the currently selected resource"; 165 } 166 167 170 public String getText() { 171 return "Archive"; 172 } 173 174 177 public String getToolTip() { 178 return this.getDescription(); 179 } 180 181 184 public Icon getIcon() { 185 return IconManager.getInstance().getIcon("16-archive-container.gif"); 186 } 187 188 191 public int getAcceleratorKeycode() { 192 return KeyEvent.VK_A; 193 } 194 195 198 public String getMnemonic() { 199 return "A"; 200 } 201 202 205 public int getAcceleratorMask() { 206 return InputEvent.CTRL_MASK; 207 } 208 209 } 210 | Popular Tags |