View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.choreography.navigator;
26  
27  import java.util.*;
28  
29  import org.wsmo.common.Entity;
30  import org.wsmo.service.choreography.Choreography;
31  import org.wsmo.service.signature.*;
32  import org.wsmostudio.ui.Utils;
33  import org.wsmostudio.ui.views.navigator.TreeProvider;
34  
35  public class ChoreographyTreeProvider implements TreeProvider {
36  
37      public Object[] getChildren(Object parent) {
38          Choreography chor = (Choreography)parent;
39          List<Entity> ll = new LinkedList<Entity>(); 
40          if (chor.getStateSignature() != null) {
41              ll.add(chor.getStateSignature());
42          }
43          if (chor.getRules() != null) {
44              ll.add(chor.getRules());
45          }
46          if (ll.size() > 0) {
47              return ll.toArray();
48          }
49          return null;
50      }
51  
52      public boolean hasChildren(Object parent) {
53          if (parent instanceof Choreography) {
54              return ((Choreography)parent).getStateSignature() != null
55                      || ((Choreography)parent).getRules() != null;
56          }
57          return true;
58      }
59  
60      public String labelFor(Object entity) {
61          return Utils.getEntityLocalName(((Entity)entity).getIdentifier().toString());
62      }
63      
64      public static class StateSigTreeProvider implements TreeProvider {
65          
66          public Object[] getChildren(Object parent) {
67              StateSignature sSig = (StateSignature)parent;
68              List<Mode> bufferModes = new LinkedList<Mode>();
69              
70              bufferModes.addAll(sSig.listInModes());
71              bufferModes.addAll(sSig.listOutModes());
72              bufferModes.addAll(sSig.listSharedModes());
73              bufferModes.addAll(sSig.listStaticModes());
74              bufferModes.addAll(sSig.listControlledModes());
75              return bufferModes.toArray();
76          }
77  
78          public boolean hasChildren(Object parent) {
79              if (false == parent instanceof StateSignature) {
80                  return false;
81              }
82              StateSignature sSig = (StateSignature)parent;
83              return sSig.listInModes().size() > 0
84                      || sSig.listOutModes().size() > 0
85                      || sSig.listSharedModes().size() > 0
86                      || sSig.listStaticModes().size() > 0
87                      || sSig.listControlledModes().size() > 0;
88          }
89  
90          public String labelFor(Object entity) {
91              return Utils.getEntityLocalName(((Entity)entity).getIdentifier().toString());
92          }
93      }
94      public static class ModesTreeProvider implements TreeProvider {
95          
96          public Object[] getChildren(Object parent) {
97              return null;
98          }
99  
100         public boolean hasChildren(Object parent) {
101             return false;
102         }
103 
104         public String labelFor(Object entity) {
105             Mode mode = (Mode)entity;
106             StringBuffer label = new StringBuffer();
107             if (mode instanceof In) {
108                 label.append("IN [");
109             }
110             else if (mode instanceof Out) {
111                 label.append("OUT [");
112             } 
113             else if (mode instanceof Shared) {
114                 label.append("SHARED [");
115             } 
116             else if (mode instanceof Static) {
117                 label.append("STATIC [");
118             } 
119             else {
120                 label.append("CONTROLLED [");
121             } 
122             label.append(Utils.getEntityLocalName(
123                     mode.getConcept().getIdentifier().toString()));
124             
125             return label.append(']').toString();
126         }
127     }
128 }
129 
130 /*
131  * $Log$
132  * Revision 1.5  2006/11/22 14:11:07  alex_simov
133  * Code refactoring: the plug-in is synchronized with the latest wsmo4j changes
134  *
135  * Revision 1.4  2006/04/18 07:27:27  alex_simov
136  * WSMO Navigator now shows Rules container for choreographies
137  *
138  * Revision 1.3  2006/01/09 12:51:11  alex_simov
139  * Copyright message in header updated
140  *
141  * Revision 1.2  2005/11/16 16:22:26  alex_simov
142  * new choreography representation in the WSMO Navigator
143  *
144  *
145  */