blob: 53c9441da256471562052ef2f45b9e2f4f3b8a9e (
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
|
/*******************************************************************************
* Copyright (c) 2009, 2015 THALES GLOBAL SERVICES and others.
* 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.actions.pinning;
import java.util.Collection;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.diagram.tools.api.layout.PinHelper;
import org.eclipse.sirius.diagram.tools.internal.commands.PinElementsCommand;
import org.eclipse.sirius.diagram.ui.provider.Messages;
import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath;
import org.eclipse.sirius.diagram.ui.tools.api.ui.actions.ActionIds;
import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry;
/**
* Eclipse action to pin elements.
*
* @author dlecan
*/
public class PinElementsEclipseAction extends AbstractPinUnpinElementsEclipseAction {
/**
* Constructor.
*/
public PinElementsEclipseAction() {
super(Messages.PinElementsEclipseAction_text, ActionIds.PIN_ELEMENTS, Messages.PinElementsEclipseAction_text, DiagramImagesPath.PIN_ELEMENTS_ICON);
}
/**
* {@inheritDoc}
*/
@Override
protected Command createCommand(final Collection<DDiagramElement> elements) {
return new PinElementsCommand(elements);
}
/**
* {@inheritDoc}
*/
@Override
protected boolean doIsEnabled(final Collection<DDiagramElement> selectedDiagramElements) {
boolean result = true;
PinHelper pinHelper = new PinHelper();
for (final DDiagramElement dDiagramElement : selectedDiagramElements) {
result = result && pinHelper.isPinned(dDiagramElement);
Resource dDiagramElementResource = dDiagramElement.eResource();
if (dDiagramElementResource == null
|| !PermissionAuthorityRegistry.getDefault().getPermissionAuthority(dDiagramElementResource.getResourceSet()).canEditInstance(dDiagramElement.getParentDiagram())) {
result = true;
break;
}
}
return !result;
}
}
|