org.topbraid.core.change
Class ChangeOperation

java.lang.Object
  extended by org.eclipse.core.commands.operations.AbstractOperation
      extended by org.topbraid.core.change.ChangeOperation
All Implemented Interfaces:
org.eclipse.core.commands.operations.IUndoableOperation
Direct Known Subclasses:
TBCChangeOperation, TripleChangeOperation

public class ChangeOperation
extends org.eclipse.core.commands.operations.AbstractOperation

An IUndoableOperation encapsulating an IChange object.

Author:
Holger Knublauch

Constructor Summary
ChangeOperation(IChange change)
           
 
Method Summary
 void add(TripleChangeRecord record)
           
 boolean canExecute()
          Checks if this operation can be executed.
 boolean contains(com.hp.hpl.jena.graph.Triple triple, boolean added)
           
protected  org.eclipse.core.runtime.Status createErrorStatus(java.lang.String message, java.lang.Exception ex)
           
 org.eclipse.core.runtime.IStatus execute(org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info)
           
 IChange getChange()
           
 java.util.Map<com.hp.hpl.jena.graph.Node,java.util.Collection<com.hp.hpl.jena.graph.Node>> getCreatedResourceNodes(com.hp.hpl.jena.ontology.OntModel ontModel, boolean undone)
          Gets all Nodes of resources that have been "created" as a result of this operation.
 java.util.Map<com.hp.hpl.jena.graph.Node,java.util.Set<com.hp.hpl.jena.graph.Node>> getDeletedResourceNodes(com.hp.hpl.jena.ontology.OntModel ontModel, boolean undone)
          Gets all Nodes of resources that have been "deleted" as a result of this operation.
 java.util.Map<com.hp.hpl.jena.graph.Node,java.util.List<TripleChangeRecord>> getPredicate2TripleChangeRecordsMap(com.hp.hpl.jena.graph.Node subjectNode)
          Creates a Map with predicate Nodes as keys and Lists of TripleChangeRecords as values.
 TripleChangeRecord[] getRecords()
           
protected  ISession getSession()
           
 java.util.Set<com.hp.hpl.jena.graph.Node> getTypeChangedResourceNodes()
           
 TripleChangeRecord[] getUniqueRecords()
          Gets the TripleChangeRecords, suppressing redundant entries.
 java.util.Iterator<TripleChangeRecord> listRecords()
           
 org.eclipse.core.runtime.IStatus redo(org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info)
           
 java.lang.String toString()
           
 org.eclipse.core.runtime.IStatus undo(org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info)
           
 
Methods inherited from class org.eclipse.core.commands.operations.AbstractOperation
addContext, canRedo, canUndo, dispose, getContexts, getLabel, hasContext, removeContext, setLabel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChangeOperation

public ChangeOperation(IChange change)
Method Detail

add

public void add(TripleChangeRecord record)

canExecute

public boolean canExecute()
Checks if this operation can be executed. This method can be used to determine whether an operation would be valid before it is being executed the first time. This allows programmers to bundle validation and execution into the same class.

Specified by:
canExecute in interface org.eclipse.core.commands.operations.IUndoableOperation
Overrides:
canExecute in class org.eclipse.core.commands.operations.AbstractOperation
Returns:
the default implementation just returns true
See Also:
ChangeOperations#execute(ISession, AbstractChangeOperation)

contains

public boolean contains(com.hp.hpl.jena.graph.Triple triple,
                        boolean added)

createErrorStatus

protected org.eclipse.core.runtime.Status createErrorStatus(java.lang.String message,
                                                            java.lang.Exception ex)

execute

public org.eclipse.core.runtime.IStatus execute(org.eclipse.core.runtime.IProgressMonitor monitor,
                                                org.eclipse.core.runtime.IAdaptable info)
                                         throws org.eclipse.core.commands.ExecutionException
Specified by:
execute in interface org.eclipse.core.commands.operations.IUndoableOperation
Specified by:
execute in class org.eclipse.core.commands.operations.AbstractOperation
Throws:
org.eclipse.core.commands.ExecutionException

getChange

public IChange getChange()

getCreatedResourceNodes

public java.util.Map<com.hp.hpl.jena.graph.Node,java.util.Collection<com.hp.hpl.jena.graph.Node>> getCreatedResourceNodes(com.hp.hpl.jena.ontology.OntModel ontModel,
                                                                                                                          boolean undone)
Gets all Nodes of resources that have been "created" as a result of this operation. A resource counts as created if it has received its first rdf:type triple.

Returns:
a Map of Node -> Collection
See Also:
#getDeletedResourceNodes()

getDeletedResourceNodes

public java.util.Map<com.hp.hpl.jena.graph.Node,java.util.Set<com.hp.hpl.jena.graph.Node>> getDeletedResourceNodes(com.hp.hpl.jena.ontology.OntModel ontModel,
                                                                                                                   boolean undone)
Gets all Nodes of resources that have been "deleted" as a result of this operation. A resource counts as deleted if it has lost its last rdf:type triple. This operation is therefore symmetrical to getCreatedResourceNodes().

Returns:
a Map of Node -> Collection
See Also:
#getCreatedResourceNodes()

getPredicate2TripleChangeRecordsMap

public java.util.Map<com.hp.hpl.jena.graph.Node,java.util.List<TripleChangeRecord>> getPredicate2TripleChangeRecordsMap(com.hp.hpl.jena.graph.Node subjectNode)
Creates a Map with predicate Nodes as keys and Lists of TripleChangeRecords as values. The Map will contain only those records that have a given resource as subject.

Returns:
a Map

getRecords

public TripleChangeRecord[] getRecords()

getSession

protected ISession getSession()

getTypeChangedResourceNodes

public java.util.Set<com.hp.hpl.jena.graph.Node> getTypeChangedResourceNodes()

getUniqueRecords

public TripleChangeRecord[] getUniqueRecords()
Gets the TripleChangeRecords, suppressing redundant entries. This will suppress add records of triples that have also been removed in the same operation, for example when a triple has been moved from the inferred to the asserted model.

Returns:
a list of TripleChangeRecords

listRecords

public java.util.Iterator<TripleChangeRecord> listRecords()

redo

public org.eclipse.core.runtime.IStatus redo(org.eclipse.core.runtime.IProgressMonitor monitor,
                                             org.eclipse.core.runtime.IAdaptable info)
                                      throws org.eclipse.core.commands.ExecutionException
Specified by:
redo in interface org.eclipse.core.commands.operations.IUndoableOperation
Specified by:
redo in class org.eclipse.core.commands.operations.AbstractOperation
Throws:
org.eclipse.core.commands.ExecutionException

toString

public java.lang.String toString()
Overrides:
toString in class org.eclipse.core.commands.operations.AbstractOperation

undo

public org.eclipse.core.runtime.IStatus undo(org.eclipse.core.runtime.IProgressMonitor monitor,
                                             org.eclipse.core.runtime.IAdaptable info)
                                      throws org.eclipse.core.commands.ExecutionException
Specified by:
undo in interface org.eclipse.core.commands.operations.IUndoableOperation
Specified by:
undo in class org.eclipse.core.commands.operations.AbstractOperation
Throws:
org.eclipse.core.commands.ExecutionException