View Javadoc

1   package org.wsmostudio.bpmo.model;
2   
3   import java.util.*;
4   
5   import org.eclipse.jface.dialogs.MessageDialog;
6   import org.eclipse.jface.resource.JFaceResources;
7   import org.eclipse.jface.window.Window;
8   import org.eclipse.swt.widgets.Display;
9   import org.omwg.ontology.Instance;
10  import org.sbpm.bpmo.BusinessActivityNonFunctionalProperties;
11  import org.sbpm.bpmo.Role;
12  import org.wsmo.common.IRI;
13  import org.wsmostudio.bpmo.Activator;
14  import org.wsmostudio.runtime.WSMORuntime;
15  import org.wsmostudio.runtime.WsmoImageRegistry;
16  import org.wsmostudio.ui.IdentifierInputDialog;
17  import org.wsmostudio.ui.Utils;
18  
19  import com.ontotext.sbpm.bpmo.common.Constants;
20  
21  public abstract class BusinessActivityNode extends WorkflowEntitiesContainer {
22  
23      protected WorkflowProperty nameProp = new WorkflowProperty(Consts.PROP_NAME, 
24      				             JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
25      				             new String[] {Consts.ACTION_SET_NAME}, false, 
26      				             WorkflowProperty.defaultValueEditOrRemovePolicies);
27      protected WorkflowProperty descrProp = new WorkflowProperty(Consts.PROP_DESCRIPTION, 
28          			             JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
29          			             new String[] {Consts.ACTION_SET_DESCR}, false,
30          			             WorkflowProperty.defaultValueEditOrRemovePolicies);
31      protected WorkflowProperty nfpsProp = new WorkflowProperty(Consts.PROP_NFP, 
32              JFaceResources.getImage(WsmoImageRegistry.CONCEPT_ICON),
33              new String[] {Consts.ACTION_SET_NFPS}, false,
34              new String[] {Consts.ACTION_DELETE_NFPS});
35      private IRI nfpsID; 
36      
37      
38      protected WorkflowProperty resourcesProp = new WorkflowProperty(Consts.PROP_RESOURCE, 
39              JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
40              new String[] {Consts.ACTION_ADD_RESOURCE, Consts.ACTION_SELECT_RESOURCE}, true);
41      protected WorkflowProperty roleProp = new WorkflowProperty(Consts.PROP_ROLE, 
42              JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
43              new String[] {Consts.ACTION_SET_ROLE}, false,
44              new String[] {Consts.ACTION_DELETE_ROLE});
45      private IRI roleID; 
46  
47      
48      public String getName() {
49          return (String)this.nameProp.getSingleValue();
50      }
51  
52      public void setName(String name) {
53      	this.nameProp.addValue(name);
54          firePropertyChange("size", null, this.size);
55      }
56  
57      public String getDescription() {
58          return (String)this.descrProp.getSingleValue();
59      }
60  
61      public void setDescription(String descr) {
62      	this.descrProp.addValue(descr);
63      }
64      
65      public void setNFP(BusinessActivityNonFunctionalProperties nfps) {
66          
67          if (nfps == null) {
68              this.nfpsID = null;
69              this.nfpsProp.clearAll();
70              return;
71          }
72          this.nfpsID = nfps.getIdentifier();
73          
74          WorkflowProperty hasConstraint = new WorkflowProperty(Consts.PROP_CONSTRAINT, 
75                  JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
76                  new String[] {Consts.ACTION_SET_CONSTRAINT}, false);
77          if (nfps.getConstraint() != null) {
78              hasConstraint.addValue(nfps.getConstraint());
79          }
80          WorkflowProperty hasCreationDate = new WorkflowProperty(Consts.PROP_CREATION_DATE, 
81                  JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
82                  new String[] {Consts.ACTION_SET_CREATION_DATE}, false);
83          if (nfps.getCreationDate() != null) {
84              hasCreationDate.addValue(nfps.getCreationDate());
85          }
86          WorkflowProperty hasCreator = new WorkflowProperty(Consts.PROP_CREATOR, 
87                  JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
88                  new String[] {Consts.ACTION_SET_CREATOR}, false);
89          if (nfps.getCreator() != null) {
90              hasCreator.addValue(nfps.getCreator());
91          }
92          WorkflowProperty hasPreference = new WorkflowProperty(Consts.PROP_PREFERENCE, 
93                  JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
94                  new String[] {Consts.ACTION_SET_PREFERENCE}, false);
95          if (nfps.getPreference() != null) {
96              hasPreference.addValue(nfps.getPreference());
97          }
98          WorkflowProperty hasPriority = new WorkflowProperty(Consts.PROP_PRIORITY, 
99                  JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
100                 new String[] {Consts.ACTION_SET_PRIORITY}, false);
101         if (nfps.getPriority() != null) {
102             hasPriority.addValue(nfps.getPriority());
103         }
104         WorkflowProperty hasStatus = new WorkflowProperty(Consts.PROP_STATUS, 
105                 JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
106                 new String[] {Consts.ACTION_SET_STATUS}, false);
107         if (nfps.getStatus() != null) {
108             hasStatus.addValue(nfps.getStatus());
109         }
110         WorkflowProperty isActive = new WorkflowProperty(Consts.PROP_IS_ACTIVE, 
111                 JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
112                 new String[] {Consts.ACTION_SET_ACTIVE}, false);
113         isActive.addValue(Boolean.valueOf(nfps.isActive()));
114         
115         WorkflowProperty nfpValueProperty = new WorkflowProperty(
116                 Utils.getEntityLocalName(
117                         nfps.getIdentifier().toString()), 
118                 JFaceResources.getImage(WsmoImageRegistry.INSTANCE_ICON),
119                 this.nfpsProp.getValueEditPolicies(), true);
120         nfpValueProperty.addValue(hasConstraint);
121         nfpValueProperty.addValue(hasCreationDate);
122         nfpValueProperty.addValue(hasCreator);
123         nfpValueProperty.addValue(hasPreference);
124         nfpValueProperty.addValue(hasPriority);
125         nfpValueProperty.addValue(hasStatus);
126         nfpValueProperty.addValue(isActive);
127         
128         this.nfpsProp.addValue(nfpValueProperty);
129     }
130     
131     public BusinessActivityNonFunctionalProperties retrieveNFPs() {
132         if (this.nfpsID == null) {
133             return null;
134         }
135         WorkflowProperty container = (WorkflowProperty)this.nfpsProp.getSingleValue();
136         List<?> props = container.listValues();
137         BusinessActivityNonFunctionalProperties result = 
138             Activator.getBpmoFactory().createBusinessActivityNonFunctionalProperties(this.nfpsID);
139         
140         String constraint = (String)((WorkflowProperty)props.get(0)).getSingleValue();
141         if (constraint != null) {
142             result.setConstraint(constraint);
143         }
144         String creationDate = (String)((WorkflowProperty)props.get(1)).getSingleValue();
145         if (creationDate != null) {
146             result.setCreationDate(creationDate);
147         }
148         String creator = (String)((WorkflowProperty)props.get(2)).getSingleValue();
149         if (creator != null) {
150             result.setCreator(creator);
151         }
152         String preference = (String)((WorkflowProperty)props.get(3)).getSingleValue();
153         if (preference != null) {
154             result.setPreference(preference);
155         }
156         String priority = (String)((WorkflowProperty)props.get(4)).getSingleValue();
157         if (priority != null) {
158             result.setPriority(priority);
159         }
160         String status = (String)((WorkflowProperty)props.get(5)).getSingleValue();
161         if (status != null) {
162             result.setStatus(status);
163         }
164         Boolean isActive = (Boolean)((WorkflowProperty)props.get(6)).getSingleValue();
165         if (constraint != null) {
166             result.setActive(isActive.booleanValue());
167         }
168         return result;
169     }
170     
171     public void addResource(IRI resID) {
172         this.resourcesProp.addValue(resID);
173     }
174     public void removeResource(IRI resID) {
175         this.resourcesProp.removeValue(resID);
176     }
177     public List<IRI> listResources() {
178         List<IRI> vals = new LinkedList<IRI>();
179         for(Object iri : this.resourcesProp.listValues()) {
180             vals.add((IRI)iri);
181         }
182         return vals;
183     }
184     
185     public void setRole(Role role) {
186         if (role == null) {
187             this.roleID = null;
188             this.roleProp.clearAll();
189             return;
190         }
191         this.roleID = role.getIdentifier();
192         
193         WorkflowProperty hasRoleName = new WorkflowProperty(Consts.PROP_NAME, 
194                 JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
195                 new String[] {Consts.ACTION_SET_ROLE_NAME}, false);
196         if (role.getName() != null) {
197             hasRoleName.addValue(role.getName());
198         }
199         WorkflowProperty hasRoleDescription = new WorkflowProperty(Consts.PROP_DESCRIPTION, 
200                 JFaceResources.getImage(WsmoImageRegistry.DATA_VALUE_ICON),
201                 new String[] {Consts.ACTION_SET_ROLE_DESCR}, false);
202         if (role.getDescription() != null) {
203             hasRoleDescription.addValue(role.getDescription());
204         }
205 
206         WorkflowProperty roleValueProperty = new WorkflowProperty(
207                 Utils.getEntityLocalName(
208                         role.getIdentifier().toString()), 
209                 JFaceResources.getImage(WsmoImageRegistry.INSTANCE_ICON),
210                 this.roleProp.getValueEditPolicies(), true);
211         roleValueProperty.addValue(hasRoleName);
212         roleValueProperty.addValue(hasRoleDescription);
213         this.roleProp.addValue(roleValueProperty);
214     }
215 
216     public Role getRole() {
217         if (this.roleID == null) {
218             return null;
219         }
220         WorkflowProperty container = (WorkflowProperty)this.roleProp.getSingleValue();
221         List<?> props = container.listValues();
222         Role result = Activator.getBpmoFactory().createRole(this.roleID);
223         
224         String roleName = (String)((WorkflowProperty)props.get(0)).getSingleValue();
225         if (roleName != null) {
226             result.setName(roleName);
227         }
228         String roleDescr = (String)((WorkflowProperty)props.get(1)).getSingleValue();
229         if (roleDescr != null) {
230             result.setDescription(roleDescr);
231         }
232         return result;
233     }
234 
235     public List<WorkflowProperty> listSupportedProperties() {
236         List<WorkflowProperty> result = super.listSupportedProperties();
237         result.add(this.nameProp);
238         result.add(this.descrProp);
239         result.add(this.nfpsProp);
240         result.add(this.resourcesProp);
241         result.add(this.roleProp);
242         return result;
243     }
244     
245     protected void cloneProperties(BusinessActivityNode clone) {
246         super.cloneProperties(clone);
247         if (getName() != null) {
248             clone.setName(getName());
249         }
250         if (getDescription() != null) {
251             clone.setDescription(getDescription());
252         }
253         BusinessActivityNonFunctionalProperties props = retrieveNFPs();
254         if (props != null) {
255             BusinessActivityNonFunctionalProperties clonnedProps = 
256                 Activator.getBpmoFactory().createBusinessActivityNonFunctionalProperties();
257             if (props.getConstraint() != null) {
258                 clonnedProps.setConstraint(props.getConstraint());
259             }
260             if (props.getCreationDate() != null) {
261                 clonnedProps.setCreationDate(props.getCreationDate());
262             }
263             if (props.getCreator() != null) {
264                 clonnedProps.setCreator(props.getCreator());
265             }
266             if (props.getPreference() != null) {
267                 clonnedProps.setPreference(props.getPreference());
268             }
269             if (props.getPriority() != null) {
270                 clonnedProps.setPriority(props.getPriority());
271             }
272             if (props.getStatus() != null) {
273                 clonnedProps.setStatus(props.getStatus());
274             }
275             clonnedProps.setActive(props.isActive());
276             clone.setNFP(clonnedProps);
277         }
278         for (IRI resourceID : listResources()) {
279             clone.addResource(resourceID);
280         }
281         Role role = getRole();
282         if (role != null) {
283             Role clonedRole = Activator.getBpmoFactory().createRole();
284             if (role.getName() != null) {
285                 clonedRole.setName(role.getName());
286             }
287             if (role.getDescription() != null) {
288                 clonedRole.setDescription(role.getDescription());
289             }
290             clone.setRole(clonedRole);
291         }
292     }
293 
294     
295     public boolean handleAction(String actionID, WorkflowProperty prop, Object value) {
296         if (actionID.equals(Consts.ACTION_SET_NAME)) {
297             boolean change = WorkflowPropertyUtils.editStringValue(prop, (String)value);
298             if (change) {
299                 firePropertyChange("size", null, this.size);
300             }
301             return change;
302         }
303         if (actionID.equals(Consts.ACTION_SET_DESCR)) {
304             return WorkflowPropertyUtils.editStringValue(prop, this.getDescription());
305         }
306         if (actionID.equals(Consts.ACTION_SET_NFPS)) {
307             IdentifierInputDialog idDialog = new IdentifierInputDialog(
308                     Display.getCurrent().getActiveShell(),
309                     "New Non-Functional Properties",
310                     "IRI",
311                     "",
312                     getTopContainer().getNSHolder(),
313                     WSMORuntime.getRuntime().getWsmoFactory(),
314                     false);
315             if (idDialog.open() != Window.OK) {
316                 return false;
317             }
318             IRI newID = (IRI)idDialog.getIdentifier();
319             BusinessActivityNonFunctionalProperties nfps = 
320                 Activator.getBpmoFactory().createBusinessActivityNonFunctionalProperties(newID);
321             setNFP(nfps);
322             return true;
323         }
324         if (actionID.equals(Consts.ACTION_SET_CONSTRAINT)
325                 || actionID.equals(Consts.ACTION_SET_CREATION_DATE)
326                 || actionID.equals(Consts.ACTION_SET_CREATOR)
327                 || actionID.equals(Consts.ACTION_SET_PREFERENCE)
328                 || actionID.equals(Consts.ACTION_SET_PRIORITY)
329                 || actionID.equals(Consts.ACTION_SET_ROLE_NAME)
330                 || actionID.equals(Consts.ACTION_SET_ROLE_DESCR)
331                 || actionID.equals(Consts.ACTION_SET_STATUS)) {
332             return WorkflowPropertyUtils.editStringValue(prop, (String)prop.getSingleValue());
333         }
334         if (actionID.equals(Consts.ACTION_SET_ACTIVE)) {
335             boolean oldValue = ((Boolean)prop.getSingleValue()).booleanValue();
336             boolean statNew = MessageDialog.openConfirm(
337                     Display.getCurrent().getActiveShell(), 
338                     (oldValue) ? "Deactivate ?" : "Activate ?", 
339                     (oldValue) ? "Deactivate Process ?" : "Activate Process ?");
340             if (statNew == true) {
341                 prop.addValue(Boolean.valueOf(oldValue == false));
342                 return true;
343             }
344         }
345         if (actionID.equals(Consts.ACTION_DELETE_NFPS)) {
346             if (this.nfpsID == null) {
347                 return false; // no NFPs set yet
348             }
349             setNFP(null);
350             return true;
351         }
352         if (actionID.equals(Consts.ACTION_DELETE_ROLE)) {
353             if (this.roleID == null) {
354                 return false; // no Role set yet
355             }
356             setRole(null);
357             return true;
358         }
359         if (actionID.equals(Consts.ACTION_ADD_RESOURCE)) {
360             IdentifierInputDialog idDialog = new IdentifierInputDialog(
361                     Display.getCurrent().getActiveShell(),
362                     "New Resource",
363                     "IRI",
364                     "",
365                     getTopContainer().getNSHolder(),
366                     WSMORuntime.getRuntime().getWsmoFactory(),
367                     false);
368             if (idDialog.open() != Window.OK) {
369                 return false;
370             }
371             addResource((IRI)idDialog.getIdentifier());
372             return true;
373         }
374         if (actionID.equals(Consts.ACTION_SELECT_RESOURCE)) {
375             Instance res = WorkflowPropertyUtils.selectInstance(Constants.RESOURCE_ID);
376             if (res != null) {
377                 addResource((IRI)res.getIdentifier());
378                 return true;
379             }
380             return false;
381         }
382         if (actionID.equals(Consts.ACTION_SET_ROLE)) {
383             IdentifierInputDialog idDialog = new IdentifierInputDialog(
384                     Display.getCurrent().getActiveShell(),
385                     "New Role",
386                     "IRI",
387                     "",
388                     getTopContainer().getNSHolder(),
389                     WSMORuntime.getRuntime().getWsmoFactory(),
390                     false);
391             if (idDialog.open() != Window.OK) {
392                 return false;
393             }
394             IRI newID = (IRI)idDialog.getIdentifier();
395             Role role = Activator.getBpmoFactory().createRole(newID);
396             setRole(role);
397             return true;
398         }
399         return super.handleAction(actionID, prop, value);
400     }
401 
402 }