1 19 20 package org.netbeans.modules.autoupdate; 21 22 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import javax.swing.Action ; 26 27 import org.openide.nodes.Node; 28 import org.openide.nodes.AbstractNode; 29 import org.openide.util.NbBundle; 30 import org.openide.util.actions.CallableSystemAction; 31 import org.openide.util.HelpCtx; 32 33 39 class UpdateNode extends Object { 40 41 42 private static final String NEW_MODULE_ICON_BASE = "org/netbeans/modules/autoupdate/resources/newModule.gif"; 44 private static final String UPDATE_MODULE_ICON_BASE = "org/netbeans/modules/autoupdate/resources/updateModule.png"; 46 private static final String MODULE_GROUP_ICON_BASE = "org/openide/loaders/defaultFolder.gif"; 48 private static final String WAIT_ICON_BASE = "org/openide/src/resources/wait.gif"; 50 private static final String PURCHASED_MODULE_ICON_BASE = "org/netbeans/modules/autoupdate/resources/purchasedModule.gif"; 52 private static final String SERVER_ICON_BASE = "org/netbeans/modules/autoupdate/resources/updateAction.gif"; 54 private static final String LOCAL_ICON_BASE = "org/openide/resources/localFS.gif"; 56 private static final String LOCALE_MODULE_ICON_BASE = "org/netbeans/modules/autoupdate/resources/localeModule.gif"; 58 59 private UpdateNode() { 60 } 61 62 private static String getBundle( String key ) { 63 return NbBundle.getMessage( UpdateNode.class, key ); 64 } 65 66 67 static class Module extends AbstractNode { 68 69 private ModuleUpdate moduleUpdate; 70 static CallableSystemAction moduleAction = null; 71 72 Module ( ModuleUpdate moduleUpdate ) { 73 super( org.openide.nodes.Children.LEAF ); 74 75 this.moduleUpdate = moduleUpdate; 76 77 setDisplayName( moduleUpdate.getName() ); 78 if ( moduleUpdate.isPurchased() ) 79 setIconBaseWithExtension( PURCHASED_MODULE_ICON_BASE ); 80 else if ( moduleUpdate instanceof L10NUpdate ) 81 setIconBaseWithExtension( LOCALE_MODULE_ICON_BASE ); 82 else 83 setIconBaseWithExtension( moduleUpdate.isNew() ? NEW_MODULE_ICON_BASE : UPDATE_MODULE_ICON_BASE ); 84 85 getCookieSet().add( moduleUpdate ); 86 } 87 88 CallableSystemAction getModuleAction() { 89 if ( moduleAction == null ) 90 moduleAction = new ModuleAction(); 91 return moduleAction; 92 } 93 94 public Action getPreferredAction () { 95 return getModuleAction (); 96 } 97 98 class ModuleAction extends CallableSystemAction { 99 public void performAction() { 100 Settings.getShared().fireNodeDefaultAction(); 101 } 102 103 public HelpCtx getHelpCtx() { 104 return null; 105 } 106 107 public String getName() { 108 return null; 109 } 110 111 protected boolean asynchronous () { 112 return false; 113 } 114 115 } 116 } 117 118 119 static class Wait extends AbstractNode { 120 121 Wait ( ) { 122 super( org.openide.nodes.Children.LEAF ); 123 124 setDisplayName( getBundle( "CTL_WaitNode" ) ); 125 setIconBaseWithExtension( WAIT_ICON_BASE ); 126 } 127 } 128 129 abstract static class FolderContent extends org.openide.nodes.Children.Keys { 130 abstract void refreshContent(boolean recursive); 131 132 final void refreshSubFolders() { 133 Node[] nodes = getNodes(); 134 for ( int i=0; i < nodes.length; i++ ) { 135 if ( nodes[i] instanceof Folder ) 136 ( (Folder) nodes[i] ).refreshContent( true ); 137 } 138 } 139 } 140 141 static class Folder extends AbstractNode { 142 143 protected FolderContent folderContent; 144 145 public Folder( FolderContent fc ) { 146 super( fc ); 147 folderContent = fc; 148 } 149 150 final void refreshContent(boolean recursive) { 151 folderContent.refreshContent( recursive ); 152 } 153 154 } 155 156 157 static class Group extends Folder { 158 159 private ModuleGroup group; 160 161 Group( ModuleGroup group ) { 162 super( new UpdateNode.Children( group ) ); 163 164 this.group = group; 165 166 setDisplayName( group.getName() ); 167 setIconBaseWithExtension( MODULE_GROUP_ICON_BASE ); 168 169 getCookieSet().add( group ); 170 } 171 172 } 173 174 175 static class Server extends Folder { 176 177 Server( AutoupdateType at ) { 178 super( new UpdateNode.ATChildren( at ) ); 179 180 setDisplayName( at.getName() ); 181 this.setIconBaseWithExtension( SERVER_ICON_BASE ); 182 183 } 184 185 } 186 187 188 static class LocalServer extends Folder { 189 190 LocalServer( Object obj ) { 191 super( new UpdateNode.ATChildren( obj ) ); 192 193 setDisplayName( getBundle( "LBL_LocalUpdate" ) ); 194 this.setIconBaseWithExtension( LOCAL_ICON_BASE ); 195 196 } 197 198 } 199 200 static AllServers getAllServers() { 201 return new AllServers(); 202 } 203 204 205 static class AllServers extends Folder { 206 207 AllServers() { 208 super( new UpdateNode.ASChildren() ); 209 } 210 211 } 212 213 214 static class Children extends FolderContent { 215 216 protected ModuleGroup moduleGroup; 217 218 220 223 224 public Children ( ModuleGroup moduleGroup ) { 225 super(); 226 this.moduleGroup = moduleGroup; 227 228 refreshContent( false ); 229 } 230 231 233 protected void addNotify() { 234 } 236 237 238 protected void removeNotify() { 239 setKeys( java.util.Collections.EMPTY_SET ); 240 } 241 242 244 246 protected Node[] createNodes( final Object key ) { 247 248 if (key instanceof ModuleUpdate) { 249 return new Node[] { new UpdateNode.Module( (ModuleUpdate)key ) }; 250 } 251 else if (key instanceof ModuleGroup ) { 252 return new Node[] { new UpdateNode.Group( (ModuleGroup)key ) }; 253 } 254 else { 255 return new Node[0]; 257 } 258 } 259 260 void refreshContent(boolean recursive) { 261 ArrayList list = new java.util.ArrayList (); 262 Iterator it = moduleGroup.getItems().iterator(); 263 while ( it.hasNext() ) { 264 Object ob = it.next(); 265 if (ob instanceof ModuleUpdate) { 266 ModuleUpdate mu = (ModuleUpdate) ob; 267 if (! mu.isSelected () && DependencyChecker.checkPlatformDependency (mu.getRemoteModule ())) { 268 list.add (mu); 269 } 270 } else { 271 list.add (ob); 272 } 273 } 274 275 setKeys( list ); 276 if ( recursive ) 277 refreshSubFolders(); 278 } 279 280 } 281 282 283 static class ATChildren extends FolderContent { 284 285 private Object autoupdateType; 286 288 291 292 public ATChildren ( Object obj ) { 293 super(); 294 this.autoupdateType = obj; 295 refreshContent( false ); 296 } 297 298 300 protected void addNotify() { 301 } 303 304 305 protected void removeNotify() { 306 setKeys( java.util.Collections.EMPTY_SET ); 307 } 308 309 311 313 protected Node[] createNodes( final Object key ) { 314 Node[] result; 315 if (key instanceof ModuleUpdate) { 316 result = new Node[] { new UpdateNode.Module( (ModuleUpdate)key ) }; 317 } 318 else if (key instanceof ModuleGroup ) { 319 result = new Node[] { new UpdateNode.Group( (ModuleGroup)key ) }; 320 int countOfChildren = ((ModuleGroup)key).getItems ().size (); 322 if (countOfChildren == 0) result = new Node[0]; 324 } 325 else { 326 result = new Node[0]; 328 } 329 return result; 330 } 331 332 void refreshContent(boolean recursive) { 333 ArrayList list = new java.util.ArrayList (); 334 ModuleGroup group = ((Updates)(Wizard.getAllUpdates().get( autoupdateType ))).getRootGroup(); 335 336 if (group != null) { 337 Iterator it = group.getItems().iterator(); 338 while ( it.hasNext() ) { 339 Object ob = it.next(); 340 if (( ob instanceof ModuleGroup ) || 341 (ob instanceof ModuleUpdate && !((ModuleUpdate)ob).isSelected () && 342 DependencyChecker.checkPlatformDependency (((ModuleUpdate) ob).getRemoteModule ())) ) 343 list.add(ob); 344 } 345 } 346 347 setKeys( list ); 348 if ( recursive ) 349 refreshSubFolders(); 350 } 351 352 } 353 354 355 static class ASChildren extends FolderContent { 356 357 359 362 363 public ASChildren () { 364 super(); 365 ArrayList list = new java.util.ArrayList (); 366 Iterator it = Wizard.getAllUpdates().keySet().iterator(); 367 while ( it.hasNext() ) { 368 Object ob = it.next(); 369 list.add(ob); 370 } 371 372 setKeys( list ); 373 } 374 375 377 protected void addNotify() { 378 } 380 381 382 protected void removeNotify() { 383 setKeys( java.util.Collections.EMPTY_SET ); 384 } 385 386 388 390 protected Node[] createNodes( final Object key ) { 391 392 if (key instanceof AutoupdateType) { 393 return new Node[] { new UpdateNode.Server( (AutoupdateType)key ) }; 394 } 395 else { 396 return new Node[] { new UpdateNode.LocalServer( key ) }; 397 } 398 } 399 400 void refreshContent(boolean recursive) { 401 if ( recursive ) 402 refreshSubFolders(); 403 } 404 405 } 406 } 407 | Popular Tags |