shortened display text of variable proposal in content assist
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / bookmarks / Bookmark.java
1 package net.sourceforge.phpdt.sql.bookmarks;
2
3 import java.sql.Connection;
4
5 import net.sourceforge.phpdt.sql.sql.ConnectionEstablisher;
6 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
7
8 /**
9  * @author root
10  * Class Bookmark holds the "static" information of a bookmark, that is the data that
11  * is saved and loaded from the external file and describes a bookmark. This info will
12  * be filled up by the end user.
13  */
14 public class Bookmark {
15         String name = ""; //$NON-NLS-1$
16         String username = ""; //$NON-NLS-1$
17         String password = ""; //$NON-NLS-1$
18         String connect = ""; //$NON-NLS-1$
19         String driver = ""; //$NON-NLS-1$
20         String type = ""; //$NON-NLS-1$
21         String driverFile = ""; //$NON-NLS-1$
22         String schema = ""; //$NON-NLS-1$
23     private ConnectionEstablisher connectionEstablisher;
24         
25         public Bookmark() {
26         this(MultiSQLServer.getInstance());
27         }
28     
29     public Bookmark(ConnectionEstablisher connectionEstablisher) {
30         this.connectionEstablisher = connectionEstablisher;
31     }
32
33         public Bookmark(Bookmark data) {
34                 setName(data.getName());
35                 setUsername(data.getUsername());
36                 setPassword(data.getPassword());
37                 setConnect(data.getConnect());
38                 setDriver(data.getDriver());
39                 setType(data.getType());
40                 setDriverFile(data.getDriverFile());
41         }
42
43         /**
44          * Returns the JDBC URL.
45          * @return String
46          */
47         public String getConnect() {
48                 return connect;
49         }
50
51         /**
52          * Returns the driver.
53          * @return String
54          */
55         public String getDriver() {
56                 return driver;
57         }
58
59         /**
60          * Returns the driverFile.
61          * @return String
62          */
63         public String getDriverFile() {
64                 return driverFile;
65         }
66
67         /**
68          * Returns the password.
69          * @return String
70          */
71         public String getPassword() {
72                 return password;
73         }
74
75         /**
76          * Returns the username.
77          * @return String
78          */
79         public String getUsername() {
80                 return username;
81         }
82
83         /**
84          * Sets the connect.
85          * @param connect The connect to set
86          */
87         public void setConnect(String connect) {
88                 if (connect == null) {
89                         connect = ""; //$NON-NLS-1$
90                 }
91                 this.connect = connect;
92         }
93
94         /**
95          * Sets the driver.
96          * @param driver The driver to set
97          */
98         public void setDriver(String driver) {
99                 if (driver == null) {
100                         driver = ""; //$NON-NLS-1$
101                 }
102                 this.driver = driver;
103         }
104
105         /**
106          * Sets the driverFile.
107          * @param driverFile The driverFile to set
108          */
109         public void setDriverFile(String driverFile) {
110                 if (driverFile == null) {
111                         driverFile = ""; //$NON-NLS-1$
112                 }
113                 this.driverFile = driverFile;
114         }
115
116         /**
117          * Sets the password.
118          * @param password The password to set
119          */
120         public void setPassword(String password) {
121                 if (password == null) {
122                         password = ""; //$NON-NLS-1$
123                 }
124                 this.password = password;
125         }
126
127         /**
128          * Sets the username.
129          * @param username The username to set
130          */
131         public void setUsername(String username) {
132                 if (username == null) {
133                         username = ""; //$NON-NLS-1$
134                 }
135                 this.username = username;
136         }
137
138         /**
139          * Returns the name.
140          * @return String
141          */
142         public String getName() {
143                 return name;
144         }
145
146         /**
147          * Sets the name.
148          * @param name The name to set
149          */
150         public void setName(String name) {
151                 if (name == null) {
152                         name = ""; //$NON-NLS-1$
153                 }
154                 this.name = name;
155         }
156
157         public boolean isEmpty() {
158                 if (name.equals("") && //$NON-NLS-1$
159                 username.equals("") && //$NON-NLS-1$
160                 password.equals("") && //$NON-NLS-1$
161                 connect.equals("") && //$NON-NLS-1$
162                 driver.equals("") && //$NON-NLS-1$
163                 type.equals("") && //$NON-NLS-1$
164                 driverFile.equals("")) { //$NON-NLS-1$
165                         return true;
166                 }
167                 return false;
168         }
169         public String toString() {
170                 StringBuffer buffer = new StringBuffer();
171                 buffer.append("["); //$NON-NLS-1$
172                 buffer.append("name="); //$NON-NLS-1$
173                 buffer.append(name);
174                 buffer.append(", "); //$NON-NLS-1$
175                 buffer.append("username="); //$NON-NLS-1$
176                 buffer.append(username);
177                 buffer.append(", "); //$NON-NLS-1$
178                 buffer.append("password=****"); //$NON-NLS-1$
179                 buffer.append(", "); //$NON-NLS-1$
180                 buffer.append("connect="); //$NON-NLS-1$
181                 buffer.append(connect);
182                 buffer.append(", "); //$NON-NLS-1$
183                 buffer.append("driver="); //$NON-NLS-1$
184                 buffer.append(driver);
185                 buffer.append(", "); //$NON-NLS-1$
186                 buffer.append("type="); //$NON-NLS-1$
187                 buffer.append(type);
188                 buffer.append(", "); //$NON-NLS-1$
189                 buffer.append("driverFile="); //$NON-NLS-1$
190                 buffer.append(driverFile);
191                 buffer.append("]"); //$NON-NLS-1$
192                 return buffer.toString();
193         }
194         
195         public String getType() {
196                 return type;
197         }
198
199         public void setType(String type) {
200                 this.type = type;
201         }
202
203         public String getSchema() {
204                 return schema;
205         }
206
207         public void setSchema(String schema) {
208                 this.schema = schema;
209         }
210
211     protected Connection connection = null;
212     /**
213          * Returns the connection object. Will automatically connect if not connected.
214          * @return the Connection object associated with the current JDBC source.
215          * 
216          */
217     public Connection getConnection() {
218         // We autoconnect if needed. (After all, reusability is a myth :)
219         if (connection == null) connection = this.connectionEstablisher.connect(this);
220         return connection;
221     }
222
223     /**
224          * @return true if the BookmarkNode is connected to a JDBC source
225          */
226     public boolean isConnected() {
227         return (connection != null);
228     }
229
230     /**
231          * Sets the connection member. From that moment on the BookmarkNode is "connected" (open)
232          * @param connection : a valid connection to a JDBC source
233          */
234     public void setConnection(Connection connection) {
235         this.connection = connection;
236     }
237
238     public void disconnect() {
239         this.connectionEstablisher.disconnect(this, this.connection);
240     }
241 }