X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FAnnotatedPropertyTabContributorFactory.java;h=7198ead22ba6ccd9ad96cc30303158f9a9b9f317;hb=01441002a94a1f4ad2b078d63cb719ce617bd6cf;hp=f0fe47ece8be37c8f0403842bb1423abfde4f2f9;hpb=c666bd50b9ef05b6f78adb83c68557955e3132e9;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java b/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java index f0fe47ec..7198ead2 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java +++ b/org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java @@ -18,6 +18,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -81,7 +82,6 @@ import org.simantics.g3d.scenegraph.structural.IStructuralNode; import org.simantics.g3d.tools.AdaptationUtils; import org.simantics.selectionview.IPropertyTab; import org.simantics.selectionview.IPropertyTab2; -import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.MapList; public class AnnotatedPropertyTabContributorFactory implements PropertyTabContributorFactory { @@ -250,6 +250,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri private static interface IPropertyItem { public String getTabId(); + public String getName(); } private static class PropertyItem implements IPropertyItem{ @@ -276,6 +277,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri public String getTabId() { return tabId; } + + @Override + public String getName() { + return name; + } } private static class CompoundPropertyItem implements IPropertyItem{ @@ -302,6 +308,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri public String getTabId() { return tabId; } + + @Override + public String getName() { + return name; + } } private static class AnnotatedPropertyTabContributor implements PropertyTabContributor { @@ -338,7 +349,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri private TableViewer viewer; - private IG3DNode node; + private INode node; private NodeMap nodeMap; private List valueColumns = new ArrayList(); @@ -389,27 +400,6 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri } }); - int valueCount = 0; - for (IPropertyItem item : contibutedItems) { - if (item instanceof PropertyItem) { - PropertyManipulator manipulator = createManipulator((PropertyItem)item, null); - if (manipulator == null) - continue; - if (valueCount < manipulator.getValueCount()) - valueCount = manipulator.getValueCount(); - } else if (item instanceof CompoundPropertyItem) { - if (valueCount < 1) - valueCount = 1; - } - } - for (int i = 0; i < valueCount; i++) { - TableViewerColumn value = new TableViewerColumn(viewer, SWT.LEFT); - //value.getColumn().setText("Value " + (i+1)); - value.getColumn().setText(""); - value.getColumn().setWidth(200); - valueColumns.add(value); - //value.setEditingSupport(new ) - } viewer.getTable().setHeaderVisible(true); viewer.getTable().setLinesVisible(true); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @@ -547,7 +537,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri @Override public void setInput(ISessionContext context, ISelection selection, boolean force) { - Collection nodes = AdaptationUtils.adaptToCollection(selection, IG3DNode.class); + Collection nodes = AdaptationUtils.adaptToCollection(selection, INode.class); if (nodes.size() != 1) { if (node != null) { node.removeListener(this); @@ -555,7 +545,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri } return; } - IG3DNode n = nodes.iterator().next(); + INode n = nodes.iterator().next(); if (node != null) { if (!node.equals(n)) { node.removeListener(this); @@ -568,11 +558,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri - private void setInput(IG3DNode node) { + private void setInput(INode node) { this.node = node; this.node.addListener(this); // resolve nodemap - IG3DNode n = node; + INode n = node; while (true) { if (n == null) { nodeMap = null; @@ -586,16 +576,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri n = (IG3DNode)n.getParent(); } boolean readOnly = (node instanceof IStructuralNode && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()); - // create label providers - PropertyValueLabelProvider2 p = new PropertyValueLabelProvider2(this); - int index = 0; - for (TableViewerColumn c : valueColumns) { - c.setLabelProvider(p); - if (!readOnly) { - PropertyEditingSupport support = new PropertyEditingSupport(this, viewer, index++, nodeMap); - c.setEditingSupport(support); - } - } + resolvedItems.clear(); manipulators.clear(); for (IPropertyItem item : contibutedItems) { @@ -613,6 +594,36 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri } } + int valueCount = 0; + for (PropertyManipulator manipulator : manipulators.values()) { + if (valueCount < manipulator.getValueCount()) + valueCount = manipulator.getValueCount(); + } + for (int i = 0; i < valueCount; i++) { + TableViewerColumn value = new TableViewerColumn(viewer, SWT.LEFT); + //value.getColumn().setText("Value " + (i+1)); + value.getColumn().setText(""); + value.getColumn().setWidth(200); + valueColumns.add(value); + //value.setEditingSupport(new ) + } + + // create label providers + PropertyValueLabelProvider2 p = new PropertyValueLabelProvider2(this); + int index = 0; + for (TableViewerColumn c : valueColumns) { + c.setLabelProvider(p); + if (!readOnly) { + PropertyEditingSupport support = new PropertyEditingSupport(this, viewer, index++, nodeMap); + c.setEditingSupport(support); + } + } + Collections.sort(resolvedItems, new Comparator() { + @Override + public int compare(IPropertyItem o1, IPropertyItem o2) { + return o1.getName().compareTo(o2.getName()); + } + }); viewer.getTable().setEnabled(!readOnly); viewer.setInput(resolvedItems); }