2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.decorators
;
18 import java
.text
.DateFormat
;
19 import java
.text
.SimpleDateFormat
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.RepositoryException
;
24 import org
.argeo
.slc
.SlcException
;
25 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
26 import org
.argeo
.slc
.client
.ui
.SlcImages
;
27 import org
.argeo
.slc
.client
.ui
.SlcUiConstants
;
28 import org
.argeo
.slc
.client
.ui
.model
.ResultFolder
;
29 import org
.argeo
.slc
.client
.ui
.model
.ResultParent
;
30 import org
.argeo
.slc
.client
.ui
.model
.SingleResultNode
;
31 import org
.argeo
.slc
.jcr
.SlcNames
;
32 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
33 import org
.eclipse
.jface
.viewers
.DecorationOverlayIcon
;
34 import org
.eclipse
.jface
.viewers
.IDecoration
;
35 import org
.eclipse
.jface
.viewers
.ILabelDecorator
;
36 import org
.eclipse
.jface
.viewers
.LabelProvider
;
37 import org
.eclipse
.swt
.graphics
.Image
;
38 import org
.eclipse
.ui
.ISharedImages
;
40 /** Dynamically decorates the results tree. */
41 public class ResultFailedDecorator
extends LabelProvider
implements
44 // FIXME why not use? org.eclipse.jface.viewers.DecoratingLabelProvider
46 // private final static Log log = LogFactory
47 // .getLog(ResultFailedDecorator.class);
49 private final static DateFormat dateFormat
= new SimpleDateFormat(
50 SlcUiConstants
.DEFAULT_DISPLAY_DATE_TIME_FORMAT
);
52 // hack for SWT resource leak
53 // see http://www.eclipse.org/articles/swt-design-2/swt-design-2.html
54 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=181215
55 private final Image passedFolder
;
56 private final Image failedFolder
;
57 private final Image failedSingleResult
;
58 private final Image errorSingleResult
;
59 private final Image passedSingleResult
;
61 public ResultFailedDecorator() {
63 ImageDescriptor failedDesc
= ClientUiPlugin
.getDefault().getWorkbench()
65 .getImageDescriptor(ISharedImages
.IMG_DEC_FIELD_ERROR
);
66 failedFolder
= new DecorationOverlayIcon(SlcImages
.FOLDER
, failedDesc
,
67 IDecoration
.TOP_LEFT
).createImage();
68 passedFolder
= new DecorationOverlayIcon(SlcImages
.FOLDER
,
69 SlcImages
.EXECUTION_PASSED
, IDecoration
.TOP_LEFT
).createImage();
70 failedSingleResult
= new DecorationOverlayIcon(
71 SlcImages
.PROCESS_COMPLETED
, failedDesc
, IDecoration
.TOP_LEFT
)
73 errorSingleResult
= new DecorationOverlayIcon(
74 SlcImages
.PROCESS_COMPLETED
, SlcImages
.EXECUTION_ERROR
,
75 IDecoration
.TOP_LEFT
).createImage();
76 passedSingleResult
= new DecorationOverlayIcon(
77 SlcImages
.PROCESS_COMPLETED
, SlcImages
.EXECUTION_PASSED
,
78 IDecoration
.TOP_LEFT
).createImage();
81 // Method to decorate Image
82 public Image
decorateImage(Image image
, Object object
) {
84 // This method returns an annotated image or null if the
85 // image need not be decorated. Returning a null image
86 // decorates resource icon with basic decorations provided
88 if (object
instanceof ResultParent
) {
89 if (((ResultParent
) object
).isPassed()) {
90 if (object
instanceof SingleResultNode
)
91 return passedSingleResult
;
92 else if (object
instanceof ResultFolder
)
97 // ImageDescriptor desc = ClientUiPlugin.getDefault()
98 // .getWorkbench().getSharedImages()
99 // .getImageDescriptor(ISharedImages.IMG_DEC_FIELD_ERROR);
100 // DecorationOverlayIcon decoratedImage = new
101 // DecorationOverlayIcon(
102 // image, desc, IDecoration.TOP_LEFT);
103 // return decoratedImage.createImage();
104 if (object
instanceof SingleResultNode
) {
105 SingleResultNode srn
= (SingleResultNode
) object
;
106 boolean isError
= false;
108 isError
= srn
.getNode()
109 .getNode(SlcNames
.SLC_AGGREGATED_STATUS
)
110 .hasProperty(SlcNames
.SLC_ERROR_MESSAGE
);
111 } catch (RepositoryException re
) {
112 // Silent node might not exist
115 return errorSingleResult
;
117 return failedSingleResult
;
126 // Method to decorate Text
127 public String
decorateText(String label
, Object object
) {
128 if (object
instanceof SingleResultNode
) {
129 SingleResultNode srNode
= (SingleResultNode
) object
;
130 Node node
= srNode
.getNode();
131 String decoration
= null;
133 if (node
.hasProperty(SlcNames
.SLC_COMPLETED
))
134 decoration
= dateFormat
.format(node
135 .getProperty(SlcNames
.SLC_COMPLETED
).getDate()
137 } catch (RepositoryException re
) {
138 throw new SlcException(
139 "Unexpected error defining text decoration for result",
142 return label
+ " [" + decoration
+ "]";
148 public void dispose() {
149 failedFolder
.dispose();
150 failedSingleResult
.dispose();