Source code: com/vinculum/processeditor/model/Wire.java
1 /* * ** ** BEGIN LICENSE BLOCK * ** **
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Vinculum Open Source.
15 *
16 * The Initial Developer of the Original Code is
17 * Gerard Toonstra.
18 * Portions created by the Initial Developer are Copyright (C) 2003
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ** ** * END LICENSE BLOCK * ** **
36 */
37
38 /***************************************************************************
39 $RCSfile: Wire.java,v $ - description
40 -------------------
41 begin : $Date: 2003/07/08 08:02:21 $
42 copyright : Vinculum (C) 2002
43 author : $Author: chiraz $
44 ***************************************************************************/
45
46 /* $Log: Wire.java,v $
47 /* Revision 1.1.1.1 2003/07/08 08:02:21 chiraz
48 /* egg
49 /* */
50
51 package com.vinculum.processeditor.model;
52
53 import java.util.List;
54 import java.util.ArrayList;
55 import java.util.Vector;
56
57 import org.eclipse.draw2d.Bendpoint;
58 import org.eclipse.ui.views.properties.IPropertyDescriptor;
59 import org.eclipse.ui.views.properties.PropertyDescriptor;
60 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
61
62 import com.vinculum.processeditor.ProcessMessages;
63
64 /**
65 * @author chilan
66 *
67 */
68 public class Wire extends ProcessElement
69 {
70 static final long serialVersionUID = 1;
71 protected boolean value;
72 private static int count;
73 private String id;
74 protected ProcessSubPart source;
75 protected ProcessSubPart target;
76 protected String sourceTerminal;
77 protected String targetTerminal;
78 protected List bendpoints = new ArrayList();
79 protected transient Vector descriptors = null;
80
81 private String scriptName;
82 private String functionName;
83 private String expression;
84
85 public static final String ID_SCRIPTNAME = "scriptname"; //$NON-NLS-1$
86 public static final String ID_FUNCTIONNAME = "functionname"; //$NON-NLS-1$
87 public static final String ID_EXPRESSION = "expression"; //$NON-NLS-1$
88
89 private static final String SCRIPT_NAME_CONTEXT = ProcessMessages.HelpContext_Wire_ScriptName; //$NON-NLS-1$
90 private static final String FUNCTION_NAME_CONTEXT = ProcessMessages.HelpContext_Wire_FunctionName; //$NON-NLS-1$
91 private static final String EXPRESSION_CONTEXT = ProcessMessages.HelpContext_Wire_Expression; //$NON-NLS-1$
92
93 public Wire()
94 {
95 setID( getNewID() );
96 }
97
98 public void attachSource()
99 {
100 if (getSource() == null)
101 return;
102 getSource().connectOutput(this);
103 }
104
105 public void attachTarget()
106 {
107 if (getTarget() == null)
108 return;
109 getTarget().connectInput(this);
110 }
111
112 public void detachSource()
113 {
114 if (getSource() == null)
115 return;
116 getSource().disconnectOutput(this);
117 }
118
119 public void detachTarget()
120 {
121 if (getTarget() == null)
122 return;
123 getTarget().disconnectInput(this);
124 }
125
126 public List getBendpoints()
127 {
128 return bendpoints;
129 }
130
131 public ProcessSubPart getSource()
132 {
133 return source;
134 }
135
136 public String getSourceTerminal()
137 {
138 return sourceTerminal;
139 }
140
141 public ProcessSubPart getTarget()
142 {
143 return target;
144 }
145
146 public String getTargetTerminal()
147 {
148 return targetTerminal;
149 }
150
151 public boolean getValue()
152 {
153 return value;
154 }
155
156 public void insertBendpoint(int index, Bendpoint point)
157 {
158 getBendpoints().add(index, point);
159 firePropertyChange("bendpoint", null, null);//$NON-NLS-1$
160 }
161
162 public void removeBendpoint(int index)
163 {
164 getBendpoints().remove(index);
165 firePropertyChange("bendpoint", null, null);//$NON-NLS-1$
166 }
167
168 public void setBendpoint(int index, Bendpoint point) {
169 getBendpoints().set(index, point);
170 firePropertyChange("bendpoint", null, null);//$NON-NLS-1$
171 }
172
173 public void setBendpoints(Vector points)
174 {
175 bendpoints = points;
176 firePropertyChange("bendpoint", null, null);//$NON-NLS-1$
177 }
178
179 public void setSource(ProcessSubPart e)
180 {
181 Object old = source;
182 source = e;
183 firePropertyChange("source", old, source);//$NON-NLS-1$
184 }
185
186 public void setSourceTerminal(String s)
187 {
188 Object old = sourceTerminal;
189 sourceTerminal = s;
190 firePropertyChange("sourceTerminal", old, sourceTerminal);//$NON-NLS-1$
191 }
192
193 public void setTarget(ProcessSubPart e)
194 {
195 target = e;
196 }
197
198 public void setTargetTerminal(String s)
199 {
200 targetTerminal = s;
201 }
202
203 public void setValue(boolean value)
204 {
205 if (value == this.value) return;
206 this.value = value;
207 if (target != null)
208 target.update();
209 firePropertyChange("value", null, null);//$NON-NLS-1$
210 }
211
212 public String toString()
213 {
214 return "Wire(" + getSource() + "," + getSourceTerminal() + "->" + getTarget() + "," + getTargetTerminal() + ")";//$NON-NLS-5$//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
215 }
216
217 protected String getNewID()
218 {
219 return Integer.toString(++count);
220 }
221
222 public String getID()
223 {
224 return id;
225 }
226
227 public void setID( String newID )
228 {
229 id = new String(newID);
230 }
231
232 public IPropertyDescriptor[] getPropertyDescriptors()
233 {
234 if ( descriptors == null )
235 {
236 refreshDescriptors();
237 }
238
239 return (IPropertyDescriptor[])descriptors.toArray(new IPropertyDescriptor[descriptors.size()]);
240 }
241
242 protected void refreshDescriptors()
243 {
244 PropertyDescriptor propertyDescriptor = null;
245
246 if (descriptors == null)
247 {
248 descriptors = new Vector();
249 }
250
251 descriptors.clear();
252
253 propertyDescriptor = new TextPropertyDescriptor(ID_SCRIPTNAME, ProcessMessages.PropertyDescriptor_Wire_ScriptName);
254 propertyDescriptor.setCategory(ProcessMessages.PropertyDescriptor_ProcessFlowStart_General);
255 propertyDescriptor.setHelpContextIds(SCRIPT_NAME_CONTEXT);
256 descriptors.add( propertyDescriptor );
257
258 propertyDescriptor = new TextPropertyDescriptor(ID_FUNCTIONNAME, ProcessMessages.PropertyDescriptor_Wire_FunctionName);
259 propertyDescriptor.setCategory(ProcessMessages.PropertyDescriptor_ProcessFlowStart_General);
260 propertyDescriptor.setHelpContextIds(FUNCTION_NAME_CONTEXT);
261 descriptors.add( propertyDescriptor );
262
263 propertyDescriptor = new TextPropertyDescriptor(ID_EXPRESSION, ProcessMessages.PropertyDescriptor_Wire_Expression);
264 propertyDescriptor.setCategory(ProcessMessages.PropertyDescriptor_ProcessFlowStart_General);
265 propertyDescriptor.setHelpContextIds(EXPRESSION_CONTEXT);
266 descriptors.add( propertyDescriptor );
267 }
268
269 public Object getPropertyValue(Object propName)
270 {
271 if ( propName.equals(ID_SCRIPTNAME) )
272 {
273 return getScriptName();
274 }
275 if ( propName.equals( ID_FUNCTIONNAME ))
276 {
277 return getFunctionName();
278 }
279 if ( propName.equals( ID_EXPRESSION))
280 {
281 return getExpression();
282 }
283 return super.getPropertyValue(propName);
284 }
285
286 public boolean isPropertySet(Object property)
287 {
288 if (property.equals(ID_SCRIPTNAME))
289 {
290 return getScriptName() != "";
291 }
292 if (property.equals(ID_FUNCTIONNAME))
293 {
294 return getFunctionName() != "";
295 }
296 if (property.equals(ID_EXPRESSION))
297 {
298 return getExpression() != "";
299 }
300 return false;
301 }
302
303 public void resetPropertyValue(Object property)
304 {
305 if (property.equals(ID_SCRIPTNAME))
306 {
307 setScriptName("");
308 return;
309 }
310 if (property.equals(ID_FUNCTIONNAME))
311 {
312 setFunctionName("");
313 return;
314 }
315 if (property.equals(ID_EXPRESSION))
316 {
317 setExpression("");
318 return;
319 }
320 }
321
322 public void setPropertyValue(Object id, Object value)
323 {
324 if ( id.equals(ID_SCRIPTNAME) )
325 {
326 setScriptName((String)value);
327 return;
328 }
329 else if ( id.equals(ID_FUNCTIONNAME))
330 {
331 setFunctionName((String)value);
332 return;
333 }
334 else if ( id.equals(ID_EXPRESSION))
335 {
336 setExpression((String)value);
337 return;
338 }
339
340 super.setPropertyValue(id,value);
341 }
342
343 public String getScriptName()
344 {
345 if ( scriptName != null )
346 {
347 return new String(scriptName);
348 }
349 else
350 {
351 return new String("");
352 }
353 }
354
355 public String getFunctionName()
356 {
357 if ( functionName != null )
358 {
359 return new String(functionName);
360 }
361 else
362 {
363 return new String("");
364 }
365 }
366
367 public String getExpression()
368 {
369 if ( expression != null )
370 {
371 return new String(expression);
372 }
373 else
374 {
375 return new String("");
376 }
377 }
378
379 public void setScriptName(String newName)
380 {
381 scriptName = new String(newName);
382 }
383
384 public void setFunctionName(String newName)
385 {
386 functionName = new String(newName);
387 }
388
389 public void setExpression(String newName)
390 {
391 expression = new String(newName);
392 }
393 }