blob: ceea2535b901ac6f6416767c29a22a26a8e9dcdc (
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
|
/*****************************************************************************
* 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:
*
* CEA LIST - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.edit.policy;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.gmf.diagram.common.edit.part.ITextAwareEditPart;
import org.eclipse.papyrus.gmf.diagram.common.parser.IMaskManagedSemanticParser;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.MaskLabelHelper;
/**
* <pre>
* Generic mask manage edit policy for {@link ITextAwareEditPart}, managed masks are assumed to be given by the
* {@link ITextAwareEditPart} parser (must implement {@link IMaskManagedSemanticParser}).
* </pre>
*/
public class MaskManagedLabelEditPolicy extends GraphicalEditPolicy implements IMaskManagedLabelEditPolicy {
/**
* {@inheritDoc}
*/
public Map<String, String> getMasks() {
Map<String, String> masks = new HashMap<String, String>();
IParser parser = getHostLabelEditPart().getParser();
if(parser instanceof IMaskManagedSemanticParser) {
masks = ((IMaskManagedSemanticParser)parser).getMasks();
}
return masks;
}
/**
* {@inheritDoc}
*/
public Collection<String> getCurrentDisplayValue() {
return MaskLabelHelper.getMaskValues(getView());
}
/**
* {@inheritDoc}
*/
public void updateDisplayValue(Collection<String> maskValues) {
MaskLabelHelper.setMaskValues(getView(), maskValues);
}
/**
* {@inheritDoc}
*/
public void setDefaultDisplayValue() {
MaskLabelHelper.unsetMaskValues(getView());
}
// @unused.
public void refreshDisplay() {
// Not implemented.
}
// @unused.
public String getPreferencePageID() {
// Not implemented.
return null;
}
/**
* Get the host label edit part (has to implement {@link ITextAwareEditPart}).
*
* @return the host label edit part.
*/
private ITextAwareEditPart getHostLabelEditPart() {
return (ITextAwareEditPart)getHost();
}
private View getView() {
return (View)getHost().getModel();
}
}
|