Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8d05553e40235fe9fc999e74e113f9aebe979730 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*****************************************************************************
 * Copyright (c) 2010 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:
 *  Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.properties.runtime.view.content;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.List;

import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.controller.PropertyEditorController;
import org.eclipse.papyrus.properties.runtime.controller.descriptor.ControllerDescriptorState;
import org.eclipse.papyrus.properties.runtime.controller.descriptor.IPropertyEditorControllerDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * Descriptor for the folder containers
 */
public class ExpandableContainerDescriptor extends ContainerDescriptor {

	/** label for the folder */
	private final String label;

	/** composite content of the expandable container */
	protected Composite expandableContainer;

	/**
	 * Creates a new ExpandableContainerDescriptor
	 * 
	 * @param layoutDescriptor
	 *        the layoutDescriptor applied to the container
	 * @param label
	 *        the label of the created composite
	 * @param containerNode
	 *        the unparsed xml configuration node for this container
	 */
	public ExpandableContainerDescriptor(LayoutDescriptor layoutDescriptor, String label, Node containerNode) {
		super(layoutDescriptor, containerNode);
		this.label = label;
	}

	/**
	 * Creates a new ExpandableContainerDescriptor
	 * 
	 * @param layoutDescriptor
	 *        the layoutDescriptor applied to the container
	 * @param label
	 *        the label of the created composite
	 * @param descriptors
	 *        the list of {@link IPropertyEditorControllerDescriptor} contained by this container
	 */
	public ExpandableContainerDescriptor(LayoutDescriptor layoutDescriptor, String label, List<IPropertyEditorControllerDescriptor> descriptors) {
		super(layoutDescriptor, descriptors);
		this.label = label;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ExpandableComposite getDescribedComposite() {
		return (ExpandableComposite)super.getDescribedComposite();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public List<PropertyEditorController> createContent(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory, List<Object> objectsToEdit) {
		this.objectsToEdit = objectsToEdit;
		if(getDescribedComposite() == null || getDescribedComposite().isDisposed()) {
			setDescribedComposite(widgetFactory.createSection(parent, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED));
			getDescribedComposite().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

			expandableContainer = widgetFactory.createComposite(getDescribedComposite());
			expandableContainer.setLayout(getLayoutDescriptor().createLayout());
			getDescribedComposite().setText(getLabel());

			widgetFactory.paintBordersFor(expandableContainer);
			getDescribedComposite().setClient(expandableContainer);
		}

		controllers = updateControllers(widgetFactory);

		return controllers;
	}

	/**
	 * Returns the Composite containing the property editors.
	 * 
	 * @return the Composite containing the property editors.
	 */
	protected Composite getPropertyEditorContainer() {
		return expandableContainer;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getText() {
		return "ExpandableContainerDescriptor";
	}

	/**
	 * {@inheritDoc}
	 */
	public Image getImage() {
		return Activator.getImage("/icons/ExpandableContainer.gif");
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ContainerDescriptorState createState(boolean readOnly) {
		return new ExpandableContainerDescriptorState(this, readOnly);
	}

	/**
	 * Returns the label of the expandable composite
	 * 
	 * @return the label of the expandable composite
	 */
	public String getLabel() {
		return label;
	}

	/**
	 * State for {@link ExpandableContainerDescriptor}
	 */
	public class ExpandableContainerDescriptorState extends ContainerDescriptorState {

		/** name of the container */
		private String name;

		/** change support for this bean */
		private PropertyChangeSupport changeSupport;

		/**
		 * Creates a new ExpandableContainerDescriptorState.
		 * 
		 * @param descriptor
		 *        the descriptor managed by the state
		 * @param readOnly
		 *        the read only mode for this state
		 */
		public ExpandableContainerDescriptorState(ExpandableContainerDescriptor descriptor, boolean readOnly) {
			super(descriptor, readOnly);

			this.name = descriptor.getLabel();
			// register change support
			changeSupport = new PropertyChangeSupport(this);
		}

		/**
		 * Sets the name of the expandable composite
		 * 
		 * @param name
		 *        the name to set
		 */
		public void setName(String name) {
			String oldName = this.name;
			this.name = name;

			// fire change event
			changeSupport.firePropertyChange("name", oldName, this.name);
		}

		/**
		 * Returns the name of the expandable composite
		 * 
		 * @return the name
		 */
		public String getName() {
			return name;
		}

		/**
		 * {@inheritDoc}
		 */
		public Node generateNode(Document document) {
			Element node = document.createElement("expandableContainer");
			node.setAttribute("label", getName());

			generateLayoutDescriptor(node, document);
			// generate for owned controllers
			generateControllers(node, document);

			return node;
		}

		/**
		 * {@inheritDoc}
		 */
		@Override
		public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
			super.addPropertyChangeListener(listener);
			changeSupport.addPropertyChangeListener(listener);
		}

		/**
		 * {@inheritDoc}
		 */
		@Override
		public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
			super.removePropertyChangeListener(listener);
			changeSupport.removePropertyChangeListener(listener);
		}

		/**
		 * {@inheritDoc}
		 */
		public String getEditionDialogId() {
			return "ExpandableContainerDescriptorStateDialog";
		}

		/**
		 * {@inheritDoc}
		 */
		public Composite createPreview(Composite parent) {
			Group composite = new TabbedPropertySheetWidgetFactory().createGroup(parent, "Expandable > " + name);
			// add layout
			composite.setLayout(layoutDescriptorState.createLayout());
			composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

			// create the content for the controllers
			for(ControllerDescriptorState controllerDescriptorState : controllerDescriptorStates) {
				controllerDescriptorState.createPreview(composite);
			}
			return composite;
		}

		/**
		 * {@inheritDoc}
		 */
		public String getText() {
			return "Expandable \"" + getName() + "\"";
		}
	}
}

Back to the top