blob: d9200de785982d01ee2086ffd09cb49a3697289e (
plain) (
blame)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
* Copyright (c) 2011, 2012, 2015, 2016 Eike Stepper (Loehne, 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.gmf.appearance;
import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicConnectionEditPartStylizerImpl;
import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicGraphicalEditPartStylizerImpl;
import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicNodeEditPartStylizerImpl;
import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicTextAwareEditPartStylizerImpl;
import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.NodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
import java.util.HashMap;
import java.util.Map;
/**
* @author Martin Fluegge
* @since 2.0
* @deprecated
*/
@Deprecated
public class DawnEditPartStylizerRegistry
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnEditPartStylizerRegistry.class);
private static final String DAWN_STYLIZER_EXTENSION_POINT_ID = "org.eclipse.emf.cdo.dawn.editpartstylizers";
public static DawnEditPartStylizerRegistry instance = new DawnEditPartStylizerRegistry();
private Map<String, DawnEditPartStylizer> registeredStylizers = new HashMap<String, DawnEditPartStylizer>();
/**
* @since 2.0
*/
public DawnEditPartStylizer getStylizer(EditPart editPart)
{
DawnEditPartStylizer stylizer = registeredStylizers.get(editPart.getClass().getCanonicalName());
if (stylizer == null)
{
stylizer = getStylizerFromExtensionPoint(editPart);
}
if (stylizer == null)
{
stylizer = getDefaultStylizer(editPart);
}
return stylizer;
}
private DawnEditPartStylizer getDefaultStylizer(EditPart editPart)
{
DawnEditPartStylizer stylizer = null;
if (editPart instanceof ConnectionEditPart)
{
stylizer = new DawnBasicConnectionEditPartStylizerImpl();
}
else if (editPart instanceof NodeEditPart)
{
stylizer = new DawnBasicNodeEditPartStylizerImpl();
}
else if (editPart instanceof DiagramEditPart)
{
stylizer = new DawnBasicNodeEditPartStylizerImpl();
}
else if (editPart instanceof ITextAwareEditPart)
{
stylizer = new DawnBasicTextAwareEditPartStylizerImpl();
}
else
{
// In the case that there is no match we use a simple border styled stylizer.
stylizer = new DawnBasicGraphicalEditPartStylizerImpl();
}
return stylizer;
}
private DawnEditPartStylizer getStylizerFromExtensionPoint(EditPart editPart)
{
try
{
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(DAWN_STYLIZER_EXTENSION_POINT_ID);
for (IConfigurationElement e : config)
{
if (editPart.getClass().getCanonicalName().equals(e.getAttribute("editpart")))
{
DawnEditPartStylizer stylizer = (DawnEditPartStylizer)e.createExecutableExtension("stylizer");
registeredStylizers.put(editPart.getClass().getCanonicalName(), stylizer);
if (TRACER.isEnabled())
{
TRACER.format("Registered DawnEditPartStylizer {0} ", stylizer); //$NON-NLS-1$
}
return stylizer;
}
}
}
catch (InvalidRegistryObjectException e1)
{
e1.printStackTrace();
}
catch (CoreException e)
{
e.printStackTrace();
}
return null;
}
}
|