KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > framework > amoda > generic > core > GenericWorkspaceAbstract


1 /*
2  * Project: AMODA - Abstract Modeled Application
3  * Class: de.gulden.framework.amoda.generic.core.GenericWorkspaceAbstract
4  * Version: snapshot-beautyj-1.1
5  *
6  * Date: 2004-09-29
7  *
8  * This is a snapshot version of the AMODA 0.2 development branch,
9  * it is not released as a seperate version.
10  * For AMODA, see http://amoda.berlios.de/.
11  *
12  * This is licensed under the GNU Lesser General Public License (LGPL)
13  * and comes with NO WARRANTY.
14  *
15  * Author: Jens Gulden
16  * Email: amoda@jensgulden.de
17  */

18
19 package de.gulden.framework.amoda.generic.core;
20
21 import de.gulden.framework.amoda.generic.metadata.*;
22 import de.gulden.framework.amoda.generic.option.*;
23 import de.gulden.framework.amoda.model.core.Workspace;
24 import de.gulden.framework.amoda.model.document.*;
25 import java.util.*;
26
27 /**
28  * Class GenericWorkspaceAbstract.
29  *
30  * @author Jens Gulden
31  * @version snapshot-beautyj-1.1
32  */

33 public abstract class GenericWorkspaceAbstract implements Workspace {
34
35     // ------------------------------------------------------------------------
36
// --- fields ---
37
// ------------------------------------------------------------------------
38

39     protected Collection documents = new ArrayList();
40
41     protected Hashtable viewsByDocument = new Hashtable();
42
43     protected Hashtable selectionByView = new Hashtable();
44
45     protected GenericApplicationEnvironment environment;
46
47
48     // ------------------------------------------------------------------------
49
// --- methods ---
50
// ------------------------------------------------------------------------
51

52     public GenericApplicationEnvironment getEnvironment() {
53         return environment;
54     }
55
56     public void setEnvironment(GenericApplicationEnvironment genericApplicationEnvironment) {
57         this.environment = genericApplicationEnvironment;
58     }
59
60     public abstract void setActiveView(DocumentView view);
61
62     public abstract DocumentView getActiveView();
63
64     public Document getActiveDocument() {
65         DocumentView view=getActiveView();
66         if (view!=null) {
67             return view.getDocument();
68         } else {
69             return null;
70         }
71     }
72
73     public DocumentSelection getActiveSelection() {
74         DocumentView v=getActiveView();
75         if (v!=null) {
76             return getSelection(v);
77         } else {
78             return null;
79         }
80     }
81
82     public Collection getViews(Document doc) {
83         return (Collection)viewsByDocument.get(doc);
84     }
85
86     public Collection getAllViews() {
87         ArrayList list=new ArrayList();
88         for (Iterator it=viewsByDocument.values().iterator();it.hasNext();) {
89             Collection c=(Collection)it.next();
90             list.addAll(c);
91         }
92         return list;
93     }
94
95     public void setSelection(DocumentView view, DocumentSelection sel) {
96         if (sel!=null) {
97             selectionByView.put(view,sel);
98         } else {
99             selectionByView.remove(view);
100         }
101     }
102
103     public Collection getAllSelections(Document doc) {
104         ArrayList list=new ArrayList();
105         for (Iterator it=getViews(doc).iterator();it.hasNext();) {
106             Object JavaDoc sel=selectionByView.get(it.next());
107             if (sel!=null) {
108                 list.add(sel);
109             }
110         }
111         return list;
112     }
113
114     public DocumentSelection getSelection(DocumentView view) {
115         return (DocumentSelection)selectionByView.get(view);
116     }
117
118     public Collection getAllSelections() {
119         return selectionByView.values();
120     }
121
122     public void addView(DocumentView view) {
123         Document doc=view.getDocument();
124         if (!documents.contains(doc)) {
125             documents.add(doc);
126             viewsByDocument.put(doc,new ArrayList());
127         }
128         ((Collection)viewsByDocument.get(doc)).add(view);
129     }
130
131     public void removeView(DocumentView view) {
132         Document doc=view.getDocument();
133         Collection views=(Collection)viewsByDocument.get(doc);
134         if (views!=null) {
135             views.remove(view);
136             if (views.isEmpty()) {
137                 viewsByDocument.remove(doc);
138                 documents.remove(doc);
139             }
140         }
141     }
142
143     public Collection getDocuments() {
144         return documents;
145     }
146
147     public void setDocuments(Collection _documents) {
148         documents = _documents;
149     }
150
151 } // end GenericWorkspaceAbstract
152
Popular Tags