Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Redor2013-12-09 03:22:59 -0500
committerGerrit Code Review @ Eclipse.org2013-12-10 07:44:48 -0500
commit2fe20261bfb4373d54edd1482d8c7c20a281644c (patch)
tree020e04a5dacac0237660f34064b4895f67dfb6b9
parent2946da1191181e248282f094e554f27d642d3d06 (diff)
downloadorg.eclipse.sirius-2fe20261bfb4373d54edd1482d8c7c20a281644c.tar.gz
org.eclipse.sirius-2fe20261bfb4373d54edd1482d8c7c20a281644c.tar.xz
org.eclipse.sirius-2fe20261bfb4373d54edd1482d8c7c20a281644c.zip
[422957] Refactor
CreateRepresentationFromRepresentationCreationDescription The class CreateRepresentationFromRepresentationCreationDescription of org.eclipse.sirius.table.ui was deprecated. All common stuffs for the same action in diagram, table.ui, tree.ui are grouped in AbstractCreateRepresentationFromRepresentationCreationDescription. Some methods of ITableCommandFactory and ITreeCommandFactory have been pull up in ICommandFactory. Change-Id: I5874f9bd39961ab92d28880c7ec4bffb4f5d681d Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/util/DelegatingDiagramCommandFactory.java8
-rw-r--r--plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/tools/internal/actions/CreateRepresentationFromRepresentationCreationDescription.java190
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release Notes.html17
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release Notes.textile3
-rw-r--r--plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/CreateRepresentationFromRepresentationCreationDescription.java115
-rw-r--r--plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/api/command/ITableCommandFactory.java26
-rw-r--r--plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/internal/command/TableCommandFactory.java10
-rw-r--r--plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/CreateRepresentationFromRepresentationCreationDescription.java115
-rw-r--r--plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/command/ITreeCommandFactory.java29
-rw-r--r--plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/TreeCommandFactory.java10
-rw-r--r--plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF7
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/actions/AbstractCreateRepresentationFromRepresentationCreationDescription.java244
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/AbstractCommandFactory.java12
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ICommandFactory.java23
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/IDiagramCommandFactory.java15
15 files changed, 369 insertions, 455 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/util/DelegatingDiagramCommandFactory.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/util/DelegatingDiagramCommandFactory.java
index 76326d6639..b09d83b618 100644
--- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/util/DelegatingDiagramCommandFactory.java
+++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/util/DelegatingDiagramCommandFactory.java
@@ -320,4 +320,12 @@ public class DelegatingDiagramCommandFactory implements IDiagramCommandFactory {
return baseFactory.buildPasteCommandFromTool(dContainer, droppedElement, tool);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.sirius.tools.api.command.ICommandFactory#getUserInterfaceCallBack()
+ */
+ public UICallBack getUserInterfaceCallBack() {
+ return baseFactory.getUserInterfaceCallBack();
+ }
}
diff --git a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/tools/internal/actions/CreateRepresentationFromRepresentationCreationDescription.java b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/tools/internal/actions/CreateRepresentationFromRepresentationCreationDescription.java
index aac89f94b9..f7d9a1ec3c 100644
--- a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/tools/internal/actions/CreateRepresentationFromRepresentationCreationDescription.java
+++ b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/tools/internal/actions/CreateRepresentationFromRepresentationCreationDescription.java
@@ -10,46 +10,23 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.tools.internal.actions;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
-import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
-import org.eclipse.sirius.common.tools.api.util.StringUtil;
-import org.eclipse.sirius.common.ui.SiriusTransPlugin;
import org.eclipse.sirius.business.api.dialect.command.CreateRepresentationCommand;
-import org.eclipse.sirius.business.api.logger.RuntimeLoggerInterpreter;
-import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager;
-import org.eclipse.sirius.business.api.query.IdentifiedElementQuery;
-import org.eclipse.sirius.business.api.session.SessionManager;
+import org.eclipse.sirius.common.tools.api.util.Option;
+import org.eclipse.sirius.common.tools.api.util.Options;
import org.eclipse.sirius.diagram.tools.api.command.GMFCommandWrapper;
import org.eclipse.sirius.diagram.tools.api.editor.DDiagramEditor;
import org.eclipse.sirius.diagram.tools.internal.commands.InitializeLayoutCommand;
import org.eclipse.sirius.tools.api.command.IDiagramCommandFactory;
import org.eclipse.sirius.tools.api.command.IDiagramCommandFactoryProvider;
-import org.eclipse.sirius.tools.api.command.ui.UICallBack;
-import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
-import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
-import org.eclipse.sirius.ui.tools.api.image.ImagesPath;
+import org.eclipse.sirius.ui.tools.api.actions.AbstractCreateRepresentationFromRepresentationCreationDescription;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationElement;
-import org.eclipse.sirius.viewpoint.DSemanticDecorator;
-import org.eclipse.sirius.viewpoint.description.DescriptionPackage;
-import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
-import org.eclipse.sirius.viewpoint.description.tool.ToolPackage;
-import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
/**
* Create a new Representation from a {@link RepresentationCreationDescription}.
@@ -57,20 +34,10 @@ import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
* @author cbrun
*
*/
-public class CreateRepresentationFromRepresentationCreationDescription extends Action {
-
- private static final AdapterFactory ADAPTER_FACTORY = DialectUIManager.INSTANCE.createAdapterFactory();
-
- private final RepresentationCreationDescription desc;
-
- private final DRepresentationElement node;
+public class CreateRepresentationFromRepresentationCreationDescription extends AbstractCreateRepresentationFromRepresentationCreationDescription {
private final IGraphicalEditPart editPart;
- private final TransactionalEditingDomain editingDomain;
-
- private final UICallBack uiCallBack;
-
/**
* Build the action.
*
@@ -82,155 +49,48 @@ public class CreateRepresentationFromRepresentationCreationDescription extends A
* @param editingDomain
* current {@link org.eclipse.emf.edit.domain.EditingDomain}.
* @param curPart
- * editpart of the current {@link org.eclipse.sirius.viewpoint.DNode}.
+ * EditPart of the current
+ * {@link org.eclipse.sirius.viewpoint.DNode}.
* @since 0.9.0
*/
- public CreateRepresentationFromRepresentationCreationDescription(final RepresentationCreationDescription desc, final DRepresentationElement dNode, final TransactionalEditingDomain editingDomain,
+ public CreateRepresentationFromRepresentationCreationDescription(final RepresentationCreationDescription desc, final DRepresentationElement target, final TransactionalEditingDomain editingDomain,
final IGraphicalEditPart curPart) {
- this.desc = desc;
- this.node = dNode;
- this.editingDomain = editingDomain;
+ super(desc, target, editingDomain, getDiagramCommandFactory(curPart, editingDomain));
this.editPart = curPart;
- ImageDescriptor imageDescriptor = null;
- RepresentationDescription representationDescription = desc.getRepresentationDescription();
- if (representationDescription != null) {
- // Search the icon for this representation description
- final IItemLabelProvider labelProvider = (IItemLabelProvider) CreateRepresentationFromRepresentationCreationDescription.ADAPTER_FACTORY.adapt(representationDescription,
- IItemLabelProvider.class);
- if (labelProvider != null) {
- imageDescriptor = ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(representationDescription));
- }
- }
- if (imageDescriptor != null) {
- setImageDescriptor(imageDescriptor);
- } else {
- setImageDescriptor(SiriusTransPlugin.getBundledImageDescriptor(ImagesPath.CREATE_VIEW_ICON));
- }
- this.uiCallBack = SiriusEditPlugin.getPlugin().getUiCallback();
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.Action#isEnabled()
- */
@Override
- public boolean isEnabled() {
-
- boolean isEnabled = super.isEnabled();
- if (isEnabled) {
- if (desc.getRepresentationDescription() == null) {
- isEnabled = false;
- } else {
- final IDiagramCommandFactory diagramCommandFactory = getDiagramCommandFactory();
- final CreateRepresentationCommand command = diagramCommandFactory.buildCreateRepresentationFromDescription(desc, node, "");
- return command.canExecute();
- }
+ protected Option<DRepresentation> executeCreationCommand(Option<Command> initialOperationCommand, CreateRepresentationCommand createRepresentationCommand) {
+ final CompositeTransactionalCommand compositeCommand = new CompositeTransactionalCommand(getEditingDomain(), "Create and open representation");
+ if (initialOperationCommand.some()) {
+ compositeCommand.compose(new GMFCommandWrapper(getEditingDomain(), initialOperationCommand.get()));
}
- return isEnabled;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public String getText() {
- final IdentifiedElementQuery query = new IdentifiedElementQuery(desc);
- return new StringBuffer("New detail : ").append(query.getLabel()).toString();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public void run() {
- doCreateRepresentation();
- }
-
- private void doCreateRepresentation() {
-
- final IdentifiedElementQuery query = new IdentifiedElementQuery(desc);
-
- // default name
- String name = "new " + query.getLabel();
- final String computedName = computeName(node);
- if (computedName != null) {
- name = computedName;
- }
-
- try {
- name = uiCallBack.askForDetailName(name, desc.getRepresentationDescription().getEndUserDocumentation());
-
- } catch (final InterruptedException e) {
- // the user pressed "cancel", we should exit
- return;
- }
- final IDiagramCommandFactory emfCommandFactory = getDiagramCommandFactory();
- final CompositeTransactionalCommand compositeCommand = new CompositeTransactionalCommand(editingDomain, "Create and open representation");
-
- if (isInitialOperation()) {
- final Command emfCommandTool = emfCommandFactory.buildDoExecuteDetailsOperation(node, desc, name);
- compositeCommand.compose(new GMFCommandWrapper(editingDomain, emfCommandTool));
- }
- CreateRepresentationCommand command = emfCommandFactory.buildCreateRepresentationFromDescription(desc, node, name);
InitializeLayoutCommand layoutCommand = null;
- DRepresentation[] createdRepresentation = { null };
- compositeCommand.compose(new GMFCommandWrapper(editingDomain, command));
- if (node != null) {
- layoutCommand = new InitializeLayoutCommand(editingDomain, command, editPart);
- compositeCommand.compose(new GMFCommandWrapper(editingDomain, layoutCommand));
+ DRepresentation createdRepresentation = null;
+ compositeCommand.compose(new GMFCommandWrapper(getEditingDomain(), createRepresentationCommand));
+ if (getTarget() != null) {
+ layoutCommand = new InitializeLayoutCommand(getEditingDomain(), createRepresentationCommand, editPart);
+ compositeCommand.compose(new GMFCommandWrapper(getEditingDomain(), layoutCommand));
}
-
editPart.getRoot().getViewer().getEditDomain().getCommandStack().execute(new ICommandProxy(compositeCommand));
- if (command.getCreatedRepresentation() != null) {
- createdRepresentation[0] = command.getCreatedRepresentation();
+ if (createRepresentationCommand.getCreatedRepresentation() != null) {
+ createdRepresentation = createRepresentationCommand.getCreatedRepresentation();
} else if (layoutCommand != null && layoutCommand.getLayoutedRepresentation() != null) {
- createdRepresentation[0] = layoutCommand.getLayoutedRepresentation();
- }
-
- if (node != null) {
- final EObject target = ((DSemanticDecorator) node).getTarget();
- if (createdRepresentation[0] == null) {
- final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- MessageDialog.openWarning(shell, "Error creating the representation", "An error occured when trying to create the representation.\nPlease check the diagram specification.");
- } else {
- DialectUIManager.INSTANCE.openEditor(SessionManager.INSTANCE.getSession(target), createdRepresentation[0], new NullProgressMonitor());
- }
+ createdRepresentation = layoutCommand.getLayoutedRepresentation();
}
- }
-
- private boolean isInitialOperation() {
- return desc.getInitialOperation() != null && desc.getInitialOperation().getFirstModelOperations() != null;
- }
-
- private String computeName(final DSemanticDecorator decorator) {
-
- final IInterpreter interpreter = InterpreterUtil.getInterpreter(decorator.getTarget());
- final RuntimeLoggerInterpreter safeInterpreter = RuntimeLoggerManager.INSTANCE.decorate(interpreter);
-
- String computedName = null;
-
- if (!StringUtil.isEmpty(desc.getTitleExpression())) {
- computedName = safeInterpreter.evaluateString(decorator.getTarget(), desc, ToolPackage.eINSTANCE.getRepresentationCreationDescription_TitleExpression());
- } else if (desc.getRepresentationDescription() != null && !StringUtil.isEmpty(desc.getRepresentationDescription().getTitleExpression())) {
- computedName = safeInterpreter.evaluateString(decorator.getTarget(), desc.getRepresentationDescription(), DescriptionPackage.eINSTANCE.getRepresentationDescription_TitleExpression());
- }
-
- return computedName;
+ return Options.newSome(createdRepresentation);
}
/**
* Returns the emf command factory.
*
+ * @param curPart
+ *
* @return the emf command factory.
*/
- private IDiagramCommandFactory getDiagramCommandFactory() {
- final DDiagramEditor diagramEditor = (DDiagramEditor) editPart.getViewer().getProperty(DDiagramEditor.EDITOR_ID);
+ private static IDiagramCommandFactory getDiagramCommandFactory(IGraphicalEditPart curPart, TransactionalEditingDomain editingDomain) {
+ final DDiagramEditor diagramEditor = (DDiagramEditor) curPart.getViewer().getProperty(DDiagramEditor.EDITOR_ID);
if (diagramEditor == null) {
return null;
}
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html
index ba5d9868e3..885b5daf69 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html
+++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html
@@ -223,6 +223,19 @@
<code>SessionFactory.createSession(DAnalysis)</code> has been removed. It is not intended to be used, but it can be replaced by
<code>SessionFactory.INSTANCE.createSession(analysis.eResource().getURI(), new NullProgressMonitor())</code>.
</li>
+ <li>The method
+ <code>buildDoExecuteDetailsOperation(DSemanticDecorator, RepresentationCreationDescription, String) has been pull up from @ITableCommandFactory</code>,
+ <code>ITreeCommandFactory</code> and
+ <code>IDiagramCommandFactory</code> to
+ <code>ICommandFactory</code>.
+ </li>
+ <li>The method
+ <code>getUserInterfaceCallBack()</code> has been pull up from
+ <code>ITableCommandFactory</code> and
+ <code>ITreeCommandFactory</code> to
+ <code>ICommandFactory</code>. And
+ <code>AbstractCommandFactory</code> now implements this method.
+ </li>
</ul>
<h4 id="Changesinorg.eclipse.sirius.diagram">Changes in
<code>org.eclipse.sirius.diagram</code>
@@ -283,6 +296,10 @@
<code>SiriusUncontrolHandler.performUncontrol(Shell, EObject)</code> has been removed. Use the variant which takes an additional
<code>IProgressMonitor</code> instead.
</li>
+ <li>New class
+ <code>AbstractCreateRepresentationFromRepresentationCreationDescription</code>: Generalization of all
+ <code>CreateRepresentationFromRepresentationCreationDescription</code> classes (iof plug-ins sirius.diagram, sirius.table.ui, sirius.tree.ui).
+ </li>
</ul>
<h4 id="Changesinorg.eclipse.sirius.table">Changes in
<code>org.eclipse.sirius.table</code>
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile
index 0a964367aa..fb569b53ca 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile
@@ -60,6 +60,8 @@ h4. Changes in @org.eclipse.sirius@
* The deprecated method @InterpreterRegistry.prepareImportsFromModelElement(IInterpreter, EObject)@ has been removed. Use @InterpreterRegistry.prepareImportsFromSession(IInterpreter, Session)@ instead. To get @Session@ from @EObject@, you can use @SessionManager.INSTANCE.getSession(EObject)@.
* The deprecated method @SiriusHelper.createDAnalysis()@ has been removed. Use @ViewpointFactory.eINSTANCE.createDAnalysis()@ instead.
* The deprecated method @SessionFactory.createSession(DAnalysis)@ has been removed. It is not intended to be used, but it can be replaced by @SessionFactory.INSTANCE.createSession(analysis.eResource().getURI(), new NullProgressMonitor())@.
+* The method @buildDoExecuteDetailsOperation(DSemanticDecorator, RepresentationCreationDescription, String) has been pull up from @ITableCommandFactory@, @ITreeCommandFactory@ and @IDiagramCommandFactory@ to @ICommandFactory@.
+* The method @getUserInterfaceCallBack()@ has been pull up from @ITableCommandFactory@ and @ITreeCommandFactory@ to @ICommandFactory@. And @AbstractCommandFactory@ now implements this method.
h4. Changes in @org.eclipse.sirius.diagram@
@@ -79,6 +81,7 @@ h4. Changes in @org.eclipse.sirius.ui@
* The deprecated method @SessionHelper.openStartupRepresentations(Session)@ has been removed. Use the variant which takes an additional @IProgressMonitor@ instead.
* The deprecated method @SiriusControlHandler.performControl(Shell, EObject)@ has been removed. Use the variant which takes an additional @IProgressMonitor@ instead.
* The deprecated method @SiriusUncontrolHandler.performUncontrol(Shell, EObject)@ has been removed. Use the variant which takes an additional @IProgressMonitor@ instead.
+* New class @AbstractCreateRepresentationFromRepresentationCreationDescription@: Generalization of all @CreateRepresentationFromRepresentationCreationDescription@ classes (iof plug-ins sirius.diagram, sirius.table.ui, sirius.tree.ui).
h4. Changes in @org.eclipse.sirius.table@
diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/CreateRepresentationFromRepresentationCreationDescription.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/CreateRepresentationFromRepresentationCreationDescription.java
index 59d2df88d5..92b3ddc41e 100644
--- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/CreateRepresentationFromRepresentationCreationDescription.java
+++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/CreateRepresentationFromRepresentationCreationDescription.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 THALES GLOBAL SERVICES.
+ * Copyright (c) 2008, 2013 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
@@ -10,51 +10,24 @@
*******************************************************************************/
package org.eclipse.sirius.table.ui.tools.internal.editor.action;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
-import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.sirius.business.api.dialect.command.CreateRepresentationCommand;
-import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager;
-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.StringUtil;
-import org.eclipse.sirius.common.ui.SiriusTransPlugin;
+import org.eclipse.sirius.common.tools.api.util.Option;
+import org.eclipse.sirius.common.tools.api.util.Options;
import org.eclipse.sirius.table.tools.api.command.ITableCommandFactory;
-import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
-import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
-import org.eclipse.sirius.ui.tools.api.image.ImagesPath;
+import org.eclipse.sirius.ui.tools.api.actions.AbstractCreateRepresentationFromRepresentationCreationDescription;
+import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationElement;
-import org.eclipse.sirius.viewpoint.description.DescriptionPackage;
-import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
-import org.eclipse.sirius.viewpoint.description.tool.ToolPackage;
/**
* Create a new Representation from a {@link RepresentationCreationDescription}.
*
* @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a>
- * @deprecated
*/
-@Deprecated
-public class CreateRepresentationFromRepresentationCreationDescription extends Action {
-
- private static final AdapterFactory ADAPTER_FACTORY = DialectUIManager.INSTANCE.createAdapterFactory();
-
- private final RepresentationCreationDescription desc;
-
- private final DRepresentationElement target;
-
- private final TransactionalEditingDomain editingDomain;
-
- private final ITableCommandFactory tableCommandFactory;
+public class CreateRepresentationFromRepresentationCreationDescription extends AbstractCreateRepresentationFromRepresentationCreationDescription {
/**
* Build the action.
@@ -69,77 +42,19 @@ public class CreateRepresentationFromRepresentationCreationDescription extends A
* @param tableCommandFactory
* The {@link ITableCommandFactory}.
*/
- public CreateRepresentationFromRepresentationCreationDescription(final RepresentationCreationDescription desc, final DRepresentationElement target, final TransactionalEditingDomain editingDomain,
- final ITableCommandFactory tableCommandFactory) {
- this.desc = desc;
- this.target = target;
- this.editingDomain = editingDomain;
- ImageDescriptor imageDescriptor = null;
- RepresentationDescription representationDescription = desc.getRepresentationDescription();
- if (representationDescription != null) {
- // Search the icon for this representation description
- final IItemLabelProvider labelProvider = (IItemLabelProvider) CreateRepresentationFromRepresentationCreationDescription.ADAPTER_FACTORY.adapt(representationDescription,
- IItemLabelProvider.class);
- if (labelProvider != null) {
- imageDescriptor = ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(representationDescription));
- }
- }
- if (imageDescriptor != null) {
- setImageDescriptor(imageDescriptor);
- } else {
- setImageDescriptor(SiriusTransPlugin.getBundledImageDescriptor(ImagesPath.CREATE_VIEW_ICON));
- }
- this.tableCommandFactory = tableCommandFactory;
- }
-
- @Override
- public String getText() {
- return new StringBuffer("New detail : ").append(desc.getName()).toString();
+ public CreateRepresentationFromRepresentationCreationDescription(RepresentationCreationDescription desc, DRepresentationElement target, TransactionalEditingDomain editingDomain,
+ ITableCommandFactory tableCommandFactory) {
+ super(desc, target, editingDomain, tableCommandFactory);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.Action#run()
- */
@Override
- public void run() {
+ protected Option<DRepresentation> executeCreationCommand(Option<Command> initialOperationCommand, CreateRepresentationCommand createRepresentationCommand) {
final CompoundCommand compoundCommand = new CompoundCommand();
-
- final IInterpreter interpreter = InterpreterUtil.getInterpreter(target.getTarget());
- // default name
- String name = "new " + desc.getName();
- if (!StringUtil.isEmpty(desc.getTitleExpression())) {
- try {
- name = interpreter.evaluateString(target.getTarget(), desc.getTitleExpression());
- } catch (final EvaluationException e) {
- RuntimeLoggerManager.INSTANCE.error(desc, ToolPackage.eINSTANCE.getRepresentationCreationDescription_TitleExpression(), e);
- }
- } else if (desc.getRepresentationDescription() != null && !StringUtil.isEmpty(desc.getRepresentationDescription().getTitleExpression())) {
- try {
- name = interpreter.evaluateString(target.getTarget(), desc.getRepresentationDescription().getTitleExpression());
- } catch (final EvaluationException e) {
- RuntimeLoggerManager.INSTANCE.error(desc.getRepresentationDescription(), DescriptionPackage.eINSTANCE.getRepresentationDescription_TitleExpression(), e);
- }
- }
-
- try {
- name = tableCommandFactory.getUserInterfaceCallBack().askForDetailName(name, desc.getRepresentationDescription().getEndUserDocumentation());
-
- if (desc.getInitialOperation() != null && desc.getInitialOperation().getFirstModelOperations() != null) {
- final Command emfCommandTool = tableCommandFactory.buildDoExecuteDetailsOperation(target, desc, name);
- compoundCommand.append(emfCommandTool);
- }
- final CreateRepresentationCommand command = tableCommandFactory.buildCreateRepresentationFromDescription(desc, target, name);
- compoundCommand.append(command);
- editingDomain.getCommandStack().execute(compoundCommand);
-
- final Session session = SessionManager.INSTANCE.getSession(target.getTarget());
-
- DialectUIManager.INSTANCE.openEditor(session, command.getCreatedRepresentation(), new NullProgressMonitor());
- } catch (final InterruptedException e) {
- // the user pressed "cancel", let's do nothing
+ if (initialOperationCommand.some()) {
+ compoundCommand.append(initialOperationCommand.get());
}
-
+ compoundCommand.append(createRepresentationCommand);
+ getEditingDomain().getCommandStack().execute(compoundCommand);
+ return Options.newSome(createRepresentationCommand.getCreatedRepresentation());
}
}
diff --git a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/api/command/ITableCommandFactory.java b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/api/command/ITableCommandFactory.java
index d0db4e3003..9f530dc2f4 100644
--- a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/api/command/ITableCommandFactory.java
+++ b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/api/command/ITableCommandFactory.java
@@ -12,6 +12,7 @@ package org.eclipse.sirius.table.tools.api.command;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor;
import org.eclipse.sirius.table.metamodel.table.DCell;
import org.eclipse.sirius.table.metamodel.table.DLine;
import org.eclipse.sirius.table.metamodel.table.DTable;
@@ -20,10 +21,6 @@ import org.eclipse.sirius.table.metamodel.table.DTargetColumn;
import org.eclipse.sirius.table.metamodel.table.LineContainer;
import org.eclipse.sirius.table.metamodel.table.description.CreateTool;
import org.eclipse.sirius.tools.api.command.ICommandFactory;
-import org.eclipse.sirius.tools.api.command.ui.UICallBack;
-import org.eclipse.sirius.viewpoint.DSemanticDecorator;
-import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
-import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor;
/**
* Describes the contract of the table command factory.
@@ -159,25 +156,4 @@ public interface ITableCommandFactory extends ICommandFactory {
* @return a command able to clear the values of an instance feature
*/
Command buildClearValue(final EObject instance, final String name);
-
- /**
- * Create a command that is able to execute the operations of a
- * {@link RepresentationCreationDescription}.
- *
- * @param target
- * the target element.
- * @param desc
- * the operations.
- * @param newRepresentationName
- * the name of the new Representation
- * @return the created command.
- */
- Command buildDoExecuteDetailsOperation(DSemanticDecorator target, RepresentationCreationDescription desc, String newRepresentationName);
-
- /**
- * Return the UI call back to use.
- *
- * @return the UI call back to use
- */
- UICallBack getUserInterfaceCallBack();
}
diff --git a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/internal/command/TableCommandFactory.java b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/internal/command/TableCommandFactory.java
index 0c9efd8172..71d2908030 100644
--- a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/internal/command/TableCommandFactory.java
+++ b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/tools/internal/command/TableCommandFactory.java
@@ -70,7 +70,6 @@ import org.eclipse.sirius.tools.api.command.DCommand;
import org.eclipse.sirius.tools.api.command.InvalidPermissionCommand;
import org.eclipse.sirius.tools.api.command.NoNullResourceCommand;
import org.eclipse.sirius.tools.api.command.SiriusCommand;
-import org.eclipse.sirius.tools.api.command.ui.UICallBack;
import org.eclipse.sirius.tools.api.interpreter.IInterpreterMessages;
import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
@@ -448,15 +447,6 @@ public class TableCommandFactory extends AbstractCommandFactory implements ITabl
return result;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.table.tools.api.command.ITableCommandFactory#getUserInterfaceCallBack()
- */
- public UICallBack getUserInterfaceCallBack() {
- return this.uiCallBack;
- }
-
private Set<EObject> addSemanticElementsToDestroy(final DSemanticDecorator element, final Set<EObject> elementsToDestroy) {
EObject semantic = null;
if (element instanceof DLine) {
diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/CreateRepresentationFromRepresentationCreationDescription.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/CreateRepresentationFromRepresentationCreationDescription.java
index 2616772aef..45c5aa42c7 100644
--- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/CreateRepresentationFromRepresentationCreationDescription.java
+++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/CreateRepresentationFromRepresentationCreationDescription.java
@@ -10,49 +10,24 @@
*******************************************************************************/
package org.eclipse.sirius.tree.ui.tools.internal.editor.actions;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
-import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.sirius.business.api.dialect.command.CreateRepresentationCommand;
-import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager;
-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.StringUtil;
-import org.eclipse.sirius.common.ui.SiriusTransPlugin;
-import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
+import org.eclipse.sirius.common.tools.api.util.Option;
+import org.eclipse.sirius.common.tools.api.util.Options;
import org.eclipse.sirius.tree.business.api.command.ITreeCommandFactory;
-import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
-import org.eclipse.sirius.ui.tools.api.image.ImagesPath;
+import org.eclipse.sirius.ui.tools.api.actions.AbstractCreateRepresentationFromRepresentationCreationDescription;
+import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationElement;
-import org.eclipse.sirius.viewpoint.description.DescriptionPackage;
-import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
-import org.eclipse.sirius.viewpoint.description.tool.ToolPackage;
/**
* Create a new Representation from a {@link RepresentationCreationDescription}.
*
* @author <a href="mailto:nathalie.lepine@obeo.fr">Nathalie Lepine</a>
*/
-public class CreateRepresentationFromRepresentationCreationDescription extends Action {
-
- private static final AdapterFactory ADAPTER_FACTORY = DialectUIManager.INSTANCE.createAdapterFactory();
-
- private final RepresentationCreationDescription desc;
-
- private final DRepresentationElement target;
-
- private final TransactionalEditingDomain editingDomain;
-
- private final ITreeCommandFactory treeCommandFactory;
+public class CreateRepresentationFromRepresentationCreationDescription extends AbstractCreateRepresentationFromRepresentationCreationDescription {
/**
* Build the action.
@@ -64,80 +39,22 @@ public class CreateRepresentationFromRepresentationCreationDescription extends A
* representation.
* @param editingDomain
* current {@link org.eclipse.emf.edit.domain.EditingDomain}.
- * @param tableCommandFactory
- * The {@link ITableCommandFactory}.
+ * @param treeCommandFactory
+ * The {@link ITreeCommandFactory}.
*/
- public CreateRepresentationFromRepresentationCreationDescription(final RepresentationCreationDescription desc, final DRepresentationElement target, final TransactionalEditingDomain editingDomain,
- final ITreeCommandFactory tableCommandFactory) {
- this.desc = desc;
- this.target = target;
- this.editingDomain = editingDomain;
- ImageDescriptor imageDescriptor = null;
- RepresentationDescription representationDescription = desc.getRepresentationDescription();
- if (representationDescription != null) {
- // Search the icon for this representation description
- final IItemLabelProvider labelProvider = (IItemLabelProvider) CreateRepresentationFromRepresentationCreationDescription.ADAPTER_FACTORY.adapt(representationDescription,
- IItemLabelProvider.class);
- if (labelProvider != null) {
- imageDescriptor = ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(representationDescription));
- }
- }
- if (imageDescriptor != null) {
- setImageDescriptor(imageDescriptor);
- } else {
- setImageDescriptor(SiriusTransPlugin.getBundledImageDescriptor(ImagesPath.CREATE_VIEW_ICON));
- }
- this.treeCommandFactory = tableCommandFactory;
- }
-
- @Override
- public String getText() {
- return new StringBuffer("New detail : ").append(desc.getName()).toString();
+ public CreateRepresentationFromRepresentationCreationDescription(RepresentationCreationDescription desc, DRepresentationElement target, TransactionalEditingDomain editingDomain,
+ ITreeCommandFactory treeCommandFactory) {
+ super(desc, target, editingDomain, treeCommandFactory);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.Action#run()
- */
@Override
- public void run() {
+ protected Option<DRepresentation> executeCreationCommand(Option<Command> initialOperationCommand, CreateRepresentationCommand createRepresentationCommand) {
final CompoundCommand compoundCommand = new CompoundCommand();
-
- final IInterpreter interpreter = InterpreterUtil.getInterpreter(target.getTarget());
- // default name
- String name = "new " + desc.getName();
- if (!StringUtil.isEmpty(desc.getTitleExpression())) {
- try {
- name = interpreter.evaluateString(target.getTarget(), desc.getTitleExpression());
- } catch (final EvaluationException e) {
- RuntimeLoggerManager.INSTANCE.error(desc, ToolPackage.eINSTANCE.getRepresentationCreationDescription_TitleExpression(), e);
- }
- } else if (desc.getRepresentationDescription() != null && !StringUtil.isEmpty(desc.getRepresentationDescription().getTitleExpression())) {
- try {
- name = interpreter.evaluateString(target.getTarget(), desc.getRepresentationDescription().getTitleExpression());
- } catch (final EvaluationException e) {
- RuntimeLoggerManager.INSTANCE.error(desc.getRepresentationDescription(), DescriptionPackage.eINSTANCE.getRepresentationDescription_TitleExpression(), e);
- }
- }
-
- try {
- name = treeCommandFactory.getUserInterfaceCallBack().askForDetailName(name, desc.getRepresentationDescription().getEndUserDocumentation());
-
- if (desc.getInitialOperation() != null && desc.getInitialOperation().getFirstModelOperations() != null) {
- final Command emfCommandTool = treeCommandFactory.buildDoExecuteDetailsOperation(target, desc, name);
- compoundCommand.append(emfCommandTool);
- }
- final CreateRepresentationCommand command = treeCommandFactory.buildCreateRepresentationFromDescription(desc, target, name);
- compoundCommand.append(command);
- editingDomain.getCommandStack().execute(compoundCommand);
-
- final Session session = SessionManager.INSTANCE.getSession(target.getTarget());
-
- DialectUIManager.INSTANCE.openEditor(session, command.getCreatedRepresentation(), new NullProgressMonitor());
- } catch (final InterruptedException e) {
- // the user pressed "cancel", let's do nothing
+ if (initialOperationCommand.some()) {
+ compoundCommand.append(initialOperationCommand.get());
}
-
+ compoundCommand.append(createRepresentationCommand);
+ getEditingDomain().getCommandStack().execute(compoundCommand);
+ return Options.newSome(createRepresentationCommand.getCreatedRepresentation());
}
}
diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/command/ITreeCommandFactory.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/command/ITreeCommandFactory.java
index 3273acba6f..671064a6cd 100644
--- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/command/ITreeCommandFactory.java
+++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/api/command/ITreeCommandFactory.java
@@ -14,8 +14,8 @@ import java.util.Collection;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor;
import org.eclipse.sirius.tools.api.command.ICommandFactory;
-import org.eclipse.sirius.tools.api.command.ui.UICallBack;
import org.eclipse.sirius.tools.api.ui.IExternalJavaAction;
import org.eclipse.sirius.tree.DTreeElement;
import org.eclipse.sirius.tree.DTreeItem;
@@ -23,11 +23,8 @@ import org.eclipse.sirius.tree.DTreeItemContainer;
import org.eclipse.sirius.tree.description.TreeItemContainerDropTool;
import org.eclipse.sirius.tree.description.TreeItemCreationTool;
import org.eclipse.sirius.tree.description.TreeItemEditionTool;
-import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.description.tool.ExternalJavaAction;
import org.eclipse.sirius.viewpoint.description.tool.OperationAction;
-import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
-import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor;
/**
* Describes the contract of the table command factory.
@@ -151,27 +148,6 @@ public interface ITreeCommandFactory extends ICommandFactory {
// Command buildClearValue(final EObject instance, final String name);
/**
- * Create a command that is able to execute the operations of a
- * {@link RepresentationCreationDescription}.
- *
- * @param target
- * the target element.
- * @param desc
- * the operations.
- * @param newRepresentationName
- * the name of the new Representation
- * @return the created command.
- */
- Command buildDoExecuteDetailsOperation(DSemanticDecorator target, RepresentationCreationDescription desc, String newRepresentationName);
-
- /**
- * Return the UI call back to use.
- *
- * @return the UI call back to use
- */
- UICallBack getUserInterfaceCallBack();
-
- /**
* Build a direct edit label command using the corresponding tool
* description.
*
@@ -233,8 +209,7 @@ public interface ITreeCommandFactory extends ICommandFactory {
* @param javaAction
* the java action to execute.
* @return a command that is able to execute the operations of
- * {@link org.eclipse.sirius.description.tool.JavaActionMenuItem}
- * .
+ * {@link org.eclipse.sirius.description.tool.JavaActionMenuItem} .
*/
Command buildJavaActionFromTool(ExternalJavaAction javaActionItem, DTreeItem selectedItem, IExternalJavaAction javaAction);
}
diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/TreeCommandFactory.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/TreeCommandFactory.java
index d25e1933d6..422ec7047e 100644
--- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/TreeCommandFactory.java
+++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/tools/internal/command/TreeCommandFactory.java
@@ -48,7 +48,6 @@ import org.eclipse.sirius.tools.api.command.DCommand;
import org.eclipse.sirius.tools.api.command.InvalidPermissionCommand;
import org.eclipse.sirius.tools.api.command.NoNullResourceCommand;
import org.eclipse.sirius.tools.api.command.SiriusCommand;
-import org.eclipse.sirius.tools.api.command.ui.UICallBack;
import org.eclipse.sirius.tools.api.command.view.JavaActionFromToolCommand;
import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
import org.eclipse.sirius.tools.api.ui.IExternalJavaAction;
@@ -103,15 +102,6 @@ public class TreeCommandFactory extends AbstractCommandFactory implements ITreeC
/**
* {@inheritDoc}
- *
- * @see org.eclipse.sirius.tree.tools.api.command.ITreeCommandFactory#getUserInterfaceCallBack()
- */
- public UICallBack getUserInterfaceCallBack() {
- return this.uiCallBack;
- }
-
- /**
- * {@inheritDoc}
*/
public void setAutoRefreshDTree(boolean autoRefreshDTree) {
// TODO Feature not implemented.
diff --git a/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF
index 428ca23502..ab22628b6f 100644
--- a/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF
@@ -7,8 +7,9 @@ Bundle-ClassPath: .
Bundle-Activator: org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin$Implementation
Bundle-Vendor: %providerName
Bundle-Localization: plugin
-Export-Package: org.eclipse.sirius.ui.business.api.action,
- org.eclipse.sirius.ui.business.api.delete,
+Export-Package: org.eclipse.sirius.description.contribution.provider,
+ org.eclipse.sirius.ui.business.api.action,
+ org.eclipse.sirius.ui.business.api.delete,
org.eclipse.sirius.ui.business.api.descriptor,
org.eclipse.sirius.ui.business.api.dialect,
org.eclipse.sirius.ui.business.api.dialect.marker,
@@ -32,6 +33,7 @@ Export-Package: org.eclipse.sirius.ui.business.api.action,
org.eclipse.sirius.ui.business.internal.session.factory;x-internal:=true,
org.eclipse.sirius.ui.business.internal.template;x-internal:=true,
org.eclipse.sirius.ui.tools.api,
+ org.eclipse.sirius.ui.tools.api.actions,
org.eclipse.sirius.ui.tools.api.actions.analysis,
org.eclipse.sirius.ui.tools.api.actions.export,
org.eclipse.sirius.ui.tools.api.assist,
@@ -87,7 +89,6 @@ Export-Package: org.eclipse.sirius.ui.business.api.action,
org.eclipse.sirius.ui.tools.internal.wizards.pages;x-internal:=true,
org.eclipse.sirius.viewpoint.description.audit.provider,
org.eclipse.sirius.viewpoint.description.concern.provider,
- org.eclipse.sirius.description.contribution.provider,
org.eclipse.sirius.viewpoint.description.filter.provider,
org.eclipse.sirius.viewpoint.description.provider,
org.eclipse.sirius.viewpoint.description.style.provider,
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/actions/AbstractCreateRepresentationFromRepresentationCreationDescription.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/actions/AbstractCreateRepresentationFromRepresentationCreationDescription.java
new file mode 100644
index 0000000000..f73761f938
--- /dev/null
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/actions/AbstractCreateRepresentationFromRepresentationCreationDescription.java
@@ -0,0 +1,244 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 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.ui.tools.api.actions;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.sirius.business.api.dialect.command.CreateRepresentationCommand;
+import org.eclipse.sirius.business.api.logger.RuntimeLoggerInterpreter;
+import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager;
+import org.eclipse.sirius.business.api.query.IdentifiedElementQuery;
+import org.eclipse.sirius.business.api.session.SessionManager;
+import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
+import org.eclipse.sirius.common.tools.api.util.Option;
+import org.eclipse.sirius.common.tools.api.util.Options;
+import org.eclipse.sirius.common.tools.api.util.StringUtil;
+import org.eclipse.sirius.common.ui.SiriusTransPlugin;
+import org.eclipse.sirius.tools.api.command.ICommandFactory;
+import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
+import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
+import org.eclipse.sirius.ui.tools.api.image.ImagesPath;
+import org.eclipse.sirius.viewpoint.DRepresentation;
+import org.eclipse.sirius.viewpoint.DRepresentationElement;
+import org.eclipse.sirius.viewpoint.DSemanticDecorator;
+import org.eclipse.sirius.viewpoint.description.DescriptionPackage;
+import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
+import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
+import org.eclipse.sirius.viewpoint.description.tool.ToolPackage;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Create a new Representation from a {@link RepresentationCreationDescription}.
+ *
+ * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a>
+ */
+public abstract class AbstractCreateRepresentationFromRepresentationCreationDescription extends Action {
+
+ private static final AdapterFactory ADAPTER_FACTORY = DialectUIManager.INSTANCE.createAdapterFactory();
+
+ private final RepresentationCreationDescription desc;
+
+ private final DRepresentationElement target;
+
+ private final TransactionalEditingDomain editingDomain;
+
+ private final ICommandFactory commandFactory;
+
+ /**
+ * Build the action.
+ *
+ * @param desc
+ * {@link RepresentationCreationDescription} to use.
+ * @param target
+ * element on which the user requested the creation of a new
+ * representation.
+ * @param editingDomain
+ * current {@link org.eclipse.emf.edit.domain.EditingDomain}.
+ * @param commandFactory
+ * The {@link ICommandFactory}.
+ */
+ public AbstractCreateRepresentationFromRepresentationCreationDescription(final RepresentationCreationDescription desc, final DRepresentationElement target,
+ final TransactionalEditingDomain editingDomain, final ICommandFactory commandFactory) {
+ this.desc = desc;
+ this.target = target;
+ this.editingDomain = editingDomain;
+ ImageDescriptor imageDescriptor = null;
+ RepresentationDescription representationDescription = desc.getRepresentationDescription();
+ if (representationDescription != null) {
+ // Search the icon for this representation description
+ final IItemLabelProvider labelProvider = (IItemLabelProvider) AbstractCreateRepresentationFromRepresentationCreationDescription.ADAPTER_FACTORY.adapt(representationDescription,
+ IItemLabelProvider.class);
+ if (labelProvider != null) {
+ imageDescriptor = ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(representationDescription));
+ }
+ }
+ if (imageDescriptor != null) {
+ setImageDescriptor(imageDescriptor);
+ } else {
+ setImageDescriptor(SiriusTransPlugin.getBundledImageDescriptor(ImagesPath.CREATE_VIEW_ICON));
+ }
+ this.commandFactory = commandFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.action.Action#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+
+ boolean isEnabled = super.isEnabled();
+ if (isEnabled) {
+ if (desc.getRepresentationDescription() == null) {
+ isEnabled = false;
+ } else {
+ final CreateRepresentationCommand command = commandFactory.buildCreateRepresentationFromDescription(desc, target, "");
+ return command.canExecute();
+ }
+ }
+ return isEnabled;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public String getText() {
+ final IdentifiedElementQuery query = new IdentifiedElementQuery(desc);
+ return new StringBuffer("New detail : ").append(query.getLabel()).toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ doCreateRepresentation();
+ }
+
+ private void doCreateRepresentation() {
+
+ final IdentifiedElementQuery query = new IdentifiedElementQuery(desc);
+
+ // default name
+ String name = "new " + query.getLabel();
+ final String computedName = computeName(target);
+ if (computedName != null) {
+ name = computedName;
+ }
+
+ try {
+ name = commandFactory.getUserInterfaceCallBack().askForDetailName(name, desc.getRepresentationDescription().getEndUserDocumentation());
+ } catch (final InterruptedException e) {
+ // the user pressed "cancel", we should exit
+ return;
+ }
+
+ Option<DRepresentation> optionalCreatedRepresentation = executeCreationCommand(getInitialOperationCommand(name), getCreateRepresentationCommand(name));
+ if (target != null) {
+ if (!optionalCreatedRepresentation.some()) {
+ final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ MessageDialog.openWarning(shell, "Error creating the representation", "An error occured when trying to create the representation.\nPlease check the representation specification.");
+ } else {
+ DialectUIManager.INSTANCE.openEditor(SessionManager.INSTANCE.getSession(target.getTarget()), optionalCreatedRepresentation.get(), new NullProgressMonitor());
+ }
+ }
+ }
+
+ /**
+ * Creates the new representation and returns it.
+ *
+ * @param initialOperationCommand
+ * Optional command that executes all the initial operations
+ * @param createRepresentationCommand
+ * Command that creates the new representation.
+ * @return The created representation
+ */
+ protected abstract Option<DRepresentation> executeCreationCommand(Option<Command> initialOperationCommand, CreateRepresentationCommand createRepresentationCommand);
+
+ /**
+ * Return the command that executes all the initial operations. This command
+ * can be null if there is not initial operation.
+ *
+ * @param defaultRepresentationName
+ * The default representation name of the new representation.
+ * @return an optional command that executes all the initial operations.
+ */
+ protected Option<Command> getInitialOperationCommand(String defaultRepresentationName) {
+ if (isInitialOperation()) {
+ return Options.newSome(commandFactory.buildDoExecuteDetailsOperation(target, desc, defaultRepresentationName));
+ }
+ return Options.newNone();
+ }
+
+ /**
+ * Return the command that creates the new representation.
+ *
+ * @param defaultRepresentationName
+ * The default representation name of the new representation.
+ * @return a command that creates the new representation.
+ */
+ protected CreateRepresentationCommand getCreateRepresentationCommand(String defaultRepresentationName) {
+ return commandFactory.buildCreateRepresentationFromDescription(desc, target, defaultRepresentationName);
+ }
+
+ /**
+ * Return the editing domain.
+ *
+ * @return the editing domain.
+ */
+ protected TransactionalEditingDomain getEditingDomain() {
+ return editingDomain;
+ }
+
+ /**
+ * Return the target.
+ *
+ * @return the target
+ */
+ protected DRepresentationElement getTarget() {
+ return target;
+ }
+
+ protected boolean isInitialOperation() {
+ return desc.getInitialOperation() != null && desc.getInitialOperation().getFirstModelOperations() != null;
+ }
+
+ private String computeName(final DSemanticDecorator decorator) {
+
+ final IInterpreter interpreter = InterpreterUtil.getInterpreter(decorator.getTarget());
+ final RuntimeLoggerInterpreter safeInterpreter = RuntimeLoggerManager.INSTANCE.decorate(interpreter);
+
+ String computedName = null;
+
+ if (!StringUtil.isEmpty(desc.getTitleExpression())) {
+ computedName = safeInterpreter.evaluateString(decorator.getTarget(), desc, ToolPackage.eINSTANCE.getRepresentationCreationDescription_TitleExpression());
+ } else if (desc.getRepresentationDescription() != null && !StringUtil.isEmpty(desc.getRepresentationDescription().getTitleExpression())) {
+ computedName = safeInterpreter.evaluateString(decorator.getTarget(), desc.getRepresentationDescription(), DescriptionPackage.eINSTANCE.getRepresentationDescription_TitleExpression());
+ }
+
+ return computedName;
+ }
+
+}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/AbstractCommandFactory.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/AbstractCommandFactory.java
index 3df02f70be..afceaf9a87 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/AbstractCommandFactory.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/AbstractCommandFactory.java
@@ -66,7 +66,8 @@ public abstract class AbstractCommandFactory implements ICommandFactory {
* {@inheritDoc}
*
* @see org.eclipse.sirius.tools.api.command.ICommandFactory#buildCreateRepresentationFromDescription(org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription,
- * org.eclipse.sirius.viewpoint.DRepresentationElement, java.lang.String)
+ * org.eclipse.sirius.viewpoint.DRepresentationElement,
+ * java.lang.String)
*/
public CreateRepresentationCommand buildCreateRepresentationFromDescription(final RepresentationCreationDescription desc, final DRepresentationElement element, final String newDiagramName) {
final Session session = SessionManager.INSTANCE.getSession(element.getTarget());
@@ -86,6 +87,15 @@ public abstract class AbstractCommandFactory implements ICommandFactory {
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.sirius.tools.api.command.ICommandFactory#getUserInterfaceCallBack()
+ */
+ public UICallBack getUserInterfaceCallBack() {
+ return this.uiCallBack;
+ }
+
+ /**
* Append the refresh representation task if necessary. The refresh task is
* appended if the <code>toolDescription.isForceRefresh()</code> is
* <code>true</code> or if {@link #autoRefreshView} is <code>true</code>.
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ICommandFactory.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ICommandFactory.java
index 53ea614c2b..e1b039cf61 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ICommandFactory.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ICommandFactory.java
@@ -10,9 +10,11 @@
*******************************************************************************/
package org.eclipse.sirius.tools.api.command;
+import org.eclipse.emf.common.command.Command;
import org.eclipse.sirius.business.api.dialect.command.CreateRepresentationCommand;
import org.eclipse.sirius.tools.api.command.ui.UICallBack;
import org.eclipse.sirius.viewpoint.DRepresentationElement;
+import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
/**
@@ -37,10 +39,31 @@ public interface ICommandFactory {
CreateRepresentationCommand buildCreateRepresentationFromDescription(RepresentationCreationDescription desc, DRepresentationElement element, String newRepresentationName);
/**
+ * Create a command that is able to execute the operations of a
+ * {@link RepresentationCreationDescription}.
+ *
+ * @param target
+ * the target element.
+ * @param desc
+ * the operations.
+ * @param newRepresentationName
+ * the name of the new Representation
+ * @return the created command.
+ */
+ Command buildDoExecuteDetailsOperation(DSemanticDecorator target, RepresentationCreationDescription desc, String newRepresentationName);
+
+ /**
* Defines the UI call back to use.
*
* @param newCB
* the new user interface call back.
*/
void setUserInterfaceCallBack(UICallBack newCB);
+
+ /**
+ * Return the UI call back to use.
+ *
+ * @return the UI call back to use
+ */
+ UICallBack getUserInterfaceCallBack();
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/IDiagramCommandFactory.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/IDiagramCommandFactory.java
index 6b894497a1..158b59c4c3 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/IDiagramCommandFactory.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/IDiagramCommandFactory.java
@@ -40,7 +40,6 @@ import org.eclipse.sirius.viewpoint.description.tool.OperationAction;
import org.eclipse.sirius.viewpoint.description.tool.PaneBasedSelectionWizardDescription;
import org.eclipse.sirius.viewpoint.description.tool.PasteDescription;
import org.eclipse.sirius.viewpoint.description.tool.ReconnectEdgeDescription;
-import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
import org.eclipse.sirius.viewpoint.description.tool.SelectionWizardDescription;
import org.eclipse.sirius.viewpoint.description.tool.ToolDescription;
import org.eclipse.sirius.viewpoint.description.validation.ValidationFix;
@@ -312,20 +311,6 @@ public interface IDiagramCommandFactory extends ICommandFactory {
Command buildCreateContainerCommandFromTool(DDiagramElementContainer nodeContainer, ContainerCreationDescription tool);
/**
- * Create a command that is able to execute the operations of a
- * {@link RepresentationCreationDescription}.
- *
- * @param target
- * the target element.
- * @param desc
- * the operations.
- * @param newRepresentationName
- * the name of the new Representation
- * @return the created command.
- */
- Command buildDoExecuteDetailsOperation(DSemanticDecorator target, RepresentationCreationDescription desc, String newRepresentationName);
-
- /**
* Create a command to delete a viewpoint.
*
* @param vp

Back to the top