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
|
/*****************************************************************************
* Copyright (c) 2012 CEA LIST.
*
*
* 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:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.manager.cell;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.edit.domain.EditingDomain;
//FIXME : should implements ICrossValueSolver?
//FIXME : should implements ICellManager or returns getCellManger
public class CellManagerFactory {
public static final String CLASS_MANAGER = "manager"; //$NON-NLS-1$
public static final String ORDER = "order"; //$NON-NLS-1$
public static final String SOLVER_ID = "id"; //$NON-NLS-1$
// private final Map<String, Class<IAxisManager>> map;
private final Collection<ICellManager> solvers;
private final Map<Integer, ICellManager> managersMap;
private static final String EXTENSION_ID = "org.eclipse.papyrus.infra.nattable.cellmanager"; //$NON-NLS-1$
public static final CellManagerFactory INSTANCE = new CellManagerFactory();
private CellManagerFactory() {
this.solvers = new ArrayList<ICellManager>();
this.managersMap = new TreeMap<Integer, ICellManager>();
final IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
for(final IConfigurationElement iConfigurationElement : configElements) {
final String id = iConfigurationElement.getAttribute(SOLVER_ID);
final Integer order = new Integer(iConfigurationElement.getAttribute(ORDER));
try {
//to avoid pb when the provided class in not this plugin!
final ICellManager solver = (ICellManager)iConfigurationElement.createExecutableExtension(CLASS_MANAGER);
this.managersMap.put(order, solver);
this.solvers.add(solver);
} catch (final CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public Object getCrossValue(final Object obj1, final Object obj2) {
final ICellManager cellManager = getCrossValueSolver(obj1, obj2);
if(cellManager != null) {
return cellManager.getValue(obj1, obj2);
}
//FIXME should return a specific error or a message?
return null;
}
/**
*
* @param obj1
* @param obj2
* @return
*/
public ICellManager getCellManager(final Object obj1, final Object obj2) {
return getCrossValueSolver(obj1, obj2);
}
//FIXME : should me removed
private ICellManager getCrossValueSolver(final Object obj1, final Object obj2) {
for(final Integer integer : this.managersMap.keySet()) {
ICellManager current = this.managersMap.get(integer);
// for(final ICellManager current : this.solvers) {
if(current.handles(obj1, obj2)) {
return current;
}
// }
}
//FIXME should return a specific error or a message?
return null;
}
public boolean isCellEditable(final Object obj1, final Object obj2) {
final ICellManager cellManager = getCrossValueSolver(obj1, obj2);
if(cellManager != null) {
return cellManager.isCellEditable(obj1, obj2);
}
return false;
}
public void setCellValue(final EditingDomain domain, final Object obj1, final Object obj2, final Object newValue) {
final ICellManager cellManager = getCrossValueSolver(obj1, obj2);
if(cellManager != null) {
cellManager.setValue(domain, obj1, obj2, newValue);
}
}
// public ICellEditor getCellEditor (final Table table, final Object obj1, final Object obj2){
// final ICellManager cellManager = getCrossValueSolver(obj1, obj2);
// if(cellManager!=null){
// return cellManager.getCellEditor(table, obj1);
// }
// return null;
// }
// public void
}
|