1 31 32 package org.opencms.workplace.explorer; 33 34 import org.opencms.main.CmsLog; 35 import org.opencms.main.OpenCms; 36 import org.opencms.util.CmsStringUtil; 37 import org.opencms.workplace.CmsWorkplaceManager; 38 39 import java.util.ArrayList ; 40 import java.util.List ; 41 42 import org.apache.commons.logging.Log; 43 44 57 public class CmsExplorerTypeSettings implements Comparable { 58 59 60 private static final Log LOG = CmsLog.getLog(CmsExplorerTypeSettings.class); 61 62 private CmsExplorerTypeAccess m_access; 63 64 65 private boolean m_addititionalModuleExplorerType; 66 private boolean m_autoSetNavigation; 67 private boolean m_autoSetTitle; 68 private CmsExplorerContextMenu m_contextMenu; 69 private List m_contextMenuEntries; 70 private boolean m_hasEditOptions; 71 private String m_icon; 72 private String m_key; 73 private String m_name; 74 75 76 private String m_newResourceHandlerClassName; 77 private Integer m_newResourceOrder; 78 private String m_newResourcePage; 79 private String m_newResourceUri; 80 private List m_properties; 81 private boolean m_propertiesEnabled; 82 private String m_reference; 83 private boolean m_showNavigation; 84 85 88 public CmsExplorerTypeSettings() { 89 90 m_access = new CmsExplorerTypeAccess(); 91 m_properties = new ArrayList (); 92 m_contextMenuEntries = new ArrayList (); 93 m_contextMenu = new CmsExplorerContextMenu(); 94 m_hasEditOptions = false; 95 m_propertiesEnabled = false; 96 m_showNavigation = false; 97 m_addititionalModuleExplorerType = false; 98 m_newResourceOrder = new Integer (0); 99 } 100 101 110 public void addContextMenuEntry(String key, String uri, String rules, String target, String order) { 111 112 Integer orderValue = new Integer (0); 113 try { 114 orderValue = Integer.valueOf(order); 115 } catch (Exception e) { 116 if (LOG.isErrorEnabled()) { 117 LOG.error(Messages.get().getBundle().key(Messages.LOG_WRONG_ORDER_CONTEXT_MENU_1, key)); 118 } 119 } 120 CmsExplorerContextMenuItem item = new CmsExplorerContextMenuItem( 121 CmsExplorerContextMenuItem.TYPE_ENTRY, 122 key, 123 uri, 124 rules, 125 target, 126 orderValue); 127 128 m_contextMenuEntries.add(item); 129 if (LOG.isDebugEnabled()) { 130 LOG.debug(Messages.get().getBundle().key(Messages.LOG_ADD_MENU_ENTRY_2, key, order)); 131 } 132 } 133 134 139 public void addContextMenuSeparator(String order) { 140 141 Integer orderValue = new Integer (0); 142 try { 143 orderValue = Integer.valueOf(order); 144 } catch (Exception e) { 145 LOG.error(Messages.get().getBundle().key(Messages.LOG_WRONG_MENU_SEP_ORDER_0, order)); 146 } 147 CmsExplorerContextMenuItem item = new CmsExplorerContextMenuItem( 148 CmsExplorerContextMenuItem.TYPE_SEPARATOR, 149 null, 150 null, 151 null, 152 null, 153 orderValue); 154 m_contextMenuEntries.add(item); 155 if (LOG.isDebugEnabled()) { 156 LOG.debug(Messages.get().getBundle().key(Messages.LOG_WRONG_MENU_SEP_ORDER_0, order)); 157 } 158 } 159 160 166 public boolean addProperty(String propertyName) { 167 168 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(propertyName)) { 169 if (LOG.isDebugEnabled()) { 170 LOG.debug(Messages.get().getBundle().key(Messages.LOG_ADD_PROP_1, propertyName)); 171 } 172 return m_properties.add(propertyName); 173 } else { 174 return false; 175 } 176 } 177 178 181 public int compareTo(Object obj) { 182 183 if (obj == this) { 184 return 0; 185 } 186 if (obj instanceof CmsExplorerTypeSettings) { 187 CmsExplorerTypeSettings other = (CmsExplorerTypeSettings)obj; 188 String myPage = getNewResourcePage(); 189 String otherPage = other.getNewResourcePage(); 190 if (CmsStringUtil.isEmptyOrWhitespaceOnly(myPage)) { 191 myPage = ""; 192 } 193 if (CmsStringUtil.isEmptyOrWhitespaceOnly(otherPage)) { 194 otherPage = ""; 195 } 196 int result = myPage.compareTo(otherPage); 197 if (result == 0) { 198 result = m_newResourceOrder.compareTo(other.m_newResourceOrder); 199 } 200 return result; 201 } 202 return 0; 203 } 204 205 211 public void createContextMenu() { 212 213 m_contextMenu.addEntries(getContextMenuEntries()); 214 if (LOG.isDebugEnabled()) { 215 LOG.debug(Messages.get().getBundle().key(Messages.LOG_CREATE_CONTEXT_MENU_1, getName())); 216 } 217 } 218 219 222 public boolean equals(Object o) { 223 224 if (!(o instanceof CmsExplorerTypeSettings)) { 225 return false; 226 } 227 CmsExplorerTypeSettings other = (CmsExplorerTypeSettings)o; 228 return getName().equals(other.getName()); 229 } 230 231 236 public CmsExplorerTypeAccess getAccess() { 237 238 if (m_access.isEmpty()) { 239 CmsWorkplaceManager workplaceManager = OpenCms.getWorkplaceManager(); 240 if (workplaceManager != null) { 241 m_access = workplaceManager.getDefaultAccess(); 242 } 243 } 244 return m_access; 245 } 246 247 251 public CmsExplorerContextMenu getContextMenu() { 252 253 if ((m_reference != null) && (m_contextMenu.isEmpty())) { 254 m_contextMenu = (CmsExplorerContextMenu)OpenCms.getWorkplaceManager().getExplorerTypeSetting(m_reference).getContextMenu().clone(); 255 } 256 return m_contextMenu; 257 } 258 259 264 public List getContextMenuEntries() { 265 266 return m_contextMenuEntries; 267 } 268 269 274 public String getIcon() { 275 276 return m_icon; 277 } 278 279 284 public String getKey() { 285 286 return m_key; 287 } 288 289 294 public String getName() { 295 296 return m_name; 297 } 298 299 304 public String getNewResourceHandlerClassName() { 305 306 return m_newResourceHandlerClassName; 307 } 308 309 314 public String getNewResourceOrder() { 315 316 return String.valueOf(m_newResourceOrder); 317 } 318 319 324 public String getNewResourcePage() { 325 326 return m_newResourcePage; 327 } 328 329 334 public String getNewResourceUri() { 335 336 return m_newResourceUri; 337 } 338 339 343 public List getProperties() { 344 345 return m_properties; 346 } 347 348 353 public String getReference() { 354 355 return m_reference; 356 } 357 358 363 public boolean hasEditOptions() { 364 365 return m_hasEditOptions; 366 } 367 368 371 public int hashCode() { 372 373 return getName().hashCode(); 374 } 375 376 381 public boolean isAddititionalModuleExplorerType() { 382 383 return m_addititionalModuleExplorerType; 384 } 385 386 391 public boolean isAutoSetNavigation() { 392 393 return m_autoSetNavigation; 394 } 395 396 401 public boolean isAutoSetTitle() { 402 403 return m_autoSetTitle; 404 } 405 406 411 public boolean isPropertiesEnabled() { 412 413 return m_propertiesEnabled; 414 } 415 416 421 public boolean isShowNavigation() { 422 423 return m_showNavigation; 424 } 425 426 431 public void setAccess(CmsExplorerTypeAccess access) { 432 433 m_access = access; 434 } 435 436 441 public void setAddititionalModuleExplorerType(boolean addititionalModuleExplorerType) { 442 443 m_addititionalModuleExplorerType = addititionalModuleExplorerType; 444 } 445 446 451 public void setAutoSetNavigation(String autoSetNavigation) { 452 453 m_autoSetNavigation = Boolean.valueOf(autoSetNavigation).booleanValue(); 454 if (LOG.isDebugEnabled()) { 455 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_AUTO_NAV_1, autoSetNavigation)); 456 } 457 } 458 459 464 public void setAutoSetTitle(String autoSetTitle) { 465 466 m_autoSetTitle = Boolean.valueOf(autoSetTitle).booleanValue(); 467 if (LOG.isDebugEnabled()) { 468 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_AUTO_TITLE_1, autoSetTitle)); 469 } 470 } 471 472 477 public void setContextMenuEntries(List entries) { 478 479 m_contextMenuEntries = entries; 480 } 481 482 487 public void setEditOptions() { 488 489 m_hasEditOptions = true; 490 } 491 492 497 public void setIcon(String icon) { 498 499 m_icon = icon; 500 if (LOG.isDebugEnabled()) { 501 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_ICON_1, icon)); 502 } 503 } 504 505 510 public void setKey(String key) { 511 512 m_key = key; 513 if (LOG.isDebugEnabled()) { 514 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_KEY_1, key)); 515 } 516 } 517 518 523 public void setName(String name) { 524 525 m_name = name; 526 if (LOG.isDebugEnabled()) { 527 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_NAME_1, name)); 528 } 529 } 530 531 536 public void setNewResourceHandlerClassName(String newResourceHandlerClassName) { 537 538 m_newResourceHandlerClassName = newResourceHandlerClassName; 539 } 540 541 546 public void setNewResourceOrder(String newResourceOrder) { 547 548 try { 549 m_newResourceOrder = Integer.valueOf(newResourceOrder); 550 if (LOG.isDebugEnabled()) { 551 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_NEW_RESOURCE_ORDER_1, newResourceOrder)); 552 } 553 } catch (Exception e) { 554 if (LOG.isInfoEnabled()) { 556 LOG.info(e); 557 } 558 m_newResourceOrder = new Integer (0); 559 } 560 } 561 562 567 public void setNewResourcePage(String page) { 568 569 m_newResourcePage = page; 570 } 571 572 577 public void setNewResourceUri(String newResourceUri) { 578 579 m_newResourceUri = newResourceUri; 580 if (LOG.isDebugEnabled()) { 581 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_NEW_RESOURCE_URI_1, newResourceUri)); 582 } 583 } 584 585 590 public void setProperties(List properties) { 591 592 m_properties = properties; 593 } 594 595 600 public void setPropertiesEnabled(boolean enabled) { 601 602 m_propertiesEnabled = enabled; 603 } 604 605 611 public void setPropertyDefaults(String enabled, String showNavigation) { 612 613 setPropertiesEnabled(Boolean.valueOf(enabled).booleanValue()); 614 setShowNavigation(Boolean.valueOf(showNavigation).booleanValue()); 615 if (LOG.isDebugEnabled()) { 616 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_PROP_DEFAULTS_2, enabled, showNavigation)); 617 } 618 } 619 620 625 public void setReference(String reference) { 626 627 m_reference = reference; 628 if (LOG.isDebugEnabled()) { 629 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_REFERENCE_1, m_reference)); 630 } 631 } 632 633 638 public void setShowNavigation(boolean navigation) { 639 640 m_showNavigation = navigation; 641 } 642 643 650 public void setTypeAttributes(String name, String key, String icon) { 651 652 setName(name); 653 setKey(key); 654 setIcon(icon); 655 } 656 657 665 public void setTypeAttributes(String name, String key, String icon, String reference) { 666 667 setName(name); 668 setKey(key); 669 setIcon(icon); 670 setReference(reference); 671 } 672 } | Popular Tags |