use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class LinkRequirementsDialog method okPressed.
@Override
protected void okPressed() {
TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(this.selectedEObject);
RecordingCommand cmd = new // $NON-NLS-1$
RecordingCommand(// $NON-NLS-1$
editingDomain, // $NON-NLS-1$
"Link Requirements") {
protected void doExecute() {
// Clear all requirements links
for (Requirement requirement : RequirementService.getLinkedRequirements(LinkRequirementsDialog.this.selectedEObject)) {
requirement.getReferencedObject().remove(LinkRequirementsDialog.this.selectedEObject);
}
// Add new requirements links
for (Object checkedElement : LinkRequirementsDialog.this.checkboxTreeViewer.getCheckedElements()) {
if (checkedElement instanceof Requirement) {
Requirement requirement = (Requirement) checkedElement;
requirement.getReferencedObject().add(LinkRequirementsDialog.this.selectedEObject);
}
}
}
};
editingDomain.getCommandStack().execute(cmd);
super.okPressed();
}
use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class ProjectLibraryImporter method executeInRecordingCommand.
private void executeInRecordingCommand(final Session session, final Runnable runnable) {
final TransactionalEditingDomain ted = session.getTransactionalEditingDomain();
ted.getCommandStack().execute(new RecordingCommand(ted) {
@Override
protected void doExecute() {
runnable.run();
}
});
}
use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class UnlinkRequirementAction method run.
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
MessageDialog dialog = new MessageDialog(linksView.getSite().getShell(), // $NON-NLS-1$
RequirementLinkerPlugin.getInstance().getString("DeleteRequirementLinkAction_ConfirmDialog_title"), null, // $NON-NLS-1$
RequirementLinkerPlugin.getInstance().getString("DeleteRequirementLinkAction_ConfirmDialog_msg"), MessageDialog.CONFIRM, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 1);
boolean openConfirm = dialog.open() == Window.OK;
if (openConfirm) {
Session session = new EObjectQuery(linksView.getInput()).getSession();
if (session != null) {
TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
RecordingCommand cmd = new // $NON-NLS-1$
RecordingCommand(// $NON-NLS-1$
editingDomain, // $NON-NLS-1$
"UnLink Requirements") {
protected void doExecute() {
for (EObjectLink link : linksView.getSelectedEntries()) {
if (link instanceof RequirementLink) {
RequirementLink reqLink = (RequirementLink) link;
reqLink.getRequirement().getReferencedObject().remove(linksView.getInput());
}
}
}
};
editingDomain.getCommandStack().execute(cmd);
}
linksView.refresh();
}
}
use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class ManifestServices method executeInRecordingCommand.
private void executeInRecordingCommand(final Session session, final Runnable runnable) {
final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
final Command cmd = new RecordingCommand(domain) {
@Override
protected void doExecute() {
runnable.run();
}
};
domain.getCommandStack().execute(cmd);
}
use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class CreateStateMachineDiagramAction method run.
@Override
public void run() {
if (context == null) {
return;
}
final Shell shell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// TransactionalEditingDomain editingDomain = EditingDomainService.getInstance().getEditingDomainProvider().getEditingDomain();
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 State machine diagram", null);
int buttonPressed = dialog.open();
if (buttonPressed == InputDialog.OK) {
String diagramName = dialog.getValue();
// Create a new state machine instance
StateMachine statemachine = StateMachineFactory.eINSTANCE.createStateMachine();
statemachine.setName(diagramName);
context.getBehaviours().add(statemachine);
Collection<RepresentationDescription> descs = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), statemachine);
for (RepresentationDescription desc : descs) {
Viewpoint viewpoint = (Viewpoint) desc.eContainer();
if (StateMachineAnalysisContextMenuActionProvider.isStateMachineViewpoint(viewpoint) && "State Machine Diagram".equals(desc.getName())) {
// Create the new diagram
if (DialectManager.INSTANCE.canCreate(statemachine, desc)) {
DRepresentation stateMachineDiagram = DialectManager.INSTANCE.createRepresentation(diagramName, statemachine, desc, session, new NullProgressMonitor());
if (stateMachineDiagram != null) {
DialectUIManager.INSTANCE.openEditor(session, stateMachineDiagram, new NullProgressMonitor());
}
}
}
}
}
}
}
};
editingDomain.getCommandStack().execute(cmd);
}
Aggregations