Skip to content

Commit

Permalink
[72] Translate the layer name in ChangeLayerActivationCommand's label
Browse files Browse the repository at this point in the history
Bug: #72
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=581801
Signed-off-by: Pierre-Charles David <[email protected]>
  • Loading branch information
pcdavid committed Nov 16, 2023
1 parent bbc00d7 commit 4f698f6
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2021 THALES GLOBAL SERVICES.
* Copyright (c) 2010, 2023 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -26,6 +26,7 @@
import org.eclipse.sirius.business.api.query.IdentifiedElementQuery;
import org.eclipse.sirius.common.tools.api.listener.Notification;
import org.eclipse.sirius.common.tools.api.listener.NotificationUtil;
import org.eclipse.sirius.common.tools.api.util.MessageTranslator;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.business.api.helper.decoration.DecorationHelper;
import org.eclipse.sirius.diagram.business.api.query.DDiagramQuery;
Expand Down Expand Up @@ -66,19 +67,28 @@ public final class ChangeLayerActivationCommand extends RecordingCommand {
* a {@link IProgressMonitor} to show progression of layer activation changes
*/
public ChangeLayerActivationCommand(TransactionalEditingDomain domain, DDiagram dDiagram, Layer layer, IProgressMonitor monitor) {
super(domain, new DDiagramQuery(dDiagram).getAllActivatedLayers().contains(layer) ? Messages.ChangeLayerActivationCommand_hideLabel
: MessageFormat.format(Messages.ChangeLayerActivationCommand_showLabel, new IdentifiedElementQuery(layer).getLabel()));
super(domain, computeCommandLabel(dDiagram, layer));
this.dDiagram = dDiagram;
this.layer = layer;
this.monitor = monitor;
}

private static String computeCommandLabel(DDiagram dDiagram, Layer layer) {
if (new DDiagramQuery(dDiagram).getAllActivatedLayers().contains(layer)) {
return Messages.ChangeLayerActivationCommand_hideLabel;
} else {
String rawLayerLabel = new IdentifiedElementQuery(layer).getLabel();
String translatedLayerLabel = MessageTranslator.INSTANCE.getMessage(layer, rawLayerLabel);
return MessageFormat.format(Messages.ChangeLayerActivationCommand_showLabel, translatedLayerLabel);
}
}

@Override
protected void doExecute() {
try {
// 553866 : testing editiingDoman of diagram to check if the command can be called
// 553866 : testing editingDomain of diagram to check if the command can be called
TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(dDiagram);
result = new ArrayList<Layer>();
result = new ArrayList<>();
if (editingDomain == null) {
return; // do nothing; getResult will return an empty collection
}
Expand Down Expand Up @@ -135,7 +145,7 @@ public void dispose() {
}

/**
* Return the list of layers activated or deactivated by the command Can be used to test if the command succeed.
* Return the list of layers activated or deactivated by the command. Can be used to test if the command succeeded.
*/
@Override
public Collection<?> getResult() {
Expand Down

0 comments on commit 4f698f6

Please sign in to comment.