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