001: /*
002: * Project: AMODA - Abstract Modeled Application
003: * Class: de.gulden.framework.amoda.generic.core.GenericWorkspaceAbstract
004: * Version: snapshot-beautyj-1.1
005: *
006: * Date: 2004-09-29
007: *
008: * This is a snapshot version of the AMODA 0.2 development branch,
009: * it is not released as a seperate version.
010: * For AMODA, see http://amoda.berlios.de/.
011: *
012: * This is licensed under the GNU Lesser General Public License (LGPL)
013: * and comes with NO WARRANTY.
014: *
015: * Author: Jens Gulden
016: * Email: amoda@jensgulden.de
017: */
018:
019: package de.gulden.framework.amoda.generic.core;
020:
021: import de.gulden.framework.amoda.generic.metadata.*;
022: import de.gulden.framework.amoda.generic.option.*;
023: import de.gulden.framework.amoda.model.core.Workspace;
024: import de.gulden.framework.amoda.model.document.*;
025: import java.util.*;
026:
027: /**
028: * Class GenericWorkspaceAbstract.
029: *
030: * @author Jens Gulden
031: * @version snapshot-beautyj-1.1
032: */
033: public abstract class GenericWorkspaceAbstract implements Workspace {
034:
035: // ------------------------------------------------------------------------
036: // --- fields ---
037: // ------------------------------------------------------------------------
038:
039: protected Collection documents = new ArrayList();
040:
041: protected Hashtable viewsByDocument = new Hashtable();
042:
043: protected Hashtable selectionByView = new Hashtable();
044:
045: protected GenericApplicationEnvironment environment;
046:
047: // ------------------------------------------------------------------------
048: // --- methods ---
049: // ------------------------------------------------------------------------
050:
051: public GenericApplicationEnvironment getEnvironment() {
052: return environment;
053: }
054:
055: public void setEnvironment(
056: GenericApplicationEnvironment genericApplicationEnvironment) {
057: this .environment = genericApplicationEnvironment;
058: }
059:
060: public abstract void setActiveView(DocumentView view);
061:
062: public abstract DocumentView getActiveView();
063:
064: public Document getActiveDocument() {
065: DocumentView view = getActiveView();
066: if (view != null) {
067: return view.getDocument();
068: } else {
069: return null;
070: }
071: }
072:
073: public DocumentSelection getActiveSelection() {
074: DocumentView v = getActiveView();
075: if (v != null) {
076: return getSelection(v);
077: } else {
078: return null;
079: }
080: }
081:
082: public Collection getViews(Document doc) {
083: return (Collection) viewsByDocument.get(doc);
084: }
085:
086: public Collection getAllViews() {
087: ArrayList list = new ArrayList();
088: for (Iterator it = viewsByDocument.values().iterator(); it
089: .hasNext();) {
090: Collection c = (Collection) it.next();
091: list.addAll(c);
092: }
093: return list;
094: }
095:
096: public void setSelection(DocumentView view, DocumentSelection sel) {
097: if (sel != null) {
098: selectionByView.put(view, sel);
099: } else {
100: selectionByView.remove(view);
101: }
102: }
103:
104: public Collection getAllSelections(Document doc) {
105: ArrayList list = new ArrayList();
106: for (Iterator it = getViews(doc).iterator(); it.hasNext();) {
107: Object sel = selectionByView.get(it.next());
108: if (sel != null) {
109: list.add(sel);
110: }
111: }
112: return list;
113: }
114:
115: public DocumentSelection getSelection(DocumentView view) {
116: return (DocumentSelection) selectionByView.get(view);
117: }
118:
119: public Collection getAllSelections() {
120: return selectionByView.values();
121: }
122:
123: public void addView(DocumentView view) {
124: Document doc = view.getDocument();
125: if (!documents.contains(doc)) {
126: documents.add(doc);
127: viewsByDocument.put(doc, new ArrayList());
128: }
129: ((Collection) viewsByDocument.get(doc)).add(view);
130: }
131:
132: public void removeView(DocumentView view) {
133: Document doc = view.getDocument();
134: Collection views = (Collection) viewsByDocument.get(doc);
135: if (views != null) {
136: views.remove(view);
137: if (views.isEmpty()) {
138: viewsByDocument.remove(doc);
139: documents.remove(doc);
140: }
141: }
142: }
143:
144: public Collection getDocuments() {
145: return documents;
146: }
147:
148: public void setDocuments(Collection _documents) {
149: documents = _documents;
150: }
151:
152: } // end GenericWorkspaceAbstract
|