org.netbeans.modules.xml.xam
Class AbstractModel<T extends Component<T>>

java.lang.Object
  extended by org.netbeans.modules.xml.xam.AbstractModel<T>
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.UndoableEditListener, Model<T>, Referenceable
Direct Known Subclasses:
AbstractDocumentModel

public abstract class AbstractModel<T extends Component<T>>
extends java.lang.Object
implements Model<T>, javax.swing.event.UndoableEditListener

Author:
Chris Webster, Rico, Nam Nguyen

Nested Class Summary
protected  class AbstractModel.ModelUndoableEdit
           
protected  class AbstractModel.ModelUndoableEditSupport
           
 
Nested classes/interfaces inherited from interface org.netbeans.modules.xml.xam.Model
Model.State
 
Field Summary
protected  AbstractModel.ModelUndoableEditSupport ues
           
 
Fields inherited from interface org.netbeans.modules.xml.xam.Model
STATE_PROPERTY
 
Constructor Summary
AbstractModel(ModelSource source)
           
 
Method Summary
 void addComponentListener(ComponentListener cl)
          Remove component event listener.
 void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
          Add property change listener which will receive events for any element in the underlying schema model.
 void addUndoableEditListener(javax.swing.event.UndoableEditListener uel)
          Adds undoable edit listener.
 void addUndoableRefactorListener(javax.swing.event.UndoableEditListener uel)
          Adds undoable refactoring edit listener.
protected  javax.swing.undo.CompoundEdit createModelUndoableEdit()
           
 void endTransaction()
          This method stops the transaction and causes all events to be fired.
protected  void endTransaction(boolean quiet)
           
protected  void finishTransaction()
           
 void fireComponentChangedEvent(ComponentEvent evt)
           
 void firePropertyChangeEvent(java.beans.PropertyChangeEvent event)
           
abstract  ModelAccess getAccess()
           
(package private)  javax.swing.event.EventListenerList getComponentListenerList()
           
 ModelSource getModelSource()
           
 Model.State getState()
           
 boolean inSync()
          return true if sync is being performed.
 boolean inUndoRedo()
           
 boolean isAutoSyncActive()
           
 boolean isIntransaction()
           
protected  boolean needsSync()
          This method is overridden by subclasses to determine if sync needs to be performed.
protected  void refresh()
          Refresh the domain model component trees.
 void removeComponentListener(ComponentListener cl)
          Add coarse-grained change listener for events on model components.
 void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
          Remove property change listener.
 void removeUndoableEditListener(javax.swing.event.UndoableEditListener uel)
          Removes undoable edit listener.
 void removeUndoableRefactorListener(javax.swing.event.UndoableEditListener uel)
          Removes undoable refactoring edit listener.
 void rollbackTransaction()
           
(package private)  void runAutoSync()
           
 void setAutoSyncActive(boolean v)
           
protected  void setInSync(boolean v)
           
protected  void setInUndoRedo(boolean v)
           
protected  void setState(Model.State s)
           
 boolean startedFiringEvents()
          Whether the model has started firing events.
 boolean startTransaction()
          This method will block until a transaction can be started.
 void sync()
          make the current memory model consistent with the underlying representation, typically a swing document.
protected  void syncCompleted()
          This method is invoked when sync has completed.
protected  void syncStarted()
          This method is invoked when sync has started.
protected  void transactionCompleted()
          This method is invoked when a transaction has completed.
protected  void transactionStarted()
          This template method is invoked when a transaction is started.
 void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
           
 void validateWrite()
          This method ensures that a transaction is currently in progress and that the current thread is able to write.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.netbeans.modules.xml.xam.Model
addChildComponent, removeChildComponent
 

Field Detail

ues

protected AbstractModel.ModelUndoableEditSupport ues
Constructor Detail

AbstractModel

public AbstractModel(ModelSource source)
Method Detail

getAccess

public abstract ModelAccess getAccess()

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
Description copied from interface: Model
Remove property change listener.

Specified by:
removePropertyChangeListener in interface Model<T extends Component<T>>

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
Add property change listener which will receive events for any element in the underlying schema model.

Specified by:
addPropertyChangeListener in interface Model<T extends Component<T>>

firePropertyChangeEvent

public void firePropertyChangeEvent(java.beans.PropertyChangeEvent event)

removeUndoableEditListener

public void removeUndoableEditListener(javax.swing.event.UndoableEditListener uel)
Description copied from interface: Model
Removes undoable edit listener.

Specified by:
removeUndoableEditListener in interface Model<T extends Component<T>>

addUndoableEditListener

public void addUndoableEditListener(javax.swing.event.UndoableEditListener uel)
Description copied from interface: Model
Adds undoable edit listener.

Specified by:
addUndoableEditListener in interface Model<T extends Component<T>>

addUndoableRefactorListener

