Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: da9129f4dbbec15107c532b4ce34146bd4c80389 (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
package org.eclipse.papyrus.uml.diagram.statemachine.custom.preferences;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
import org.eclipse.papyrus.uml.diagram.statemachine.preferences.TransitionPreferencePage;
import org.eclipse.papyrus.uml.tools.utils.ICustomAppearence;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class CustomTransitionPreferencePage extends TransitionPreferencePage {
	
	/**
	 * Button: if selected, indicate signals/call events with parameters by means of (...)
	 */
	Button bIndicateParameters; 
	
	/**
	 * Button: if selected, add a line/break before a non-empty effect
	 */
	Button bLineBreakBeforeEffector; 

	/**
	 * Cut text of opaque bodies after certain length
	 */
	Text tBodyCutLength;
	
	/**
	 * initialize the preferences
	 * @param store the preference store associated with the state machine diagram.
	 */
	public static void initDefaults(IPreferenceStore store) {
		boolean refresh = false;
		int cutLength = 1;
		if(cutLength != store.getInt(PreferenceConstants.BODY_CUT_LENGTH)) {
			store.setValue(PreferenceConstants.BODY_CUT_LENGTH, cutLength);
			refresh = true;
		}
		
		boolean indicateParams = true;
		if(indicateParams != store.getBoolean(PreferenceConstants.INDICATE_PARAMETERS)) {
			store.setValue(PreferenceConstants.INDICATE_PARAMETERS, indicateParams);
			refresh = true;
		}
		TransitionPreferencePage.initDefaults(store);
		
		boolean lineBreakBeforeEffect = true;
		if(lineBreakBeforeEffect != store.getBoolean(PreferenceConstants.LINEBREAK_BEFORE_EFFECT)) {
			store.setValue(PreferenceConstants.LINEBREAK_BEFORE_EFFECT, lineBreakBeforeEffect);
			refresh = true;
		}
		TransitionPreferencePage.initDefaults(store);
		if (refresh) {
			DiagramHelper.refreshDiagrams();
		}
	}
	
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void createPageContents(Composite parent) {
		super.createPageContents(parent);
		// adds the label preferences checkboxes
		createTransitionPreferencesButtons(parent);
		// refreshButtons();
	}
	
	/**
	 * Creates the group and check boxes to choose the kind of display
	 * 
	 * @param parent
	 *        the parent composite that holds the group
	 */
	protected void createTransitionPreferencesButtons(Composite parent) {
		IPreferenceStore store = getPreferenceStore();

		// create group that host the buttons
		Group group = new Group(parent, SWT.SHADOW_NONE);
		group.setText("Transition Display");
		group.setLayout(new FormLayout());
		// group.setLayout(new GridLayout(1, false));

		FormData data;
		
		bIndicateParameters = createCheckButton(group, "Indicate parameters", ICustomAppearence.DISP_VISIBILITY);
		bIndicateParameters.setSelection(store.getBoolean(PreferenceConstants.INDICATE_PARAMETERS));
		data = new FormData();
		data.left = new FormAttachment(0, 0);
		data.top = new FormAttachment(0, 0);
		bIndicateParameters.setLayoutData(data);
		
		bLineBreakBeforeEffector = createCheckButton(group, "Line break before effect label", ICustomAppearence.DISP_VISIBILITY);
		bLineBreakBeforeEffector.setSelection(store.getBoolean(PreferenceConstants.LINEBREAK_BEFORE_EFFECT));
		data = new FormData();
		data.left = new FormAttachment(0, 0);
		data.top = new FormAttachment(bIndicateParameters, 0);
		bLineBreakBeforeEffector.setLayoutData(data);
		
		Composite maxLengthComposite = new Composite(group, SWT.NONE);
		maxLengthComposite.setLayout(new GridLayout(2, false));
		data = new FormData();
		data.left = new FormAttachment(0, 0);
		data.top = new FormAttachment(bLineBreakBeforeEffector, 0);
		maxLengthComposite.setLayoutData(data);
		Label l = new Label(maxLengthComposite, SWT.NONE);
		l.setText("Shown number of lines for opaque expressions/behaviors: ");
		tBodyCutLength = new Text(maxLengthComposite, SWT.NONE);
		tBodyCutLength.setText(store.getInt(PreferenceConstants.BODY_CUT_LENGTH) + ""); // $NON-NLS-1$
		final GridData gridData = new GridData();
		gridData.widthHint = 50;		// minimal width to assure entering larger numbers
		tBodyCutLength.setLayoutData(gridData);
	}

	
	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void performDefaults() {
		IPreferenceStore store = getPreferenceStore();
		initDefaults(store);
		
		bIndicateParameters.setSelection(store.getBoolean(PreferenceConstants.INDICATE_PARAMETERS));
		bLineBreakBeforeEffector.setSelection(store.getBoolean(PreferenceConstants.LINEBREAK_BEFORE_EFFECT));
		tBodyCutLength.setText("" + store.getInt(PreferenceConstants.BODY_CUT_LENGTH));
		
		super.performDefaults();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean performOk() {
		storePreferences();
		return super.performOk();
	}
	
	
	/**
	 * Creates a button with the {@link SWT#CHECK} style.
	 * 
	 * @param parent
	 *        the parent of the button
	 * @param label
	 *        the label of the button
	 * @param mask
	 *        the value controlled by the button
	 * @return the button created
	 */
	protected Button createCheckButton(Composite parent, String label, int mask) {
		Button button = new Button(parent, SWT.CHECK);
		button.setText(label);
		return button;
	}
	
	/**
	 * Stores the values of the fields contained in this page into the preference store.
	 */
	protected void storePreferences() {
		IPreferenceStore store = getPreferenceStore();
		boolean refresh = false;
		// checks the stored value and the actual one, so does not refresh diagram if it is not
		// needed
		boolean lineBreakBeforeEffect = bLineBreakBeforeEffector.getSelection();
		if(lineBreakBeforeEffect != store.getBoolean(PreferenceConstants.LINEBREAK_BEFORE_EFFECT)) {
			store.setValue(PreferenceConstants.LINEBREAK_BEFORE_EFFECT, lineBreakBeforeEffect);
			refresh = true;
		}

		int cutLength = new Integer(tBodyCutLength.getText().trim());
		if(cutLength != store.getInt(PreferenceConstants.BODY_CUT_LENGTH)) {
			store.setValue(PreferenceConstants.BODY_CUT_LENGTH, cutLength);
			refresh = true;
		}
		
		boolean indicateParams = bIndicateParameters.getSelection();
		if(indicateParams != store.getBoolean(PreferenceConstants.INDICATE_PARAMETERS)) {
			store.setValue(PreferenceConstants.INDICATE_PARAMETERS, indicateParams);
			refresh = true;
		}
		if (refresh) {
			DiagramHelper.setNeedsRefresh();
			DiagramHelper.refreshDiagrams();
		}
	}
}

Back to the top