001: package abbot.editor;
002:
003: import abbot.finder.TestHierarchy;
004:
005: import abbot.script.Script;
006:
007: import java.awt.Component;
008:
009: import java.io.File;
010:
011: import java.util.HashSet;
012: import java.util.Set;
013:
014: /**
015: * Provide a transport for the editor context. This is usefull in cases where
016: * the costello editor is invoked inside of another application. It can also
017: * be used to provide further editor customization, for example a new file
018: * template, depending on the context.
019: */
020:
021: public class EditorContext {
022:
023: private String _arguments[];
024: private boolean _embedded;
025: private TestHierarchy _hierarchy = null;
026: private SecurityManager _securityManager = null;
027: private File _newFileTemplate = null;
028: private FileSystemHelper _fileSystemHelper = new FileSystemHelper();
029:
030: public EditorContext(String[] arguments) {
031: _arguments = arguments;
032: }
033:
034: public EditorContext() {
035: _arguments = new String[0];
036: }
037:
038: //
039: // Getters and setters
040: //
041:
042: public String[] getArguments() {
043: return (String[]) _arguments.clone();
044: }
045:
046: public void setArguments(String[] arguments) {
047: _arguments = arguments;
048: }
049:
050: /**
051: * @return Whether the costello editor is being embdeed in another application
052: */
053: public boolean isEmbedded() {
054: return _embedded;
055: }
056:
057: /**
058: * @param embedded Whether costello is embedded in another application
059: */
060: public void setEmbedded(boolean embedded) {
061: _embedded = embedded;
062: }
063:
064: /**
065: * @return A hierarchy that can preconfigured to filter certain components
066: * ignoreExisting call. This is usefull in the embedded case.
067: */
068: public TestHierarchy getTestHierarchy() {
069: return _hierarchy;
070: }
071:
072: /**
073: * @param hierarchy A hierarchy that can preconfigured to filter certain components
074: * @throws IllegalStateException if we are not in an embedded mode
075: */
076: public void setTestHierarchy(TestHierarchy hierarchy) {
077: if (!isEmbedded()) {
078: throw new IllegalStateException(
079: "Only value when Costello is to be embedded");
080: }
081:
082: _hierarchy = hierarchy;
083: }
084:
085: /**
086: * @param newFileTemplate The file to be used when creating new
087: * scripts.
088: */
089: public void setNewFileTemplate(File newFileTemplate) {
090: if (!newFileTemplate.exists()) {
091: throw new IllegalArgumentException("File doesn't exist");
092: }
093: if (!Script.isScript(newFileTemplate)) {
094: throw new IllegalArgumentException(
095: "File doesn't appears to be a script");
096: }
097:
098: _newFileTemplate = newFileTemplate;
099: }
100:
101: /**
102: * @return The file to be used
103: */
104: public File getNewFileTemplate() {
105: return _newFileTemplate;
106: }
107:
108: /**
109: * @param securityManager The secutiry manager for this context
110: */
111:
112: public void setSecurityManager(SecurityManager securityManager) {
113: _securityManager = securityManager;
114: }
115:
116: /**
117: * @return The security manage for this context
118: */
119:
120: public SecurityManager getSecurityManager() {
121: return _securityManager;
122: }
123:
124: /**
125: * @param helper A file system helper for this context, usefull for the
126: * case where the costello editor is emdedded in an IDE
127: */
128: public void setFileSysteHelper(FileSystemHelper helper) {
129: _fileSystemHelper = helper;
130: }
131:
132: /**
133: * @return A file system helper for this context
134: */
135:
136: public FileSystemHelper getFileSystemHelper() {
137: return _fileSystemHelper;
138: }
139:
140: }
|