Class SpreadsheetModel
- java.lang.Object
-
- org.eclipse.epsilon.eol.models.Model
-
- org.eclipse.epsilon.emc.spreadsheets.SpreadsheetModel
-
- All Implemented Interfaces:
AutoCloseable
,IModel
,ISearchableModel
- Direct Known Subclasses:
ConcreteModel
,ExcelModel
,GSModel
public abstract class SpreadsheetModel extends Model implements ISearchableModel
This class enables spreadsheets to be viewed as models in Epsilon.- Author:
- Martins Francis
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.epsilon.eol.models.IModel
IModel.AmbiguityCheckResult
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
isLoaded
protected List<SpreadsheetReference>
references
protected List<SpreadsheetWorksheet>
worksheets
-
Fields inherited from class org.eclipse.epsilon.eol.models.Model
aliases, ENV_PREFIX, name, PROPERTY_ALIASES, PROPERTY_NAME, PROPERTY_READONLOAD, PROPERTY_READONLY, PROPERTY_STOREONDISPOSAL, propertyGetter, propertySetter, readOnLoad, storeOnDisposal
-
-
Constructor Summary
Constructors Constructor Description SpreadsheetModel()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addReference(SpreadsheetReference reference)
Associate the given reference with this spreadsheet.void
addWorksheet(SpreadsheetWorksheet worksheet)
The purpose of this method is to associate the given worksheet with this spreadsheet.List<SpreadsheetRow>
allContents()
This method returns all rows of all worksheets.Object
createInstance(String type)
This method creates a blank row in the worksheet identifiable by type.Object
createInstance(String type, Collection<Object> parameters)
This method creates a new row in the worksheet identifiable by type.Object
createInstance(String type, Map<String,Object> parameters)
This method creates a new row in the worksheet identifiable by type.protected abstract SpreadsheetWorksheet
createWorksheet(ISpreadsheetMetadata.SpreadsheetWorksheetMetadata worksheetMetadata)
The purpose of this method is to create a worksheet.void
deleteElement(Object instance)
This method deletes the given instance (row) from the worksheet it belongs to.protected abstract void
deleteWorksheet(SpreadsheetWorksheet worksheet)
The purpose of this method is to delete the given worksheet from this spreadsheetvoid
dispose()
abstract Collection<SpreadsheetRow>
find(Variable iterator, ModuleElement ast, IEolContext context)
Object
findOne(Variable iterator, ModuleElement ast, IEolContext context)
Collection<SpreadsheetRow>
getAllOfKind(String type)
List<SpreadsheetRow>
getAllOfType(String type)
Returns every row contained by the worksheet identifiable by the given type.Object
getElementById(String id)
String
getElementId(Object instance)
Object
getEnumerationValue(String enumeration, String label)
IPropertySetter
getPropertySetter()
List<SpreadsheetReference>
getReferences()
Set<SpreadsheetReference>
getReferencesBySource(SpreadsheetWorksheet worksheet)
The purpose of this method is to find all references where the given worksheet is a source i.e.Set<SpreadsheetReference>
getReferencesBySource(SpreadsheetWorksheet worksheet, SpreadsheetColumn column)
The purpose of this method is to find all references where the given worksheet and column is a source i.e.Set<SpreadsheetReference>
getReferencesByTarget(SpreadsheetWorksheet worksheet)
The purpose of this method is to find all references where the given worksheet is a target i.e.Set<SpreadsheetReference>
getReferencesByTarget(SpreadsheetWorksheet worksheet, SpreadsheetColumn column)
The purpose of this method is to find all references where the given worksheet and column is a target i.e.protected abstract ISpreadsheetMetadata
getSpreadsheetMetadata()
The purpose of this method is to return an instance of the ISpreadsheetMetadata implementation for retrieving metadata for this spreadsheet modelString
getTypeNameOf(Object instance)
This method returns the name of the worksheet that the instance (row) belongs to.SpreadsheetWorksheet
getTypeOf(Object instance)
This method returns the worksheet that the given instance (row) belongs to.SpreadsheetWorksheet
getWorksheetByType(String type)
This method returns the first worksheet of the given type as determined bySpreadsheetWorksheet.isIdentifiablyBy(String)
method.List<SpreadsheetWorksheet>
getWorksheets()
boolean
hasType(String type)
boolean
isInstantiable(String type)
boolean
isLoaded()
protected abstract boolean
isMetadataConfigurationDefined()
void
load()
protected void
loadColumnsFromMetadata(ISpreadsheetMetadata metadata, SpreadsheetWorksheet worksheet)
protected void
loadConfigurationFile()
The purpose of this method is to load the configuration fileprotected void
loadReferenceFromConfigurationFile(ISpreadsheetMetadata.SpreadsheetReferenceMetadata referenceMetadata)
protected abstract void
loadSpreadsheet()
The purpose of this method is to load the spreadsheet.protected void
loadWorksheetFromConfigurationFile(ISpreadsheetMetadata metadata, ISpreadsheetMetadata.SpreadsheetWorksheetMetadata worksheetMetadata)
boolean
owns(Object instance)
Used to test whether an object is contained in this model.void
setElementId(Object instance, String newId)
boolean
store()
boolean
store(String location)
-
Methods inherited from class org.eclipse.epsilon.eol.models.Model
allInstances, getAliases, getFullyQualifiedTypeNameOf, getMetamodel, getName, getPropertyGetter, getTransactionSupport, isModelElement, isOfKind, isOfType, isPropertySet, isReadOnLoad, isStoredOnDisposal, knowsAboutProperty, load, load, load, setName, setReadOnLoad, setStoredOnDisposal
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.epsilon.eol.models.IModel
checkAmbiguity, close
-
-
-
-
Field Detail
-
worksheets
protected List<SpreadsheetWorksheet> worksheets
-
references
protected List<SpreadsheetReference> references
-
isLoaded
protected boolean isLoaded
-
-
Method Detail
-
getPropertySetter
public IPropertySetter getPropertySetter()
- Specified by:
getPropertySetter
in interfaceIModel
- Overrides:
getPropertySetter
in classModel
-
getWorksheets
public List<SpreadsheetWorksheet> getWorksheets()
-
addWorksheet
public void addWorksheet(SpreadsheetWorksheet worksheet)
The purpose of this method is to associate the given worksheet with this spreadsheet. Any worksheet that starts with SpreadsheetConstants.WSH_IGNORE_CHARS is ignored.- Parameters:
worksheet
-
-
getReferences
public List<SpreadsheetReference> getReferences()
-
addReference
public void addReference(SpreadsheetReference reference)
Associate the given reference with this spreadsheet.- Parameters:
reference
-
-
load
public void load() throws EolModelLoadingException
- Specified by:
load
in interfaceIModel
- Throws:
EolModelLoadingException
-
isLoaded
public boolean isLoaded()
- Since:
- 1.6
-
dispose
public void dispose()
-
loadSpreadsheet
protected abstract void loadSpreadsheet() throws Exception
The purpose of this method is to load the spreadsheet.- Throws:
Exception
-
getSpreadsheetMetadata
protected abstract ISpreadsheetMetadata getSpreadsheetMetadata()
The purpose of this method is to return an instance of the ISpreadsheetMetadata implementation for retrieving metadata for this spreadsheet model
-
loadConfigurationFile
protected void loadConfigurationFile() throws Exception
The purpose of this method is to load the configuration file- Throws:
Exception
-
isMetadataConfigurationDefined
protected abstract boolean isMetadataConfigurationDefined()
- Returns:
- true if metadata has been provided, false otherwise
-
loadWorksheetFromConfigurationFile
protected void loadWorksheetFromConfigurationFile(ISpreadsheetMetadata metadata, ISpreadsheetMetadata.SpreadsheetWorksheetMetadata worksheetMetadata) throws Exception
- Throws:
Exception
-
createWorksheet
protected abstract SpreadsheetWorksheet createWorksheet(ISpreadsheetMetadata.SpreadsheetWorksheetMetadata worksheetMetadata) throws Exception
The purpose of this method is to create a worksheet.- Parameters:
worksheetMetadata
-- Returns:
- newly created worksheet
- Throws:
Exception
-
loadColumnsFromMetadata
protected void loadColumnsFromMetadata(ISpreadsheetMetadata metadata, SpreadsheetWorksheet worksheet)
-
loadReferenceFromConfigurationFile
protected void loadReferenceFromConfigurationFile(ISpreadsheetMetadata.SpreadsheetReferenceMetadata referenceMetadata)
-
getEnumerationValue
public Object getEnumerationValue(String enumeration, String label)
- Specified by:
getEnumerationValue
in interfaceIModel
-
allContents
public List<SpreadsheetRow> allContents()
This method returns all rows of all worksheets.- Specified by:
allContents
in interfaceIModel
- Returns:
- all of the objects contained in this model.
-
getAllOfType
public List<SpreadsheetRow> getAllOfType(String type) throws EolModelElementTypeNotFoundException
Returns every row contained by the worksheet identifiable by the given type.- Specified by:
getAllOfType
in interfaceIModel
- Throws:
EolModelElementTypeNotFoundException
-
getAllOfKind
public Collection<SpreadsheetRow> getAllOfKind(String type) throws EolModelElementTypeNotFoundException
- Specified by:
getAllOfKind
in interfaceIModel
- Throws:
EolModelElementTypeNotFoundException
-
getTypeOf
public SpreadsheetWorksheet getTypeOf(Object instance)
This method returns the worksheet that the given instance (row) belongs to. If the instance is not a SpreadsheetRow object then null is returned.
-
getTypeNameOf
public String getTypeNameOf(Object instance)
This method returns the name of the worksheet that the instance (row) belongs to.- Specified by:
getTypeNameOf
in interfaceIModel
- Parameters:
instance
- The model object whose type is to be determined.- Returns:
- the name of the type of the model object, instance.
-
createInstance
public Object createInstance(String type) throws EolModelElementTypeNotFoundException
This method creates a blank row in the worksheet identifiable by type. The newly created SpreadsheetRow is returned.- Specified by:
createInstance
in interfaceIModel
- Throws:
EolModelElementTypeNotFoundException
-
createInstance
public Object createInstance(String type, Collection<Object> parameters) throws EolModelElementTypeNotFoundException
This method creates a new row in the worksheet identifiable by type. The given collection is expected to contain one instance of map. Every cell is assigned a value from the map in the order in which the values are returned by the collections framework. If the worksheet does not exist in the spreadsheet then an attempt is made to create it.- Specified by:
createInstance
in interfaceIModel
- Overrides:
createInstance
in classModel
- Throws:
EolModelElementTypeNotFoundException
-
createInstance
public Object createInstance(String type, Map<String,Object> parameters) throws EolModelElementTypeNotFoundException
This method creates a new row in the worksheet identifiable by type. Every cell is assigned a value from the map in the order in which the values are returned by the collections framework. If the worksheet does not exist in the spreadsheet then an attempt is made to create it.- Parameters:
type
-parameters
-- Returns:
- newly created SpreadsheetRow
- Throws:
EolModelElementTypeNotFoundException
- if worksheet cannot be found
-
getElementById
public Object getElementById(String id)
- Specified by:
getElementById
in interfaceIModel
-
getElementId
public String getElementId(Object instance)
- Specified by:
getElementId
in interfaceIModel
-
setElementId
public void setElementId(Object instance, String newId)
- Specified by:
setElementId
in interfaceIModel
-
deleteElement
public void deleteElement(Object instance) throws EolRuntimeException
This method deletes the given instance (row) from the worksheet it belongs to.- Specified by:
deleteElement
in interfaceIModel
- Throws:
EolRuntimeException
-
owns
public boolean owns(Object instance)
Description copied from interface:IModel
Used to test whether an object is contained in this model.
-
isInstantiable
public boolean isInstantiable(String type)
- Specified by:
isInstantiable
in interfaceIModel
-
getWorksheetByType
public SpreadsheetWorksheet getWorksheetByType(String type)
This method returns the first worksheet of the given type as determined bySpreadsheetWorksheet.isIdentifiablyBy(String)
method.- Parameters:
type
-- Returns:
- worksheet identifiable by type or null if none found
-
getReferencesBySource
public Set<SpreadsheetReference> getReferencesBySource(SpreadsheetWorksheet worksheet)
The purpose of this method is to find all references where the given worksheet is a source i.e. is referencing.- Parameters:
worksheet
-- Returns:
- Set
-
getReferencesBySource
public Set<SpreadsheetReference> getReferencesBySource(SpreadsheetWorksheet worksheet, SpreadsheetColumn column)
The purpose of this method is to find all references where the given worksheet and column is a source i.e. are referencing.- Parameters:
worksheet
-column
-- Returns:
- Set
-
getReferencesByTarget
public Set<SpreadsheetReference> getReferencesByTarget(SpreadsheetWorksheet worksheet)
The purpose of this method is to find all references where the given worksheet is a target i.e. being referenced.- Parameters:
worksheet
-- Returns:
- Set
-
getReferencesByTarget
public Set<SpreadsheetReference> getReferencesByTarget(SpreadsheetWorksheet worksheet, SpreadsheetColumn column)
The purpose of this method is to find all references where the given worksheet and column is a target i.e. being referenced.- Parameters:
worksheet
-column
-- Returns:
- Set
-
findOne
public Object findOne(Variable iterator, ModuleElement ast, IEolContext context) throws EolRuntimeException
- Specified by:
findOne
in interfaceISearchableModel
- Throws:
EolRuntimeException
-
find
public abstract Collection<SpreadsheetRow> find(Variable iterator, ModuleElement ast, IEolContext context) throws EolRuntimeException
- Specified by:
find
in interfaceISearchableModel
- Throws:
EolRuntimeException
-
deleteWorksheet
protected abstract void deleteWorksheet(SpreadsheetWorksheet worksheet)
The purpose of this method is to delete the given worksheet from this spreadsheet- Parameters:
worksheet
-
-
-