1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*
* Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Martin Fluegge - initial API and implementation
*/
package org.eclipse.emf.cdo.dawn.ui;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer;
import org.eclipse.emf.cdo.dawn.spi.DawnState;
import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnElementStylizerRegistry;
import org.eclipse.emf.cdo.ui.CDOLabelProvider;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
/**
* @author Martin Fluegge
* @since 1.0
*/
public class DawnLabelProvider extends CDOLabelProvider
{
public DawnLabelProvider(AdapterFactory adapterFactory, CDOView view, TreeViewer viewer)
{
super(adapterFactory, view, viewer);
}
@Override
public Color getForeground(Object object)
{
// makes sure that the object is adapted
Color foreground = super.getForeground(object);
DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(object);
CDOObject cdoObject = CDOUtil.getCDOObject((EObject)object);
if (cdoObject.cdoWriteLock().isLocked())
{
return stylizer.getForegroundColor(cdoObject, DawnState.LOCKED_LOCALLY);
}
else if (CDOUtil.getCDOObject((EObject)object).cdoWriteLock().isLockedByOthers())
{
return stylizer.getForegroundColor(cdoObject, DawnState.LOCKED_REMOTELY);
}
// Use default
return foreground;
}
@Override
public Color getBackground(Object object)
{
// makes sure that the object is adapted
Color background = super.getBackground(object);
DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(object);
CDOObject cdoObject = CDOUtil.getCDOObject((EObject)object);
if (cdoObject.cdoWriteLock().isLocked())
{
return stylizer.getBackgroundColor(cdoObject, DawnState.LOCKED_LOCALLY);
}
else if (CDOUtil.getCDOObject((EObject)object).cdoWriteLock().isLockedByOthers())
{
return stylizer.getBackgroundColor(cdoObject, DawnState.LOCKED_REMOTELY);
}
// Use default
return background;
}
@Override
public Image getImage(Object object)
{
DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(object);
CDOObject cdoObject = CDOUtil.getCDOObject((EObject)object);
if (cdoObject.cdoWriteLock().isLocked())
{
return stylizer.getImage(cdoObject, DawnState.LOCKED_LOCALLY);
}
else if (CDOUtil.getCDOObject((EObject)object).cdoWriteLock().isLockedByOthers())
{
return stylizer.getImage(cdoObject, DawnState.LOCKED_REMOTELY);
}
return super.getImage(object);
}
}
|