Commit 1f9be658 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

fix(debug): Diagram is open twice after clicking on Debug button (#259)

* remove validation before opening wizard

fixes [BS-16131](https://bonitasoft.atlassian.net/browse/BS-16131)
parent 21895ebc
/**
* Copyright (C) 2011-2013 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.debug.command;
......@@ -45,65 +42,65 @@ import org.eclipse.ui.PlatformUI;
/**
* @author Romain Bioteau
*
*/
public class DebugProcessCommand extends AbstractHandler {
private boolean runSynchronously;
private MainProcess selectedProcess;
private boolean runSynchronously;
public DebugProcessCommand() {
this(false);
}
public DebugProcessCommand() {
this(false);
}
public DebugProcessCommand(boolean runSynchronously) {
this.runSynchronously = runSynchronously;
}
public DebugProcessCommand(boolean runSynchronously) {
this.runSynchronously = runSynchronously;
}
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
public Object execute(ExecutionEvent event) throws ExecutionException {
DebugProcessWizard wizard = new DebugProcessWizard(getSelectedProcess());
CustomWizardDialog dialog = new CustomWizardDialog(Display.getDefault().getActiveShell(), wizard,
Messages.DebugProcessButtonLabel);
if (dialog.open() == Dialog.OK) {
Set<EObject> exludedObject = wizard.getExcludedObjects();
new RunProcessCommand(exludedObject, runSynchronously).execute(event);
}
return null;
}
if (editorPart instanceof ProcessDiagramEditor ) {
org.bonitasoft.studio.model.process.diagram.part.ValidateAction.runValidation(((DiagramEditor)editorPart).getDiagram());
Object selection = ((IStructuredSelection)editorPart.getSite().getSelectionProvider().getSelection()).getFirstElement() ;
if(selection instanceof IGraphicalEditPart){
EObject semanticObject = ((IGraphicalEditPart)selection).resolveSemanticElement() ;
if(semanticObject instanceof Element){
selectedProcess = ModelHelper.getMainProcess(semanticObject) ;
}
}
}else if(editorPart instanceof FormDiagramEditor){
org.bonitasoft.studio.model.process.diagram.form.part.ValidateAction.runValidation(((DiagramEditor)editorPart).getDiagram());
DiagramEditPart formDiagram = ((DiagramDocumentEditor)editorPart).getDiagramEditPart();
Form form = (Form) formDiagram.resolveSemanticElement();
selectedProcess = ModelHelper.getMainProcess(form.eContainer());
}
DebugProcessWizard wizard = new DebugProcessWizard(selectedProcess) ;
CustomWizardDialog dialog = new CustomWizardDialog(Display.getDefault().getActiveShell(),wizard , Messages.DebugProcessButtonLabel) ;
if(dialog.open() == Dialog.OK){
Set<EObject> exludedObject = wizard.getExcludedObjects() ;
new RunProcessCommand(exludedObject, runSynchronously).execute(event) ;
}
return null;
}
private MainProcess getSelectedProcess() {
IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editorPart instanceof ProcessDiagramEditor) {
Object selection = ((IStructuredSelection) editorPart.getSite().getSelectionProvider().getSelection())
.getFirstElement();
if (selection instanceof IGraphicalEditPart) {
EObject semanticObject = ((IGraphicalEditPart) selection).resolveSemanticElement();
if (semanticObject instanceof Element) {
return ModelHelper.getMainProcess(semanticObject);
}
}
} else if (editorPart instanceof FormDiagramEditor) {
DiagramEditPart formDiagram = ((DiagramDocumentEditor) editorPart).getDiagramEditPart();
Form form = (Form) formDiagram.resolveSemanticElement();
return ModelHelper.getMainProcess(form.eContainer());
}
return null;
}
@Override
public boolean isEnabled() {
MainProcess process = (MainProcess) getProcessInEditor() ;
return process != null && process.isEnableValidation() ;
}
@Override
public boolean isEnabled() {
MainProcess process = (MainProcess) getProcessInEditor();
return process != null && process.isEnableValidation();
}
protected MainProcess getProcessInEditor() {
if( PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null){
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() ;
boolean isADiagram = editor != null && editor instanceof DiagramEditor;
if(isADiagram){
EObject root = ((DiagramEditor)editor).getDiagramEditPart().resolveSemanticElement() ;
MainProcess mainProc = ModelHelper.getMainProcess(root) ;
return mainProc ;
}
}
return null;
}
protected MainProcess getProcessInEditor() {
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
boolean isADiagram = editor != null && editor instanceof DiagramEditor;
if (isADiagram) {
EObject root = ((DiagramEditor) editor).getDiagramEditPart().resolveSemanticElement();
return ModelHelper.getMainProcess(root);
}
}
return null;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment