Commit dc35dd73 authored by Romain Bioteau's avatar Romain Bioteau

fix(diagram) fix pool resize (#1569)

Closes BS-19297
parent bfd9cd07
...@@ -18,6 +18,7 @@ import java.lang.reflect.InvocationTargetException; ...@@ -18,6 +18,7 @@ import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.studio.common.log.BonitaStudioLog; import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager; import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.diagram.custom.parts.CustomPoolEditPart;
import org.bonitasoft.studio.diagram.custom.repository.DiagramFileStore; import org.bonitasoft.studio.diagram.custom.repository.DiagramFileStore;
import org.bonitasoft.studio.diagram.custom.repository.NewDiagramFactory; import org.bonitasoft.studio.diagram.custom.repository.NewDiagramFactory;
import org.bonitasoft.studio.model.process.ProcessPackage; import org.bonitasoft.studio.model.process.ProcessPackage;
...@@ -61,7 +62,7 @@ public class NewDiagramCommandHandler extends AbstractHandler { ...@@ -61,7 +62,7 @@ public class NewDiagramCommandHandler extends AbstractHandler {
final NewDiagramFactory diagramFactory = new NewDiagramFactory( final NewDiagramFactory diagramFactory = new NewDiagramFactory(
RepositoryManager.getInstance().getCurrentRepository(), RepositoryManager.getInstance().getCurrentRepository(),
BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore()); BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore());
diagramFactory.setDefaultPoolWidth(getDefaultWidth()); diagramFactory.setDefaultPoolWidth(CustomPoolEditPart.getDefaultWidth());
final IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); final IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try { try {
progressService.run(true, false, new IRunnableWithProgress() { progressService.run(true, false, new IRunnableWithProgress() {
...@@ -81,14 +82,6 @@ public class NewDiagramCommandHandler extends AbstractHandler { ...@@ -81,14 +82,6 @@ public class NewDiagramCommandHandler extends AbstractHandler {
return diagramFileStore; return diagramFileStore;
} }
private int getDefaultWidth() {
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() != null) {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getClientArea().width - 600;
}
return 800;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.core.commands.AbstractHandler#isEnabled() * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
......
...@@ -94,7 +94,6 @@ public class UpdatePoolSizeCommand extends AbstractTransactionalCommand { ...@@ -94,7 +94,6 @@ public class UpdatePoolSizeCommand extends AbstractTransactionalCommand {
setRequest1.setResizeDirection(PositionConstants.NORTH); setRequest1.setResizeDirection(PositionConstants.NORTH);
setRequest1.setSizeDelta(new Dimension(0,-150)); setRequest1.setSizeDelta(new Dimension(0,-150));
gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1)); gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1));
for(Object o : gep.getChildren()){ for(Object o : gep.getChildren()){
if(o instanceof CustomPoolCompartmentEditPart){ if(o instanceof CustomPoolCompartmentEditPart){
for(CustomLaneEditPart lane : ((CustomPoolCompartmentEditPart)o).getPoolLanes()){ for(CustomLaneEditPart lane : ((CustomPoolCompartmentEditPart)o).getPoolLanes()){
...@@ -114,7 +113,6 @@ public class UpdatePoolSizeCommand extends AbstractTransactionalCommand { ...@@ -114,7 +113,6 @@ public class UpdatePoolSizeCommand extends AbstractTransactionalCommand {
setRequest1.setResizeDirection(PositionConstants.SOUTH); setRequest1.setResizeDirection(PositionConstants.SOUTH);
setRequest1.setSizeDelta(new Dimension(0,150)); setRequest1.setSizeDelta(new Dimension(0,150));
gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1)); gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1));
for(Object o : gep.getChildren()){ for(Object o : gep.getChildren()){
if(o instanceof CustomPoolCompartmentEditPart){ if(o instanceof CustomPoolCompartmentEditPart){
for(CustomLaneEditPart lane : ((CustomPoolCompartmentEditPart)o).getPoolLanes()){ for(CustomLaneEditPart lane : ((CustomPoolCompartmentEditPart)o).getPoolLanes()){
...@@ -135,13 +133,11 @@ public class UpdatePoolSizeCommand extends AbstractTransactionalCommand { ...@@ -135,13 +133,11 @@ public class UpdatePoolSizeCommand extends AbstractTransactionalCommand {
epToMove.add(lane); epToMove.add(lane);
} }
} }
} }
setRequest1.setEditParts(epToMove); setRequest1.setEditParts(epToMove);
setRequest1.setResizeDirection(PositionConstants.EAST); setRequest1.setResizeDirection(PositionConstants.EAST);
setRequest1.setSizeDelta(new Dimension(-150,0)); setRequest1.setSizeDelta(new Dimension(-150,0));
if(gep.getFigure().getSize().width > gep.getFigure().getMinimumSize().width ){ if(gep.getFigure().getSize().width - 150 > gep.getFigure().getMinimumSize().width ){
gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1)); gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1));
for(Object o : gep.getChildren()){ for(Object o : gep.getChildren()){
if(o instanceof CustomPoolCompartmentEditPart){ if(o instanceof CustomPoolCompartmentEditPart){
......
...@@ -168,12 +168,6 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple ...@@ -168,12 +168,6 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
hideSelection(); hideSelection();
layer = getLayer(LayerConstants.HANDLE_LAYER); layer = getLayer(LayerConstants.HANDLE_LAYER);
/*
* need to flush in order to have the new correct size of the host
* figure
*/
// poolEditPart.getViewer().flush();
//FIXME
Rectangle ref = sourceFigure.getBounds(); Rectangle ref = sourceFigure.getBounds();
if (ref.x == 0 && ref.y == 0 && ref.height == 0 && ref.width == 0) { if (ref.x == 0 && ref.y == 0 && ref.height == 0 && ref.width == 0) {
...@@ -205,7 +199,6 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple ...@@ -205,7 +199,6 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
result = ((AbstractConnectionEditPart) host).getSource(); result = ((AbstractConnectionEditPart) host).getSource();
} }
EditPart tempEditPart = result;
/*first search for a CustomLaneEditPart*/ /*first search for a CustomLaneEditPart*/
while(!(result instanceof CustomPoolEditPart) && result != null){ while(!(result instanceof CustomPoolEditPart) && result != null){
result = result.getParent() ; result = result.getParent() ;
...@@ -231,7 +224,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple ...@@ -231,7 +224,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
Rectangle ref = sourceFigure.getBounds(); Rectangle ref = sourceFigure.getBounds();
IFigure f = new ImageFigure(Pics.getImage(PicsConstants.plusBlack)); IFigure f = new ImageFigure(Pics.getImage(PicsConstants.plusBlack));
f.setSize(20, 20); f.setSize(20, 20);
f.setLocation(ref.getRight().translate(10, -20)); f.setLocation(ref.getRight().getCopy().translate(10, -20));
f.getBounds().performScale(zoom) ; f.getBounds().performScale(zoom) ;
f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.ADD_RIGHT)); f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.ADD_RIGHT));
layer.add(f); layer.add(f);
...@@ -253,7 +246,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple ...@@ -253,7 +246,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
Rectangle ref = sourceFigure.getBounds(); Rectangle ref = sourceFigure.getBounds();
IFigure f = new ImageFigure(Pics.getImage(PicsConstants.plusBlack)); IFigure f = new ImageFigure(Pics.getImage(PicsConstants.plusBlack));
f.setSize(20, 20); f.setSize(20, 20);
f.setLocation(ref.getBottom().translate(20, 0)); f.setLocation(ref.getBottom().getCopy().translate(20, 0));
f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.ADD_BOTTOM)); f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.ADD_BOTTOM));
f.getBounds().performScale(zoom); f.getBounds().performScale(zoom);
layer.add(f); layer.add(f);
...@@ -274,7 +267,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple ...@@ -274,7 +267,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
Rectangle ref = sourceFigure.getBounds(); Rectangle ref = sourceFigure.getBounds();
IFigure f = new ImageFigure(Pics.getImage(PicsConstants.minusBlack)); IFigure f = new ImageFigure(Pics.getImage(PicsConstants.minusBlack));
f.setSize(20, 20); f.setSize(20, 20);
f.setLocation(ref.getBottom().translate(20, -20)); f.setLocation(ref.getBottom().getCopy().translate(20, -20));
f.getBounds().performScale(zoom); f.getBounds().performScale(zoom);
f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.REMOVE_BOTTOM)); f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.REMOVE_BOTTOM));
layer.add(f); layer.add(f);
...@@ -298,7 +291,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple ...@@ -298,7 +291,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
Rectangle ref = sourceFigure.getBounds(); Rectangle ref = sourceFigure.getBounds();
IFigure f = new ImageFigure(Pics.getImage(PicsConstants.minusBlack)); IFigure f = new ImageFigure(Pics.getImage(PicsConstants.minusBlack));
f.setSize(20, 20); f.setSize(20, 20);
f.setLocation(ref.getLeft().translate(-25, -10)); f.setLocation(ref.getLeft().getCopy().translate(-25, -10));
f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.REMOVE_RIGHT)); f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.REMOVE_RIGHT));
f.getBounds().performScale(zoom); f.getBounds().performScale(zoom);
......
...@@ -81,9 +81,7 @@ public class CustomLaneEditPart extends LaneEditPart { ...@@ -81,9 +81,7 @@ public class CustomLaneEditPart extends LaneEditPart {
@Override @Override
protected NodeFigure createNodePlate() { protected NodeFigure createNodePlate() {
final NodeFigure figure = new DefaultSizeNodeFigure(getMapMode().DPtoLP(975), getMapMode().DPtoLP(100)); return new DefaultSizeNodeFigure(getMapMode().DPtoLP(975), getMapMode().DPtoLP(100));
figure.setMinimumSize(new Dimension(975, 100));
return figure;
} }
@Override @Override
...@@ -202,7 +200,7 @@ public class CustomLaneEditPart extends LaneEditPart { ...@@ -202,7 +200,7 @@ public class CustomLaneEditPart extends LaneEditPart {
} }
final CustomPoolEditPart parent = (CustomPoolEditPart) getParent().getParent(); final CustomPoolEditPart parent = (CustomPoolEditPart) getParent().getParent();
int width = parent.getFigure().getSize().width; int width = parent.getCurrentSize().width;
int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue(); int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue();
if (height == -1) { if (height == -1) {
...@@ -345,7 +343,7 @@ public class CustomLaneEditPart extends LaneEditPart { ...@@ -345,7 +343,7 @@ public class CustomLaneEditPart extends LaneEditPart {
setBackgroundColor(THIS_BACK); setBackgroundColor(THIS_BACK);
this.setPreferredSize(new Dimension(getMapMode().DPtoLP(975), this.setPreferredSize(new Dimension(getMapMode().DPtoLP(975),
getMapMode().DPtoLP(100))); getMapMode().DPtoLP(100)));
setMinimumSize(new Dimension(getMapMode().DPtoLP(975), setMinimumSize(new Dimension(-1,
getMapMode().DPtoLP(100))); getMapMode().DPtoLP(100)));
createContents(); createContents();
} }
......
...@@ -32,9 +32,12 @@ import org.eclipse.gef.EditPart; ...@@ -32,9 +32,12 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request; import org.eclipse.gef.Request;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx; import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities; import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View; import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
...@@ -55,27 +58,22 @@ public class CustomPoolEditPart extends PoolEditPart { ...@@ -55,27 +58,22 @@ public class CustomPoolEditPart extends PoolEditPart {
super(view); super(view);
} }
/**
* @return the currentSize
*/
public Dimension getCurrentSize() { public Dimension getCurrentSize() {
return currentSize; return currentSize;
} }
private static int CONSTANT_LEFT_MARGIN = 20; private static int CONSTANT_LEFT_MARGIN = 20;
private static int CONSTANT_RIGHT_MARGIN = 240; private static final int CONSTANT_RIGHT_MARGIN = 600;
private static int CONSTANT_DEFAULT_HEIGHT = 250; public static final int CONSTANT_DEFAULT_HEIGHT = 250;
public static final int MIN_POOL_WIDTH = 800; public static final int MIN_POOL_WIDTH = 800;
/** public static int getDefaultWidth() {
* @return the defaultWidth int width = 0;
*/ if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
public int getDefaultWidth() { && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() != null) {
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() != null) { width = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getClientArea().width - CONSTANT_RIGHT_MARGIN;
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getClientArea().width - CONSTANT_RIGHT_MARGIN;
} else {
return MIN_POOL_WIDTH;
} }
return Math.max(MIN_POOL_WIDTH, width);
} }
/** /**
...@@ -188,6 +186,13 @@ public class CustomPoolEditPart extends PoolEditPart { ...@@ -188,6 +186,13 @@ public class CustomPoolEditPart extends PoolEditPart {
figure.setUseLocalCoordinates(true); figure.setUseLocalCoordinates(true);
return primaryShape = figure; return primaryShape = figure;
} }
@Override
protected NodeFigure createNodePlate() {
NodeFigure nodeFigure = new DefaultSizeNodeFigure(new Dimension(-1, 100));
nodeFigure.setMinimumSize(new Dimension(-1, 100));
return nodeFigure;
}
public class CustomPoolFigure extends PoolFigure { public class CustomPoolFigure extends PoolFigure {
...@@ -205,7 +210,6 @@ public class CustomPoolEditPart extends PoolEditPart { ...@@ -205,7 +210,6 @@ public class CustomPoolEditPart extends PoolEditPart {
* @generated * @generated
*/ */
public CustomPoolFigure() { public CustomPoolFigure() {
final GridLayout layoutThis = new GridLayout(); final GridLayout layoutThis = new GridLayout();
layoutThis.numColumns = 2; layoutThis.numColumns = 2;
layoutThis.makeColumnsEqualWidth = false; layoutThis.makeColumnsEqualWidth = false;
...@@ -222,12 +226,12 @@ public class CustomPoolEditPart extends PoolEditPart { ...@@ -222,12 +226,12 @@ public class CustomPoolEditPart extends PoolEditPart {
getMapMode().DPtoLP(getDefaultHeight())); getMapMode().DPtoLP(getDefaultHeight()));
this.setSize(defaultSize); this.setSize(defaultSize);
this.setPreferredSize(defaultSize); this.setPreferredSize(defaultSize);
setMinimumSize(new Dimension(getMapMode().DPtoLP(MIN_POOL_WIDTH), getMapMode().DPtoLP(100))); setMinimumSize(new Dimension(MIN_POOL_WIDTH, getMapMode().DPtoLP(100)));
currentSize = new Dimension(defaultSize); currentSize = new Dimension(defaultSize);
setLocation(new Point(20, 20)); setLocation(new Point(20, 20));
createContents(); createContents();
} }
@Override @Override
public void validate() { public void validate() {
super.validate(); super.validate();
...@@ -422,7 +426,8 @@ public class CustomPoolEditPart extends PoolEditPart { ...@@ -422,7 +426,8 @@ public class CustomPoolEditPart extends PoolEditPart {
super.setFont(fontData); super.setFont(fontData);
if (fontData != null && ((Element) resolveSemanticElement()).getName() != null) { if (fontData != null && ((Element) resolveSemanticElement()).getName() != null) {
final Font font = new Font(Display.getCurrent(), fontData); final Font font = new Font(Display.getCurrent(), fontData);
final int height = FigureUtilities.getStringExtents(((Element) resolveSemanticElement()).getName(), font).height; final int height = FigureUtilities.getStringExtents(((Element) resolveSemanticElement()).getName(),
font).height;
font.dispose(); font.dispose();
((CustomPoolFigure) getContentPane()).getLabelGridData().widthHint = height + 2; ((CustomPoolFigure) getContentPane()).getLabelGridData().widthHint = height + 2;
} }
......
...@@ -16,6 +16,7 @@ package org.bonitasoft.studio.diagram.custom.providers; ...@@ -16,6 +16,7 @@ package org.bonitasoft.studio.diagram.custom.providers;
import java.util.ArrayList; import java.util.ArrayList;
import org.bonitasoft.studio.diagram.custom.parts.CustomPoolEditPart;
import org.bonitasoft.studio.model.process.diagram.edit.parts.MessageFlowEditPart; import org.bonitasoft.studio.model.process.diagram.edit.parts.MessageFlowEditPart;
import org.bonitasoft.studio.model.process.diagram.edit.parts.MessageFlowLabelEditPart; import org.bonitasoft.studio.model.process.diagram.edit.parts.MessageFlowLabelEditPart;
import org.bonitasoft.studio.model.process.diagram.edit.parts.SequenceFlowEditPart; import org.bonitasoft.studio.model.process.diagram.edit.parts.SequenceFlowEditPart;
...@@ -61,8 +62,9 @@ public class CustomProcessViewProvider extends ProcessViewProvider { ...@@ -61,8 +62,9 @@ public class CustomProcessViewProvider extends ProcessViewProvider {
node.getStyles().add(NotationFactory.eINSTANCE.createFillStyle()); node.getStyles().add(NotationFactory.eINSTANCE.createFillStyle());
final Size layoutConstraint = (Size) node.getLayoutConstraint(); final Size layoutConstraint = (Size) node.getLayoutConstraint();
if (layoutConstraint.getWidth() <= 0) { if (layoutConstraint.getWidth() <= 0) {
layoutConstraint.setWidth(((IPreferenceStore) preferencesHint.getPreferenceStore()).getDefaultInt("poolDefaultWidth")); int defaultInt = ((IPreferenceStore) preferencesHint.getPreferenceStore()).getDefaultInt("poolDefaultWidth");
layoutConstraint.setHeight(250); layoutConstraint.setWidth(defaultInt > 0 ? defaultInt : CustomPoolEditPart.getDefaultWidth());
layoutConstraint.setHeight(CustomPoolEditPart.CONSTANT_DEFAULT_HEIGHT);
} }
return node; return node;
} }
......
...@@ -202,9 +202,6 @@ public class NewDiagramFactory { ...@@ -202,9 +202,6 @@ public class NewDiagramFactory {
return mapping; return mapping;
} }
/**
* @return the artifact
*/
public DiagramFileStore getNewDiagramFileStore() { public DiagramFileStore getNewDiagramFileStore() {
return fileStore; return fileStore;
} }
......
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