Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4af7834512fd0c415a3ba506899b6ef022ce624c (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
/*****************************************************************************
 * Copyright (c) 2013, 2017 CEA LIST and others.
 *
 * 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:
 *
 *  CEA LIST - Initial API and implementation
 *  Christian W. Damus (CEA) - bug 417409
 *  Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 491816
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.properties.modelelement;

import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.draw2d.Graphics;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gef.rulers.RulerProvider;
import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomBooleanStyleWithStoreObservableValue;
import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomDoubleStyleWithStoreObservableValue;
import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomIntStyleWithStoreObservableValue;
import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.RulersUnitStyleObservableValue;
import org.eclipse.papyrus.infra.gmfdiag.common.providers.LineStyleLabelProvider;
import org.eclipse.papyrus.infra.gmfdiag.common.providers.UnitsLabelProvider;
import org.eclipse.papyrus.infra.gmfdiag.properties.util.RulersAndGridPropertyConstants;
import org.eclipse.papyrus.infra.properties.contexts.DataContextElement;
import org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.StaticContentProvider;

/**
 *
 * @author vl222926
 *         This class provides the ModelElement for the property view
 */
@SuppressWarnings("restriction")
// suppress the warning for WorkspaceViewerProperties
public class RulerAndGridModelElement extends AbstractModelElement {



	/**
	 * the diagram for which we are editing preferences
	 */
	protected Diagram diagram;

	/**
	 * the edited preference store
	 */
	protected IPreferenceStore store;

	/**
	 * The editing domain.
	 * @since 3.0
	 */
	protected EditingDomain domain;

	/**
	 *
	 * Constructor.
	 *
	 * @param view
	 *            the diagram for which we are editing preferences
	 * @param domain
	 *            the editing domain
	 * @param context
	 *            the data context
	 * @param preferenceStore
	 *            the edited preference store
	 */
	public RulerAndGridModelElement(final Diagram view, final EditingDomain domain, final DataContextElement context, final IPreferenceStore preferenceStore) {
		this.diagram = view;
		this.domain = domain;
		this.store = preferenceStore;
	}

	/**
	 *
	 * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement#dispose()
	 *
	 */
	@Override
	public void dispose() {
		super.dispose();
		this.diagram = null;
		this.store = null;
	}

	/**
	 *
	 * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement#doGetObservable(java.lang.String)
	 *
	 * @param propertyPath
	 * @return
	 */
	@Override
	protected IObservable doGetObservable(final String propertyPath) {
		IObservable observable = null;

		if (RulersAndGridPropertyConstants.GRID_IS_DISPLAYING_GRID.equals(propertyPath)) {
			observable = new CustomBooleanStyleWithStoreObservableValue(this.diagram, this.domain, WorkspaceViewerProperties.VIEWGRID, this.store);
		}
		if (RulersAndGridPropertyConstants.RULERS_IS_DISPLAYING_RULER.equals(propertyPath)) {
			observable = new CustomBooleanStyleWithStoreObservableValue(this.diagram, this.domain, WorkspaceViewerProperties.VIEWRULERS, this.store);
		}
		if (RulersAndGridPropertyConstants.GRID_IS_IN_FRONT.equals(propertyPath)) {
			observable = new CustomBooleanStyleWithStoreObservableValue(this.diagram, this.domain, WorkspaceViewerProperties.GRIDORDER, this.store);
		}
		if (RulersAndGridPropertyConstants.GRID_COLOR.equals(propertyPath)) {
			observable = new CustomIntStyleWithStoreObservableValue(this.diagram, this.domain, WorkspaceViewerProperties.GRIDLINECOLOR, this.store);
		}
		if (RulersAndGridPropertyConstants.GRID_STYLE.equals(propertyPath)) {
			observable = new CustomIntStyleWithStoreObservableValue(this.diagram, this.domain, WorkspaceViewerProperties.GRIDLINESTYLE, this.store);
		}
		if (RulersAndGridPropertyConstants.GRID_SPACING.equals(propertyPath)) {
			observable = new CustomDoubleStyleWithStoreObservableValue(this.diagram, this.domain, WorkspaceViewerProperties.GRIDSPACING, this.store);
		}
		if (RulersAndGridPropertyConstants.GRID_IS_SNAP_TO_GRID.equals(propertyPath)) {
			observable = new CustomBooleanStyleWithStoreObservableValue(this.diagram, this.domain, WorkspaceViewerProperties.SNAPTOGRID, this.store);
		}
		if (RulersAndGridPropertyConstants.GRID_IS_SNAP_TO_SHAPE.equals(propertyPath)) {
			observable = new CustomBooleanStyleWithStoreObservableValue(this.diagram, this.domain, WorkspaceViewerProperties.SNAPTOGEOMETRY, this.store);
		}
		if (RulersAndGridPropertyConstants.RULERS_UNITS.equals(propertyPath)) {
			observable = new RulersUnitStyleObservableValue(this.diagram, this.domain, this.store);
		}
		return observable;
	}



	/**
	 *
	 * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement#getContentProvider(java.lang.String)
	 *
	 * @param propertyPath
	 * @return
	 */
	@Override
	public IStaticContentProvider getContentProvider(String propertyPath) {
		if (RulersAndGridPropertyConstants.GRID_STYLE.equals(propertyPath)) {
			return new StaticContentProvider(new Object[] { Graphics.LINE_DASH, Graphics.LINE_DASHDOT, Graphics.LINE_DASHDOTDOT, Graphics.LINE_DOT, Graphics.LINE_SOLID, Graphics.LINE_CUSTOM });
		}
		if (RulersAndGridPropertyConstants.RULERS_UNITS.equals(propertyPath)) {
			return new StaticContentProvider(new Object[] { RulerProvider.UNIT_INCHES, RulerProvider.UNIT_CENTIMETERS, RulerProvider.UNIT_PIXELS });
		}
		return super.getContentProvider(propertyPath);
	}

	/**
	 *
	 * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement#getLabelProvider(java.lang.String)
	 *
	 * @param propertyPath
	 * @return
	 */
	@Override
	public ILabelProvider getLabelProvider(final String propertyPath) {
		if (RulersAndGridPropertyConstants.GRID_STYLE.equals(propertyPath)) {
			return new LineStyleLabelProvider();
		}
		if (RulersAndGridPropertyConstants.RULERS_UNITS.equals(propertyPath)) {
			return new UnitsLabelProvider();
		}
		return null;
	}

	/**
	 *
	 * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement#isMandatory(java.lang.String)
	 *
	 * @param propertyPath
	 * @return
	 */
	@Override
	public boolean isMandatory(final String propertyPath) {
		if (RulersAndGridPropertyConstants.GRID_STYLE.equals(propertyPath) || RulersAndGridPropertyConstants.RULERS_UNITS.equals(propertyPath)) {
			return true;
		}
		return false;
	}

	/**
	 *
	 * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement#forceRefresh(java.lang.String)
	 *
	 * @param propertyPath
	 * @return
	 */
	@Override
	public boolean forceRefresh(final String propertyPath) {
		return true;
	}
}

Back to the top