Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » AbstractTransactionalCommand
AbstractTransactionalCommand [message #1114956] Mon, 23 September 2013 13:14 Go to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
Hi all,

i need to customize element via command. So i write;

IWorkbench workbench = PlatformUI.getWorkbench();
		Shell shell = workbench.getActiveWorkbenchWindow().getShell();
		FormCreationWizard wizard = new FormCreationWizard();
		wizard.init(workbench, new StructuredSelection());
		WizardDialog dialog = new WizardDialog(shell, wizard);
		dialog.create();

		if (dialog.open() != Window.OK) {
			// return null;
		} else {
			final ResourceSet resourceSet = wizard.getDiagram().getResourceSet();

			FormModel fm = (FormModel) resourceSet.getResources().get(1)
					.getContents().get(0);
			
			TransactionalEditingDomain editingDomain = TransactionUtil
					.getEditingDomain(fm);
				IFile affectedFile = WorkspaceSynchronizer.getFile(fm.eResource());
				
				new AbstractTransactionalCommand(
						editingDomain,
						"Set Values", affectedFile == null ? null : Collections.singletonList(affectedFile)) { //$NON-NLS-1$ 
					protected CommandResult doExecuteWithResult(
							IProgressMonitor monitor, IAdaptable info)
							throws ExecutionException {
						((FormModel) (resourceSet.getResources().get(1).getContents().get(0))).setContext(ct);
						((FormModel) (resourceSet.getResources().get(1).getContents().get(0))).setName("FormModel");
						
						return new CommandResult(new Status(IStatus.OK, CommonCorePlugin.getPluginId(),
								CommonCoreStatusCodes.OK, StringStatics.BLANK, null));
					}
				};
			}


but

((FormModel) (resourceSet.getResources().get(1).getContents().get(0))).setContext(ct);
((FormModel)(resourceSet.getResources().get(1).getContents().get(0))).setName("FormModel");


these are not executed. why don't understand.

anyone can help me ?

Regards

[Updated on: Mon, 23 September 2013 13:15]

Report message to a moderator

Re: AbstractTransactionalCommand [message #1114991 is a reply to message #1114956] Mon, 23 September 2013 14:02 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

did you try executing an EMF SetCommand? You can use SetCommand.create(...) to create one for execution.

Ralph
Re: AbstractTransactionalCommand [message #1115018 is a reply to message #1114991] Mon, 23 September 2013 14:33 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 243
Registered: January 2013
Location: Izmir
Senior Member
Hi,

i don't try and don't know how can i

can u explain more pls ?

Regards
Re: AbstractTransactionalCommand [message #1115546 is a reply to message #1115018] Tue, 24 September 2013 08:36 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

you create a SetCommannd with SetCommannd.create(...) get the command stack of the emf edit domain TransactionUtil helps here a lot and execute the command on this command stack.

Ralph
Re: AbstractTransactionalCommand [message #1115667 is a reply to message #1114956] Tue, 24 September 2013 12:09 Go to previous message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 703
Registered: July 2009
Senior Member
Le 23/09/2013 15:14, serhat gezgin a écrit :
> Hi all,
> i need to customize element via command. So i write;
>
>
> IWorkbench workbench = PlatformUI.getWorkbench();
> Shell shell = workbench.getActiveWorkbenchWindow().getShell();
> FormCreationWizard wizard = new FormCreationWizard();
> wizard.init(workbench, new StructuredSelection());
> WizardDialog dialog = new WizardDialog(shell, wizard);
> dialog.create();
>
> if (dialog.open() != Window.OK) {
> // return null;
> } else {
> final ResourceSet resourceSet =
> wizard.getDiagram().getResourceSet();
>
> FormModel fm = (FormModel) resourceSet.getResources().get(1)
> .getContents().get(0);
>
> TransactionalEditingDomain editingDomain = TransactionUtil
> .getEditingDomain(fm);
> IFile affectedFile =
> WorkspaceSynchronizer.getFile(fm.eResource());
>
> new AbstractTransactionalCommand(
> editingDomain,
> "Set Values", affectedFile == null ? null :
> Collections.singletonList(affectedFile)) { //$NON-NLS-1$
> protected CommandResult doExecuteWithResult(
> IProgressMonitor monitor, IAdaptable info)
> throws ExecutionException {
> ((FormModel)
> (resourceSet.getResources().get(1).getContents().get(0))).setContext(ct);
> ((FormModel)
> (resourceSet.getResources().get(1).getContents().get(0))).setName("FormModel");
>
>
> return new CommandResult(new Status(IStatus.OK,
> CommonCorePlugin.getPluginId(),
> CommonCoreStatusCodes.OK,
> StringStatics.BLANK, null));
> }
> };
> }
>
>
> these are not executed. why don't understand.

Your code creates an instance of (an anynymous subclass of)
AbstractTransactionalCommand, but this is not enough: you must request
explicitly that is is executed.

AbstractTransactionalCommand cmd = ...
editingDomain.getCommandStack().execute(cmd);


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:GMF Command
Next Topic:GMF navigator window
Goto Forum:
  


Current Time: Thu Apr 18 13:16:39 GMT 2024

Powered by FUDForum. Page generated in 0.02151 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top