]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java
Prevent editing null values
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / property / AnnotatedPropertyTabContributorFactory.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g3d.property;
13
14 import java.lang.annotation.Annotation;
15 import java.lang.reflect.Field;
16 import java.lang.reflect.InvocationTargetException;
17 import java.lang.reflect.Method;
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27 import java.util.function.Consumer;
28
29 import org.eclipse.jface.layout.GridDataFactory;
30 import org.eclipse.jface.viewers.AbstractTableViewer;
31 import org.eclipse.jface.viewers.CellEditor;
32 import org.eclipse.jface.viewers.CellEditor.LayoutData;
33 import org.eclipse.jface.viewers.CellLabelProvider;
34 import org.eclipse.jface.viewers.CellNavigationStrategy;
35 import org.eclipse.jface.viewers.ColumnViewer;
36 import org.eclipse.jface.viewers.ColumnViewerEditor;
37 import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
38 import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener;
39 import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
40 import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent;
41 import org.eclipse.jface.viewers.EditingSupport;
42 import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter;
43 import org.eclipse.jface.viewers.ISelection;
44 import org.eclipse.jface.viewers.ISelectionChangedListener;
45 import org.eclipse.jface.viewers.ISelectionProvider;
46 import org.eclipse.jface.viewers.IStructuredContentProvider;
47 import org.eclipse.jface.viewers.SelectionChangedEvent;
48 import org.eclipse.jface.viewers.StructuredSelection;
49 import org.eclipse.jface.viewers.TableViewer;
50 import org.eclipse.jface.viewers.TableViewerColumn;
51 import org.eclipse.jface.viewers.TableViewerFocusCellManager;
52 import org.eclipse.jface.viewers.TextCellEditor;
53 import org.eclipse.jface.viewers.Viewer;
54 import org.eclipse.jface.viewers.ViewerCell;
55 import org.eclipse.jface.viewers.ViewerColumn;
56 import org.eclipse.jface.viewers.ViewerRow;
57 import org.eclipse.swt.SWT;
58 import org.eclipse.swt.custom.TableEditor;
59 import org.eclipse.swt.events.TraverseEvent;
60 import org.eclipse.swt.widgets.Composite;
61 import org.eclipse.swt.widgets.Control;
62 import org.eclipse.swt.widgets.Display;
63 import org.eclipse.swt.widgets.Event;
64 import org.eclipse.swt.widgets.Item;
65 import org.eclipse.swt.widgets.TableColumn;
66 import org.eclipse.swt.widgets.TableItem;
67 import org.eclipse.ui.IWorkbenchSite;
68 import org.simantics.db.management.ISessionContext;
69 import org.simantics.g3d.property.annotations.CompoundGetPropertyValue;
70 import org.simantics.g3d.property.annotations.CompoundSetPropertyValue;
71 import org.simantics.g3d.property.annotations.GetPropertyValue;
72 import org.simantics.g3d.property.annotations.PropertyTabBlacklist;
73 import org.simantics.g3d.property.annotations.SetPropertyValue;
74 import org.simantics.g3d.scenegraph.IG3DNode;
75 import org.simantics.g3d.scenegraph.NodeMap;
76 import org.simantics.g3d.scenegraph.NodeMapProvider;
77 import org.simantics.g3d.scenegraph.base.INode;
78 import org.simantics.g3d.scenegraph.base.NodeListener;
79 import org.simantics.g3d.scenegraph.base.ParentNode;
80 import org.simantics.g3d.scenegraph.structural.IStructuralNode;
81 import org.simantics.g3d.tools.AdaptationUtils;
82 import org.simantics.selectionview.IPropertyTab;
83 import org.simantics.selectionview.IPropertyTab2;
84 import org.simantics.utils.datastructures.Callback;
85 import org.simantics.utils.datastructures.MapList;
86
87 public class AnnotatedPropertyTabContributorFactory implements PropertyTabContributorFactory {
88
89         private static final boolean DEBUG = false;
90         
91         @SuppressWarnings("unchecked")
92         @Override
93         public List<PropertyTabContributor> getContributors(Object input) {
94                 Map<String,IPropertyItem> items = new LinkedHashMap<String, IPropertyItem>();
95                 List<String> blacklist = new ArrayList<String>();
96                 try {
97                         collectItems(input.getClass(), items);
98                         collectBlacklist(input.getClass(), blacklist);
99                 } catch (InstantiationException e) {
100                         // TODO Auto-generated catch block
101                         e.printStackTrace();
102                 } catch (IllegalAccessException e) {
103                         // TODO Auto-generated catch block
104                         e.printStackTrace();
105                 }
106                 
107                 if (items.size() == 0)
108                         return Collections.EMPTY_LIST;
109                 
110                 MapList<String, IPropertyItem> tabMap = new MapList<String, IPropertyItem>();
111                 List<String> tabs = new ArrayList<String>();
112                 for (String id : items.keySet()) {
113                         IPropertyItem item = items.get(id);
114                         tabMap.add(item.getTabId(), item);
115                         if (!tabs.contains(item.getTabId())) {
116                                 tabs.add(item.getTabId());
117                                 //System.out.println(item.tabId + " " + item.name + " " + item.id);
118                         }
119                 }
120                 for (String s : blacklist) {
121                         tabs.remove(s);
122                 }
123                 
124                 List<PropertyTabContributor> contributors = new ArrayList<PropertyTabContributor>(tabs.size());
125                 for (String tabId : tabs) {
126                         contributors.add(new AnnotatedPropertyTabContributor(tabId, tabMap.getValues(tabId)));
127                 }
128                 
129                 return contributors;
130         }
131         
132         
133         private static void collectItems(Class<?> clazz, Map<String, IPropertyItem> items) throws InstantiationException, IllegalAccessException {
134                  Class<?> superclass = clazz.getSuperclass();
135                  if(superclass != null)
136                          collectItems(superclass, items);
137                  
138                  for (Method m : clazz.getDeclaredMethods()) {
139                          m.setAccessible(true);
140                 for (Annotation annotation : m.getAnnotations()) {
141                         if (annotation.annotationType().equals(GetPropertyValue.class)) {
142                                 GetPropertyValue get = (GetPropertyValue)annotation;
143                                 PropertyItem item = (PropertyItem)items.get(get.value());
144                                 if (item == null) {
145                                         item = new PropertyItem(get.value());
146                                         items.put(item.id, item);
147                                 }
148
149                                 item.getter = m;
150                                 item.manipulatorClass = get.manipulator().newInstance().get(m,null);
151
152                                 item.tabId = get.tabId();
153
154                                 item.name = get.name();
155                                 
156                                 
157                         } else if (annotation.annotationType().equals(SetPropertyValue.class)) {
158                                 SetPropertyValue set = (SetPropertyValue)annotation;
159                                 PropertyItem item = (PropertyItem)items.get(set.value());
160                                 if (item == null) {
161                                         item = new PropertyItem(set.value());
162                                         items.put(item.id, item);
163                                 }
164                                 
165                                 item.setter = m;
166                         } else if (annotation.annotationType().equals(CompoundGetPropertyValue.class)) {
167                                 CompoundGetPropertyValue get = (CompoundGetPropertyValue)annotation;
168                                 CompoundPropertyItem item = (CompoundPropertyItem)items.get(get.value());
169                                 if (item == null) {
170                                         item = new CompoundPropertyItem(get.value());
171                                         items.put(item.id, item);
172                                 }
173
174                                 item.getter = m;
175                                 item.manipulatorFactory = get.manipulator().newInstance();
176
177                                 item.tabId = get.tabId();
178
179                                 item.name = get.name();
180                         } else if (annotation.annotationType().equals(CompoundSetPropertyValue.class)) {
181                                 CompoundSetPropertyValue set = (CompoundSetPropertyValue)annotation;
182                                 CompoundPropertyItem item = (CompoundPropertyItem)items.get(set.value());
183                                 if (item == null) {
184                                         item = new CompoundPropertyItem(set.value());
185                                         items.put(item.id, item);
186                                 }
187                                 
188                                 item.setter = m;
189                         }
190                 }
191                  }
192                 
193                 
194         }
195         
196         private static void collectBlacklist(Class<?> clazz, List<String> blacklist) throws InstantiationException, IllegalAccessException {
197                  Class<?> superclass = clazz.getSuperclass();
198                  if(superclass != null)
199                          collectBlacklist(superclass, blacklist);
200                  
201                  PropertyTabBlacklist ann = clazz.getAnnotation(PropertyTabBlacklist.class);
202                  if (ann == null)
203                          return;
204                  String s = ann.value();
205                  if (s == null)
206                          return;
207                  if (s.length() == 0)
208                          return;
209                  for (String item : s.split(";")) {
210                          blacklist.add(item);
211                  }
212                  
213                 
214         }
215         
216         private static Map<PropertyItem, PropertyManipulator> createManipulators(CompoundPropertyItem item, Object obj) {
217                 try {
218                         
219                         Map<String,Object> map = (Map<String, Object>)item.getter.invoke(obj);
220                         Map<PropertyItem, PropertyManipulator> result = new HashMap<AnnotatedPropertyTabContributorFactory.PropertyItem, PropertyManipulator>();
221                         for (String key : map.keySet()) {
222                                 MethodWithMapValueProvider provider = new MethodWithMapValueProvider(item.getter, item.setter, key);
223                                 Class<? extends PropertyManipulator> clazz = item.manipulatorFactory.get(null,map.get(key));
224                                 PropertyManipulator manipulator = clazz.getConstructor(ValueProvider.class,Object.class).newInstance(provider,obj);
225                                 PropertyItem i = new PropertyItem(item.id+"."+key);
226                                 i.getter = item.getter;
227                                 i.setter = item.setter;
228                                 i.name = key;
229                                 i.tabId = item.tabId;
230                                 result.put(i,manipulator);
231                         }
232                         return result;
233                 } catch (Exception e) {
234                         e.printStackTrace();
235                         return Collections.EMPTY_MAP;
236                 } 
237                 
238         }
239         
240         private static PropertyManipulator createManipulator(PropertyItem item, Object obj) {
241                 try {
242                         MethodValueProvider provider = new MethodValueProvider(item.getter, item.setter);
243                         PropertyManipulator manipulator = item.manipulatorClass.getConstructor(ValueProvider.class,Object.class).newInstance(provider,obj);
244                         return manipulator;
245                 } catch (Exception e) {
246                         e.printStackTrace();
247                         return null;
248                 } 
249         }
250         
251         private static interface IPropertyItem {
252                 public String getTabId();
253         }
254         
255         private static class PropertyItem implements IPropertyItem{
256                 private String id;
257                 private String name;
258                 private String tabId;
259                 private Method getter;
260                 private Method setter;
261                 private Class<? extends PropertyManipulator> manipulatorClass;
262                 
263                 
264                 public PropertyItem(String id) {
265                         if (id == null)
266                                 throw new NullPointerException();
267                         this.id = id;
268                 }
269                 
270                 @Override
271                 public int hashCode() {
272                         return id.hashCode();
273                 }
274                 
275                 @Override
276                 public String getTabId() {
277                         return tabId;
278                 }
279         }
280         
281         private static class CompoundPropertyItem implements IPropertyItem{
282                 private String id;
283                 private String name;
284                 private String tabId;
285                 private Method getter;
286                 private Method setter;
287                 private PropertyManipulatorFactory manipulatorFactory;
288                 
289                 
290                 public CompoundPropertyItem(String id) {
291                         if (id == null)
292                                 throw new NullPointerException();
293                         this.id = id;
294                 }
295                 
296                 @Override
297                 public int hashCode() {
298                         return id.hashCode();
299                 }
300                 
301                 @Override
302                 public String getTabId() {
303                         return tabId;
304                 }
305         }
306         
307         private static class AnnotatedPropertyTabContributor implements PropertyTabContributor {
308                 private String id; 
309                 List<IPropertyItem> items;
310                 
311                 public AnnotatedPropertyTabContributor(String id, List<IPropertyItem> items) {
312                         if (id == null)
313                                 throw new NullPointerException();
314                         this.id = id;
315                         this.items = items;
316                 }
317                 
318                 @Override
319                 public IPropertyTab create(Composite parent, IWorkbenchSite site,
320                                 ISessionContext context, Object input) {
321                         AnnotatedPropertyTab tab = new AnnotatedPropertyTab(id, items);
322                         tab.createControl(parent, context);
323                         return tab;
324                 }
325                 
326                 @Override
327                 public String getId() {
328                         return id;
329                 }
330                 
331         }
332         
333         private static class AnnotatedPropertyTab implements IPropertyTab2, NodeListener {
334                 //private String id; 
335                 List<IPropertyItem> contibutedItems;
336                 List<PropertyItem> resolvedItems = new ArrayList<PropertyItem>();
337                 private Map<PropertyItem,PropertyManipulator> manipulators = new HashMap<PropertyItem, PropertyManipulator>();
338                 
339                 private TableViewer viewer;
340                 
341                 private IG3DNode node;
342                 private NodeMap<?,?> nodeMap;
343                 
344                 private List<TableViewerColumn> valueColumns = new ArrayList<TableViewerColumn>();
345                 
346                 public AnnotatedPropertyTab(String id, List<IPropertyItem> items) {
347                         //this.id = id;
348                         this.contibutedItems = items;
349                         
350                                         
351                 }
352                 
353                 @Override
354                 public void createControl(Composite parent, ISessionContext context) {
355                         //parent.setLayout(new FillLayout());
356                         viewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.SINGLE);
357                         
358                         GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(viewer.getTable());
359                         
360                         //viewer.setLabelProvider(new AnnotatedTableLabelProvider(object))
361                         
362                         viewer.setContentProvider(new PropertyItemContentsProvider());
363                         
364                         TableViewerColumn name = new TableViewerColumn(viewer, SWT.LEFT);
365                         //TableViewerColumn value = new TableViewerColumn(viewer, SWT.LEFT);
366                         name.setLabelProvider(new PropertyItemNameProvider());
367                         //value.setLabelProvider(new PropertyValueLabelProvider(null));
368                         name.getColumn().setText("Property");
369                         //value.getColumn().setText("Value");
370                         name.getColumn().setWidth(200);
371                         //value.getColumn().setWidth(200);
372                         name.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
373                                 
374                                 @Override
375                                 public void selectionChanged(SelectionChangedEvent event) {
376                                         PropertyItem item = AdaptationUtils.adaptToSingle(event.getSelection(),PropertyItem.class);
377                                         if (item != null) {
378                                                 PropertyManipulator manipulator = manipulators.get(item);//createManipulator(item, null);
379                                                 for (int i = 0; i < valueColumns.size(); i++) {
380                                                         TableViewerColumn c = valueColumns.get(i);
381                                                         if (i < manipulator.getValueCount()) {
382                                                                 c.getColumn().setText(manipulator.getDescription(i));
383                                                         } else {
384                                                                 c.getColumn().setText("");
385                                                         }
386                                                 }
387                                         }
388                                         
389                                 }
390                         });
391                         
392                         int valueCount = 0;
393                         for (IPropertyItem item : contibutedItems) {
394                                 if (item instanceof PropertyItem) {
395                                         PropertyManipulator manipulator = createManipulator((PropertyItem)item, null);
396                                         if (manipulator == null)
397                                                 continue;
398                                         if (valueCount < manipulator.getValueCount())
399                                                 valueCount = manipulator.getValueCount();
400                                 } else if (item instanceof CompoundPropertyItem) {
401                                         if (valueCount < 1)
402                                                 valueCount = 1;
403                                 }
404                         }
405                         for (int i = 0; i < valueCount; i++) {
406                                 TableViewerColumn value = new TableViewerColumn(viewer, SWT.LEFT);
407                                 //value.getColumn().setText("Value " + (i+1));
408                                 value.getColumn().setText("");
409                                 value.getColumn().setWidth(200);
410                                 valueColumns.add(value);
411                                 //value.setEditingSupport(new )
412                         }
413                         viewer.getTable().setHeaderVisible(true);
414                         viewer.getTable().setLinesVisible(true);
415                         viewer.addSelectionChangedListener(new ISelectionChangedListener() {
416                                 
417                                 @Override
418                                 public void selectionChanged(SelectionChangedEvent event) {
419                                         PropertyItem item = AdaptationUtils.adaptToSingle(event.getSelection(), PropertyItem.class);
420                                         selectedItem = item;
421                                         if (!manipulators.get(selectedItem).getEditMode())
422                                                 manipulators.get(selectedItem).setEditMode(true);
423                                         
424
425                                         for (IPropertyItem i : delayedUpdate) {
426                                                 if (!i.equals(selectedItem)) {
427                                                         manipulators.get(i).setEditMode(false);
428                                                         viewer.update(i,null);
429                                                 }
430                                         }
431                                         if (delayedUpdate.contains(selectedItem)) {
432                                                 delayedUpdate.clear();
433                                                 delayedUpdate.add(selectedItem);
434                                         } else {
435                                                 delayedUpdate.clear();
436                                         }
437                                 }
438                         });
439                         
440                         CellNavigationStrategy nStrategy = new CellNavigationStrategy() {
441                                 private ViewerCell internalFindSelectedCell(
442                                                 ColumnViewer viewer, ViewerCell currentSelectedCell,
443                                                 Event event) {
444                                         switch (event.keyCode) {
445                                         case SWT.ARROW_UP:
446                                                 if (currentSelectedCell != null) {
447                                                         return getNeighbor(currentSelectedCell,
448                                                                         ViewerCell.ABOVE, false);
449                                                 }
450                                                 break;
451                                         case SWT.ARROW_DOWN:
452                                                 if (currentSelectedCell != null) {
453                                                         return getNeighbor(currentSelectedCell,
454                                                                         ViewerCell.BELOW, false);
455                                                 }
456                                                 break;
457                                         case SWT.ARROW_LEFT:
458                                                 if (currentSelectedCell != null) {
459                                                         return getNeighbor(currentSelectedCell,
460                                                                         ViewerCell.LEFT, true);
461                                                 }
462                                                 break;
463                                         case SWT.ARROW_RIGHT:
464                                                 if (currentSelectedCell != null) {
465                                                         return getNeighbor(currentSelectedCell,
466                                                                         ViewerCell.RIGHT, true);
467                                                 }
468                                                 break;
469                                         }
470                                         return null;
471                                 }
472                                 
473                                 public ViewerCell findSelectedCell(ColumnViewer viewer,
474                                                 ViewerCell currentSelectedCell, Event event) {
475                                         ViewerCell cell = internalFindSelectedCell(viewer,
476                                                         currentSelectedCell, event);
477                                         if (cell != null) {
478                                                 TableColumn t = AnnotatedPropertyTab.this.viewer.getTable().getColumn(
479                                                                 cell.getColumnIndex());
480                                                 AnnotatedPropertyTab.this.viewer.getTable().showColumn(t);
481                                         }
482                                         return cell;
483                                 }
484                         };
485                         
486                         TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(
487                                         viewer, new FocusCellOwnerDrawHighlighter(viewer));
488                         try {
489                                 Field f = focusCellManager.getClass().getSuperclass()
490                                                 .getDeclaredField("navigationStrategy");
491                                 f.setAccessible(true);
492                                 f.set(focusCellManager, nStrategy);
493                         } catch (SecurityException e) {
494                                 e.printStackTrace();
495                         } catch (NoSuchFieldException e) {
496                                 e.printStackTrace();
497                         } catch (IllegalArgumentException e) {
498                                 e.printStackTrace();
499                         } catch (IllegalAccessException e) {
500                                 e.printStackTrace();
501                         }
502                         ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
503                                         viewer) {
504                                 protected boolean isEditorActivationEvent(
505                                                 ColumnViewerEditorActivationEvent event) {
506                                         return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
507                                                         || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
508                                                         || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
509                                                         || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
510                                 }
511                         };
512                         TableViewerEditor.create(viewer, focusCellManager, actSupport,
513                                         ColumnViewerEditor.TABBING_HORIZONTAL
514                                                         | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
515                                                         | ColumnViewerEditor.TABBING_VERTICAL
516                                                         | ColumnViewerEditor.KEYBOARD_ACTIVATION);
517                         viewer.getColumnViewerEditor().addEditorActivationListener(
518                                         new ColumnViewerEditorActivationListener() {
519                                                 public void afterEditorActivated(
520                                                                 ColumnViewerEditorActivationEvent event) {
521                                                 }
522
523                                                 public void afterEditorDeactivated(
524                                                                 ColumnViewerEditorDeactivationEvent event) {
525                                                 }
526
527                                                 public void beforeEditorActivated(
528                                                                 ColumnViewerEditorActivationEvent event) {
529                                                         ViewerCell cell = (ViewerCell) event.getSource();
530                                                         viewer.getTable().showColumn(
531                                                                         viewer.getTable().getColumn(cell.getColumnIndex()));
532                                                 }
533
534                                                 public void beforeEditorDeactivated(
535                                                                 ColumnViewerEditorDeactivationEvent event) {
536                                                 }
537                                         });
538                 }
539                 
540                 
541                 
542                 
543                 private IPropertyItem selectedItem = null;
544                 private Set<IPropertyItem> delayedUpdate = new HashSet<IPropertyItem>();
545                 
546                 
547                 @Override
548                 public void setInput(ISessionContext context, ISelection selection,
549                                 boolean force) {
550                         Collection<IG3DNode> nodes = AdaptationUtils.adaptToCollection(selection, IG3DNode.class);
551                         if (nodes.size() != 1) {
552                                 if (node != null) {
553                                         node.removeListener(this);
554                                         node = null;
555                                 }
556                                 return;
557                         }
558                         IG3DNode n = nodes.iterator().next();
559                         if (node != null) {
560                                 if (!node.equals(n)) {
561                                         node.removeListener(this);
562                                         setInput(n);
563                                 }
564                         } else {
565                                 setInput(n);
566                         }
567                 }
568                 
569                 
570                 
571                 private void setInput(IG3DNode node) {
572                         this.node = node;
573                         this.node.addListener(this);
574                         // resolve nodemap
575                         IG3DNode n = node;
576                         while (true) {
577                                 if (n == null) {
578                                         nodeMap = null;
579                                         break;
580                                 }
581                                 if (n instanceof NodeMapProvider<?,?>) {
582                                         nodeMap = ((NodeMapProvider<?,?>) n).getNodeMap();
583                                         if (nodeMap != null)
584                                                 break;
585                                 }
586                                 n = (IG3DNode)n.getParent();
587                         }
588                         boolean readOnly =  (node instanceof IStructuralNode && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot());
589                         // create label providers
590                         PropertyValueLabelProvider2 p = new PropertyValueLabelProvider2(this);
591                         int index = 0;
592                         for (TableViewerColumn c : valueColumns) {
593                                 c.setLabelProvider(p);
594                                 if (!readOnly) {
595                                         PropertyEditingSupport support = new PropertyEditingSupport(this, viewer, index++, nodeMap);
596                                         c.setEditingSupport(support);
597                                 }
598                         }
599                         resolvedItems.clear();
600                         manipulators.clear();
601                         for (IPropertyItem item : contibutedItems) {
602                                 if (item instanceof PropertyItem) {
603                                         resolvedItems.add((PropertyItem)item);
604                                         manipulators.put((PropertyItem)item, createManipulator((PropertyItem)item, node));
605                                 }
606                                 else {
607                                         CompoundPropertyItem compound = (CompoundPropertyItem)item;
608                                         Map<PropertyItem, PropertyManipulator> manipulators = createManipulators(compound, node);
609                                         for (PropertyItem i : manipulators.keySet()) {
610                                                 resolvedItems.add(i);
611                                                 this.manipulators.put(i, manipulators.get(i));
612                                         }
613                                 }
614                         }
615                         
616                         viewer.getTable().setEnabled(!readOnly);
617                         viewer.setInput(resolvedItems);
618                 }
619                 
620                 @Override
621                 public void requestFocus() {
622                         viewer.getTable().forceFocus();
623                 }
624                 
625                 @Override
626                 public void dispose() {
627                         if (node != null) {
628                                 node.removeListener(this);
629                                 node = null;
630                         }
631                         
632                 }
633                 
634                 @Override
635                 public Control getControl() {
636                         return viewer.getTable();
637                 }
638                 
639                 @Override
640                 public ISelectionProvider getSelectionProvider() {
641                         return null;
642                 }
643                 
644                 @Override
645                 public boolean isDisposed() {
646                         return viewer.getTable().isDisposed();
647                 }
648                 
649                 @Override
650                 public <T extends INode> void nodeAdded(ParentNode<T> node,
651                                 INode child, String rel) {
652                         
653                 }
654                 
655                 @Override
656                 public <T extends INode> void nodeRemoved(ParentNode<T> node,
657                                 INode child, String rel) {
658                         
659                 }
660                 
661                 @Override
662                 public void propertyChanged(INode node, final String id) {
663 //                      for (final PropertyItem item : items) {
664 //                              if (item.id.equals(id)) {
665 //                                      Display.getDefault().asyncExec(new Runnable() {
666 //                                              
667 //                                              @Override
668 //                                              public void run() {
669 //                                                      viewer.update(item, null);
670 //                                                      
671 //                                              }
672 //                                      });
673 //                              }
674 //                      }
675                         if (Thread.currentThread() == Display.getDefault().getThread()) {
676                                 if (DEBUG)System.out.println("Viewer refresh " + id);
677                                 for (PropertyItem item : resolvedItems)
678                                         if (!item.equals(selectedItem))
679                                                 viewer.refresh(item);
680                                 if (selectedItem != null)
681                                         delayedUpdate.add(selectedItem);
682                         } else if (!editing){
683                                 // running delayed refresh when a cell editor is active would cancel cell editing.
684                                 Display.getDefault().asyncExec(new Runnable() {
685                                         @Override
686                                         public void run() {
687                                                 if (viewer.getTable().isDisposed()) {
688                                                         if (AnnotatedPropertyTab.this.node != null)
689                                                                 AnnotatedPropertyTab.this.node.removeListener(AnnotatedPropertyTab.this);
690                                                         return;
691                                                 }
692                                                 if (DEBUG) System.out.println("Viewer threaded refresh " + id);
693                                                 for (PropertyItem item : resolvedItems)
694                                                         if (!item.equals(selectedItem))
695                                                                 viewer.refresh(item);
696                                                 if (selectedItem != null)
697                                                         delayedUpdate.add(selectedItem);
698                                                 
699                                         }
700                                 });
701                         } else {
702                                 for (PropertyItem item : resolvedItems) {
703                                         delayedUpdate.add(item);
704                                 }
705                         }
706                         
707                 }
708                 
709
710                 
711                 @Override
712                 public void updatePartName(Consumer<String> updateCallback) {
713                         if (node != null)
714                                 updateCallback.accept(node.toString()); 
715                         
716                 }
717                 
718                 public PropertyManipulator getManipulator(PropertyItem item) {
719                         return manipulators.get(item);
720                 }
721                 
722                 private boolean editing = false;
723                 
724                 public void setEditing(boolean editing) {
725                         this.editing = editing;
726                 }
727         }
728         
729         
730         
731         private static class PropertyEditingSupport extends EditingSupport {
732                 AnnotatedPropertyTab tab;
733                 int index;
734                 NodeMap<?,?> nodeMap;
735                 TableViewer viewer;
736                 CellEditor editor;
737
738                 public PropertyEditingSupport(AnnotatedPropertyTab tab, TableViewer viewer, int index, NodeMap<?,?> nodeMap) {
739                         super(viewer);
740                         this.tab = tab;
741                         this.index = index;
742                         this.viewer = viewer;
743                         this.nodeMap = nodeMap;
744                 }
745                 
746                 @Override
747                 protected boolean canEdit(Object element) {
748                         PropertyItem item = (PropertyItem)element;
749                         if (tab.getManipulator(item).getValueCount() <= index)
750                                 return false;
751                         if (item.setter == null)
752                                 return false;
753                         if (getValue(element) == null)
754                                 return false;
755                         return true;
756                 }
757                 
758                 @Override
759                 protected CellEditor getCellEditor(Object element) {
760                         
761                         if (tab.getManipulator((PropertyItem)element).getValueCount() <= index)
762                                 return null;
763                         if (editor == null)
764                                 editor = new TextCellEditor(viewer.getTable(),SWT.NONE) {
765                                 @Override
766                                 public void activate() {
767                                         tab.setEditing(true);
768                                 }
769                                 
770                                 @Override
771                                 public void deactivate() {
772                                         super.deactivate();
773                                         tab.setEditing(false);
774                                 }
775                         };
776                         if (DEBUG)System.err.println("CELL EDITOR: " + element);
777                         return editor;
778                 }
779                 
780                 @Override
781                 protected Object getValue(Object element) {
782                         PropertyItem item = (PropertyItem)element;
783                         PropertyManipulator manipulator = tab.getManipulator(item);//createManipulator(item, obj);
784                         if (manipulator.getValueCount() <= index)
785                                 return null;
786                         Object value = manipulator.getValue(index);
787                         return value;
788                 }
789                 
790                 @Override
791                 protected void setValue(Object element, Object value) {
792                         
793                         PropertyItem item = (PropertyItem)element;
794                         PropertyManipulator manipulator = tab.getManipulator(item);//createManipulator(item, obj);
795                         if (manipulator.getValueCount() <= index)
796                                 throw new IllegalAccessError("Editing value in index " + index + " is not allowed.");
797                         if (DEBUG)System.err.println("CELL SET VALUE: " + element + " " + value);
798                         manipulator.setValue((String)value,index);
799                         viewer.refresh(item);
800                         nodeMap.commit();
801                         
802                 }
803                 
804                 
805
806         }
807         
808         private static class PropertyItemNameProvider extends CellLabelProvider {
809
810                 
811                 @Override
812                 public void update(ViewerCell cell) {
813                         PropertyItem item = (PropertyItem)cell.getElement();
814
815                         if (item.name.length() > 0)
816                                 cell.setText(item.name);
817                         else
818                                 cell.setText(item.id);
819                         
820                         
821                 }
822         }
823         
824         private static class PropertyValueLabelProvider2 extends CellLabelProvider {
825                 AnnotatedPropertyTab tab;
826                 //private Object object;
827                 
828                 public PropertyValueLabelProvider2(AnnotatedPropertyTab tab) {
829                         this.tab = tab;
830                 }
831                 
832                 @Override
833                 public void update(ViewerCell cell) {
834                         PropertyItem item = (PropertyItem)cell.getElement();
835                         int index = cell.getColumnIndex() -1;
836                         PropertyManipulator manipulator = tab.getManipulator(item);//createManipulator(item, object);
837                         if (manipulator.getValueCount() <= index)
838                                 return;
839                         cell.setText(manipulator.getValue(index));
840                 }
841         }
842         
843         private static class PropertyItemContentsProvider implements IStructuredContentProvider {
844                 @SuppressWarnings("unchecked")
845                 @Override
846                 public Object[] getElements(Object inputElement) {
847                         List<PropertyItem> items = (List<PropertyItem>)inputElement;
848                         return items.toArray();
849                 }
850                 
851                 @Override
852                 public void dispose() {
853                         
854                 }
855                 
856                 @Override
857                 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
858                         
859                 }
860         }
861         
862         
863         
864         private static ViewerCell getNeighbor(ViewerCell currentCell,
865                         int directionMask, boolean sameLevel) {
866                 ViewerRow row;
867                 if ((directionMask & ViewerCell.ABOVE) == ViewerCell.ABOVE) {
868                         row = currentCell.getViewerRow().getNeighbor(ViewerRow.ABOVE,
869                                         sameLevel);
870                 } else if ((directionMask & ViewerCell.BELOW) == ViewerCell.BELOW) {
871                         row = currentCell.getViewerRow().getNeighbor(ViewerRow.BELOW,
872                                         sameLevel);
873                 } else {
874                         row = currentCell.getViewerRow();
875                 }
876                 if (row != null) {
877                         int columnIndex;
878                         columnIndex = getVisualIndex(row, currentCell.getColumnIndex());
879                         int modifier = 0;
880                         if ((directionMask & ViewerCell.LEFT) == ViewerCell.LEFT) {
881                                 modifier = -1;
882                         } else if ((directionMask & ViewerCell.RIGHT) == ViewerCell.RIGHT) {
883                                 modifier = 1;
884                         }
885                         columnIndex += modifier;
886                         if (columnIndex >= 0 && columnIndex < row.getColumnCount()) {
887                                 ViewerCell cell = getCellAtVisualIndex(row, columnIndex);
888                                 if (cell != null) {
889                                         while (cell != null
890                                                         && columnIndex < row.getColumnCount() - 1
891                                                         && columnIndex > 0) {
892                                                 if (isVisible(cell)) {
893                                                         break;
894                                                 }
895                                                 columnIndex += modifier;
896                                                 cell = getCellAtVisualIndex(row, columnIndex);
897                                                 if (cell == null) {
898                                                         break;
899                                                 }
900                                         }
901                                 }
902                                 return cell;
903                         }
904                 }
905                 return null;
906         }
907         
908         
909         
910         public static class TableViewerEditor extends ColumnViewerEditor {
911                 /**
912                  * This viewer's table editor.
913                  */
914                 private TableEditor tableEditor;
915                 private TableViewerFocusCellManager focusCellManager;
916                 private int feature;
917
918                 /**
919                  * @param viewer
920                  *            the viewer the editor is attached to
921                  * @param focusCellManager
922                  *            the cell focus manager if one used or <code>null</code>
923                  * @param editorActivationStrategy
924                  *            the strategy used to decide about the editor activation
925                  * @param feature
926                  *            the feature mask
927                  */
928                 TableViewerEditor(TableViewer viewer,
929                                 TableViewerFocusCellManager focusCellManager,
930                                 ColumnViewerEditorActivationStrategy editorActivationStrategy,
931                                 int feature) {
932                         super(viewer, editorActivationStrategy, feature);
933                         this.feature = feature;
934                         tableEditor = new TableEditor(viewer.getTable());
935                         this.focusCellManager = focusCellManager;
936                 }
937
938                 /**
939                  * Create a customized editor with focusable cells
940                  * 
941                  * @param viewer
942                  *            the viewer the editor is created for
943                  * @param focusCellManager
944                  *            the cell focus manager if one needed else
945                  *            <code>null</code>
946                  * @param editorActivationStrategy
947                  *            activation strategy to control if an editor activated
948                  * @param feature
949                  *            bit mask controlling the editor
950                  *            <ul>
951                  *            <li>{@link ColumnViewerEditor#DEFAULT}</li>
952                  *            <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li>
953                  *            <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li>
954                  *            <li>
955                  *            {@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
956                  *            <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li>
957                  *            </ul>
958                  * @see #create(TableViewer, ColumnViewerEditorActivationStrategy, int)
959                  */
960                 public static void create(TableViewer viewer,
961                                 TableViewerFocusCellManager focusCellManager,
962                                 ColumnViewerEditorActivationStrategy editorActivationStrategy,
963                                 int feature) {
964                         TableViewerEditor editor = new TableViewerEditor(viewer,
965                                         focusCellManager, editorActivationStrategy, feature);
966                         viewer.setColumnViewerEditor(editor);
967                         if (focusCellManager != null) {
968                                 try {
969                                         Method m = focusCellManager.getClass().getSuperclass()
970                                                         .getDeclaredMethod("init", null);
971                                         m.setAccessible(true);
972                                         m.invoke(focusCellManager, null);
973                                 } catch (SecurityException e) {
974                                         e.printStackTrace();
975                                 } catch (IllegalArgumentException e) {
976                                         e.printStackTrace();
977                                 } catch (IllegalAccessException e) {
978                                         e.printStackTrace();
979                                 } catch (NoSuchMethodException e) {
980                                         e.printStackTrace();
981                                 } catch (InvocationTargetException e) {
982                                         e.printStackTrace();
983                                 }
984                                 // focusCellManager.init();
985                         }
986                 }
987
988                 /**
989                  * Create a customized editor whose activation process is customized
990                  * 
991                  * @param viewer
992                  *            the viewer the editor is created for
993                  * @param editorActivationStrategy
994                  *            activation strategy to control if an editor activated
995                  * @param feature
996                  *            bit mask controlling the editor
997                  *            <ul>
998                  *            <li>{@link ColumnViewerEditor#DEFAULT}</li>
999                  *            <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li>
1000                  *            <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li>
1001                  *            <li>
1002                  *            {@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
1003                  *            <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li>
1004                  *            </ul>
1005                  */
1006                 public static void create(TableViewer viewer,
1007                                 ColumnViewerEditorActivationStrategy editorActivationStrategy,
1008                                 int feature) {
1009                         create(viewer, null, editorActivationStrategy, feature);
1010                 }
1011
1012                 protected void setEditor(Control w, Item item, int columnNumber) {
1013                         tableEditor.setEditor(w, (TableItem) item, columnNumber);
1014                 }
1015
1016                 protected void setLayoutData(LayoutData layoutData) {
1017                         tableEditor.grabHorizontal = layoutData.grabHorizontal;
1018                         tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
1019                         tableEditor.minimumWidth = layoutData.minimumWidth;
1020                 }
1021
1022                 public ViewerCell getFocusCell() {
1023                         if (focusCellManager != null) {
1024                                 return focusCellManager.getFocusCell();
1025                         }
1026                         return super.getFocusCell();
1027                 }
1028
1029                 protected void updateFocusCell(ViewerCell focusCell,
1030                                 ColumnViewerEditorActivationEvent event) {
1031                         // Update the focus cell when we activated the editor with these 2
1032                         // events
1033                         if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC
1034                                         || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
1035                                 if (focusCellManager != null) {
1036                                         try {
1037                                                 if (DEBUG)System.err.println("FOCUS CELL: " + focusCell);
1038                                                 
1039                                                 Method m = AbstractTableViewer.class.getDeclaredMethod(
1040                                                                 "getSelectionFromWidget", null);
1041                                                 m.setAccessible(true);
1042                                                 List l = (List) m.invoke(getViewer(), null);
1043                                                 if (focusCellManager != null) {
1044                                                         m = focusCellManager
1045                                                                         .getClass()
1046                                                                         .getSuperclass()
1047                                                                         .getDeclaredMethod("setFocusCell",
1048                                                                                         new Class[] { ViewerCell.class });
1049                                                         m.setAccessible(true);
1050                                                         m.invoke(focusCellManager,
1051                                                                         new Object[] { focusCell });
1052                                                 }
1053                                                 if (!l.contains(focusCell.getElement())) {
1054                                                         getViewer().setSelection(
1055                                                                         new StructuredSelection(focusCell
1056                                                                                         .getElement()));
1057                                                 }
1058                                         } catch (SecurityException e) {
1059                                                 e.printStackTrace();
1060                                         } catch (IllegalArgumentException e) {
1061                                                 e.printStackTrace();
1062                                         } catch (IllegalAccessException e) {
1063                                                 e.printStackTrace();
1064                                         } catch (NoSuchMethodException e) {
1065                                                 e.printStackTrace();
1066                                         } catch (InvocationTargetException e) {
1067                                                 e.printStackTrace();
1068                                         }
1069                                 }
1070                         }
1071                 }
1072
1073                 protected void processTraverseEvent(int columnIndex, ViewerRow row,
1074                                 TraverseEvent event) {
1075                         ViewerCell cell2edit = null;
1076                         if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
1077                                 event.doit = false;
1078                                 if ((event.stateMask & SWT.CTRL) == SWT.CTRL
1079                                                 && (feature & TABBING_VERTICAL) == TABBING_VERTICAL) {
1080                                         cell2edit = searchCellAboveBelow(row, getViewer(),
1081                                                         columnIndex, true);
1082                                 } else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
1083                                         cell2edit = searchPreviousCell(row,
1084                                                         row.getCell(columnIndex), row.getCell(columnIndex),
1085                                                         getViewer());
1086                                 }
1087                         } else if (event.detail == SWT.TRAVERSE_TAB_NEXT) {
1088                                 event.doit = false;
1089                                 if ((event.stateMask & SWT.CTRL) == SWT.CTRL
1090                                                 && (feature & TABBING_VERTICAL) == TABBING_VERTICAL) {
1091                                         cell2edit = searchCellAboveBelow(row, getViewer(),
1092                                                         columnIndex, false);
1093                                 } else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
1094                                         cell2edit = searchNextCell(row, row.getCell(columnIndex),
1095                                                         row.getCell(columnIndex), getViewer());
1096                                 }
1097                         }
1098                         if (DEBUG) System.err.println("NEXT CELL: " + cell2edit);
1099                         if (cell2edit != null) {
1100                                 getViewer().getControl().setRedraw(false);
1101                                 ColumnViewerEditorActivationEvent acEvent = new ColumnViewerEditorActivationEvent(
1102                                                 cell2edit, event);
1103                                 try {
1104                                         Method m = ColumnViewer.class
1105                                                         .getDeclaredMethod(
1106                                                                         "triggerEditorActivationEvent",
1107                                                                         new Class[] { ColumnViewerEditorActivationEvent.class });
1108                                         m.setAccessible(true);
1109                                         m.invoke(getViewer(), new Object[] { acEvent });
1110                                 } catch (SecurityException e) {
1111                                         e.printStackTrace();
1112                                 } catch (NoSuchMethodException e) {
1113                                         e.printStackTrace();
1114                                 } catch (IllegalArgumentException e) {
1115                                         e.printStackTrace();
1116                                 } catch (IllegalAccessException e) {
1117                                         e.printStackTrace();
1118                                 } catch (InvocationTargetException e) {
1119                                         e.printStackTrace();
1120                                 }
1121                                 getViewer().getControl().setRedraw(true);
1122                         }
1123                 }
1124
1125                 private ViewerCell searchCellAboveBelow(ViewerRow row,
1126                                 ColumnViewer viewer, int columnIndex, boolean above) {
1127                         ViewerCell rv = null;
1128                         ViewerRow newRow = null;
1129                         if (above) {
1130                                 newRow = row.getNeighbor(ViewerRow.ABOVE, false);
1131                         } else {
1132                                 newRow = row.getNeighbor(ViewerRow.BELOW, false);
1133                         }
1134                         try {
1135                                 if (newRow != null) {
1136                                         Method m = ColumnViewer.class.getDeclaredMethod(
1137                                                         "getViewerColumn", new Class[] { int.class });
1138                                         m.setAccessible(true);
1139                                         ViewerColumn column = (ViewerColumn) m.invoke(viewer,
1140                                                         new Object[] { new Integer(columnIndex) });
1141                                         m = ViewerColumn.class.getDeclaredMethod(
1142                                                         "getEditingSupport", null);
1143                                         m.setAccessible(true);
1144                                         EditingSupport es = (EditingSupport) m.invoke(column, null);
1145                                         if (column != null && es != null) {
1146                                                 m = EditingSupport.class.getDeclaredMethod("canEdit",
1147                                                                 new Class[] { Object.class });
1148                                                 m.setAccessible(true);
1149                                                 Boolean b = (Boolean) m.invoke(es,
1150                                                                 new Object[] { newRow.getItem().getData() });
1151                                                 if (b.booleanValue()) {
1152                                                         rv = newRow.getCell(columnIndex);
1153                                                 }
1154                                         } else {
1155                                                 rv = searchCellAboveBelow(newRow, viewer, columnIndex,
1156                                                                 above);
1157                                         }
1158                                 }
1159                         } catch (Exception e) {
1160                                 e.printStackTrace();
1161                         }
1162                         return rv;
1163                 }
1164
1165                 private ViewerCell searchPreviousCell(ViewerRow row,
1166                                 ViewerCell currentCell, ViewerCell originalCell,
1167                                 ColumnViewer viewer) {
1168                         ViewerCell rv = null;
1169                         ViewerCell previousCell;
1170                         if (currentCell != null) {
1171                                 previousCell = getNeighbor(currentCell, ViewerCell.LEFT, true);
1172                         } else {
1173                                 if (row.getColumnCount() != 0) {
1174                                         previousCell = row.getCell(getCreationIndex(row,
1175                                                         row.getColumnCount() - 1));
1176                                 } else {
1177                                         previousCell = row.getCell(0);
1178                                 }
1179                         }
1180                         // No endless loop
1181                         if (originalCell.equals(previousCell)) {
1182                                 return null;
1183                         }
1184                         if (previousCell != null) {
1185                                 if (isCellEditable(viewer, previousCell)) {
1186                                         rv = previousCell;
1187                                 } else {
1188                                         rv = searchPreviousCell(row, previousCell, originalCell,
1189                                                         viewer);
1190                                 }
1191                         } else {
1192                                 if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
1193                                         rv = searchPreviousCell(row, null, originalCell, viewer);
1194                                 } else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
1195                                         ViewerRow rowAbove = row
1196                                                         .getNeighbor(ViewerRow.ABOVE, false);
1197                                         if (rowAbove != null) {
1198                                                 rv = searchPreviousCell(rowAbove, null, originalCell,
1199                                                                 viewer);
1200                                         }
1201                                 }
1202                         }
1203                         return rv;
1204                 }
1205
1206                 private ViewerCell searchNextCell(ViewerRow row,
1207                                 ViewerCell currentCell, ViewerCell originalCell,
1208                                 ColumnViewer viewer) {
1209                         ViewerCell rv = null;
1210                         ViewerCell nextCell;
1211                         if (currentCell != null) {
1212                                 nextCell = getNeighbor(currentCell, ViewerCell.RIGHT, true);
1213                         } else {
1214                                 nextCell = row.getCell(getCreationIndex(row, 0));
1215                         }
1216                         // No endless loop
1217                         if (originalCell.equals(nextCell)) {
1218                                 return null;
1219                         }
1220                         if (nextCell != null) {
1221                                 if (isCellEditable(viewer, nextCell)) {
1222                                         rv = nextCell;
1223                                 } else {
1224                                         rv = searchNextCell(row, nextCell, originalCell, viewer);
1225                                 }
1226                         } else {
1227                                 if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
1228                                         rv = searchNextCell(row, null, originalCell, viewer);
1229                                 } else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
1230                                         ViewerRow rowBelow = row
1231                                                         .getNeighbor(ViewerRow.BELOW, false);
1232                                         if (rowBelow != null) {
1233                                                 rv = searchNextCell(rowBelow, null, originalCell,
1234                                                                 viewer);
1235                                         }
1236                                 }
1237                         }
1238                         return rv;
1239                 }
1240
1241                 private boolean isCellEditable(ColumnViewer viewer, ViewerCell cell) {
1242                         try {
1243                                 Method m = ColumnViewer.class.getDeclaredMethod(
1244                                                 "getViewerColumn", new Class[] { int.class });
1245                                 m.setAccessible(true);
1246                                 ViewerColumn column = (ViewerColumn) m.invoke(viewer,
1247                                                 new Object[] { new Integer(cell.getColumnIndex()) });
1248                                 m = ViewerColumn.class.getDeclaredMethod("getEditingSupport",
1249                                                 null);
1250                                 m.setAccessible(true);
1251                                 EditingSupport es = (EditingSupport) m.invoke(column, null);
1252                                 if (column != null && es != null) {
1253                                         m = EditingSupport.class.getDeclaredMethod("canEdit",
1254                                                         new Class[] { Object.class });
1255                                         m.setAccessible(true);
1256                                         // return true;
1257                                         Boolean b = (Boolean) m.invoke(es,
1258                                                         new Object[] { cell.getElement() });
1259                                         return b.booleanValue();
1260                                 }
1261                         } catch (Exception e) {
1262                                 e.printStackTrace();
1263                         }
1264                         return false;
1265                 }
1266         }
1267         
1268         // Reimplementation of ViewerCell-Methods
1269         private static int getVisualIndex(ViewerRow row, int creationIndex) {
1270                 TableItem item = (TableItem) row.getItem();
1271                 int[] order = item.getParent().getColumnOrder();
1272                 for (int i = 0; i < order.length; i++) {
1273                         if (order[i] == creationIndex) {
1274                                 return i;
1275                         }
1276                 }
1277                 return creationIndex;
1278         }
1279         
1280         private static int getCreationIndex(ViewerRow row, int visualIndex) {
1281                 TableItem item = (TableItem) row.getItem();
1282                 if (item != null && !item.isDisposed() /*
1283                                                                                                  * && hasColumns() &&
1284                                                                                                  * isValidOrderIndex
1285                                                                                                  * (visualIndex)
1286                                                                                                  */) {
1287                         return item.getParent().getColumnOrder()[visualIndex];
1288                 }
1289                 return visualIndex;
1290         }
1291         
1292         private static ViewerCell getCellAtVisualIndex(ViewerRow row,
1293                         int visualIndex) {
1294                 return getCell(row, getCreationIndex(row, visualIndex));
1295         }
1296
1297         private static boolean isVisible(ViewerCell cell) {
1298                 return getWidth(cell) > 0;
1299         }
1300
1301         private static int getWidth(ViewerCell cell) {
1302                 TableItem item = (TableItem) cell.getViewerRow().getItem();
1303                 return item.getParent().getColumn(cell.getColumnIndex()).getWidth();
1304         }
1305
1306         private static ViewerCell getCell(ViewerRow row, int index) {
1307                 return row.getCell(index);
1308         }
1309         
1310         
1311 }