Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4ecdc462e35139e5de0dfd3eddab9230f2eeb365 (plain) (blame)
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
/*****************************************************************************
 * Copyright (c) 2011 CEA LIST.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.views.properties.widgets;

import java.util.Set;

import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.editors.AbstractListEditor;
import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
import org.eclipse.papyrus.infra.widgets.editors.MultipleReferenceEditor;
import org.eclipse.papyrus.views.properties.contexts.View;
import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager;
import org.eclipse.papyrus.views.properties.runtime.EmbeddedDisplayEngine;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

public class MultiReferenceEditorWithPropertyView extends AbstractListEditor implements ISelectionChangedListener {

	protected MultipleReferenceEditor multiReferenceEditor;

	protected Composite propertiesComposite;

	protected EmbeddedDisplayEngine displayEngine = new EmbeddedDisplayEngine();

	public MultiReferenceEditorWithPropertyView(Composite parent, int style) {
		super(parent, style);
		// parent.setBackground(getDisplay().getSystemColor(SWT.COLOR_RED));
		((GridLayout)getLayout()).numColumns++;

		multiReferenceEditor = createMultipleReferenceEditor(style);
		multiReferenceEditor.addSelectionChangedListener(this);
		multiReferenceEditor.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true));

		propertiesComposite = new Composite(this, style);
		propertiesComposite.setLayout(new FillLayout());
		propertiesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	}

	/**
	 * Creates the multi reference editor.
	 * 
	 * @param parent
	 *        The composite in which the widget will be displayed
	 * @param style
	 *        The style for the widget
	 * @return the multi reference editor.
	 */
	protected MultipleReferenceEditor createMultipleReferenceEditor(int style) {
		return new MultipleReferenceEditor(this, style);
	}

	@Override
	public GridData getDefaultLayoutData() {
		GridData data = super.getDefaultLayoutData();
		data.grabExcessVerticalSpace = true;
		data.grabExcessHorizontalSpace = true;
		data.verticalAlignment = SWT.FILL;
		return data;
	}

	@Override
	public Object getEditableType() {
		return Object.class;
	}

	@Override
	public void setReadOnly(boolean readOnly) {
		multiReferenceEditor.setReadOnly(readOnly);
		propertiesComposite.setEnabled(!readOnly);
	}

	@Override
	public boolean isReadOnly() {
		return multiReferenceEditor.isReadOnly();
	}

	@Override
	public void setToolTipText(String text) {
		multiReferenceEditor.setToolTipText(text);
	}

	@Override
	public void setLabel(String label) {
		multiReferenceEditor.setLabel(label);
	}

	public void setOrdered(boolean ordered) {
		multiReferenceEditor.setOrdered(ordered);
	}

	public void setUnique(boolean unique) {
		multiReferenceEditor.setUnique(unique);
	}

	@Override
	public void setModelObservable(IObservableList modelObservable) {
		multiReferenceEditor.setModelObservable(modelObservable);

		//If the properties view of the first element contains a recursive view, we may have a StackOverFlow here.
		//Do not force the initial selection.

		//		if(!modelObservable.isEmpty()) {
		//			multiReferenceEditor.getViewer().setSelection(new StructuredSelection(modelObservable.get(0)));
		//		}
	}

	@Override
	public void dispose() {
		super.dispose();
		multiReferenceEditor.removeSelectionChangedListener(this);
	}

	public void selectionChanged(SelectionChangedEvent event) {
		ISelection selection = event.getSelection();

		Set<View> views = ConfigurationManager.getInstance().getConstraintEngine().getViews(selection);
		displayEngine.display(views, propertiesComposite, selection, SWT.NONE);
		this.layout();
		propertiesComposite.layout();

		// TODO : How can we force the property view layout ?
		// In the tabbed property view, we need to go up to the 4th parent
		getParent().layout(); // This one works in the embedded editor

		// In the Eclipse Tabbed Property View, we need to go this far...
		getParent().getParent().getParent().getParent().layout();
	}

	public void setFactory(ReferenceValueFactory valueFactory) {
		multiReferenceEditor.setFactory(valueFactory);
	}

	public void setDirectCreation(boolean directCreation) {
		multiReferenceEditor.setDirectCreation(directCreation);
	}

	public void setLabelProvider(ILabelProvider labelProvider) {
		multiReferenceEditor.setLabelProvider(labelProvider);
	}

	@Override
	public void addCommitListener(ICommitListener commitListener) {
		multiReferenceEditor.addCommitListener(commitListener);
	}
}

Back to the top