Source code: com/vinculum/processeditor/model/OutArgument.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: OutArgument.java,v $ - description
40 -------------------
41 begin : $Date: 2003/07/08 08:02:22 $
42 copyright : Vinculum (C) 2002
43 author : $Author: chiraz $
44 ***************************************************************************/
45
46 /* $Log: OutArgument.java,v $
47 /* Revision 1.1.1.1 2003/07/08 08:02:22 chiraz
48 /* egg
49 /* */
50
51 package com.vinculum.processeditor.model;
52
53 import java.util.Vector;
54
55 import org.eclipse.jdt.core.IMethod;
56 import org.eclipse.jdt.core.Signature;
57 import org.eclipse.ui.views.properties.IPropertyDescriptor;
58 import org.eclipse.ui.views.properties.IPropertySource;
59 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
60 import java.io.Serializable;
61
62 /**
63 * @author chilan
64 */
65 public class OutArgument implements IPropertySource, Serializable
66 {
67 private transient Vector descriptors = null;
68 public static String ID_ARGUMENT = "outargvalue";
69 private String argument = null;
70 private String retSig = null;
71 private int retType = 0;
72 private transient IMethod method = null;
73
74 public OutArgument()
75 {
76 super();
77 }
78
79 public OutArgument(IMethod[] methods, int value)
80 {
81 method = methods[value];
82 refreshDescriptors(method);
83 }
84
85 public OutArgument(IMethod[] methods, int value, OutArgument outArgument )
86 {
87 method = methods[value];
88 refreshDescriptors(method);
89 if ( outArgument != null )
90 {
91 this.argument = outArgument.getArgument();
92 this.retSig = outArgument.getRetSig();
93 this.retType = outArgument.getRetType();
94 }
95 }
96
97 private void refreshDescriptors(IMethod method)
98 {
99 int i = 0;
100 argument = new String();
101 TextPropertyDescriptor propertyDescriptor = null;
102 descriptors = new Vector();
103
104 if ( method == null)
105 {
106 return;
107 }
108
109 try
110 {
111 propertyDescriptor = new TextPropertyDescriptor(
112 ID_ARGUMENT,
113 Signature.toString( method.getReturnType()) );
114 descriptors.add( propertyDescriptor );
115 argument = new String( Signature.toString( method.getReturnType()) );
116 }
117 catch (Exception e)
118 {
119 return;
120 }
121 }
122
123 public Object getEditableValue()
124 {
125 if ( argument == null )
126 {
127 return new String("");
128 }
129
130 return new String("\"" + argument + "\"");
131 }
132
133 public IPropertyDescriptor[] getPropertyDescriptors()
134 {
135 if ( descriptors == null )
136 {
137 refreshDescriptors( method );
138 }
139 return (IPropertyDescriptor[])descriptors.toArray(new IPropertyDescriptor[descriptors.size()]);
140 }
141
142 public Object getPropertyValue(Object id)
143 {
144 if ( id.equals(ID_ARGUMENT))
145 {
146 return new String(argument);
147 }
148 return new String("");
149 }
150
151 public boolean isPropertySet(Object id)
152 {
153 if ( argument != null )
154 {
155 if ( argument.equals(""))
156 {
157 return false;
158 }
159 else
160 {
161 return true;
162 }
163 }
164 return false;
165 }
166
167 public void resetPropertyValue(Object id)
168 {
169 if ( id.equals( ID_ARGUMENT ))
170 {
171 argument = new String("");
172 }
173 }
174
175 public void setPropertyValue(Object id, Object value)
176 {
177 if ( id.equals( ID_ARGUMENT ))
178 {
179 argument = new String((String)value);
180 }
181 }
182
183 public String getArgument()
184 {
185 if ( argument == null )
186 {
187 argument = new String("");
188 }
189 return argument;
190 }
191
192 public String getRetSig()
193 {
194 if ( retSig == null )
195 {
196 retSig = new String("");
197 }
198 return retSig;
199 }
200
201 public int getRetType()
202 {
203 return retType;
204 }
205 }