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
.ResultParent
;
29 import org
.argeo
.slc
.client
.ui
.model
.SingleResultNode
;
30 import org
.argeo
.slc
.jcr
.SlcNames
;
31 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
32 import org
.eclipse
.jface
.viewers
.DecorationOverlayIcon
;
33 import org
.eclipse
.jface
.viewers
.IDecoration
;
34 import org
.eclipse
.jface
.viewers
.ILabelDecorator
;
35 import org
.eclipse
.jface
.viewers
.LabelProvider
;
36 import org
.eclipse
.swt
.graphics
.Image
;
37 import org
.eclipse
.ui
.ISharedImages
;
39 /** Dynamically decorates the results tree. */
40 public class ResultFailedDecorator
extends LabelProvider
implements
43 // FIXME why not use? org.eclipse.jface.viewers.DecoratingLabelProvider
45 // private final static Log log = LogFactory
46 // .getLog(ResultFailedDecorator.class);
48 private final static DateFormat dateFormat
= new SimpleDateFormat(
49 SlcUiConstants
.DEFAULT_DISPLAY_DATE_TIME_FORMAT
);
51 // hack for SWT resource leak
52 // see http://www.eclipse.org/articles/swt-design-2/swt-design-2.html
53 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=181215
54 private final Image failedFolder
;
55 private final Image failedSingleResult
;
57 public ResultFailedDecorator() {
59 ImageDescriptor desc
= ClientUiPlugin
.getDefault().getWorkbench()
61 .getImageDescriptor(ISharedImages
.IMG_DEC_FIELD_ERROR
);
62 failedFolder
= new DecorationOverlayIcon(SlcImages
.FOLDER
, desc
,
63 IDecoration
.TOP_LEFT
).createImage();
64 failedSingleResult
= new DecorationOverlayIcon(
65 SlcImages
.PROCESS_COMPLETED
, desc
, IDecoration
.TOP_LEFT
)
69 // Method to decorate Image
70 public Image
decorateImage(Image image
, Object object
) {
72 // This method returns an annotated image or null if the
73 // image need not be decorated. Returning a null image
74 // decorates resource icon with basic decorations provided
76 if (object
instanceof ResultParent
) {
77 if (!((ResultParent
) object
).isPassed()) {
78 // ImageDescriptor desc = ClientUiPlugin.getDefault()
79 // .getWorkbench().getSharedImages()
80 // .getImageDescriptor(ISharedImages.IMG_DEC_FIELD_ERROR);
81 // DecorationOverlayIcon decoratedImage = new
82 // DecorationOverlayIcon(
83 // image, desc, IDecoration.TOP_LEFT);
84 // return decoratedImage.createImage();
85 if (object
instanceof SingleResultNode
)
86 return failedSingleResult
;
95 // Method to decorate Text
96 public String
decorateText(String label
, Object object
) {
97 if (object
instanceof SingleResultNode
) {
98 SingleResultNode srNode
= (SingleResultNode
) object
;
99 Node node
= srNode
.getNode();
100 String decoration
= null;
102 if (node
.hasProperty(SlcNames
.SLC_COMPLETED
))
103 decoration
= dateFormat
.format(node
104 .getProperty(SlcNames
.SLC_COMPLETED
).getDate()
106 } catch (RepositoryException re
) {
107 throw new SlcException(
108 "Unexpected error defining text decoration for result",
111 return label
+ " [" + decoration
+ "]";
117 public void dispose() {
118 failedFolder
.dispose();
119 failedSingleResult
.dispose();