]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java
Merge "Remove static DEBUG flags and use slf4j.Logger.trace()" into release/1.43.0
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / property / AnnotatedPropertyTabContributorFactory.java
index 65b267cb6b96017eb49cf3ece8a92650433c025f..36da53ab504ec4989339fc51dbf6f2daf4b3074e 100644 (file)
@@ -39,7 +39,6 @@ import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
 import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener;
 import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
 import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent;
-import org.eclipse.jface.viewers.ComboBoxCellEditor;
 import org.eclipse.jface.viewers.EditingSupport;
 import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter;
 import org.eclipse.jface.viewers.ISelection;
@@ -67,6 +66,7 @@ import org.eclipse.swt.widgets.Item;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.ui.IWorkbenchSite;
+import org.simantics.browsing.ui.swt.ComboBoxCellEditor2;
 import org.simantics.db.management.ISessionContext;
 import org.simantics.g3d.property.annotations.CompoundGetPropertyValue;
 import org.simantics.g3d.property.annotations.CompoundSetPropertyValue;
@@ -76,7 +76,6 @@ import org.simantics.g3d.property.annotations.GetPropertyValue;
 import org.simantics.g3d.property.annotations.PropertyTabBlacklist;
 import org.simantics.g3d.property.annotations.SetComboPropertyValue;
 import org.simantics.g3d.property.annotations.SetPropertyValue;
-import org.simantics.g3d.scenegraph.IG3DNode;
 import org.simantics.g3d.scenegraph.NodeMap;
 import org.simantics.g3d.scenegraph.NodeMapProvider;
 import org.simantics.g3d.scenegraph.base.INode;
@@ -87,10 +86,12 @@ import org.simantics.g3d.tools.AdaptationUtils;
 import org.simantics.selectionview.IPropertyTab;
 import org.simantics.selectionview.IPropertyTab2;
 import org.simantics.utils.datastructures.MapList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class AnnotatedPropertyTabContributorFactory implements PropertyTabContributorFactory {
 
-       private static final boolean DEBUG = false;
+       private static final Logger LOGGER = LoggerFactory.getLogger(AnnotatedPropertyTabContributorFactory.class);
        
        @SuppressWarnings("unchecked")
        @Override
@@ -603,8 +604,9 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                protected boolean isEditorActivationEvent(
                                                ColumnViewerEditorActivationEvent event) {
                                        return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
+                                                       || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION
                                                        || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
-                                                       || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
+                                                       || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && (event.keyCode == SWT.CR || event.keyCode == SWT.F2))
                                                        || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
                                }
                        };
@@ -682,7 +684,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                        if (nodeMap != null)
                                                break;
                                }
-                               n = (IG3DNode)n.getParent();
+                               n = (INode)n.getParent();
                        }
                        boolean readOnly =  (node instanceof IStructuralNode && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot());
                        
@@ -799,7 +801,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                        if (Thread.currentThread() == Display.getDefault().getThread()) {
                                if (viewer.getTable().isDisposed())
                                        return;
-                               if (DEBUG)System.out.println("Viewer refresh " + id);
+                               if (LOGGER.isTraceEnabled()) LOGGER.trace("Viewer refresh " + id);
                                for (IPropertyItem item : resolvedItems)
                                        if (!item.equals(selectedItem))
                                                viewer.refresh(item);
@@ -815,7 +817,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                                                AnnotatedPropertyTab.this.node.removeListener(AnnotatedPropertyTab.this);
                                                        return;
                                                }
-                                               if (DEBUG) System.out.println("Viewer threaded refresh " + id);
+                                               if (LOGGER.isTraceEnabled()) LOGGER.trace("Viewer threaded refresh " + id);
                                                for (IPropertyItem item : resolvedItems)
                                                        if (!item.equals(selectedItem))
                                                                viewer.refresh(item);
@@ -859,7 +861,8 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                int index;
                NodeMap<?,?,?> nodeMap;
                TableViewer viewer;
