Commit 9847022e authored by Adrien's avatar Adrien Committed by Romain Bioteau

feat(process explorer) duplicate diagram from explorer (#1396)


closes [BS-18954](https://bonitasoft.atlassian.net/browse/BS-18954)
parent 9e74fe92
......@@ -14,47 +14,29 @@
*/
package org.bonitasoft.studio.application.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.bonitasoft.studio.common.diagram.Identifier;
import org.bonitasoft.studio.common.diagram.dialog.OpenNameAndVersionForDiagramDialog;
import org.bonitasoft.studio.common.diagram.dialog.ProcessesNameVersion;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.diagram.custom.operation.DuplicateDiagramOperation;
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.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.diagram.custom.actions.DuplicateDiagramAction;
import org.bonitasoft.studio.model.process.diagram.part.ProcessDiagramEditor;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
/**
* @author Mickael Istria
*/
public class SaveProcessAsCommand extends AbstractHandler {
private String newProcessLabel;
private String newProcessVersion;
private List<ProcessesNameVersion> pools;
private DiagramRepositoryStore diagramStore;
/*
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
diagramStore = RepositoryManager.getInstance().getCurrentRepository().getRepositoryStore(DiagramRepositoryStore.class);
RepositoryAccessor repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (!(editor instanceof ProcessDiagramEditor)) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "This is not a process diagram!",
......@@ -63,45 +45,16 @@ public class SaveProcessAsCommand extends AbstractHandler {
}
final ProcessDiagramEditor processEditor = (ProcessDiagramEditor) editor;
final MainProcess process = (MainProcess) ((IGraphicalEditPart) processEditor.getDiagramEditPart()).resolveSemanticElement();
newProcessLabel = process.getName();
newProcessVersion = process.getVersion();
final OpenNameAndVersionForDiagramDialog dialog = new OpenNameAndVersionForDiagramDialog(Display.getDefault().getActiveShell(),
ModelHelper.getMainProcess(process), diagramStore);
dialog.forceNameUpdate();
if (dialog.open() == Dialog.OK) {
final Identifier identifier = dialog.getIdentifier();
newProcessLabel = identifier.getName();
newProcessVersion = dialog.getIdentifier().getVersion();
pools = dialog.getPools();
final DuplicateDiagramOperation op = new DuplicateDiagramOperation();
op.setDiagramToDuplicate(process);
op.setNewDiagramName(newProcessLabel);
op.setNewDiagramVersion(newProcessVersion);
op.setPoolsRenamed(pools);
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.run(true, false, op);
} catch (final InvocationTargetException e) {
throw new ExecutionException(e.getMessage(), e);
} catch (final InterruptedException e) {
throw new ExecutionException(e.getMessage(), e);
}
final DiagramFileStore store = diagramStore.getDiagram(newProcessLabel, newProcessVersion);
store.open();
}
final EObject process = ((IGraphicalEditPart) processEditor.getDiagramEditPart()).resolveSemanticElement();
new DuplicateDiagramAction(repositoryAccessor).duplicate(ModelHelper.getMainProcess(process));
return null;
}
/*
* (non-Javadoc)
* @see org.eclipse.core.commands.AbstractHandler#isEnabled()
*/
@Override
public boolean isEnabled() {
if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
return editor != null && editor instanceof ProcessDiagramEditor;
}
return false;
......
......@@ -3,9 +3,29 @@ Bundle-ManifestVersion: 2
Bundle-Name: Bonita Process Editor customization classes
Bundle-SymbolicName: org.bonitasoft.studio.diagram.custom;singleton:=true
Bundle-Version: 7.8.0.qualifier
Bundle-Localization: plugin
Bundle-Activator: org.bonitasoft.studio.diagram.custom.Activator
Bundle-Vendor: BonitaSoft S.A.
Bundle-Localization: plugin
Export-Package: org.bonitasoft.studio.diagram.custom;
x-friends:="org.bonitasoft.studio.properties.test,
org.bonitasoft.studio.tests,
org.bonitasoft.studio.diagram.test,
org.bonitasoft.studio.tests.ex",
org.bonitasoft.studio.diagram.custom.actions,
org.bonitasoft.studio.diagram.custom.clipboard,
org.bonitasoft.studio.diagram.custom.commands,
org.bonitasoft.studio.diagram.custom.contributionItem,
org.bonitasoft.studio.diagram.custom.editPolicies,
org.bonitasoft.studio.diagram.custom.figures,
org.bonitasoft.studio.diagram.custom.i18n,
org.bonitasoft.studio.diagram.custom.operation,
org.bonitasoft.studio.diagram.custom.part,
org.bonitasoft.studio.diagram.custom.parts,
org.bonitasoft.studio.diagram.custom.perspective,
org.bonitasoft.studio.diagram.custom.providers,
org.bonitasoft.studio.diagram.custom.refactoring,
org.bonitasoft.studio.diagram.custom.repository,
org.bonitasoft.studio.diagram.custom.wizard
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.emf.common,
......@@ -34,26 +54,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.databinding.beans,
org.eclipse.jface.databinding,
org.bonitasoft.studio.tests-utils;bundle-version="7.1.0";resolution:=optional,
org.eclipse.e4.core.commands
org.eclipse.e4.core.commands,
org.eclipse.e4.ui.model.workbench;bundle-version="2.0.1.v20170713-1800",
org.eclipse.e4.core.di.annotations
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.diagram.custom;
x-friends:="org.bonitasoft.studio.properties.test,
org.bonitasoft.studio.tests,
org.bonitasoft.studio.diagram.test,
org.bonitasoft.studio.tests.ex",
org.bonitasoft.studio.diagram.custom.actions,
org.bonitasoft.studio.diagram.custom.clipboard,
org.bonitasoft.studio.diagram.custom.commands,
org.bonitasoft.studio.diagram.custom.contributionItem,
org.bonitasoft.studio.diagram.custom.editPolicies,
org.bonitasoft.studio.diagram.custom.figures,
org.bonitasoft.studio.diagram.custom.i18n,
org.bonitasoft.studio.diagram.custom.operation,
org.bonitasoft.studio.diagram.custom.part,
org.bonitasoft.studio.diagram.custom.parts,
org.bonitasoft.studio.diagram.custom.perspective,
org.bonitasoft.studio.diagram.custom.providers,
org.bonitasoft.studio.diagram.custom.refactoring,
org.bonitasoft.studio.diagram.custom.repository,
org.bonitasoft.studio.diagram.custom.wizard
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
messages*.properties,\
icons/,\
plugin*.properties
plugin*.properties,\
fragment.e4xmi
source.. = src/
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_U2BRYNEgEeiZw5b_HoiMJA">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_WCqqsNEgEeiZw5b_HoiMJA" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_YUdHINEgEeiZw5b_HoiMJA" elementId="org.bonitasoft.studio.diagram.custom.command.duplicate" commandName="%duplicateDiagram"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_cp_kANEgEeiZw5b_HoiMJA" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_ecdAINEgEeiZw5b_HoiMJA" elementId="org.bonitasoft.studio.diagram.custom.handler.duplicateDiagram" contributionURI="bundleclass://org.bonitasoft.studio.diagram.custom/org.bonitasoft.studio.diagram.custom.handlers.DuplicateDiagramHandler" command="_YUdHINEgEeiZw5b_HoiMJA"/>
</fragments>
</fragment:ModelFragments>
......@@ -13,4 +13,5 @@ extractSubprocess=Extract subprocess
processPerspective=Process perspective
bpmnPalette=BPMN elements
newDiagram=Diagram
run=Run
\ No newline at end of file
run=Run
duplicateDiagram=Duplicate...
\ No newline at end of file
/**
* Copyright (C) 2018 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.diagram.custom.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.bonitasoft.studio.common.diagram.Identifier;
import org.bonitasoft.studio.common.diagram.dialog.OpenNameAndVersionForDiagramDialog;
import org.bonitasoft.studio.common.diagram.dialog.ProcessesNameVersion;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.diagram.custom.operation.DuplicateDiagramOperation;
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.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
public class DuplicateDiagramAction {
private RepositoryAccessor repositoryAccessor;
public DuplicateDiagramAction(RepositoryAccessor repositoryAccessor) {
this.repositoryAccessor = repositoryAccessor;
}
public void duplicate(MainProcess diagram) {
String newProcessLabel = diagram.getName();
String newProcessVersion = diagram.getVersion();
DiagramRepositoryStore diagramRepositoryStore = repositoryAccessor.getRepositoryStore(DiagramRepositoryStore.class);
final OpenNameAndVersionForDiagramDialog dialog = new OpenNameAndVersionForDiagramDialog(
Display.getDefault().getActiveShell(),
diagram, diagramRepositoryStore);
dialog.forceNameUpdate();
if (dialog.open() == Dialog.OK) {
final Identifier identifier = dialog.getIdentifier();
newProcessLabel = identifier.getName();
newProcessVersion = dialog.getIdentifier().getVersion();
List<ProcessesNameVersion> pools = dialog.getPools();
final DuplicateDiagramOperation op = new DuplicateDiagramOperation();
op.setDiagramToDuplicate(diagram);
op.setNewDiagramName(newProcessLabel);
op.setNewDiagramVersion(newProcessVersion);
op.setPoolsRenamed(pools);
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.run(true, false, op);
} catch (InvocationTargetException | InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
}
DiagramFileStore store = diagramRepositoryStore.getDiagram(newProcessLabel, newProcessVersion);
store.open();
}
}
}
/**
* Copyright (C) 2018 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.diagram.custom.handlers;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.bonitasoft.studio.diagram.custom.actions.DuplicateDiagramAction;
import org.bonitasoft.studio.diagram.custom.repository.DiagramFileStore;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
public class DuplicateDiagramHandler {
private FileStoreFinder fileStoreFinder;
public DuplicateDiagramHandler() {
fileStoreFinder = new FileStoreFinder();
}
@Execute
public void execute(RepositoryAccessor repositoryAccessor) {
DiagramFileStore fileStore = fileStoreFinder
.findSelectedFileStore(repositoryAccessor.getCurrentRepository())
.filter(DiagramFileStore.class::isInstance)
.map(DiagramFileStore.class::cast)
.orElseThrow(() -> new IllegalArgumentException("The selected element should be a diagram"));
new DuplicateDiagramAction(repositoryAccessor).duplicate(fileStore.getContent());
}
@CanExecute
public boolean canExecute(RepositoryAccessor repositoryAccessor) {
return fileStoreFinder
.findSelectedFileStore(repositoryAccessor.getCurrentRepository())
.filter(DiagramFileStore.class::isInstance)
.isPresent();
}
}
Markdown is supported
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