blob: 81db67df9490ae42cbb6801cba91e432a1ee8469 (
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
|
/*****************************************************************************
* Copyright (c) 2013 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomBooleanStyleObservableValue;
/**
* this edit policy has in charge to set the ratio of the symbol if is displayed
* associated figure has to be a {@link NodeNamedElementFigure}
*/
public class MaintainSymbolRatioEditPolicy extends GraphicalEditPolicy implements IChangeListener {
public static final String MAINTAIN_SYMBOL_RATIO = "maintainSymbolRatio";
/** key for this edit policy */
public static final String MAINTAIN_SYMBOL_RATIO_EDITPOLICY = "MAINTAIN_SYMBOL_RATIO_EDITPOLICY";
protected IObservableValue styleObservable;
/**
*
* {@inheritDoc}
*/
@Override
public void activate() {
// retrieve the view and the element managed by the edit part
View view = (View) getHost().getModel();
if (view == null) {
return;
}
styleObservable = new CustomBooleanStyleObservableValue(view, EMFHelper.resolveEditingDomain(view), MAINTAIN_SYMBOL_RATIO);
styleObservable.addChangeListener(this);
}
/**
*
* @param currentView
* @return the current Style that reperesent the boder
*/
protected BooleanValueStyle getMaintainSymbolRatioStyle(View currentView) {
return (BooleanValueStyle) currentView.getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), MAINTAIN_SYMBOL_RATIO);
}
/**
*
* {@inheritDoc}
*/
@Override
public void deactivate() {
if (styleObservable != null) {
styleObservable.removeChangeListener(this);
styleObservable.dispose();
styleObservable = null;
}
}
@Override
public void handleChange(ChangeEvent event) {
getHost().refresh();
}
}
|