1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.util.*; 23 24 import org.openide.util.HelpCtx; 25 import org.openide.util.NbBundle; 26 import org.openide.ServiceType; 27 import org.openide.util.Lookup; 28 29 33 public abstract class AutoupdateType extends org.openide.ServiceType 34 { 35 36 37 static final long serialVersionUID = 362844512378569452L; 38 39 final static String PROP_ENABLED = "enabled"; final static String PROP_LAST_TIME_STAMP = "lastTimeStamp"; 42 43 private boolean enabled = true; 44 45 46 private Date lastTimeStamp; 47 48 static { 49 if ( java.beans.PropertyEditorManager.findEditor( ServiceType.class ) != null ) 50 java.beans.PropertyEditorManager.registerEditor( 51 AutoupdateType.class, 52 java.beans.PropertyEditorManager.findEditor( ServiceType.class ).getClass() 53 ); 54 } 55 56 public AutoupdateType() { 57 } 58 59 60 public String displayName() { 61 return NbBundle.getBundle( AutoupdateType.class).getString("CTL_Settings_Name"); 62 } 63 64 public HelpCtx getHelpCtx () { 65 return null; 66 } 67 68 public abstract Updates connectForUpdates(); 69 70 73 public static Enumeration autoupdateTypes () { 74 Collection col = Lookup.getDefault ().lookup ( new Lookup.Template( AutoupdateType.class ) ).allInstances(); 75 Iterator it = col.iterator(); 76 java.util.List lst = new ArrayList(); 77 while ( it.hasNext() ) { 78 AutoupdateType at = (AutoupdateType)it.next(); 79 if (at instanceof XMLAutoupdateType) { 80 if (((XMLAutoupdateType) at).isValid ()) { 82 lst.add (at); 83 } 84 } else { 85 lst.add (at); 87 } 88 } 89 return Collections.enumeration( lst ); 90 } 91 92 103 public static AutoupdateType find (Class clazz) { 104 return (AutoupdateType) Lookup.getDefault ().lookup ( AutoupdateType.class ); 105 } 106 107 118 public static AutoupdateType find (String name) { 119 Iterator it = Lookup.getDefault ().lookup ( new Lookup.Template( AutoupdateType.class ) ).allInstances().iterator(); 120 while ( it.hasNext() ) { 121 AutoupdateType at = (AutoupdateType)it.next(); 122 if ( name.equals( at.getName() ) ) 123 return at; 124 } 125 return null; 126 } 127 128 131 public static AutoupdateType getDefault () { 132 if (autoupdateTypes ().hasMoreElements ()) { 133 return (AutoupdateType)autoupdateTypes ().nextElement (); 134 } else { 135 return null; 136 } 137 } 138 139 142 public boolean isEnabled() { 143 return enabled; 144 } 145 146 149 public void setEnabled(boolean enabled) { 150 boolean old = this.enabled; 151 this.enabled = enabled; 152 firePropertyChange( PROP_ENABLED, old ? Boolean.TRUE : Boolean.FALSE, enabled ? Boolean.TRUE : Boolean.FALSE ); 153 } 154 155 158 public Date getLastTimeStamp() { 159 return lastTimeStamp; 160 } 161 162 165 public void setLastTimeStamp(Date lastTimeStamp) { 166 Date oldTime = this.lastTimeStamp; 167 this.lastTimeStamp = lastTimeStamp; 168 firePropertyChange (PROP_LAST_TIME_STAMP, oldTime, lastTimeStamp); 169 } 170 171 } 172 173 | Popular Tags |