Source code: org/modama/framework/entities/AbstractEntity.java
1 /**
2 Modama project, Institute for Polymer Research Dresden
3 Copyright (C) 2003 P. Fritsche, A. Uhlig
4 http://www.modama.org
5 info@modama.org
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 file created: Apr 2, 2003
22 */
23 package org.modama.framework.entities;
24
25 import org.modama.framework.exceptions.DeleteCancelledException;
26 import org.modama.framework.AbstractFrameworkModel;
27 import org.modama.framework.world.World;
28
29 import java.awt.datatransfer.*;
30 import java.io.IOException;
31 import java.net.URL;
32
33 /**
34 * The base class for all entities.<br>
35 * A entity a piece of data, wrapped so it can be loaded, saved,...<br>
36 * An entity has a name to display, a fullname if additional naming is required
37 * (i.e. filename) and some data and a unique ID
38 */
39 public abstract class AbstractEntity extends AbstractFrameworkModel
40 {
41 public static final String PROP_FULLNAME = "fullName";
42 public static final String PROP_DATA = "data";
43 /**
44 * the full name
45 */
46 protected String fullName;
47 /**
48 * the piece of data that is wrapped by this entity
49 *
50 * this should be defined in the concret entity classes
51 */
52 //protected Object data;
53 /**
54 * a unique id
55 */
56 protected Long ID;
57 /**
58 * counter to create uniqe ids
59 */
60 protected static long IDcnt = 0;
61
62 /**
63 * create an empty entity
64 */
65 public AbstractEntity()
66 {
67 this("enity");
68 }
69
70 /**
71 * make entity with given name
72 * @param name
73 */
74 public AbstractEntity( String name )
75 {
76 this.name = name;
77 ID = new Long(IDcnt++);
78 create();
79 }
80
81 /**
82 * put the entity to the world
83 */
84 protected void create() {
85 state = CREATED;
86 World.getInstance().put( this );
87 }
88
89 /**
90 * delete the entity from the world
91 * @throws DeleteCancelledException
92 */
93 public void delete() throws DeleteCancelledException {
94 state = DELETED;
95 World.getInstance().remove( this );
96 }
97
98 /**
99 * getter for full name
100 * @return
101 */
102 public String getFullName()
103 {
104 return fullName;
105 }
106
107 /**
108 * setter for fullname, causes fire
109 * @param fullName
110 */
111 public void setFullName( String fullName )
112 {
113 String old= this.fullName;
114 this.fullName = fullName;
115 this.fullName = (String)this.fire(PROP_FULLNAME, old, fullName );
116 }
117
118 /**
119 * should return true if their is no data, this is used by the operations to know wether they can execute
120 * @return
121 */
122 public abstract boolean isEmpty();
123
124 /**
125 * getter for data
126 * @return
127 */
128 public abstract Object getData();
129 /*
130 public Object getData()
131 {
132 return data;
133 }
134 */
135
136 /**
137 * setter for data, cause fire
138 * @param data
139 */
140 public abstract void setData( Object data );
141 /*
142 public void setData( Object data )
143 {
144 Object old = this.data;
145 if( old != data ){
146 this.data = data;
147 state = MODIFIED;
148 this.data = (Object)this.fire(PROP_DATA, old, data );
149 }
150 }
151 */
152
153 public Object getID()
154 {
155 return ID;
156 }
157 }