Reusing ValidateAction in doSave [message #412013] |
Tue, 14 August 2007 15:29  |
Eclipse User |
|
|
|
When the user saves the current model or uses Save All from the File menu, I'd like to invoke validation of the model such that it shows the dialog of problems (or ok status) just as it does when the user right-clicks on a node in the tree and selects "Validate". I found the ValidateAction but the methods I think I would use on it are protected and the code itself depends on a selection. I guess I can get around this through some hacking (making a SelectionChangedEvent or some such and calling run()) but I thought there must be a better way to go about it.
What's the best way to get the validate behavior (dialog, problems view update, etc) without hacking into ValidateAction or dismantling the code there for use in my doSave method?
|
|
|
|
|
|
|
|
|
|
Re: Reusing ValidateAction in doSave [message #649844 is a reply to message #649660] |
Thu, 20 January 2011 12:50  |
Eclipse User |
|
|
|
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...
|
|
|
Powered by
FUDForum. Page generated in 0.08088 seconds