View Javadoc

1   /*
2    * Copyright (c) 2005, The K-Wf Grid Consortium
3    * Fraunhofer Institute for Computer Architecture and Software Technology
4    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
5    */
6   package net.kwfgrid.gwui.graphview;
7   
8   import net.kwfgrid.gworkflowdl.structure.*;
9   
10  /***
11   * Implementation of <code>OperationProperties</code> for <code>WSClassOperation</code>.
12   */
13  public class OperationCandidateProperties implements OperationProperties {
14      private static final String[] EMPTY_TEXT = new String[0];
15  
16      private static String[] parseText(String owl) {
17          if (owl == null) return EMPTY_TEXT;
18          String line1 = null;
19          String line2 = null;
20          if (owl.lastIndexOf("#") >= 0) {
21              line1 = owl.substring(owl.lastIndexOf("/") + 1, owl.lastIndexOf("#"));
22              line2 = owl.substring(owl.lastIndexOf("#") + 1);
23          } else {
24              line2 = owl.substring(owl.lastIndexOf("/") + 1);
25          }
26          if (line2 != null && line2.lastIndexOf("_") >= 0) {
27              line2 = line2.substring(0, line2.lastIndexOf("_"));
28          }
29  
30          if (line1 != null && line1.length() > 0 &&
31                  line2 != null && line2.length() > 0)
32              return new String[]{line1, line2};
33          else if (line1 != null && line1.length() > 0)
34              return new String[]{line1};
35          else if (line2 != null && line2.length() > 0)
36              return new String[]{line2};
37          else
38              return EMPTY_TEXT;
39      }
40  
41      private static String[] createText(OperationClass operationClass) {
42          OperationCandidate selectedOperation = null;
43          if (operationClass.getAbstractionLevel() == Operation.GREEN) {
44              OperationCandidate[] ops = operationClass.getOperationCandidates();
45              for (int i = 0; i < ops.length; i++) {
46                  if (ops[i].isSelected()) {
47                      selectedOperation = ops[i];
48                      break;
49                  }
50              }
51              if (selectedOperation != null && selectedOperation.getOperationName() != null) {
52                  return new String[]{selectedOperation.getOperationName(),selectedOperation.getResourceName()};
53              }
54          }
55  
56          String operationClassName = operationClass.getName();
57          if (operationClassName != null && operationClassName.length() > 0 )
58              return new String[]{operationClassName};
59  
60          return EMPTY_TEXT;
61      }
62  
63      private static String createToolTip(OperationClass operationClass) {
64          StringBuffer buf = new StringBuffer();
65          buf.append("<br><br>Operation Class: <b>").append(operationClass.getName()).append("</b>");
66          if (operationClass.getAbstractionLevel()>=Operation.BLUE) {
67              OperationCandidate[] candidates = operationClass.getOperationCandidates();
68              if (candidates.length>0) {
69                  buf.append("<br><br>Operation Candidates: ");
70                  for (int i=0; i<candidates.length; i++) {
71                      buf.append("<br>&nbsp;Operation Candidate "+candidates[i].getType()+": ");
72                      if (candidates[i].isSelected()) buf.append("<br>");
73                      buf.append(candidates[i].getResourceName());
74                      float q=candidates[i].getQuality();
75                      if (q > OperationCandidate.DEFAULT_QUALITY) buf.append(" (q=").append(q).append(")");
76                      if (candidates[i].isSelected()) buf.append("</br>");
77                  }
78              }
79  
80          }
81          return buf.toString();
82      }
83  
84      private OperationClass _operationClass;
85      private String[] _text;
86      private String _tooltip;
87  
88      public OperationCandidateProperties(OperationClass operationClass) {
89          _operationClass = operationClass;
90          _text = null;
91          _tooltip = null;
92      }
93  
94      public String[] getText() {
95          if (_text == null) {
96              _text = createText(_operationClass);
97          }
98          return _text;
99      }
100 
101     public String getToolTipText() {
102         if (_tooltip == null) {
103             _tooltip = createToolTip(_operationClass);
104         }
105         return _tooltip;
106     }
107 
108     public void invalidate() {
109         _text = null;
110         _tooltip = null;
111     }
112 }