001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.plugin.ui;
034:
035: /**
036: * @author Guillaume Bort
037: */
038: import org.eclipse.core.resources.IProject;
039: import org.eclipse.core.resources.IResource;
040:
041: import org.eclipse.jface.resource.ImageDescriptor;
042: import org.eclipse.jface.viewers.IDecoration;
043: import org.eclipse.jface.viewers.ILightweightLabelDecorator;
044: import org.eclipse.jface.viewers.LabelProvider;
045:
046: import org.eclipse.swt.widgets.Display;
047:
048: import org.eclipse.ui.IWorkbench;
049: import org.eclipse.ui.PlatformUI;
050:
051: import org.libresource.so6.core.WsConnection;
052: import org.libresource.so6.core.engine.DBType;
053: import org.libresource.so6.plugin.core.So6Util;
054:
055: /**
056: * DOCUMENT ME!
057: *
058: * @author $author$
059: * @version $Revision: 1.3 $
060: */
061: public class So6ResourceUILabelDecorator extends LabelProvider
062: implements ILightweightLabelDecorator {
063: /** DOCUMENT ME! */
064: public static final String ID = "org.libresource.so6.plugin.ui.So6ResourceUILabelDecorator";
065:
066: /**
067: * DOCUMENT ME!
068: *
069: * @param element DOCUMENT ME!
070: * @param decoration DOCUMENT ME!
071: */
072: public void decorate(Object element, IDecoration decoration) {
073: if (element instanceof IProject) {
074: if (So6Util.isSo6Project((IProject) element)) {
075: ImageDescriptor overlay = So6Images
076: .getSo6OverlayImage();
077: decoration.addOverlay(overlay);
078:
079: try {
080: if (!So6Util.isUpToDate((IProject) element)) {
081: decoration.addPrefix("> ");
082: }
083: } catch (Exception e1) {
084: e1.printStackTrace();
085: }
086:
087: try {
088: WsConnection connection = So6Util
089: .getWsConnection((IProject) element);
090: long tickets = connection.getNs();
091: decoration
092: .addSuffix(" - "
093: + tickets
094: + " ["
095: + So6Util
096: .getSo6PropertiesPath((IProject) element)
097: + "]");
098: } catch (Exception e) {
099: e.printStackTrace();
100: }
101: }
102: } else {
103: IResource resource = (IResource) element;
104:
105: if (So6Util.isSo6Project((IProject) resource.getProject())) {
106: try {
107: WsConnection connection = So6Util
108: .getWsConnection(resource.getProject());
109: boolean ignored = So6Util.isIgnored(resource);
110:
111: if (ignored
112: || connection.getRefCopy().exists(
113: resource.getProjectRelativePath()
114: .toString())) {
115: ImageDescriptor overlay;
116:
117: if (ignored) {
118: overlay = So6Images
119: .getSo6OverlayIgnoreImage();
120: } else {
121: overlay = So6Images.getSo6OverlayImage();
122: }
123:
124: decoration.addOverlay(overlay);
125:
126: if (!ignored) {
127: int type = connection.getDBType().getType(
128: resource.getProjectRelativePath()
129: .toString());
130:
131: switch (type) {
132: case DBType.TYPE_DIR:
133: decoration.addSuffix(" (Directory)");
134:
135: break;
136:
137: case DBType.TYPE_FILE_BIN:
138: decoration.addSuffix(" (Binary)");
139:
140: break;
141:
142: case DBType.TYPE_FILE_TXT:
143: decoration.addSuffix(" (Text)");
144:
145: break;
146:
147: case DBType.TYPE_FILE_XML:
148: decoration.addSuffix(" (XML)");
149:
150: break;
151:
152: case DBType.TYPE_UNKNOWN:
153: decoration.addSuffix(" (?)");
154:
155: break;
156:
157: default:
158: decoration.addSuffix(" (?)");
159:
160: break;
161: }
162: }
163: }
164: } catch (Exception e) {
165: e.printStackTrace();
166: }
167: }
168: }
169: }
170:
171: /**
172: * DOCUMENT ME!
173: */
174: public static final void update() {
175: getStandardDisplay().asyncExec(new Runnable() {
176: public void run() {
177: IWorkbench workbench = PlatformUI.getWorkbench();
178: workbench.getDecoratorManager().update(
179: So6ResourceUILabelDecorator.class.getName());
180: }
181: });
182: }
183:
184: /**
185: * DOCUMENT ME!
186: *
187: * @return DOCUMENT ME!
188: */
189: public static Display getStandardDisplay() {
190: Display display = Display.getCurrent();
191:
192: if (display == null) {
193: display = Display.getDefault();
194: }
195:
196: return display;
197: }
198: }
|