Skip to content

Commit

Permalink
[551512] The label of representation needs to be translated by Sirius
Browse files Browse the repository at this point in the history
Translator

Bug: 551512
Change-Id: If721b2bd287e1fbe52056a551502ccc1cf168374
Signed-off-by: cong-bang.do <[email protected]>
  • Loading branch information
bang-dc committed Sep 26, 2019
1 parent 7985ac0 commit 5b33435
Showing 1 changed file with 12 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2016 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2019 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
Expand All @@ -19,35 +19,30 @@
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.query.IdentifiedElementQuery;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
import org.eclipse.sirius.common.tools.api.util.MessageTranslator;
import org.eclipse.sirius.common.tools.api.util.StringUtil;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.description.Layer;
import org.eclipse.sirius.diagram.description.filter.FilterDescription;
import org.eclipse.sirius.table.metamodel.table.description.CrossTableDescription;
import org.eclipse.sirius.table.metamodel.table.description.EditionTableDescription;
import org.eclipse.sirius.table.metamodel.table.provider.TableUIPlugin;
import org.eclipse.sirius.tools.api.interpreter.IInterpreterMessages;
import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.SiriusPlugin;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.BaseSelectionListenerAction;
import org.eclipse.ui.plugin.AbstractUIPlugin;

/**
* The action allowing to create new representations.
*
*/
public class NewRepresentationAction extends BaseSelectionListenerAction {
private EObject selectedEObject;
Expand Down Expand Up @@ -94,29 +89,8 @@ public NewRepresentationAction(RepresentationDescription description, EObject se
*/
public NewRepresentationAction(RepresentationDescription description, EObject selectedEObject,
Session session, boolean forceDefaultName, boolean openRepresentation, Collection<Layer> extraLayers, Collection<FilterDescription> extraFilters) {
super(description.getName());
String label = description.getLabel();
if ((null != label) && (label.length() > 1)) {
setText(label);
}
ImageDescriptor imageDescriptor = null;
// Handle specific diagrams : Table ones.
if (description instanceof CrossTableDescription) {
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(TableUIPlugin.ID,
"/icons/full/obj16/CrossTableDescription.gif"); //$NON-NLS-1$
} else if (description instanceof EditionTableDescription) {
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(TableUIPlugin.ID,
"/icons/full/obj16/DTable.gif"); //$NON-NLS-1$
} else {
// Standard diagram.
imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(SiriusEditPlugin.ID,
"/icons/full/obj16/DAnalysis.gif"); //$NON-NLS-1$
}
if (null == imageDescriptor) {
imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
}
setImageDescriptor(imageDescriptor);

super(description.getName());

// Registers local fields.
this.selectedEObject = selectedEObject;
this.description = description;
Expand All @@ -136,8 +110,8 @@ public void run() {
String defaultName = computeDefaultName(selectedEObject, description);

if (!forceDefaultName) {
String label = MessageTranslator.INSTANCE.getMessage(description, new IdentifiedElementQuery(description).getLabel());

String label = description.getLabel();
if (label == null || label.isEmpty()) {
label = description.getName();
}
Expand Down Expand Up @@ -175,12 +149,7 @@ protected String computeDefaultName(EObject eObject, RepresentationDescription r
IInterpreter interpreter = InterpreterUtil.getInterpreter(eObject);

// Computes new representation name.
String newName = "New "; //$NON-NLS-1$
if (!StringUtil.isEmpty(repDescription.getLabel())) {
newName += repDescription.getLabel();
} else {
newName += repDescription.getName();
}
String newName = ""; //$NON-NLS-1$

String titleExpression = repDescription.getTitleExpression();
if (!StringUtil.isEmpty(titleExpression)) {
Expand All @@ -189,7 +158,11 @@ protected String computeDefaultName(EObject eObject, RepresentationDescription r
} catch (EvaluationException e) {
SiriusPlugin.getDefault().error(IInterpreterMessages.EVALUATION_ERROR_ON_MODEL_MODIFICATION, e);
}
}
} else if (!StringUtil.isEmpty(repDescription.getLabel())) {
newName = "New " + MessageTranslator.INSTANCE.getMessage(description, new IdentifiedElementQuery(repDescription).getLabel());
} else {
newName = "New " + repDescription.getName();
}

return newName;
}
Expand Down Expand Up @@ -259,16 +232,8 @@ public DRepresentation getRepresentation() {
return representation;
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("synthetic-access")
public void doExecute() {
NullProgressMonitor monitor = new NullProgressMonitor();
/*
* if (selectedEObject instanceof Scenario) { Scenario scenario =
* (Scenario) selectedEObject; scenario.setName(newName); }
*/

representation = DialectManager.INSTANCE.createRepresentation(newName, eObject, repDescription,
currentSession, monitor);
Expand Down

0 comments on commit 5b33435

Please sign in to comment.