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

Refactor validation

Improve monitor
parent 08f91b2d
......@@ -489,8 +489,8 @@
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
<plugin
id="org.bonitasoft.studio.parameters"
download-size="0"
install-size="0"
......@@ -511,4 +511,11 @@
version="0.0.0"
unpack="false"/>
<plugin
id="org.bonitasoft.studio.validation.common"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>
......@@ -63,7 +63,9 @@ Require-Bundle: org.bonitasoft.studio.diagram,
org.mockito;bundle-version="1.9.5";resolution:=optional,
org.junit;bundle-version="4.11.0";resolution:=optional,
assertj-core;bundle-version="1.5.0";resolution:=optional,
org.bonitasoft.studio.tests-utils;bundle-version="6.4.1";resolution:=optional
org.bonitasoft.studio.tests-utils;bundle-version="6.4.1";resolution:=optional,
org.eclipse.debug.ui,
org.codehaus.groovy.eclipse.ui;bundle-version="2.9.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Import-Package: javax.annotation;version="1.1.0",
......
......@@ -482,6 +482,11 @@
id="org.bonitasoft.studio.application.command.rename"
name="Rename Command">
</command>
<command
defaultHandler="org.bonitasoft.studio.application.handler.ImportArtifactsFromZipHandler"
id="org.bonitasoft.studio.repository.importArtifacts"
name="import artifacts">
</command>
</extension>
<extension
point="org.eclipse.ui.views">
......
/**
* Copyright (C) 2009-2012 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.application;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.debug.DebugPlugin;
import org.bonitasoft.studio.validation.ValidationPlugin;
......@@ -32,72 +28,71 @@ import org.osgi.framework.BundleException;
*/
public class ApplicationPlugin extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.bonitasoft.studio.application"; //$NON-NLS-1$
// The plug-in ID
public static final String PLUGIN_ID = "org.bonitasoft.studio.application"; //$NON-NLS-1$
public static final String BAR_DEFAULT_PATH = "barPath";
public static final String BAR_DEFAULT_PATH = "barPath";
// The shared instance
private static ApplicationPlugin plugin;
// The shared instance
private static ApplicationPlugin plugin;
/**
* The constructor
*/
public ApplicationPlugin() {
}
/**
* The constructor
*/
public ApplicationPlugin() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
plugin = this;
init(context);
}
super.start(context);
plugin = this;
init(context);
}
private void init(final BundleContext context) throws CoreException {
if(getDialogSettings().get(BAR_DEFAULT_PATH) == null){
getDialogSettings().put(BAR_DEFAULT_PATH, System.getProperty("user.home"));
}
try {
DebugPlugin.getDefault().getBundle().start();
ValidationPlugin.getDefault().getBundle().start();
} catch (final BundleException e) {
BonitaStudioLog.error(e);
}
}
private void init(final BundleContext context) throws CoreException {
if (getDialogSettings().get(BAR_DEFAULT_PATH) == null) {
getDialogSettings().put(BAR_DEFAULT_PATH, System.getProperty("user.home"));
}
try {
DebugPlugin.getDefault().getBundle().start();
ValidationPlugin.getDefault().getBundle().start();
} catch (final BundleException e) {
BonitaStudioLog.error(e);
}
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(final BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static ApplicationPlugin getDefault() {
return plugin;
}
plugin = null;
super.stop(context);
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(final String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static ApplicationPlugin getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(final String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}
......@@ -73,6 +73,7 @@ import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
import org.eclipse.ui.internal.splash.SplashHandlerFactory;
import org.osgi.framework.BundleException;
public class BonitaStudioWorkbenchAdvisor extends WorkbenchAdvisor implements IStartup {
......@@ -148,6 +149,8 @@ public class BonitaStudioWorkbenchAdvisor extends WorkbenchAdvisor implements IS
}
monitor.beginTask(BOSSplashHandler.BONITA_TASK, 100);
startGroovyPlugin();
monitor.subTask(Messages.initializingCurrentRepository);
disableInternalWebBrowser();
......@@ -156,7 +159,6 @@ public class BonitaStudioWorkbenchAdvisor extends WorkbenchAdvisor implements IS
final List<IConfigurationElement> sortedConfigElems = retrievePreStartupContribution();
sortConfigurationElementsByPriority(sortedConfigElems);
executeConfigurationElement(sortedConfigElems);
try {
ResourcesPlugin.getWorkspace().run(initRepositoryRunnable(), monitor);
} catch (final CoreException e) {
......@@ -167,6 +169,14 @@ public class BonitaStudioWorkbenchAdvisor extends WorkbenchAdvisor implements IS
executeContributions();
}
protected void startGroovyPlugin() {
try {
org.codehaus.groovy.eclipse.GroovyPlugin.getDefault().getBundle().start();
} catch (final BundleException e1) {
BonitaStudioLog.error("Failed to loag Groovy plugin", e1);
}
}
private void checkCurrentRepository(final IProgressMonitor monitor) {
final String current = CommonRepositoryPlugin.getDefault().getPreferenceStore().getString(RepositoryPreferenceConstant.CURRENT_REPOSITORY);
final IRepository repository = RepositoryManager.getInstance().getCurrentRepository();
......
......@@ -17,10 +17,13 @@ package org.bonitasoft.studio.application.advisor;
import java.io.File;
import java.io.FileFilter;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepository;
import org.bonitasoft.studio.importer.ImporterRegistry;
import org.bonitasoft.studio.importer.processors.ToProcProcessor;
import org.eclipse.core.resources.ResourcesPlugin;
/**
......@@ -49,7 +52,13 @@ public class InitWorkspaceAdvisor extends InstallerApplicationWorkbenchAdvisor {
final IRepository repository = RepositoryManager.getInstance().getRepository(repositoryName);
if (repository != null) {
try {
repository.importFromArchive(workspaceArchive, false, false);
final boolean disableConfirmation = FileActionDialog.getDisablePopup();
FileActionDialog.setDisablePopup(false);
final ToProcProcessor importer = ImporterRegistry.getInstance().createImporterFor(workspaceArchive.getName());
if (importer != null) {
importer.createDiagram(workspaceArchive.toURL(), Repository.NULL_PROGRESS_MONITOR);
}
FileActionDialog.setDisablePopup(disableConfirmation);
workspaceArchive.delete();
} catch (final Exception e) {
BonitaStudioLog.error(e);
......@@ -59,5 +68,4 @@ public class InitWorkspaceAdvisor extends InstallerApplicationWorkbenchAdvisor {
RepositoryManager.getInstance().setRepository("default", Repository.NULL_PROGRESS_MONITOR);
}
}
}
......@@ -3,16 +3,18 @@
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
*/
package org.bonitasoft.studio.common.repository.handler;
package org.bonitasoft.studio.application.handler;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.Messages;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.operation.ImportBosArchiveOperation;
import org.bonitasoft.studio.importer.ImporterRegistry;
import org.bonitasoft.studio.importer.processors.ToProcProcessor;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
......@@ -26,13 +28,10 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
/**
*
* @author Baptiste Mesta
*
* Handler that launch a dialog to import artifacts from a zip
*
*/
public class ImportArtifactsFromZip extends AbstractHandler {
public class ImportArtifactsFromZipHandler extends AbstractHandler {
public static final String FILE_EXTENSION_OLD = ".bosworkspace";
......@@ -50,10 +49,14 @@ public class ImportArtifactsFromZip extends AbstractHandler {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final ImportBosArchiveOperation operation = new ImportBosArchiveOperation();
operation.setArchiveFile(workspaceArchiveFile);
operation.setCurrentRepository(RepositoryManager.getInstance().getCurrentRepository());
operation.run(monitor);
final ToProcProcessor importer = ImporterRegistry.getInstance().createImporterFor(workspaceArchiveFile);
try {
importer.createDiagram(new File(workspaceArchiveFile).toURL(), monitor);
} catch (final MalformedURLException e) {
throw new InvocationTargetException(e);
} catch (final Exception e) {
throw new InvocationTargetException(e);
}
}
};
......
......@@ -5,14 +5,12 @@
* 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.common.gmf.command;
......@@ -40,6 +38,7 @@ import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.requests.ReconnectRequest;
import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredCreateConnectionViewAndElementCommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
......@@ -63,173 +62,179 @@ import org.eclipse.gmf.runtime.notation.View;
/**
* @author Romain Bioteau
*
*/
public class InsertElementOnSequenceFlowCommand extends AbstractCommand {
private boolean correctOffset;
private Collection objects;
private IGraphicalEditPart targetEditPart;
private Map epRegistry;
private EditPart originalTargetEditPart;
private SetConnectionBendpointsCommand setBendpointsCmdForNewEdge;
private SetConnectionBendpointsCommand setBendpointsCmdForOriginalEdge;
private DeferredCreateConnectionViewAndElementCommand createConnectionCommand;
private Command creationCommand;
private SetBoundsCommand correctOffsetCmd;
public InsertElementOnSequenceFlowCommand(Command command,
IGraphicalEditPart targetEditPart, EditPartViewer viewer,
boolean correctOffset) {
super("Insert element on SequenceFlow");
this.correctOffset = correctOffset;
this.creationCommand = command;
this.objects = DiagramCommandStack.getReturnValues(creationCommand) ;
this.targetEditPart = targetEditPart;
this.epRegistry = viewer.getEditPartRegistry();
}
@Override
protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
if(targetEditPart instanceof ConnectionEditPart){
ConnectionEditPart targetConnectionEditPart = (ConnectionEditPart) targetEditPart;
for (Iterator i = objects.iterator(); i.hasNext();) {
Object object = i.next();
if (object instanceof ViewAndElementDescriptor) {
final ViewAndElementDescriptor descriptor = (ViewAndElementDescriptor) object;
final ShapeEditPart editPart = (ShapeEditPart) epRegistry.get(descriptor.getAdapter(View.class));
Bounds b = (Bounds) ((Node)editPart.getNotationView()).getLayoutConstraint();
correctOffsetCmd = new SetBoundsCommand(editPart.getEditingDomain(), "", descriptor,new Point(b.getX()-25,b.getY()-25 ));
final ReconnectRequest reconnect = new ReconnectRequest(RequestConstants.REQ_RECONNECT_TARGET);
reconnect.setConnectionEditPart(targetConnectionEditPart);
reconnect.setTargetEditPart(editPart);
CompoundCommand reconnectCommand = (CompoundCommand) editPart.getCommand(reconnect);
CreateConnectionViewAndElementRequest connectionRequest = new CreateConnectionViewAndElementRequest(BonitaConnectionTypes.getElementType("org.bonitasoft.studio.diagram.SequenceFlow_4001"),
((IHintedType) BonitaConnectionTypes.getElementType("org.bonitasoft.studio.diagram.SequenceFlow_4001")).getSemanticHint(), new PreferencesHint("org.bonitasoft.studio.diagram"));
originalTargetEditPart = targetConnectionEditPart.getTarget();
createConnectionCommand = new DeferredCreateConnectionViewAndElementCommand(connectionRequest, descriptor, originalTargetEditPart, editPart.getViewer());
if(correctOffset){
correctOffsetCmd.execute(monitor, info);
}
CompoundCommand ccc = (CompoundCommand) reconnectCommand.getChildren()[1];
for(Object proxy : ccc.getChildren()){
if(proxy instanceof ICommandProxy){
((ICommandProxy) proxy).getICommand().execute(monitor, info);
}
}
createConnectionCommand.execute(monitor, info);
if(connectionRequest != null){
ConnectionViewAndElementDescriptor connectionDescriptor = (ConnectionViewAndElementDescriptor) connectionRequest.getNewObject() ;
Connector edge = (Connector) connectionDescriptor.getAdapter(Edge.class) ;
org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart connectionEP = (org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) editPart.getViewer().getEditPartRegistry().get(edge);
if(connectionEP != null){
TransactionalEditingDomain editingDomain = connectionEP.getEditingDomain();
setBendpointsCmdForNewEdge = createSetBendpointsCommand(monitor, info, edge,editingDomain);
setBendpointsCmdForNewEdge.execute(monitor, info);
setBendpointsCmdForOriginalEdge = createSetBendpointsCommand(monitor, info, (Connector)targetEditPart.getNotationView(), editingDomain);
setBendpointsCmdForOriginalEdge.execute(monitor, info);
}
}
}
}
}
correctBoundsToAvoidCollisions(monitor,info);
return CommandResult.newOKCommandResult();
}
@SuppressWarnings("restriction")
protected SetConnectionBendpointsCommand createSetBendpointsCommand(
IProgressMonitor monitor,
IAdaptable info,
Connector edge,
TransactionalEditingDomain domain) {
SetConnectionBendpointsCommand setConnectionBendPointsCommand = new SetConnectionBendpointsCommand(domain);
setConnectionBendPointsCommand.setEdgeAdapter(new EObjectAdapter(edge));
PointList bendpoints = new PointList() ;
bendpoints.addPoint(0, 0) ;
bendpoints.addPoint(0, 0) ;
setConnectionBendPointsCommand.setNewPointList(bendpoints, bendpoints.getFirstPoint(), bendpoints.getLastPoint());
return setConnectionBendPointsCommand;
}
protected void correctBoundsToAvoidCollisions(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {
final List editparts = new ArrayList();
for (Iterator i = objects.iterator(); i.hasNext();) {
Object object = i.next();
if (object instanceof IAdaptable) {
Object editPart = epRegistry.get(((IAdaptable) object).getAdapter(View.class));
if (editPart != null) {
editparts.add(editPart);
}
}
}
for(Object ep :editparts){
if(ep instanceof IGraphicalEditPart){
Location loc = (Location) ((Node)((IGraphicalEditPart) ep).getNotationView()).getLayoutConstraint() ;
Point newLoc = FiguresHelper.handleCompartmentMargin((IGraphicalEditPart) ep, loc.getX(), loc.getY(),(((IGraphicalEditPart) ep).resolveSemanticElement() instanceof SubProcessEvent)) ;
if(((IGraphicalEditPart) ep).getParent() instanceof ShapeCompartmentEditPart && !(((IGraphicalEditPart)((IGraphicalEditPart) ep).getParent()).resolveSemanticElement() instanceof SubProcessEvent)){
ShapeCompartmentEditPart compartment = (ShapeCompartmentEditPart) ((IGraphicalEditPart) ep).getParent();
while(newLoc.y + 65 > compartment.getFigure().getBounds().height){
newLoc.y = newLoc.y -10;
}
while(newLoc.x + 100 > compartment.getFigure().getBounds().width){
newLoc.x = newLoc.x -10;
}
}
new SetBoundsCommand(((IGraphicalEditPart) ep).getEditingDomain(), "Check Overlap", new EObjectAdapter(((IGraphicalEditPart) ep).getNotationView()),newLoc).execute(monitor, info);
}
}
}
@Override
protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor,
IAdaptable info) throws ExecutionException {
if(creationCommand != null && creationCommand.canExecute()){
creationCommand.execute();
}
return doExecuteWithResult(progressMonitor, info);
}
@Override
protected CommandResult doUndoWithResult(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {
if(setBendpointsCmdForOriginalEdge != null){
setBendpointsCmdForOriginalEdge.undo(monitor, info);
}
if(createConnectionCommand != null){
createConnectionCommand.undo(monitor, info);
}
if(targetEditPart instanceof ConnectionEditPart && originalTargetEditPart != null){
final ReconnectRequest reconnect = new ReconnectRequest(RequestConstants.REQ_RECONNECT_TARGET);
reconnect.setConnectionEditPart((ConnectionEditPart) targetEditPart);
reconnect.setTargetEditPart(originalTargetEditPart);
CompoundCommand reconnectCommand = (CompoundCommand) originalTargetEditPart.getCommand(reconnect);
CompoundCommand ccc = (CompoundCommand) reconnectCommand.getChildren()[1];
for(Object proxy : ccc.getChildren()){
if(proxy instanceof ICommandProxy){
((ICommandProxy) proxy).getICommand().execute(monitor, info);
}
}
}
if(correctOffset && correctOffsetCmd != null && correctOffsetCmd.canUndo()){
correctOffsetCmd.undo(monitor, info);
}
if(creationCommand != null && creationCommand.canUndo()){
creationCommand.undo();
creationCommand.dispose();
}
return CommandResult.newOKCommandResult();
}
private final boolean correctOffset;
private final Collection objects;
private final IGraphicalEditPart targetEditPart;
private final Map epRegistry;
private EditPart originalTargetEditPart;
private SetConnectionBendpointsCommand setBendpointsCmdForNewEdge;
private SetConnectionBendpointsCommand setBendpointsCmdForOriginalEdge;
private DeferredCreateConnectionViewAndElementCommand createConnectionCommand;
private final Command creationCommand;
private SetBoundsCommand correctOffsetCmd;
public InsertElementOnSequenceFlowCommand(final Command command,
final IGraphicalEditPart targetEditPart, final EditPartViewer viewer,
final boolean correctOffset) {
super("Insert element on SequenceFlow");
this.correctOffset = correctOffset;
creationCommand = command;
objects = DiagramCommandStack.getReturnValues(creationCommand);
this.targetEditPart = targetEditPart;