public void addUndoableRefactorListener(javax.swing.event.UndoableEditListener uel)
Description copied from interface: Model
Adds undoable refactoring edit listener. This is typically called by a refactoring manager before start refactoring changes. This will also save existing undoable edit listeners. Note, if these listeners are UndoManager instances, their queues will be cleared of existing edits.

Specified by:
addUndoableRefactorListener in interface Model<T extends Component<T>>

removeUndoableRefactorListener

public void removeUndoableRefactorListener(javax.swing.event.UndoableEditListener uel)
Description copied from interface: Model
Removes undoable refactoring edit listener. This will also restored the existing undoable edit listeners to the set before the start of refactoring. Note, if these listeners are UndoManager instances their queues are cleared of existing edits.

Specified by:
removeUndoableRefactorListener in interface Model<T extends Component<T>>

createModelUndoableEdit

protected javax.swing.undo.CompoundEdit createModelUndoableEdit()

inSync

public boolean inSync()
Description copied from interface: Model
return true if sync is being performed.

Specified by:
inSync in interface Model<T extends Component<T>>

setInSync

protected void setInSync(boolean v)

inUndoRedo

public boolean inUndoRedo()

setInUndoRedo

protected void setInUndoRedo(boolean v)

getState

public Model.State getState()
Specified by:
getState in interface Model<T extends Component<T>>
Returns:
the last known state of the document. This method is affected by invocations of #sync().

setState

protected void setState(Model.State s)

needsSync

protected boolean needsSync()
This method is overridden by subclasses to determine if sync needs to be performed. The default implementation simply returns true.


transactionStarted

protected void transactionStarted()
This template method is invoked when a transaction is started. The default implementation does nothing.


transactionCompleted

protected void transactionCompleted()
This method is invoked when a transaction has completed. The default implementation does nothing.


syncStarted

protected void syncStarted()
This method is invoked when sync has started. The default implementation does nothing.


syncCompleted

protected void syncCompleted()
This method is invoked when sync has completed. The default implementation does nothing.


sync

public void sync()
          throws java.io.IOException
Description copied from interface: Model
make the current memory model consistent with the underlying representation, typically a swing document.

Specified by:
sync in interface Model<T extends Component<T>>
Throws:
java.io.IOException

refresh

protected void refresh()
Refresh the domain model component trees. The model state should be VALID as the result of this call. Note: subclasses need to override to provide the actual refresh service.


removeComponentListener

public void removeComponentListener(ComponentListener cl)
Description copied from interface: Model
Add coarse-grained change listener for events on model components.

Specified by:
removeComponentListener in interface Model<T extends Component<T>>

addComponentListener

public void addComponentListener(ComponentListener cl)
Description copied from interface: Model
Remove component event listener.

Specified by:
addComponentListener in interface Model<T extends Component<T>>

fireComponentChangedEvent

public void fireComponentChangedEvent(ComponentEvent evt)

isIntransaction

public boolean isIntransaction()
Specified by:
isIntransaction in interface Model<T extends Component<T>>
Returns:
true if model is in middle of transformation tranasction.

endTransaction

public void endTransaction()
Description copied from interface: Model
This method stops the transaction and causes all events to be fired. After all events have been fired, the document representation will be modified to reflect the current value of the model (flush).

Specified by:
endTransaction in interface Model<T extends Component<T>>

endTransaction

protected void endTransaction(boolean quiet)

startTransaction

public boolean startTransaction()
Description copied from interface: Model
This method will block until a transaction can be started. A transaction in this context will fire events (such as property change) when #endTransaction() has been invoked. A transaction must be be acquired during a mutation, reading can be performed without a transaction. Only a single transaction at a time is supported. Mutations which occur based on events will not be reflected until the transaction has completed.

Specified by:
startTransaction in interface Model<T extends Component<T>>
Returns:
true if transaction is acquired successfully, else false, for example if model has transitioned into invalid state.

rollbackTransaction

public void rollbackTransaction()

finishTransaction

protected void finishTransaction()

validateWrite

public void validateWrite()
This method ensures that a transaction is currently in progress and that the current thread is able to write.


startedFiringEvents

public boolean startedFiringEvents()
Whether the model has started firing events. This is the indication of beginning of endTransaction call and any subsequent mutations are from handlers of main transaction events or some of their own events.


undoableEditHappened

public void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
Specified by:
undoableEditHappened in interface javax.swing.event.UndoableEditListener

getModelSource

public ModelSource getModelSource()
Specified by:
getModelSource in interface Model<T extends Component<T>>
Returns:
the source of this model or null if this model does associate with any model source.

getComponentListenerList

javax.swing.event.EventListenerList getComponentListenerList()

isAutoSyncActive

public boolean isAutoSyncActive()

setAutoSyncActive

public void setAutoSyncActive(boolean v)

runAutoSync

void runAutoSync()