Commit bfdceb4c authored by Romain Bioteau's avatar Romain Bioteau
Browse files

Fix invalid thread access

parent e3969357
......@@ -27,6 +27,8 @@ import org.bonitasoft.studio.diagram.custom.repository.DiagramFileStore;
import org.bonitasoft.studio.diagram.custom.repository.DiagramRepositoryStore;
import org.bonitasoft.studio.model.process.MainProcess;
import org.bonitasoft.studio.validation.i18n.Messages;
import org.bonitasoft.studio.validation.operation.BatchValidationOperation;
import org.bonitasoft.studio.validation.operation.OffscreenEditPartFactory;
import org.bonitasoft.studio.validation.ui.view.ValidationViewPart;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
......@@ -59,7 +61,7 @@ public class BatchValidationHandler extends AbstractHandler {
public Object execute(final ExecutionEvent event) throws ExecutionException {
if (PlatformUI.isWorkbenchRunning()) {
final Map<?, ?> parameters = event.getParameters();
final BatchValidationOperation validateOperation = new BatchValidationOperation();
final BatchValidationOperation validateOperation = new BatchValidationOperation(new OffscreenEditPartFactory());
if (parameters != null && !parameters.isEmpty()) {
String files = event.getParameter("diagrams");
if (files != null) {
......@@ -95,22 +97,20 @@ public class BatchValidationHandler extends AbstractHandler {
}
}
// if (!toValidate.isEmpty()) {
// final Resource eResource = toValidate.iterator().next().eResource();
// final IFile target = eResource != null ? WorkspaceSynchronizer.getFile(eResource) : null;
// if (target != null) {
// ProcessMarkerNavigationProvider.deleteMarkers(target);
// }
// }
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.run(true, false, validateOperation);
} catch (final InvocationTargetException e) {
BonitaStudioLog.error(e);
} catch (final InterruptedException e) {
BonitaStudioLog.error(e);
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.run(true, false, validateOperation);
} catch (final InvocationTargetException e) {
BonitaStudioLog.error(e);
} catch (final InterruptedException e) {
BonitaStudioLog.error(e);
}
}
});
Object showReport = parameters.get("showReport");
if (showReport == null) {
......
......@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.validation;
package org.bonitasoft.studio.validation.operation;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
......@@ -27,6 +27,7 @@ import org.bonitasoft.studio.model.form.Form;
import org.bonitasoft.studio.model.process.MainProcess;
import org.bonitasoft.studio.model.process.diagram.form.providers.ProcessMarkerNavigationProvider;
import org.bonitasoft.studio.model.process.diagram.part.ValidateAction;
import org.bonitasoft.studio.validation.ValidationPlugin;
import org.bonitasoft.studio.validation.i18n.Messages;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
......@@ -38,16 +39,11 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
......@@ -59,9 +55,12 @@ import org.eclipse.ui.PlatformUI;
public class BatchValidationOperation implements IRunnableWithProgress {
private final Map<Diagram, DiagramEditPart> diagramsToDiagramEditPart = new HashMap<Diagram, DiagramEditPart>();
private final List<Shell> toDispose = new ArrayList<Shell>();
private final List<IFile> fileProcessed = new ArrayList<IFile>(); //Avoid duplicate
private final org.bonitasoft.studio.validation.operation.OffscreenEditPartFactory offscreenEditPartFactory;
public BatchValidationOperation(final org.bonitasoft.studio.validation.operation.OffscreenEditPartFactory offscreenEditPartFactory) {
this.offscreenEditPartFactory = offscreenEditPartFactory;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
......@@ -86,8 +85,7 @@ public class BatchValidationOperation implements IRunnableWithProgress {
}
}
dispose();
offscreenEditPartFactory.dispose();
}
private void clearMarkers() {
......@@ -109,21 +107,6 @@ public class BatchValidationOperation implements IRunnableWithProgress {
}
}
protected boolean inUIThread() {
return Thread.currentThread() == Display.getDefault().getThread();
}
private void dispose() {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
for (final Shell s : toDispose) {
s.dispose();
}
}
});
}
private DiagramEditPart getDiagramEditPart(final Diagram d) {
final IWorkbenchPage activePage = getActivePage();
......@@ -138,7 +121,7 @@ public class BatchValidationOperation implements IRunnableWithProgress {
}
}
if (d != null && d.eResource() != null) {
return createOffscreenDiagramEditPart(d);
return offscreenEditPartFactory.createOffscreenDiagramEditPart(d);
}
return null;
}
......@@ -150,20 +133,6 @@ public class BatchValidationOperation implements IRunnableWithProgress {
return null;
}
private DiagramEditPart createOffscreenDiagramEditPart(final Diagram d) {
final ResourceSet rSet = d.eResource().getResourceSet();
if (GMFEditingDomainFactory.getInstance().getEditingDomain(rSet) == null) {
GMFEditingDomainFactory.getInstance().createEditingDomain(rSet);
}
final EObject element = d.getElement();
DiagramEditPart diagramEp = null;
if (element != null) {
final Shell shell = new Shell();
diagramEp = OffscreenEditPartFactory.getInstance().createDiagramEditPart(d, shell);
toDispose.add(shell);
}
return diagramEp;
}
public IStatus getResult() {
final MultiStatus result = new MultiStatus(ValidationPlugin.PLUGIN_ID, IStatus.OK, "", null);
......
/**
* Copyright (C) 2014 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
* 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/>.
*/
package org.bonitasoft.studio.validation.operation;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.swt.widgets.Shell;
/**
* @author Romain Bioteau
*
*/
public class OffscreenDiagramEditPartRunnable implements Runnable {
private DiagramEditPart diagramEp;
private final Diagram diagram;
private Shell shell;
public OffscreenDiagramEditPartRunnable(final Diagram diagram) {
this.diagram = diagram;
}
@Override
public void run() {
shell = new Shell();
diagramEp = org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory.getInstance().createDiagramEditPart(diagram, shell);
}
public DiagramEditPart getDiagramEditPart() {
return diagramEp;
}
public Shell getDisposable() {
return shell;
}
}
/**
* Copyright (C) 2014 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
* 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/>.
*/
package org.bonitasoft.studio.validation.operation;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* @author Romain Bioteau
*
*/
public class OffscreenEditPartFactory {
private final List<Shell> toDispose = new ArrayList<Shell>();
public DiagramEditPart createOffscreenDiagramEditPart(final Diagram d) {
final ResourceSet rSet = d.eResource().getResourceSet();
if (GMFEditingDomainFactory.getInstance().getEditingDomain(rSet) == null) {
GMFEditingDomainFactory.getInstance().createEditingDomain(rSet);
}
final EObject element = d.getElement();
if (element != null) {
final OffscreenDiagramEditPartRunnable runnable = new OffscreenDiagramEditPartRunnable(d);
if (inUIThread()) {
runnable.run();
} else {
Display.getDefault().syncExec(runnable);
}
toDispose.add(runnable.getDisposable());
return runnable.getDiagramEditPart();
}
return null;
}
protected boolean inUIThread() {
return Thread.currentThread() == Display.getDefault().getThread();
}
public void dispose() {
for (final Shell s : toDispose) {
if (inUIThread()) {
s.dispose();
} else {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
s.dispose();
}
});
}
}
toDispose.clear();
}
}
......@@ -20,8 +20,9 @@ package org.bonitasoft.studio.validation.ui.view;
import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.validation.BatchValidationOperation;
import org.bonitasoft.studio.validation.i18n.Messages;
import org.bonitasoft.studio.validation.operation.BatchValidationOperation;
import org.bonitasoft.studio.validation.operation.OffscreenEditPartFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
......@@ -69,7 +70,7 @@ public class ValidationViewAction extends Action {
*/
@Override
public void run() {
final BatchValidationOperation validateOperation = new BatchValidationOperation();
final BatchValidationOperation validateOperation = new BatchValidationOperation(new OffscreenEditPartFactory());
final IEditorPart ieditor = activePage.getActiveEditor();
if (ieditor instanceof DiagramEditor) {
......
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