001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright © 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.pm.graphic.graph;
051:
052: import java.io.Serializable;
053: import java.util.EventListener;
054: import java.util.Iterator;
055: import java.util.LinkedList;
056: import java.util.List;
057: import java.util.ListIterator;
058:
059: import javax.swing.event.EventListenerList;
060:
061: import com.projity.configuration.Configuration;
062: import com.projity.field.Field;
063: import com.projity.graphic.configuration.BarStyles;
064: import com.projity.grouping.core.model.NodeModel;
065: import com.projity.pm.assignment.Assignment;
066: import com.projity.pm.graphic.graph.event.GraphEvent;
067: import com.projity.pm.graphic.graph.event.GraphListener;
068: import com.projity.pm.graphic.model.cache.GraphicNode;
069: import com.projity.pm.graphic.model.cache.NodeModelCache;
070: import com.projity.pm.graphic.model.event.CacheListener;
071: import com.projity.pm.graphic.model.event.CompositeCacheEvent;
072: import com.projity.pm.task.Project;
073: import com.projity.pm.task.Task;
074: import com.projity.util.Environment;
075:
076: /**
077: *
078: */
079: public class GraphModel implements Serializable, /*ScheduleEventListener,*/
080: CacheListener /*ObjectEvent.Listener*/{
081: private static final long serialVersionUID = -6589463266745797527L;
082: protected NodeModelCache cache;
083: protected BarStyles barStyles;
084: protected Project project;
085: protected static Field nameField = Configuration
086: .getFieldFromId("Field.name");
087:
088: public GraphModel(Project project, String viewName) {
089: this .project = project;
090: }
091:
092: public void close() {
093: setCache(null);
094: }
095:
096: protected void finalize() throws Throwable {
097: super .finalize();
098: close();
099: }
100:
101: public BarStyles getBarStyles() {
102: return barStyles;
103: }
104:
105: public void setBarStyles(BarStyles barStyles) {
106: this .barStyles = barStyles;
107: }
108:
109: //cache: nodes
110: public NodeModelCache getCache() {
111: return cache;
112: }
113:
114: public void setCache(NodeModelCache cache) {
115: if (this .cache != null) {
116: this .cache.removeNodeModelListener(this );
117: }
118: this .cache = cache;
119: cache.addNodeModelListener(this );
120:
121: }
122:
123: public ListIterator getNodeIterator() {
124: return cache.getIterator();
125: }
126:
127: public ListIterator getNodeIterator(int i) {
128: return cache.getIterator(i);
129: }
130:
131: public ListIterator getDependencyIterator() {
132: return cache.getEdgesIterator();
133: }
134:
135: public List searchJustModifiedNodes() {
136: LinkedList gnodes = new LinkedList();
137: GraphicNode gnode;
138: Object impl;
139: for (Iterator i = getCache().getIterator(); i.hasNext();) {
140: gnode = (GraphicNode) i.next();
141: impl = gnode.getNode().getImpl();
142: if (impl instanceof Task) {
143: if (((Task) impl).isJustModified())
144: gnodes.add(gnode);
145: } else if (impl instanceof Assignment) { //assignment
146: if (((Task) getCache().getModel().getParent(
147: gnode.getNode()).getImpl()).isJustModified())
148: gnodes.add(gnode);
149: }
150: }
151: return gnodes;
152: }
153:
154: public List searchNode(Object impl) {
155: LinkedList gnodes = new LinkedList();
156: GraphicNode gnode;
157: for (Iterator i = getCache().getIterator(); i.hasNext();) {
158: gnode = (GraphicNode) i.next();
159: if (gnode.getNode().getImpl() == impl) {
160: gnodes.add(gnode);
161: break;
162: }
163: }
164: return gnodes;
165: }
166:
167: //ScheduleEventListener
168: // public void scheduleChanged(ScheduleEvent evt) {
169: // //update((evt.getObject()==null)?searchJustModifiedNodes():searchNode(evt.getObject()),true);
170: //// done throught cache
171: // }
172: //
173: // //ObjectEvent.Listener
174: // public void objectChanged(ObjectEvent objectEvent) {
175: // }
176:
177: //NodeModelListener
178: public void graphicNodesCompositeEvent(
179: CompositeCacheEvent compositeEvent) {
180: if (compositeEvent.getRemovedNodes() != null)
181: remove(compositeEvent.getRemovedNodes(), false);
182:
183: if (compositeEvent.getInsertedNodes() != null)
184: insert(compositeEvent.getInsertedNodes(), false);
185:
186: // updateAll(false);
187: update(compositeEvent.getUpdatedNodes(), false);
188:
189: if (compositeEvent.getRemovedEdges() != null)
190: removeEdges(compositeEvent.getRemovedEdges(), false);
191:
192: if (compositeEvent.getInsertedEdges() != null)
193: insertEdges(compositeEvent.getInsertedEdges(), false);
194:
195: if (compositeEvent.getUpdatedEdges() != null)
196: updateEdges(compositeEvent.getUpdatedEdges(), false);
197: }
198:
199: public void updateAll(boolean event) {
200: update(null, event);
201: }
202:
203: protected void update(List nodes, boolean event) {
204: fireUpdate(this , nodes);
205: }
206:
207: public void insertAll(boolean event) {
208: if (cache.getSize() > 0)
209: insert(null, true, event);
210: }
211:
212: protected void insert(List nodes, boolean event) {
213: insert(nodes, false, event);
214: }
215:
216: protected void insert(List nodes, boolean init, boolean event) {
217: }
218:
219: public void removeAll(boolean event) {
220: remove((List) null, event);
221: }
222:
223: protected void remove(List nodes, boolean event) {
224: }
225:
226: protected void insertEdges(List edges, boolean event) {
227: }
228:
229: protected void removeEdges(List edges, boolean event) {
230: }
231:
232: protected void updateEdges(List edges, boolean event) {
233: }
234:
235: /*public void scheduleChanged(ScheduleEvent evt) {
236: super.scheduleChanged(evt);
237: if (evt.getType() == ScheduleEvent.BASELINE){
238: if (evt.isSaveSnapshot())
239: baseLines.add(evt.getSnapshot());
240: else baseLines.remove(evt.getSnapshot());
241: int num=(baseLines.size()==0)?0:((Integer)baseLines.last()).intValue();
242: rowHeight=GraphicConfiguration.getInstance().getRowHeight()
243: +(num+1)*GraphicConfiguration.getInstance().getBaselineHeight();
244: updateAll(true);
245: }
246: }*/
247:
248: //view events
249: protected EventListenerList listenerList = new EventListenerList();
250:
251: public void addGraphListener(GraphListener l) {
252: listenerList.add(GraphListener.class, l);
253: }
254:
255: public void removeGraphListener(GraphListener l) {
256: listenerList.remove(GraphListener.class, l);
257: }
258:
259: public GraphListener[] getGraphListeners() {
260: return (GraphListener[]) listenerList
261: .getListeners(GraphListener.class);
262: }
263:
264: protected void fireUpdate(Object source, List nodes) {
265: Object[] listeners = listenerList.getListenerList();
266: GraphEvent e = null;
267: for (int i = listeners.length - 2; i >= 0; i -= 2) {
268: if (listeners[i] == GraphListener.class) {
269: if (e == null) {
270: e = new GraphEvent(source, nodes);
271: }
272: ((GraphListener) listeners[i + 1]).updateGraph(e);
273: }
274: }
275: }
276:
277: public EventListener[] getListeners(Class listenerType) {
278: return listenerList.getListeners(listenerType);
279: }
280:
281: public boolean isReadOnly() {
282: NodeModel nodeModel = cache.getModel();
283: return !nodeModel.isLocal() && !nodeModel.isMaster()
284: && !Environment.getStandAlone();
285: }
286:
287: }
|