Commit c24d888e 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;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
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.NewDiagramFactory;
import org.bonitasoft.studio.model.process.ProcessPackage;
......@@ -61,7 +62,7 @@ public class NewDiagramCommandHandler extends AbstractHandler {
final NewDiagramFactory diagramFactory = new NewDiagramFactory(
RepositoryManager.getInstance().getCurrentRepository(),
BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore());
diagramFactory.setDefaultPoolWidth(getDefaultWidth());
diagramFactory.setDefaultPoolWidth(CustomPoolEditPart.getDefaultWidth());
final IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.run(true, false, new IRunnableWithProgress() {
......@@ -81,14 +82,6 @@ public class NewDiagramCommandHandler extends AbstractHandler {
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)
* @see org.eclipse.core.commands.AbstractHandler#isEnabled()
......
......@@ -94,7 +94,6 @@ public class UpdatePoolSizeCommand extends AbstractTransactionalCommand {
setRequest1.setResizeDirection(PositionConstants.NORTH);
setRequest1.setSizeDelta(new Dimension(0,-150));
gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1));
for(Object o : gep.getChildren()){
if(o instanceof CustomPoolCompartmentEditPart){
for(CustomLaneEditPart lane : ((CustomPoolCompartmentEditPart)o).getPoolLanes()){
......@@ -114,7 +113,6 @@ public class UpdatePoolSizeCommand extends AbstractTransactionalCommand {
setRequest1.setResizeDirection(PositionConstants.SOUTH);
setRequest1.setSizeDelta(new Dimension(0,150));
gep.getDiagramEditDomain().getDiagramCommandStack().execute(gep.getCommand(setRequest1));
for(Object o : gep.getChildren()){
if(o instanceof CustomPoolCompartmentEditPart){
for(CustomLaneEditPart lane : ((CustomPoolCompartmentEditPart)o).getPoolLanes()){
......@@ -135,13 +133,11 @@ public class UpdatePoolSizeCommand extends AbstractTransactionalCommand {
epToMove.add(lane);
}
}
}
setRequest1.setEditParts(epToMove);
setRequest1.setResizeDirection(PositionConstants.EAST);
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));
for(Object o : gep.getChildren()){
if(o instanceof CustomPoolCompartmentEditPart){
......
......@@ -168,12 +168,6 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
hideSelection();
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();
if (ref.x == 0 && ref.y == 0 && ref.height == 0 && ref.width == 0) {
......@@ -205,7 +199,6 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
result = ((AbstractConnectionEditPart) host).getSource();
}
EditPart tempEditPart = result;
/*first search for a CustomLaneEditPart*/
while(!(result instanceof CustomPoolEditPart) && result != null){
result = result.getParent() ;
......@@ -231,7 +224,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
Rectangle ref = sourceFigure.getBounds();
IFigure f = new ImageFigure(Pics.getImage(PicsConstants.plusBlack));
f.setSize(20, 20);
f.setLocation(ref.getRight().translate(10, -20));
f.setLocation(ref.getRight().getCopy().translate(10, -20));
f.getBounds().performScale(zoom) ;
f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.ADD_RIGHT));
layer.add(f);
......@@ -253,7 +246,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
Rectangle ref = sourceFigure.getBounds();
IFigure f = new ImageFigure(Pics.getImage(PicsConstants.plusBlack));
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.getBounds().performScale(zoom);
layer.add(f);
......@@ -274,7 +267,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
Rectangle ref = sourceFigure.getBounds();
IFigure f = new ImageFigure(Pics.getImage(PicsConstants.minusBlack));
f.setSize(20, 20);
f.setLocation(ref.getBottom().translate(20, -20));
f.setLocation(ref.getBottom().getCopy().translate(20, -20));
f.getBounds().performScale(zoom);
f.addMouseListener(new MouseListenerForSpan(UpdateSizePoolSelectionEditPolicy.REMOVE_BOTTOM));
layer.add(f);
......@@ -298,7 +291,7 @@ public class UpdateSizePoolSelectionEditPolicy extends SelectionEditPolicy imple
Rectangle ref = sourceFigure.getBounds();
IFigure f = new ImageFigure(Pics.getImage(PicsConstants.minusBlack));
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.getBounds().performScale(zoom);
......
......@@ -81,9 +81,7 @@ public class CustomLaneEditPart extends LaneEditPart {
@Override
protected NodeFigure createNodePlate() {
final NodeFigure figure = new DefaultSizeNodeFigure(getMapMode().DPtoLP(975), getMapMode().DPtoLP(100));
figure.setMinimumSize(new Dimension(975, 100));
return figure;
return new DefaultSizeNodeFigure(getMapMode().DPtoLP(975), getMapMode().DPtoLP(100));
}
@Override
......@@ -202,7 +200,7 @@ public class CustomLaneEditPart extends LaneEditPart {
}
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();
if (height == -1) {
......@@ -345,7 +343,7 @@ public class CustomLaneEditPart extends LaneEditPart {
setBackgroundColor(THIS_BACK);
this.setPreferredSize(new Dimension(getMapMode().DPtoLP(975),
getMapMode().DPtoLP(100)));
setMinimumSize(new Dimension(getMapMode().DPtoLP(975),
setMinimumSize(new Dimension(-1,
getMapMode().DPtoLP(100)));
createContents();
}
......
......@@ -32,9 +32,12 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
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.parts.DiagramEditor;
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.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.View;
import org.eclipse.swt.graphics.Color;
......@@ -55,24 +58,20 @@ public class CustomPoolEditPart extends PoolEditPart {
super(view);
}
/**
* @return the currentSize
*/
public Dimension getCurrentSize() {
return currentSize;
}
private static int CONSTANT_LEFT_MARGIN = 20;
private static int CONSTANT_RIGHT_MARGIN = 240;
private static int CONSTANT_DEFAULT_HEIGHT = 250;
public static final int CONSTANT_DEFAULT_HEIGHT = 250;
public static final int MIN_POOL_WIDTH = 800;
/**
* @return the defaultWidth
*/
public int getDefaultWidth() {
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() != null) {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getClientArea().width - CONSTANT_RIGHT_MARGIN;
public static int getDefaultWidth() {
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() != null) {
return ((DiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor()).getDiagramGraphicalViewer().getControl().getBounds().width - 100;
} else {
return MIN_POOL_WIDTH;
}
......@@ -188,6 +187,13 @@ public class CustomPoolEditPart extends PoolEditPart {
figure.setUseLocalCoordinates(true);
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 {
......@@ -205,7 +211,6 @@ public class CustomPoolEditPart extends PoolEditPart {
* @generated
*/
public CustomPoolFigure() {
final GridLayout layoutThis = new GridLayout();
layoutThis.numColumns = 2;
layoutThis.makeColumnsEqualWidth = false;
......@@ -222,12 +227,12 @@ public class CustomPoolEditPart extends PoolEditPart {
getMapMode().DPtoLP(getDefaultHeight()));
this.setSize(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);
setLocation(new Point(20, 20));
createContents();
}
@Override
public void validate() {
super.validate();
......@@ -422,7 +427,8 @@ public class CustomPoolEditPart extends PoolEditPart {
super.setFont(fontData);
if (fontData != null && ((Element) resolveSemanticElement()).getName() != null) {
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();
((CustomPoolFigure) getContentPane()).getLabelGridData().widthHint = height + 2;
}
......
......@@ -16,6 +16,7 @@ package org.bonitasoft.studio.diagram.custom.providers;
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.MessageFlowLabelEditPart;
import org.bonitasoft.studio.model.process.diagram.edit.parts.SequenceFlowEditPart;
......@@ -62,7 +63,7 @@ public class CustomProcessViewProvider extends ProcessViewProvider {
final Size layoutConstraint = (Size) node.getLayoutConstraint();
if (layoutConstraint.getWidth() <= 0) {
layoutConstraint.setWidth(((IPreferenceStore) preferencesHint.getPreferenceStore()).getDefaultInt("poolDefaultWidth"));
layoutConstraint.setHeight(250);
layoutConstraint.setHeight(CustomPoolEditPart.CONSTANT_DEFAULT_HEIGHT);
}
return node;
}
......
......@@ -202,9 +202,6 @@ public class NewDiagramFactory {
return mapping;
}
/**
* @return the artifact
*/
public DiagramFileStore getNewDiagramFileStore() {
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