|
|
|
Re: Reusing ValidateAction in doSave [message #647264 is a reply to message #412031] |
Wed, 05 January 2011 13:12 |
Esin Karabacakoglu Messages: 11 Registered: May 2010 Location: Turkey |
Junior Member |
|
|
Hi all,
I would like to do the same in my EMF editor. I am using Eclipse Helios SR1 and EMF 2.6.0.
In doSave() method of the editor class which extends MultiPageEditorPart, I create an instance of the ValidateAction, set the requirements and call the run method. My code is below:
EObject root = resource.getContents().get(0);
ValidateAction validateAction = new ValidateAction();
validateAction.updateSelection(new StructuredSelection(root));
validateAction.setActiveWorkbenchPart(getSite().getPart());
validateAction.run();
But, get the NullPointerException from the first line of the run() method.
Root exception:
java.lang.NullPointerException
at org.eclipse.emf.edit.ui.action.ValidateAction.run(ValidateAc tion.java:170)
at psm.seagentontology.presentation.SeagentontologyEditor.valid ateEditor(SeagentontologyEditor.java:1899)
at psm.seagentontology.presentation.SeagentontologyEditor.acces s$2(SeagentontologyEditor.java:1894)
at psm.seagentontology.presentation.SeagentontologyEditor$18.ex ecute(SeagentontologyEditor.java:1524)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(Worksp aceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace. java:1975)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(Workspac eModifyOperation.java:118)
at org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:121)
I see that PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l() throws the exception because the activeWorkbenchWindow is null.
Do you have any idea about the problem?
[Updated on: Wed, 05 January 2011 13:14] Report message to a moderator
|
|
|
|
|
|
|
Re: Reusing ValidateAction in doSave [message #649844 is a reply to message #649660] |
Thu, 20 January 2011 17:50 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Esin,
Comments below.
Esin Karabacakoglu wrote:
> Yes, I do that in the doSave method of the editor class, and the
> active workbench cannot be found in the run method of the
> ValidateAction. You mean that it's strange, right?
Yes, it's not clear how it's possible for there not be an active
workbench window when you must be invoking save from the active
workbench window.
>
> Here's the code part in the doSave method:
>
> WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
> // This is the method that gets invoked when the operation runs.
> //
> @Override
> public void execute(IProgressMonitor monitor) {
> // Save the resources to the file system.
> //
> boolean first = true;
> for (Resource resource :
> editingDomain.getResourceSet().getResources()) {
> // validate the editor before saving...
> EObject root = resource.getContents().get(0);
> ValidateAction validateAction = new ValidateAction();
> validateAction.updateSelection(new
> StructuredSelection(root));
> validateAction.setActiveWorkbenchPart(getSite().getPart());
> validateAction.run();
> if ((first || !resource.getContents().isEmpty()
> || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) {
> try {
> long timeStamp = resource.getTimeStamp();
> resource.save(saveOptions);
> if (resource.getTimeStamp() != timeStamp) {
> savedResources.add(resource);
> }
> }
> catch (Exception exception) {
> resourceToDiagnosticMap.put(resource,
> analyzeResourceProblems(resource, exception));
> }
> first = false;
> }
> }
> }
> }
Worst comes to worst, you'll have to override the ValidateAction.run
method to get the shell in some other way...
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04754 seconds