Bonjour,

Je souhaite à partir d'un arbre eclipse pour certaines selection afficher une page de propriétés de l'élément selectionné. Le code ci-dessous correspond à mon travail. Je pense qu'il 'y a plus simple, plus efficace, plus clair.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package galera3D.parts.explorer;
 
import galera.displayable.filter.commonFilter.provider.CommonFilterItemProviderAdapterFactory;
import galera.displayable.filter.drillholeFilter.provider.DrillholeFilterItemProviderAdapterFactory;
import galera.displayable.filter.geologicalFilter.provider.GeologicalFilterItemProviderAdapterFactory;
import galera.displayable.filter.gridFilter.provider.GridFilterItemProviderAdapterFactory;
import galera.displayable.filter.imageFilter.provider.ImageFilterItemProviderAdapterFactory;
import galera.displayable.filter.meshFilter.provider.MeshFilterItemProviderAdapterFactory;
import galera.displayable.filter.provider.FilterItemProviderAdapterFactory;
import galera.displayable.moduleVisualization.provider.ModuleVisualizationItemProviderAdapterFactory;
import galera.displayable.provider.DisplayableItemProviderAdapterFactory;
import galera.fieldProcess.processor.provider.ProcessorItemProviderAdapterFactory;
import galera.geologicalEntities.provider.GeologicalEntitiesItemProviderAdapterFactory;
import galera.geophysic.physicalProperties.provider.PhysicalPropertiesItemProviderAdapterFactory;
import galera.graphic.provider.GraphicItemProviderAdapterFactory;
import galera.kriging.provider.KrigingItemProviderAdapterFactory;
import galera.meshGrid.field.provider.FieldItemProviderAdapterFactory;
import galera.meshGrid.provider.MeshGridItemProviderAdapterFactory;
import galera.model.provider.ModelItemProviderAdapterFactory;
import galera.modelInterpolator.provider.ModelInterpolatorItemProviderAdapterFactory;
import galera.project.Group;
import galera.project.provider.ProjectItemProviderAdapterFactory;
import galera.structuralData.provider.StructuralDataItemProviderAdapterFactory;
import galera.supports.provider.SupportsItemProviderAdapterFactory;
 
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
 
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor.PropertyValueWrapper;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
 
public class PropertyEditorPart {
 
	private ComposedAdapterFactory adapterFactory;
	private TreeViewer treeViewerWithColumns;
	private AdapterFactoryContentProvider contentProvider;
	private Tree tree;
 
 
 
	/**
         * Create contents of the property page.
         * @param parent
         */
	@PostConstruct
	public void createComposite(Composite parent) {
		adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
		adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
 
		adapterFactory.addAdapterFactory(new StructuralDataItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new MeshGridItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new FieldItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new ProjectItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new ModelItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new GeologicalEntitiesItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new SupportsItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new ModelInterpolatorItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new KrigingItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new PhysicalPropertiesItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new GraphicItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new DisplayableItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new FilterItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new MeshFilterItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new DrillholeFilterItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new GeologicalFilterItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new GridFilterItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new CommonFilterItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new ImageFilterItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new ModuleVisualizationItemProviderAdapterFactory());
		adapterFactory.addAdapterFactory(new ProcessorItemProviderAdapterFactory());
 
		adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
 
 
		treeViewerWithColumns = new TreeViewer(parent, SWT.MULTI);
 
		tree = treeViewerWithColumns.getTree();
		tree.setLayoutData(new FillLayout());
		tree.setHeaderVisible(true);
		tree.setLinesVisible(true);
 
		TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
		objectColumn.setText("Attribute");
		objectColumn.setResizable(true);
		objectColumn.setWidth(250);
 
		TreeColumn valueColumn = new TreeColumn(tree, SWT.NONE);
		valueColumn.setText("Value");
		valueColumn.setResizable(true);
		valueColumn.setWidth(200);
 
		TreeColumn infoColumn = new TreeColumn(tree, SWT.NONE);
		infoColumn.setText("Info on  parameter");
		infoColumn.setResizable(true);
		infoColumn.setWidth(200);
 
		treeViewerWithColumns.setColumnProperties(new String [] {"a", "b", "c"});
		contentProvider =  new AdapterFactoryContentProvider(adapterFactory);
		treeViewerWithColumns.setContentProvider(contentProvider);
		treeViewerWithColumns.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
		treeViewerWithColumns.getLabelProvider();
	}
 
 
	@Inject
	public void receiveSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) EObject o) {
		if(o != null && treeViewerWithColumns != null && !(o instanceof Group)) {
			treeViewerWithColumns.setInput(o);
			IPropertySource tt = contentProvider.getPropertySource(o);
			String attributes, values;
			for(Object e: contentProvider.getChildren(o)) {
				System.out.println("Children" + e);
			}
			for(IPropertyDescriptor x: tt.getPropertyDescriptors()) {
				TreeItem treeItem = new TreeItem(tree, 0);
				attributes = x.getDisplayName();
				try {
					PropertyValueWrapper  thisObject = (PropertyValueWrapper) (tt.getPropertyValue(x.getId()));
					if (((PropertyValueWrapper) thisObject).getEditableValue(thisObject) instanceof EList<?>) {
						treeItem.setText(new String[] {attributes, " ", " "});
						String[] val = ((PropertyValueWrapper) thisObject).getText(thisObject).split(", ");
						for(String s: val) {
							TreeItem subtreeItem = new TreeItem(tree, SWT.NONE);
							subtreeItem.setText(new String[] {"     " + x.getId().toString(), s, x.getDescription()});
						}
					}
					else {
						values = ((PropertyValueWrapper) thisObject).getText(thisObject);
						treeItem.setText(new String[] {attributes, values, x.getDescription()});
					}
				}
				catch (Exception e){
					values = "null";
					treeItem.setText(new String[] {attributes, values});
				}
			}
		}
	}
 
 
	@Focus
	public boolean setFocus() {
		if(treeViewerWithColumns != null) return treeViewerWithColumns.getControl().setFocus();
		return false;
	}
 
}
Sur l'image ci dessous, je ne suis pas satisfait pour l'affichage de histograms et values. Que puis-je faire?

Nom : property.png
Affichages : 92
Taille : 100,7 Ko