Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 500f933bb99f7a82c45295e732bac243d346e040 (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
/*****************************************************************************
 * Copyright (c) 2014 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:
 *  Patrick Tessier (CEA LIST) - Initial API and implementation
 /*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.menu.actions;

/*****************************************************************************
 * Copyright (c) 2009-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:
 *  Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
 *
 *****************************************************************************/


import java.util.List;

import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.papyrus.uml.diagram.common.layout.DistributionConstants;



/**
 * The Class AbstractDistributeAction.
 */
public abstract class AbstractDistributeAction {

	/**
	 * Indicates if we are in a degraded mode for the vertical distribution
	 * this value is changed by {@link #calculatesSpaceBetweenNodes(PrecisionRectangle, List)}
	 */
	protected boolean verticalDegradedMode = false;


	/**
	 * Indicates if we are in a degraded mode for the horizontal distribution
	 * this value is changed by {@link #calculatesSpaceBetweenNodes(PrecisionRectangle, List)}
	 */
	protected boolean horizontalDegradedMode = false;

	/** the selected elements for this action */
	protected List<IGraphicalEditPart> selectedElements;

	/** the distribution type */
	protected int distribution;

	/**
	 * Checks if is horizontal degraded mode.
	 *
	 * @return true, if is horizontal degraded mode
	 */
	public boolean isHorizontalDegradedMode() {
		return horizontalDegradedMode;
	}

	/**
	 * Checks if is vertical degraded mode.
	 *
	 * @return true, if is vertical degraded mode
	 */
	public boolean isVerticalDegradedMode() {
		return verticalDegradedMode;
	}


	/**
	 * Sets the vertical degraded mode.
	 *
	 * @param verticalDegradedMode
	 *            the new vertical degraded mode
	 */
	public void setVerticalDegradedMode(boolean verticalDegradedMode) {
		this.verticalDegradedMode = verticalDegradedMode;
	}

	/**
	 * Sets the horizontal degraded mode.
	 *
	 * @param horizontalDegradedMode
	 *            the new horizontal degraded mode
	 */
	public void setHorizontalDegradedMode(boolean horizontalDegradedMode) {
		this.horizontalDegradedMode = horizontalDegradedMode;
	}

	/**
	 * Gets the distribution.
	 *
	 * @return the distribution
	 */
	public int getDistribution() {
		return this.distribution;
	}


	/**
	 *
	 * Constructor.
	 *
	 * @param distribution
	 *            the distribution
	 * @param selectedElements
	 *            the selected elements for the action
	 */
	public AbstractDistributeAction(int distribution, List<IGraphicalEditPart> selectedElements) {
		this.distribution = distribution;
		this.selectedElements = selectedElements;
		buildAction(selectedElements);
	}

	/**
	 * We build the different elements used to do the action
	 *
	 * @param elementsForAction
	 *            the elements on which this action is applied
	 */
	protected abstract void buildAction(List<?> elementsForAction);

	/**
	 * Return the command to do this action
	 *
	 * @return
	 *         the command to do this action
	 */
	public abstract Command getCommand();

	/**
	 *
	 * @param selectedElements
	 *            the element on which the command is applied
	 * @return
	 *         <ul>
	 *         <li> <code>true</code> if the command can be build</li>
	 *         <li> <code>false</code> if not</li>
	 *         </ul>
	 */
	protected boolean canExistCommand(List<?> selectedElements) {
		switch (this.distribution) {
		case DistributionConstants.DISTRIBUTE_H_CONTAINER_INT:
			if (selectedElements.size() >= 1) {
				return true;
			}
			break;
		case DistributionConstants.DISTRIBUTE_H_NODES_INT:
			if (selectedElements.size() > 2) {
				return true;
			}
			break;
		case DistributionConstants.DISTRIBUTE_V_CONTAINER_INT:
			if (selectedElements.size() >= 1) {
				return true;
			}
			break;
		case DistributionConstants.DISTRIBUTE_V_NODES_INT:
			if (selectedElements.size() > 2) {
				return true;
			}
			break;
		default:
			break;
		}
		return false;
	}
}

Back to the top