TreeBrowserCellRenderer.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. /**
  9. * TreeBrowserCellRenderer.java
  10. *
  11. * Copyright (C) 2005 Cognos ULC, an IBM Company. All rights reserved.
  12. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. */
  14. import javax.swing.JTree;
  15. import javax.swing.tree.DefaultMutableTreeNode;
  16. import javax.swing.tree.DefaultTreeCellRenderer;
  17. import javax.swing.ImageIcon;
  18. import java.awt.Component;
  19. class TreeBrowserCellRenderer extends DefaultTreeCellRenderer
  20. {
  21. public Component getTreeCellRendererComponent(
  22. JTree tree,
  23. Object value,
  24. boolean sel,
  25. boolean expanded,
  26. boolean leaf,
  27. int row,
  28. boolean hasFocus)
  29. {
  30. super.getTreeCellRendererComponent(
  31. tree,
  32. value,
  33. sel,
  34. expanded,
  35. leaf,
  36. row,
  37. hasFocus);
  38. String iconPath =
  39. getIconPath(
  40. ((TreeBrowserNode) ((DefaultMutableTreeNode)value)
  41. .getUserObject())
  42. .getCMObject()
  43. .getObjectClass()
  44. .getValue()
  45. .toString());
  46. ImageIcon currentImageIcon = new ImageIcon(iconPath);
  47. java.io.File iconFile = new java.io.File(iconPath);
  48. if (iconFile.exists())
  49. {
  50. setIcon(currentImageIcon);
  51. }
  52. else
  53. {
  54. setIcon(getDefaultLeafIcon());
  55. }
  56. return this;
  57. }
  58. public String getIconPath(String className)
  59. {
  60. String iconPathPrefix =
  61. "../../../webcontent/ps/portal/images/icon_";
  62. String iconPathVarfix = "";
  63. String iconPathSuffix = ".gif";
  64. if (className.compareTo("configuration") == 0)
  65. {
  66. iconPathVarfix = "_folder";
  67. }
  68. if (className.compareTo("root") == 0)
  69. {
  70. className = "folder";
  71. }
  72. if (className.compareTo("directory") == 0)
  73. {
  74. className = "folder";
  75. }
  76. if (className.compareTo("importDeploymentFolder") == 0)
  77. {
  78. className = "deployment";
  79. }
  80. if (className.compareTo("exportDeploymentFolder") == 0)
  81. {
  82. className = "deployment";
  83. }
  84. if (className.compareTo("capability") == 0)
  85. {
  86. className = "folder";
  87. }
  88. if (className.compareTo("content") == 0)
  89. {
  90. className = "folder";
  91. }
  92. if (className.compareTo("securedFunction") == 0)
  93. {
  94. className = "secured_function";
  95. }
  96. if (className.compareTo("securedFeature") == 0)
  97. {
  98. className = "secured_feature";
  99. }
  100. if (className.compareTo("dataSource") == 0)
  101. {
  102. className = "data_source";
  103. }
  104. if (className.compareTo("group") == 0)
  105. {
  106. className = "user_group";
  107. }
  108. if (className.compareTo("role") == 0)
  109. {
  110. className = "user_role";
  111. }
  112. if (className.compareTo("account") == 0)
  113. {
  114. className = "user";
  115. }
  116. if (className.compareTo("dataSourceConnection") == 0)
  117. {
  118. className = "data_source_connection";
  119. }
  120. if (className.compareTo("dataSourceSignon") == 0)
  121. {
  122. className = "signon";
  123. }
  124. if ( (className.compareTo("logService") == 0)
  125. || (className.compareTo("reportService") == 0)
  126. || (className.compareTo("presentationService") == 0)
  127. || (className.compareTo("jobAndScheduleMonitoringService") == 0)
  128. || (className.compareTo("contentManagerService") == 0)
  129. || (className.compareTo("batchReportService") == 0)
  130. )
  131. {
  132. className = "service";
  133. }
  134. if (className.compareTo("jobDefinition") == 0)
  135. {
  136. className = "job";
  137. }
  138. return (iconPathPrefix + className + iconPathVarfix + iconPathSuffix);
  139. }
  140. }