]> git.argeo.org Git - gpl/argeo-slc.git/blob - ResultFailedDecorator.java
e714756485e284368969f6c3ad5e17611619e0e3
[gpl/argeo-slc.git] / ResultFailedDecorator.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.client.ui.decorators;
17
18 import java.text.DateFormat;
19 import java.text.SimpleDateFormat;
20
21 import javax.jcr.Node;
22 import javax.jcr.RepositoryException;
23
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;
37
38 public class ResultFailedDecorator extends LabelProvider implements
39 ILabelDecorator {
40
41 // private final static Log log = LogFactory
42 // .getLog(ResultFailedDecorator.class);
43
44 private final static DateFormat dateFormat = new SimpleDateFormat(
45 SlcUiConstants.DEFAULT_DISPLAY_DATE_TIME_FORMAT);
46
47 public ResultFailedDecorator() {
48 super();
49 }
50
51 // Method to decorate Image
52 public Image decorateImage(Image image, Object object) {
53
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
57 // by Eclipse
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();
66 } else
67 return null;
68 }
69 return null;
70 }
71
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;
78 try {
79 if (node.hasProperty(SlcNames.SLC_COMPLETED))
80 decoration = dateFormat.format(node
81 .getProperty(SlcNames.SLC_COMPLETED).getDate()
82 .getTime());
83 } catch (RepositoryException re) {
84 throw new SlcException(
85 "Unexpected error defining text decoration for result", re);
86 }
87 return label + " [" + decoration + "]";
88 } else
89 return null;
90 }
91
92 }