1 19 package org.openharmonise.him.actions.file; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.util.*; 24 import java.util.List ; 25 26 import javax.swing.*; 27 28 import org.openharmonise.him.actions.*; 29 import org.openharmonise.him.actions.rules.*; 30 import org.openharmonise.him.configuration.*; 31 import org.openharmonise.him.context.StateHandler; 32 import org.openharmonise.him.harmonise.*; 33 import org.openharmonise.him.window.messages.builders.*; 34 import org.openharmonise.him.window.session.*; 35 import org.openharmonise.swing.*; 36 import org.openharmonise.vfs.*; 37 import org.openharmonise.vfs.context.*; 38 import org.openharmonise.vfs.gui.*; 39 import org.openharmonise.vfs.status.*; 40 41 42 49 public class ActionNewCollection extends AbstractHIMAction implements HIMAction { 50 51 public static String ACTION_NAME = "NEW_COLLECTION"; 52 53 56 boolean m_bIsEnabled = false; 57 58 61 private HashMap m_nameIconMapping = new HashMap(); 62 63 66 private String m_sCurrentPath = ""; 67 68 71 public ActionNewCollection() { 72 super(); 73 this.setup(); 74 } 75 76 79 public ActionNewCollection(VirtualFile vfFile) { 80 super(vfFile); 81 this.setup(); 82 } 83 84 88 private void setup() { 89 RuleGroup andGroup = new RuleGroup(); 90 andGroup.setGroupType(RuleGroup.GROUPTYPE_AND); 91 92 RuleGroup orGroup = new RuleGroup(); 93 orGroup.setGroupType(RuleGroup.GROUPTYPE_OR); 94 95 orGroup.addEnableRule( new PathRule("/webdav/Content/Documents") ); 96 orGroup.addEnableRule( new PathRule("/webdav/Content/Assets/flash") ); 97 orGroup.addEnableRule( new PathRule("/webdav/Content/Assets/movies") ); 98 orGroup.addEnableRule( new PathRule("/webdav/Content/Assets/office") ); 99 orGroup.addEnableRule( new PathRule("/webdav/Content/Assets/audio") ); 100 orGroup.addEnableRule( new PathRule("/webdav/Content/Assets/Image") ); 101 orGroup.addEnableRule( new PathRule("/webdav/Content/Assets/image") ); 102 orGroup.addEnableRule( new PathRule("/webdav/Content/Assets/pdf") ); 103 orGroup.addEnableRule( new PathRule("/webdav/Content/Assets/e-mail") ); 104 orGroup.addEnableRule( new PathRule("/webdav/Content/Assets/links") ); 105 orGroup.addEnableRule( new PathRule("/webdav/Metadata/Properties") ); 106 orGroup.addEnableRule( new PathRule("/webdav/Metadata/Values") ); 107 orGroup.addEnableRule( new PathRule("/webdav/Newsletter/draft") ); 108 orGroup.addEnableRule( new PathRule("/webdav/Reports/Queries") ); 109 orGroup.addEnableRule( new PathRule("/webdav/Users") ); 110 orGroup.addEnableRule( new PathRule("/webdav/Templates/Page Definition") ); 111 orGroup.addEnableRule( new PathRule("/webdav/Templates/Composition/Page Templates") ); 112 orGroup.addEnableRule( new PathRule("/webdav/Templates/Composition/Object Templates") ); 113 orGroup.addEnableRule( new PathRule("/webdav/Templates/Display/XSLT") ); 114 orGroup.addEnableRule( new PathRule("/webdav/Templates/Site Assets/Flash Navigation") ); 115 orGroup.addEnableRule( new PathRule( HarmonisePaths.PATH_WEBSITE ) ); 116 orGroup.addEnableRule( new PathRule( HarmonisePaths.PATH_WORKFLOW_DEFINITIONS ) ); 117 orGroup.addEnableRule( new PathRule( HarmonisePaths.PATH_WORKFLOW_PROPS ) ); 118 orGroup.addEnableRule( new PathRule( HarmonisePaths.PATH_WORKFLOW_STAGES ) ); 119 orGroup.addEnableRule( new PathRule( HarmonisePaths.PATH_REPORTS_QUERIES ) ); 120 121 andGroup.addEnableRule(orGroup); 122 123 SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_MKDIR); 124 andGroup.addEnableRule(secRule); 125 126 super.addEnableRule(andGroup); 127 128 this.m_nameIconMapping.put("/webdav/Content/Assets/flash", "16-flash-folder.gif"); 129 this.m_nameIconMapping.put("/webdav/Content/Assets/movies", "16-movie-folder.gif"); 130 this.m_nameIconMapping.put("/webdav/Content/Assets/office", "16-assets-folder.gif"); 131 this.m_nameIconMapping.put("/webdav/Content/Assets/audio", "16-assets-folder.gif"); 132 this.m_nameIconMapping.put("/webdav/Content/Assets/image", "16-image-folder.gif"); 133 this.m_nameIconMapping.put("/webdav/Content/Assets/Web Resources", "16-link-folder.gif"); 134 this.m_nameIconMapping.put("/webdav/Content/Assets/e-mail", "16-email-folder.gif"); 135 this.m_nameIconMapping.put("/webdav/Content/Assets/links", "16-link-folder.gif"); 136 this.m_nameIconMapping.put("/webdav/Content/Assets/pdf", "16-pdf-folder.gif"); 137 this.m_nameIconMapping.put("/webdav/Content/Documents", "16-section.gif"); 138 this.m_nameIconMapping.put("/webdav/Metadata/Properties", "16-property-container.gif"); 139 this.m_nameIconMapping.put("/webdav/Metadata/Values", "16-value-container.gif"); 140 this.m_nameIconMapping.put("/webdav/Newsletter/draft", "16-newsletter-draft.gif"); 141 this.m_nameIconMapping.put("/webdav/Reports/Queries", "16-report-folder.gif"); 142 this.m_nameIconMapping.put("/webdav/Users", "16-user-container.gif"); 143 this.m_nameIconMapping.put("/webdav/Website/Page Definition", "16-page-definition-folder.gif"); 144 this.m_nameIconMapping.put("/webdav/Website/Composition/Page Templates", "16-template-folder.gif"); 145 this.m_nameIconMapping.put("/webdav/Website/Composition/Object Templates", "16-object-template-folder.gif"); 146 this.m_nameIconMapping.put("/webdav/Website/Composition/Includes", "16-includes-folder.gif"); 147 this.m_nameIconMapping.put("/webdav/Website/Display/XSLT", "16-xslt-folder.gif"); 148 this.m_nameIconMapping.put("/webdav/Website/Site Assets/FlashNav", "16-flash-folder.gif"); 149 } 150 151 154 public void actionPerformed(ActionEvent arg0) { 155 boolean bChange = (ConfigStore.getInstance().getPropertyValue("FILENAME_DISPLAY")!=null && ConfigStore.getInstance().getPropertyValue("FILENAME_DISPLAY").equals("DISPLAYNAME")); 156 157 if(bChange) { 158 ConfigStore.getInstance().setProperty("FILENAME_DISPLAY", "FILENAME"); 159 ContextEvent ce = new ContextEvent(ContextType.CONTEXT_FILENAME_DISPLAY); 160 ContextHandler.getInstance().fireContextEvent(ce); 161 } 162 163 String sDirPath = null; 164 165 String sDirName = this.getNewName(); 166 StateHandler.getInstance().addWait("NEW-COL-ACTION"); 167 StatusData statusOverall = new VFSStatus(); 168 169 try { 170 if(!sDirName.equals("")) { 171 sDirPath = this.getLastContextDirectory().getFullPath() + "/" + sDirName; 172 StatusData status = this.getLastContextDirectory().mkDir(sDirName); 173 statusOverall.addStatusData(status); 174 if( status.isOK() ) { 175 super.fireSessionEvent("Created", this.getLastContextDirectory().getVFS(), this.getLastContextDirectory().getFullPath() + "/" + sDirName, SessionEventData.RESOURCE_CREATED); 176 } else { 177 } 178 } 179 } catch (Exception e) { 180 e.printStackTrace(System.err); 181 statusOverall.setStatusLevel(StatusData.LEVEL_ERROR); 182 } finally { 183 if(bChange) { 184 ConfigStore.getInstance().setProperty("FILENAME_DISPLAY", "DISPLAYNAME"); 185 ContextEvent ce = new ContextEvent(ContextType.CONTEXT_FILENAME_DISPLAY); 186 ContextHandler.getInstance().fireContextEvent(ce); 187 } 188 StatusMessage statusMessage = new StatusMessage(ActionNewCollection.ACTION_NAME, statusOverall); 189 statusMessage.setResourceTitle(sDirName); 190 statusMessage.setPath(sDirPath); 191 VFSMessageBuilder.getInstance().fireMessage( statusMessage ); 192 StateHandler.getInstance().removeWait("NEW-COL-ACTION"); 194 } 195 } 196 197 202 private String getNewName() { 203 JFrame frame = new JFrame(); 204 frame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 205 206 SingleTextEntryDialog dialog = new SingleTextEntryDialog(frame, "Collection name"); 207 dialog.setLabelText("Only use a-z,A-Z,_ and 0-9 in name."); 208 dialog.show(); 209 String sName = dialog.getTextValue(); 210 211 while(!sName.equals("") && !this.checkName(sName)) { 212 dialog = new SingleTextEntryDialog(frame, "Collection name"); 213 dialog.setLabelText("Only use a-z,A-Z,_ and 0-9 in name."); 214 dialog.setLabelColor(Color.RED); 215 dialog.show(); 216 sName = dialog.getTextValue(); 217 } 218 219 return sName; 220 221 } 222 223 229 private boolean checkName(String sName) { 230 boolean bRetn = true; 231 String [] validChars = new String []{"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","0","_"}; 232 List aValidChars = Arrays.asList(validChars); 233 234 char[] chars = sName.toCharArray(); 235 for (int i = 0; i < chars.length; i++) { 236 char c = chars[i]; 237 if(!aValidChars.contains(new String (new char[]{c}))) { 238 bRetn=false; 239 break; 240 } 241 } 242 243 return bRetn; 244 } 245 246 249 public String getDescription() { 250 return "Creates a new collection under the currently selected collection"; 251 } 252 253 256 public String getText() { 257 return "New Collection"; 258 } 259 260 263 public String getToolTip() { 264 return this.getDescription(); 265 } 266 267 270 public Icon getIcon() { 271 return IconManager.getInstance().getIcon("16-section.gif"); 272 } 273 274 277 public JMenuItem getMenuItem() { 278 JMenuItem menuItem = super.getMenuItem(); 279 menuItem.setAccelerator( KeyStroke.getKeyStroke(this.getAcceleratorKeycode(), this.getAcceleratorMask()) ); 280 281 return menuItem; 282 } 283 284 287 public int getAcceleratorKeycode() { 288 return KeyEvent.VK_N; 289 } 290 291 294 public String getMnemonic() { 295 return "C"; 296 } 297 298 301 public int getAcceleratorMask() { 302 return InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK; 303 } 304 305 308 public boolean isEnabled(ContextEvent ce) { 309 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_DIRS) { 310 m_bIsEnabled = super.isEnabled(ce); 311 312 renameButton(ce.getPath()); 313 return m_bIsEnabled; 314 } else if(ce.CONTEXT_TYPE==ContextType.CONTEXT_TABS) { 315 m_bIsEnabled = false; 316 this.setEnabled(m_bIsEnabled); 317 this.setEnabled(false); 318 return m_bIsEnabled; 319 } else { 320 return m_bIsEnabled; 321 } 322 } 323 324 329 private void renameButton(String sPath) { 330 if(!sPath.equals(this.m_sCurrentPath)) { 331 Iterator itor = this.m_nameIconMapping.keySet().iterator(); 332 boolean bFound=false; 333 while(itor.hasNext()) { 334 String sTestPath = (String )itor.next(); 335 if(sPath.startsWith(sTestPath)) { 336 try { 337 this.getButton().setIcon( IconManager.getInstance().getIcon((String ) this.m_nameIconMapping.get(sTestPath)) ); 338 this.getMenuItem().setIcon( IconManager.getInstance().getIcon((String ) this.m_nameIconMapping.get(sTestPath)) ); 339 } catch(Exception e) { 340 341 } 342 bFound=true; 343 } 344 } 345 346 if(!bFound) { 347 this.getButton().setText("New collection"); 348 this.getButton().setIcon( IconManager.getInstance().getIcon("16-section.gif") ); 349 this.getMenuItem().setText("New collection"); 350 this.getMenuItem().setIcon( IconManager.getInstance().getIcon("16-section.gif") ); 351 this.m_sCurrentPath = ""; 352 } else { 353 this.m_sCurrentPath = sPath; 354 } 355 } 356 } 357 358 } 359 | Popular Tags |