1 29 package net.sourceforge.groboutils.pmti.v1.defimpl; 30 31 import net.sourceforge.groboutils.pmti.v1.IIssue; 32 import net.sourceforge.groboutils.pmti.v1.IIssueState; 33 import net.sourceforge.groboutils.pmti.v1.IAttributeSet; 34 import net.sourceforge.groboutils.pmti.v1.IEditableIssue; 35 import net.sourceforge.groboutils.pmti.v1.IEditableIssueState; 36 import net.sourceforge.groboutils.pmti.v1.IEditableAttributeSet; 37 import net.sourceforge.groboutils.pmti.v1.ProblemManagerException; 38 39 40 62 public abstract class AbstractEditableIssue implements IEditableIssue 63 { 64 private IIssue baseIssue; 65 66 private String newDesc; 67 private boolean changedDesc; 68 69 private IIssueState newState; 70 private boolean changedState; 71 72 private IEditableAttributeSet nextSet; 73 74 75 76 public AbstractEditableIssue( IIssue base ) 77 { 78 if (base == null) 79 { 80 throw new IllegalArgumentException ("no null arguments"); 81 } 82 this.baseIssue = base; 83 } 84 85 86 89 90 public String getID() 91 { 92 return this.baseIssue.getID(); 93 } 94 95 96 public String getType() 97 { 98 return this.baseIssue.getType(); 99 } 100 101 102 public String getShortDescription() 103 { 104 if (this.changedDesc) 105 { 106 return this.newDesc; 107 } 108 else 109 { 110 return this.baseIssue.getShortDescription(); 111 } 112 } 113 114 115 public IIssueState getState() 116 { 117 if (this.changedState) 118 { 119 return this.newState; 120 } 121 else 122 { 123 return this.baseIssue.getState(); 124 } 125 } 126 127 128 public IAttributeSet getAttributes() 129 { 130 return getEditableAttributes(); 131 } 132 133 134 public abstract IIssue reload() 135 throws ProblemManagerException; 136 137 138 141 142 145 public void setShortDescription( String desc ) 146 { 147 String orig = this.baseIssue.getShortDescription(); 148 if ( desc == orig || ( desc != null && desc.equals( orig ) ) ) 149 { 150 this.changedDesc = false; 152 } 153 else 154 { 155 this.changedDesc = true; 157 this.newDesc = desc; 158 } 159 } 160 161 162 163 164 169 public boolean hasShortDescriptionChanged() 170 { 171 return this.changedDesc; 172 } 173 174 175 182 public IEditableIssueState[] getNextStates() 183 { 184 return createNextEditableIssueStates( getState() ); 185 } 186 187 188 199 public void setState( IIssueState state ) 200 throws ProblemManagerException 201 { 202 assertStateCanBeNext( state ); 203 204 if (state instanceof IEditableIssueState) 205 { 206 state = createImmutableIssueState( (IEditableIssueState)state ); 207 } 208 this.newState = state; 209 this.changedState = true; 210 } 211 212 213 220 public boolean hasStateChanged() 221 { 222 return this.changedState; 223 } 224 225 226 232 public IEditableAttributeSet getEditableAttributes() 233 { 234 if (this.nextSet == null) 235 { 236 IAttributeSet s = this.baseIssue.getAttributes(); 238 this.nextSet = createEditableAttributeSet( s ); 239 } 240 return this.nextSet; 241 } 242 243 244 254 public abstract void commit() 255 throws ProblemManagerException; 256 257 258 259 262 263 268 protected abstract IEditableIssueState[] createNextEditableIssueStates( 269 IIssueState is ); 270 271 272 277 protected abstract IEditableAttributeSet createEditableAttributeSet( 278 IAttributeSet as ); 279 280 281 284 protected abstract IIssueState createImmutableIssueState( 285 IEditableIssueState eis ); 286 287 288 289 protected void assertStateCanBeNext( IIssueState state ) 290 throws ProblemManagerException 291 { 292 IEditableIssueState[] eis = getNextStates(); 293 if (eis == null || eis.length < 1) 294 { 295 throw new IllegalStateException ("Invalid set of next states."); 296 } 297 298 String name = null; 299 if (state != null) 300 { 301 name = state.getName(); 302 } 303 304 for (int i = 0; i < eis.length; ++i) 305 { 306 if (eis[i] == null) 307 { 308 if (state == null) 309 { 310 return; 312 } 313 } 314 else 315 if (eis[i].getName().equals( name )) 318 { 319 return; 322 } 323 } 324 throw new ProblemManagerException( "State "+state+ 326 " cannot be a next state for "+getState() ); 327 } 328 } 329 330 | Popular Tags |