]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/decorators/ResultFailedDecorator.java
Prepare next development cycle
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / decorators / 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.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;
36
37 public class ResultFailedDecorator extends LabelProvider implements
38 ILabelDecorator {
39
40 // private final static Log log = LogFactory
41 // .getLog(ResultFailedDecorator.class);
42
43 private final static DateFormat dateFormat = new SimpleDateFormat(
44 "yyyy-MM-dd HH:mm");
45
46 public ResultFailedDecorator() {
47 super();
48 }
49
50 // Method to decorate Image
51 public Image decorateImage(Image image, Object object) {
52
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
56 // by Eclipse
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();
65 } else
66 return null;
67 }
68 return null;
69 }
70
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;
77 try {
78 if (node.hasProperty(SlcNames.SLC_COMPLETED))
79 decoration = dateFormat.format(node
80 .getProperty(SlcNames.SLC_COMPLETED).getDate()
81 .getTime());
82 } catch (RepositoryException re) {
83 throw new SlcException(
84 "Unexpected error defining text decoration for result", re);
85 }
86 return label + " [" + decoration + "]";
87 } else
88 return null;
89 }
90
91 }