use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class AddAdditionalObjectsWizard method performFinish.
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
public boolean performFinish() {
final Collection<EObject> newAdditionalObjects1 = additionalResourcesPage.getAdditionalObjects1();
final Collection<EObject> newAdditionalObjects2 = additionalResourcesPage.getAdditionalObjects2();
final boolean hasBeenModified1 = hasBeenModified(scaffoldInfo.getLeftToRightAdditionalObjects(), newAdditionalObjects1);
final boolean hasBeenModified2 = hasBeenModified(scaffoldInfo.getRightToLeftAdditionalObjects(), newAdditionalObjects2);
if (hasBeenModified1 || hasBeenModified2) {
Session session = SessionManager.INSTANCE.getSession(scaffoldInfo);
TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
RecordingCommand updatingCmd = new RecordingCommand(editingDomain, "Updating additional objects") {
@Override
protected void doExecute() {
if (hasBeenModified1) {
ScaffoldType leftToRightScaffoldType = scaffoldInfo.getLeftToRightTransformationType();
scaffoldInfo.clearAdditionalObjectsForTransformation(leftToRightScaffoldType);
for (EObject newObject : newAdditionalObjects1) {
scaffoldInfo.addAdditionalObjectsForTransformation(newObject, leftToRightScaffoldType);
}
}
if (hasBeenModified2) {
ScaffoldType rightToleftScaffoldType = scaffoldInfo.getRightToLeftTransformationType();
scaffoldInfo.clearAdditionalObjectsForTransformation(rightToleftScaffoldType);
for (EObject newObject : newAdditionalObjects2) {
scaffoldInfo.addAdditionalObjectsForTransformation(newObject, rightToleftScaffoldType);
}
}
}
};
editingDomain.getCommandStack().execute(updatingCmd);
}
return true;
}
use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class UIConfigurationServices method saveUIConfiguration.
/**
* Save the configuration on the specified viewpoint analysis
* @param configuration Configuration to be saved
* @param analysis Viewpoint analysis concerned by the configuration
*/
public static void saveUIConfiguration(final UIConfiguration configuration, final DAnalysis analysis) {
if (!analysis.equals(configuration.getViewpointAnalysis())) {
configuration.setViewpointAnalysis(analysis);
}
final Session session = getSessionFromAnalysis(analysis);
if (session != null) {
final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(analysis);
final Command cmd = new RecordingCommand(domain) {
@Override
protected void doExecute() {
FeatureExtensionsManager.INSTANCE.saveFeatureExtensionData(GraalFeatureExtension.FEATURE_EXTENSION_NAME, session, analysis, configuration);
}
};
domain.getCommandStack().execute(cmd);
}
}
use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class CreateSequenceDiagramAction method run.
@Override
public void run() {
if (context == null) {
return;
}
final Shell shell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
Session session = SessionManager.INSTANCE.getSession(context);
if (session == null) {
return;
}
TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
if (editingDomain == null) {
return;
}
RecordingCommand cmd = new RecordingCommand(editingDomain, "Create Sequence diagram") {
protected void doExecute() {
// Get Session
Session session = SessionManager.INSTANCE.getSession(context);
if (session != null) {
// Ask the user to provide a name for the diagram
InputDialog dialog = new InputDialog(shell, "New representation", "New representation name", "new Sequence diagram", null);
int buttonPressed = dialog.open();
if (buttonPressed == InputDialog.OK) {
String diagramName = dialog.getValue();
// Create a new interaction instance
Interaction interaction = InteractionFactory.eINSTANCE.createInteraction();
interaction.setName(diagramName);
context.getBehaviours().add(interaction);
Collection<RepresentationDescription> descs = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), interaction);
for (RepresentationDescription desc : descs) {
Viewpoint viewpoint = (Viewpoint) desc.eContainer();
if (InteractionAnalysisContextMenuActionProvider.isInteractionViewpoint(viewpoint) && "Sequence Diagram".equals(desc.getName())) {
// Create the new diagram
if (DialectManager.INSTANCE.canCreate(interaction, desc)) {
DRepresentation sequenceDiagram = DialectManager.INSTANCE.createRepresentation(diagramName, interaction, desc, session, new NullProgressMonitor());
if (sequenceDiagram != null) {
DialectUIManager.INSTANCE.openEditor(session, sequenceDiagram, new NullProgressMonitor());
}
}
}
}
}
}
}
};
editingDomain.getCommandStack().execute(cmd);
}
use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class DeleteInteractionHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final Interaction interaction = extractInteraction(event);
if (interaction == null) {
return null;
}
boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Delete interaction", "Delete the selected interaction ?");
if (confirm) {
final Session session = SessionManager.INSTANCE.getSession(interaction);
final ModelAccessor modelAccessor = session.getModelAccessor();
final ECrossReferenceAdapter semanticCrossReferencer = session.getSemanticCrossReferencer();
TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain();
transactionalEditingDomain.getCommandStack().execute(new RecordingCommand(transactionalEditingDomain) {
@Override
protected void doExecute() {
// Retrieve associated representations
Collection<DRepresentationDescriptor> representationDescriptors = DialectManager.INSTANCE.getRepresentationDescriptors(interaction, session);
// Delete representations
for (DRepresentationDescriptor representationDescriptor : representationDescriptors) {
closeEditor(session, representationDescriptor.getRepresentation());
DialectManager.INSTANCE.deleteRepresentation(representationDescriptor, session);
}
// Delete interaction
modelAccessor.eDelete(interaction, semanticCrossReferencer);
}
});
}
return null;
}
use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class Activator method refreshDecorationsOnDiagram.
private void refreshDecorationsOnDiagram(final DSemanticDiagram diagram, final Session session) {
EList<AdditionalLayer> activatedTransientLayers = diagram.getActivatedTransientLayers();
for (final AdditionalLayer additionalLayer : activatedTransientLayers) {
// We want the "EObjectWithRequirement" layer
if (REQUIREMENTS_DECORATION_LAYER_NAME.equals(additionalLayer.getName())) {
TransactionalEditingDomain ted = session.getTransactionalEditingDomain();
ted.getCommandStack().execute(new RecordingCommand(ted) {
@Override
protected void doExecute() {
// Due to a bug in Sirius we have to remove the existing decorations before calling the update method
for (DDiagramElement diagElement : diagram.getDiagramElements()) {
Iterator<Decoration> it = diagElement.getTransientDecorations().iterator();
while (it.hasNext()) {
Decoration decoration = it.next();
if (REQUIREMENTS_DECORATION_NAME.equals(decoration.getDescription().getName())) {
it.remove();
}
}
}
List<Layer> layersToRefresh = Arrays.asList((Layer) additionalLayer);
new DecorationHelper(diagram).updateDecorations(layersToRefresh);
}
});
}
}
}
Aggregations