-               CellEditor editor;
+               CellEditor propertyItemEditor;
+               Map<ComboPropertyItem,CellEditor> comboEditors = new HashMap<>();
 
                public PropertyEditingSupport(AnnotatedPropertyTab tab, TableViewer viewer, int index, NodeMap<?,?,?> nodeMap) {
                        super(viewer);
@@ -886,38 +889,52 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                        IPropertyItem item = (IPropertyItem)element;
                        if (tab.getManipulator(item).getValueCount() <= index)
                                return null;
-                       if (editor == null)
-                           if (item instanceof PropertyItem)
-                               editor = new TextCellEditor(viewer.getTable(),SWT.NONE) {
-                               @Override
-                               public void activate() {
-                                       tab.setEditing(true);
-                               }
-                               
-                               @Override
-                               public void deactivate() {
-                                       super.deactivate();
-                                       tab.setEditing(false);
-                               }
-                       };
-                       else if (item instanceof ComboPropertyItem) {
-                           ComboPropertyItem comboPropertyItem = (ComboPropertyItem)item;
-                           ComboPropertyManipulator manipulator = (ComboPropertyManipulator)tab.manipulators.get(comboPropertyItem);
-                           editor = new ComboBoxCellEditor(viewer.getTable(), manipulator.getItems()) {
-                               @Override
-                        public void activate() {
-                            tab.setEditing(true);
-                        }
-                        
-                        @Override
-                        public void deactivate() {
-                            super.deactivate();
-                            tab.setEditing(false);
-                        }    
-                           };
-                       }
-                       if (DEBUG)System.err.println("CELL EDITOR: " + element);
-                       return editor;
+                       if (item instanceof PropertyItem) {
+                               if (propertyItemEditor == null) {
+                               propertyItemEditor = new TextCellEditor(viewer.getTable(),SWT.NONE) {
+                                       @Override
+                                       public void activate() {
+                                               tab.setEditing(true);
+                                       }
+                                       
+                                       @Override
+                                       public void deactivate() {
+                                               super.deactivate();
+                                               tab.setEditing(false);
+                                       }
+                               };
+                               }
+                               
+                               if (LOGGER.isTraceEnabled()) LOGGER.trace("CELL EDITOR: " + element);
+                               return propertyItemEditor;
+                       }
+                       else if (item instanceof ComboPropertyItem) {
+                           ComboPropertyItem comboPropertyItem = (ComboPropertyItem)item;
+                           CellEditor editor = comboEditors.get(comboPropertyItem);
+                           if (editor == null) {
+                                   ComboPropertyManipulator manipulator = (ComboPropertyManipulator)tab.manipulators.get(comboPropertyItem);
+                                   editor = new ComboBoxCellEditor2(viewer.getTable(), manipulator.getItems(), SWT.DROP_DOWN | SWT.READ_ONLY) {
+                                       @Override
+                           public void activate() {
+                               tab.setEditing(true);
+                           }
+                           
+                           @Override
+                           public void deactivate() {
+                               super.deactivate();
+                               tab.setEditing(false);
+                           }    
+                                   };
+                                   
+                                   comboEditors.put(comboPropertyItem, editor);
+                           }
+                           
+                           if (LOGGER.isTraceEnabled()) LOGGER.trace("CELL EDITOR: " + element);
+                           return editor;
+                       }
+                       else {
+                               throw new IllegalStateException("Unsupported property item type " + item.getClass().getName());
+                       }
                }
                
                @Override
@@ -940,7 +957,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                        PropertyManipulator manipulator = tab.getManipulator(item);//createManipulator(item, obj);
                        if (manipulator.getValueCount() <= index)
                                throw new IllegalAccessError("Editing value in index " + index + " is not allowed.");
-                       if (DEBUG)System.err.println("CELL SET VALUE: " + element + " " + value);
+                       if (LOGGER.isTraceEnabled()) LOGGER.trace("CELL SET VALUE: " + element + " " + value);
                        manipulator.setValue(value.toString(),index);
                        viewer.refresh(item);
                        nodeMap.commit("Set " + item.getId() + " value to " + value);
@@ -1180,7 +1197,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                        || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
                                if (focusCellManager != null) {
                                        try {
-                                               if (DEBUG)System.err.println("FOCUS CELL: " + focusCell);
+                                               if (LOGGER.isTraceEnabled()) LOGGER.trace("FOCUS CELL: " + focusCell);
                                                
                                                Method m = AbstractTableViewer.class.getDeclaredMethod(
                                                                "getSelectionFromWidget");
@@ -1242,7 +1259,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                                        row.getCell(columnIndex), getViewer());
                                }
                        }
-                       if (DEBUG) System.err.println("NEXT CELL: " + cell2edit);
+                       if (LOGGER.isTraceEnabled()) LOGGER.trace("NEXT CELL: " + cell2edit);
                        if (cell2edit != null) {
                                getViewer().getControl().setRedraw(false);
                                ColumnViewerEditorActivationEvent acEvent = new ColumnViewerEditorActivationEvent(