Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 199f88dd3b491daec90b6e22fb682c5930bca7c5 (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
/*****************************************************************************
 * 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.tabbed.core.view;

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

import org.eclipse.papyrus.properties.runtime.state.AbstractState;
import org.eclipse.papyrus.properties.runtime.state.ITraversableModelElement;
import org.eclipse.papyrus.properties.runtime.view.IConfigurableDescriptor;
import org.eclipse.papyrus.properties.tabbed.core.Activator;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.views.properties.tabbed.ITabDescriptor;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * State for tab descriptors
 */
public class TabDescriptorState extends AbstractState {

	/** tab descriptor managed by this state */
	protected ITabDescriptor tabDescriptor;

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

	/** id of the tab descriptor */
	private String id;

	/** category of the tab descriptor */
	private String category;

	/** label of the tab descriptor */
	private String label;

	/** after tab info of the tab descriptor */
	private String afterTab;

	/**
	 * Creates a new TabDescriptorState.
	 * 
	 * @param tabDescriptor
	 *        tab descriptor managed by this state
	 * @param readOnly
	 *        read only mode of the descriptor
	 */
	public TabDescriptorState(ITabDescriptor tabDescriptor, boolean readOnly) {
		super(readOnly);
		this.tabDescriptor = tabDescriptor;
		this.id = tabDescriptor.getId();
		this.label = tabDescriptor.getLabel();
		this.afterTab = tabDescriptor.getAfterTab();
		this.category = tabDescriptor.getCategory();

		// register change support
		changeSupport = new PropertyChangeSupport(this);
	}


	/**
	 * Returns the tabDescriptor managed by this state
	 * 
	 * @return the tabDescriptor managed by this state
	 */
	public ITabDescriptor getTabDescriptor() {
		return tabDescriptor;
	}


	/**
	 * {@inheritDoc}
	 */
	public String getText() {
		return label + " (Caterory: " + category + ")";
	}

	/**
	 * Returns the id of the descriptor managed by this state
	 * 
	 * @return the id of the descriptor managed by this state
	 */
	public String getId() {
		return id;
	}

	/**
	 * Returns the label of the descriptor managed by this state
	 * 
	 * @return the label of the descriptor managed by this state
	 */
	public String getLabel() {
		return label;
	}

	/**
	 * Returns the after tab info of the descriptor managed by this state
	 * 
	 * @return the after tab info of the descriptor managed by this state
	 */
	public String getAfterTab() {
		return afterTab;
	}

	/**
	 * Returns the category of the descriptor managed by this state
	 * 
	 * @return the category of the descriptor managed by this state
	 */
	public String getCategory() {
		return category;
	}

	/**
	 * Sets the id of this tab
	 * 
	 * @param id
	 *        the identifier to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * Sets the new label for this state
	 * 
	 * @param label
	 *        the new label to set
	 */
	public void setLabel(String label) {
		this.label = label;
	}

	/**
	 * Sets the new after tab info for this state
	 * 
	 * @param afterTab
	 *        the new after tab to set
	 */
	public void setAfterTab(String afterTab) {
		this.afterTab = afterTab;
	}

	/**
	 * Sets the new category for this state
	 * 
	 * @param category
	 *        the new category to set
	 */
	public void setCategory(String category) {
		this.category = category;
	}


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


	/**
	 * {@inheritDoc}
	 */
	public IConfigurableDescriptor getDescriptor() {
		return null;
	}

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

	/**
	 * Adds a property change listener to this class
	 * 
	 * @param listener
	 *        the listener to add
	 */
	public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
		changeSupport.addPropertyChangeListener(listener);
	}

	/**
	 * Removes a property change listener from this class
	 * 
	 * @param listener
	 *        the listener to remove
	 */
	public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
		changeSupport.removePropertyChangeListener(listener);
	}


	/**
	 * {@inheritDoc}
	 */
	public Node generateNode(Document document) {
		Element tabDescriptorNode = document.createElement("tab");
		tabDescriptorNode.setAttribute("category", category);
		tabDescriptorNode.setAttribute("id", id);
		tabDescriptorNode.setAttribute("label", label);

		List<TabDescriptorState> tabDescriptorStates = StatesStore.getTabDescriptorStates();
		int index = tabDescriptorStates.indexOf(this);
		if(index != 0) {
			tabDescriptorNode.setAttribute("afterTab", tabDescriptorStates.get(index - 1).id);
		}

		return tabDescriptorNode;
	}


	/**
	 * {@inheritDoc}
	 */
	public List<? extends ITraversableModelElement> getChildren() {
		return Collections.emptyList();
	}
}

Back to the top