2 * Copyright (C) 2007-2012 Mathieu Baudier
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
.model
.ResultParent
;
27 import org
.argeo
.slc
.client
.ui
.model
.SingleResultNode
;
28 import org
.argeo
.slc
.jcr
.SlcNames
;
29 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
30 import org
.eclipse
.jface
.viewers
.DecorationOverlayIcon
;
31 import org
.eclipse
.jface
.viewers
.IDecoration
;
32 import org
.eclipse
.jface
.viewers
.ILabelDecorator
;
33 import org
.eclipse
.jface
.viewers
.LabelProvider
;
34 import org
.eclipse
.swt
.graphics
.Image
;
35 import org
.eclipse
.ui
.ISharedImages
;
37 public class ResultFailedDecorator
extends LabelProvider
implements
40 // private final static Log log = LogFactory
41 // .getLog(ResultFailedDecorator.class);
43 private final static DateFormat dateFormat
= new SimpleDateFormat(
46 public ResultFailedDecorator() {
50 // Method to decorate Image
51 public Image
decorateImage(Image image
, Object object
) {
53 // This method returns an annotated image or null if the
54 // image need not be decorated. Returning a null image
55 // decorates resource icon with basic decorations provided
57 if (object
instanceof ResultParent
) {
58 if (!((ResultParent
) object
).isPassed()) {
59 ImageDescriptor desc
= ClientUiPlugin
.getDefault()
60 .getWorkbench().getSharedImages()
61 .getImageDescriptor(ISharedImages
.IMG_DEC_FIELD_ERROR
);
62 DecorationOverlayIcon decoratedImage
= new DecorationOverlayIcon(
63 image
, desc
, IDecoration
.TOP_LEFT
);
64 return decoratedImage
.createImage();
71 // Method to decorate Text
72 public String
decorateText(String label
, Object object
) {
73 if (object
instanceof SingleResultNode
) {
74 SingleResultNode srNode
= (SingleResultNode
) object
;
75 Node node
= srNode
.getNode();
76 String decoration
= null;
78 if (node
.hasProperty(SlcNames
.SLC_COMPLETED
))
79 decoration
= dateFormat
.format(node
80 .getProperty(SlcNames
.SLC_COMPLETED
).getDate()
82 } catch (RepositoryException re
) {
83 throw new SlcException(
84 "Unexpected defining text decoration for result", re
);
86 return label
+ " [" + decoration
+ "]";