Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2d03436e94940fefc62dcb966cfdc074f7cc3db1 (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
/*******************************************************************************
 * Copyright (c) 2007, 2009 THALES GLOBAL SERVICES.
 * 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:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.internal.layout.provider;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
import org.eclipse.sirius.diagram.ui.tools.api.layout.provider.GridLayoutProvider;
import org.eclipse.sirius.diagram.ui.tools.internal.layout.ArrangeAllWithAutoSize;

/**
 * Specialization of the {@link GridLayoutProvider} to handle the specific
 * layout adjustements made on the arrange all.
 * 
 * @author cbrun
 * 
 */
public class AdjustedGridLayout extends GridLayoutProvider {
    /**
     * {@inheritDoc}
     */
    @Override
    protected Command createChangeBoundsCommand(final IGraphicalEditPart editPart, final Point newPosition) {
        Command result = null;
        final Command settingBounds = super.createChangeBoundsCommand(editPart, newPosition);
        if (ArrangeAllWithAutoSize.isEnabled() && ArrangeAllWithAutoSize.shouldBeAutosized(editPart)) {
            final Command autoSizeCmd = editPart.getCommand(new Request(RequestConstants.REQ_AUTOSIZE));
            if (settingBounds != null) {
                final CompoundCommand cpd = new CompoundCommand();
                cpd.add(settingBounds);
                cpd.add(autoSizeCmd);
                result = cpd;

            } else {
                result = autoSizeCmd;
            }

        } else {
            result = settingBounds;
        }
        return result;
    }

}

Back to the top