]> 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
enhance management of context menus and commands. Remove a few bugs.
[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.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;
38
39 /** Dynamically decorates the results tree. */
40 public class ResultFailedDecorator extends LabelProvider implements
41 ILabelDecorator {
42
43 // FIXME why not use? org.eclipse.jface.viewers.DecoratingLabelProvider
44
45 // private final static Log log = LogFactory
46 // .getLog(ResultFailedDecorator.class);
47
48 private final static DateFormat dateFormat = new SimpleDateFormat(
49 SlcUiConstants.DEFAULT_DISPLAY_DATE_TIME_FORMAT);
50
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;
56
57 public ResultFailedDecorator() {
58 super();
59 ImageDescriptor desc = ClientUiPlugin.getDefault().getWorkbench()
60 .getSharedImages()
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)
66 .createImage();
67 }
68
69 // Method to decorate Image
70 public Image decorateImage(Image image, Object object) {
71
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
75 // by Eclipse
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;
87 else
88 return failedFolder;
89 } else
90 return null;
91 }
92 return null;
93 }
94
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;
101 try {
102 if (node.hasProperty(SlcNames.SLC_COMPLETED))
103 decoration = dateFormat.format(node
104 .getProperty(SlcNames.SLC_COMPLETED).getDate()
105 .getTime());
106 } catch (RepositoryException re) {
107 throw new SlcException(
108 "Unexpected error defining text decoration for result",
109 re);
110 }
111 return label + " [" + decoration + "]";
112 } else
113 return null;
114 }
115
116 @Override
117 public void dispose() {
118 failedFolder.dispose();
119 failedSingleResult.dispose();
120 super.dispose();
121 }
122
123 }