Commit 8f8bbcee authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-11185

parent bf58fd02
/**
* 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.data.ui.wizard;
import static org.assertj.core.api.Assertions.assertThat;
import org.bonitasoft.studio.model.process.Activity;
import org.bonitasoft.studio.model.process.Pool;
import org.bonitasoft.studio.model.process.builders.ActivityBuilder;
import org.bonitasoft.studio.model.process.builders.PoolBuilder;
import org.bonitasoft.studio.model.process.builders.ReceiveTaskBuilder;
import org.bonitasoft.studio.model.process.builders.SendTaskBuilder;
import org.eclipse.emf.ecore.EObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author Romain Bioteau
*
*/
public class CreateVariableProposalListenerTest {
private CreateVariableProposalListener createVariableProposalListener;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
createVariableProposalListener = new CreateVariableProposalListener();
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void should_getDataContainer_return_process_if_in_a_send_task() throws Exception {
final SendTaskBuilder sendTask = SendTaskBuilder.createSendTaskBuilder();
PoolBuilder.create().havingElements(sendTask).build();
final EObject dataContainer = createVariableProposalListener.getDataContainer(sendTask.build());
assertThat(dataContainer).isInstanceOf(Pool.class);
}
@Test
public void should_getDataContainer_return_process_if_in_a_receive_task() throws Exception {
final ReceiveTaskBuilder receiveTask = ReceiveTaskBuilder.createReceiveTaskBuilder();
PoolBuilder.create().havingElements(receiveTask).build();
final EObject dataContainer = createVariableProposalListener.getDataContainer(receiveTask.build());
assertThat(dataContainer).isInstanceOf(Pool.class);
}
@Test
public void should_getDataContainer_return_activity_if_in_an_activity() throws Exception {
final EObject dataContainer = createVariableProposalListener.getDataContainer(ActivityBuilder.createActivityBuilder().build());
assertThat(dataContainer).isInstanceOf(Activity.class);
}
@Test
public void should_getDataContainer_return_pool_if_at_pool_level() throws Exception {
final EObject dataContainer = createVariableProposalListener.getDataContainer(PoolBuilder.create().build());
assertThat(dataContainer).isInstanceOf(Pool.class);
}
}
......@@ -23,6 +23,8 @@ import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.Activity;
import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.ProcessPackage;
import org.bonitasoft.studio.model.process.ReceiveTask;
import org.bonitasoft.studio.model.process.SendTask;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
......@@ -37,22 +39,20 @@ import org.eclipse.swt.widgets.Shell;
*/
public class CreateVariableProposalListener implements IProposalListener {
private boolean isPageFlowContext = false;
private boolean isPageFlowContext = true;
private EStructuralFeature feature;
@Override
public String handleEvent(EObject context, final String fixedReturnType) {
public String handleEvent(final EObject context, final String fixedReturnType) {
Assert.isNotNull(context);
while (!(context instanceof AbstractProcess || context instanceof Activity)) {
context = context.eContainer();
}
final EObject dataContainer = getDataContainer(context);
if (feature == null) {
feature = ProcessPackage.Literals.DATA_AWARE__DATA;
}
final Set<EStructuralFeature> res = new HashSet<EStructuralFeature>();
res.add(feature);
final DataWizard newWizard = new DataWizard(TransactionUtil.getEditingDomain(context), context, feature, res, true, fixedReturnType);
final DataWizard newWizard = new DataWizard(TransactionUtil.getEditingDomain(context), dataContainer, feature, res, true, fixedReturnType);
newWizard.setIsPageFlowContext(isPageFlowContext);
Shell activeShell = Display
.getDefault().getActiveShell();
......@@ -70,9 +70,21 @@ public class CreateVariableProposalListener implements IProposalListener {
}
}
}
return null;
}
protected EObject getDataContainer(EObject context) {
while (!isValidContainer(context)) {
context = context.eContainer();
}
return context;
}
private boolean isValidContainer(final EObject context) {
return (context instanceof AbstractProcess
|| context instanceof Activity)
&& !(context instanceof SendTask)
&& !(context instanceof ReceiveTask);
}
@Override
......@@ -86,7 +98,7 @@ public class CreateVariableProposalListener implements IProposalListener {
*/
@Override
public boolean isPageFlowContext() {
return true;
return isPageFlowContext;
}
/*
......@@ -96,7 +108,6 @@ public class CreateVariableProposalListener implements IProposalListener {
@Override
public void setIsPageFlowContext(final boolean isPageFlowContext) {
this.isPageFlowContext = isPageFlowContext;
}
/*
......
......@@ -585,9 +585,11 @@ public class MigrationStatusView extends ViewPart implements ISelectionListener,
private Report getReportFromEditor(final IEditorPart editorPart) {
if(editorPart instanceof DiagramEditor){
final Resource resource = ((DiagramEditor) editorPart).getDiagramEditPart().getNotationView().eResource();
for(final EObject r : resource.getContents()){
if(r instanceof Report){
return (Report) r;
if (resource != null) {
for (final EObject r : resource.getContents()) {
if (r instanceof Report) {
return (Report) r;
}
}
}
}
......
/**
* 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.model.process.builders;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.model.process.ReceiveTask;
/**
* @author Romain Bioteau
*
*/
public class ReceiveTaskBuilder extends ActivityBuilder<ReceiveTask, ReceiveTaskBuilder> {
public static ReceiveTaskBuilder createReceiveTaskBuilder() {
return new ReceiveTaskBuilder();
}
@Override
protected ReceiveTask newInstance() {
return ProcessFactory.eINSTANCE.createReceiveTask();
}
}
/**
* 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.model.process.builders;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.model.process.SendTask;
/**
* @author Romain Bioteau
*
*/
public class SendTaskBuilder extends ActivityBuilder<SendTask, SendTaskBuilder> {
public static SendTaskBuilder createSendTaskBuilder() {
return new SendTaskBuilder();
}
@Override
protected SendTask newInstance() {
return ProcessFactory.eINSTANCE.createSendTask();
}
}
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