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  
26  package org.wsmostudio.ui;
27  
28  import org.eclipse.core.resources.*;
29  import org.eclipse.core.runtime.CoreException;
30  import org.eclipse.jface.resource.*;
31  import org.eclipse.jface.viewers.*;
32  import org.eclipse.swt.graphics.*;
33  import org.wsmostudio.runtime.WsmoImageRegistry;
34  
35  public class ResourcesDecorator implements ILabelDecorator {
36  
37      private boolean forceImageLoadPerformed = false;
38  
39      public Image decorateImage(Image image, Object element) {
40          if (false == element instanceof IFile) {
41              return image;
42          }
43          
44          IMarker[] markers = null;
45          try {
46              markers = ((IFile)element).findMarkers("org.wsmostudio.runtime.wsmlmarker", true, 1);
47          }
48          catch(CoreException coreEx) { }
49          if (markers == null 
50                  || markers.length == 0) {
51              return image;
52          }
53          boolean containsWarning = false;
54          for(int i = 0; i < markers.length; i++) {
55              if (markers[i].getAttribute(IMarker.SEVERITY, 0) == IMarker.SEVERITY_ERROR) { 
56                  return findImage(WsmoImageRegistry.RESOURCE_ERROR_ICON);
57              }
58              else  if (markers[i].getAttribute(IMarker.SEVERITY, 0) == IMarker.SEVERITY_WARNING) {
59                  containsWarning = true;
60              }
61          }
62          if (containsWarning == true) {
63              return findImage(WsmoImageRegistry.RESOURCE_WARNING_ICON);
64          }
65          return image;
66      }
67  
68      public String decorateText(String text, Object element) {
69          return text;
70      }
71  
72      public void addListener(ILabelProviderListener listener) {
73      }
74  
75      public void dispose() {
76      }
77  
78      public boolean isLabelProperty(Object element, String property) {
79          return false;
80      }
81  
82      public void removeListener(ILabelProviderListener listener) {
83      }
84      
85      private Image findImage(String imageID) {
86          Image image = JFaceResources.getImageRegistry().get(imageID);
87          if (image != null) {
88              return image;
89          }
90          if (false == forceImageLoadPerformed) {
91              WsmoImageRegistry.declareStudioImages();
92              forceImageLoadPerformed = true;
93          }
94          return JFaceResources.getImageRegistry().get(imageID);
95      }
96  
97  }
98  
99  /*
100  * $Log$
101  * Revision 1.3  2006/01/25 14:08:45  alex_simov
102  * wsmo images not loaded early enough at start-up to be used.
103  * Now loading is forced
104  *
105  * Revision 1.2  2006/01/09 12:51:13  alex_simov
106  * Copyright message in header updated
107  *
108  */