Commit 4b6d584f authored by Romain Bioteau's avatar Romain Bioteau
Browse files

STUDIO-2588

parent 6682ef57
<?xml version="1.0" encoding="UTF-8"?>
<gmfgen:GenEditorGenerator xmi:version="2.0"
<gmfgen:GenEditorGenerator
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gmfgen="http://www.eclipse.org/gmf/2009/GenModel" packageNamePrefix="org.bonitasoft.studio.model.process.diagram"
xmlns:gmfgen="http://www.eclipse.org/gmf/2009/GenModel"
packageNamePrefix="org.bonitasoft.studio.model.process.diagram"
sameFileForDiagramAndModel="true"
diagramFileExtension="proc"
domainFileExtension="proc"
......@@ -6788,7 +6790,7 @@
genNodes="//@diagram/@childNodes.37 //@diagram/@topLevelNodes.29"/>
</groups>
<groups
title="Intermediate Events"
title="Int. Events"
stack="true"
collapse="true">
<entries
......
<?xml version="1.0" encoding="UTF-8"?>
<gmftool:ToolRegistry xmi:version="2.0"
<gmftool:ToolRegistry
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gmftool="http://www.eclipse.org/gmf/2005/ToolDefinition">
......@@ -114,7 +115,7 @@
</tools>
<tools
xsi:type="gmftool:ToolGroup"
title="Intermediate Events"
title="Int. Events"
collapsible="true"
stack="true">
<tools
......
/**
* Copyright (C) 2013 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.common.diagram.palette;
import org.eclipse.draw2d.FocusEvent;
import org.eclipse.draw2d.FocusListener;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RangeModel;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.gef.AccessibleEditPart;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.ExposeHelper;
import org.eclipse.gef.MouseWheelHelper;
import org.eclipse.gef.editparts.ViewportExposeHelper;
import org.eclipse.gef.editparts.ViewportMouseWheelHelper;
import org.eclipse.gef.internal.InternalImages;
import org.eclipse.gef.internal.ui.palette.PaletteColorUtil;
import org.eclipse.gef.internal.ui.palette.editparts.PaletteScrollBar;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteTemplateEntry;
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
import org.eclipse.gef.ui.palette.editparts.PaletteAnimator;
import org.eclipse.gef.ui.palette.editparts.PaletteEditPart;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.accessibility.ACC;
import org.eclipse.swt.accessibility.AccessibleControlEvent;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IMemento;
/**
* @author Romain Bioteau
*
*/
public class CustomDrawerEditPart extends PaletteEditPart implements EditPart {
private String label;
public CustomDrawerEditPart(PaletteDrawer model) {
super(model);
}
@Override
public IFigure createFigure() {
final CustomDrawerFigure fig = new CustomDrawerFigure(getViewer().getControl());
fig.setExpanded(true);
fig.setPinned(true);
fig.getCollapseToggle().addFocusListener(new FocusListener.Stub() {
public void focusGained(FocusEvent fe) {
getViewer().select(CustomDrawerEditPart.this);
}
});
return fig;
}
/**
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
*/
public Object getAdapter(Class key) {
if (key == ExposeHelper.class) {
ViewportExposeHelper helper = new ViewportExposeHelper(this);
helper.setMinimumFrameCount(6);
helper.setMargin(new Insets(PaletteScrollBar.BUTTON_HEIGHT, 0,
PaletteScrollBar.BUTTON_HEIGHT, 0));
return helper;
}
if (key == MouseWheelHelper.class)
return new ViewportMouseWheelHelper(this);
return super.getAdapter(key);
}
private PaletteAnimator getPaletteAnimator() {
return (PaletteAnimator) getViewer().getEditPartRegistry().get(
PaletteAnimator.class);
}
/**
* Convenience method that provides access to the PaletteDrawer that is the
* model.
*
* @return The model PaletteDrawer
*/
public PaletteDrawer getDrawer() {
return (PaletteDrawer) getPaletteEntry();
}
/**
* Convenience method to get the DrawerFigure for the model drawer.
*
* @return The DrawerFigure created in {@link #createFigure()}
*/
public CustomDrawerFigure getDrawerFigure() {
return (CustomDrawerFigure) getFigure();
}
/**
* @see org.eclipse.gef.GraphicalEditPart#getContentPane()
*/
public IFigure getContentPane() {
return getDrawerFigure().getContentPane();
}
public boolean isExpanded() {
return getDrawerFigure().isExpanded();
}
public boolean isPinnedOpen() {
return getDrawerFigure().isPinnedOpen();
}
/**
* @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#nameNeededInToolTip()
*/
protected boolean nameNeededInToolTip() {
return false;
}
/**
* @return <code>true</code> if the DrawerFigure can be pinned open. This is
* only true when the drawer is expanded and the auto-collapse
* strategy is
* <code>PaletteViewerPreferences.COLLAPSE_AS_NEEDED</code>.
*/
public boolean canBePinned() {
return getDrawerFigure().isPinShowing();
}
/**
* @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#createAccessible()
*/
protected AccessibleEditPart createAccessible() {
return new AccessibleGraphicalEditPart() {
public void getDescription(AccessibleEvent e) {
e.result = getPaletteEntry().getDescription();
}
public void getName(AccessibleEvent e) {
e.result = getPaletteEntry().getLabel();
}
public void getRole(AccessibleControlEvent e) {
e.detail = ACC.ROLE_TREE;
}
public void getState(AccessibleControlEvent e) {
super.getState(e);
e.detail |= isExpanded() ? ACC.STATE_EXPANDED
: ACC.STATE_COLLAPSED;
}
};
}
/**
* @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals()
*/
protected void refreshVisuals() {
getDrawerFigure().setToolTip(createToolTip());
ImageDescriptor img = getDrawer().getSmallIcon();
if (img == null && getDrawer().showDefaultIcon()) {
img = InternalImages.DESC_FOLDER_OPEN;
}
setImageDescriptor(img);
getDrawerFigure().setTitle(getPaletteEntry().getLabel());
getDrawerFigure().setLayoutMode(getLayoutSetting());
boolean showPin = getPreferenceSource().getAutoCollapseSetting() == PaletteViewerPreferences.COLLAPSE_AS_NEEDED;
getDrawerFigure().showPin(showPin);
Color background = getDrawer().getDrawerType().equals(
PaletteTemplateEntry.PALETTE_TYPE_TEMPLATE) ? PaletteColorUtil.WIDGET_LIST_BACKGROUND
: null;
// getDrawerFigure().getScrollpane().setBackgroundColor(background);
}
/**
* @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#restoreState(org.eclipse.ui.IMemento)
*/
public void restoreState(IMemento memento) {
RangeModel rModel = getDrawerFigure().getScrollpane().getViewport()
.getVerticalRangeModel();
rModel.setMinimum(memento.getInteger(RangeModel.PROPERTY_MINIMUM)
.intValue());
rModel.setMaximum(memento.getInteger(RangeModel.PROPERTY_MAXIMUM)
.intValue());
rModel.setExtent(memento.getInteger(RangeModel.PROPERTY_EXTENT)
.intValue());
rModel.setValue(memento.getInteger(RangeModel.PROPERTY_VALUE)
.intValue());
super.restoreState(memento);
}
/**
* @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#saveState(org.eclipse.ui.IMemento)
*/
public void saveState(IMemento memento) {
RangeModel rModel = getDrawerFigure().getScrollpane().getViewport()
.getVerticalRangeModel();
memento.putInteger(RangeModel.PROPERTY_MINIMUM, rModel.getMinimum());
memento.putInteger(RangeModel.PROPERTY_MAXIMUM, rModel.getMaximum());
memento.putInteger(RangeModel.PROPERTY_EXTENT, rModel.getExtent());
memento.putInteger(RangeModel.PROPERTY_VALUE, rModel.getValue());
super.saveState(memento);
}
/**
* Sets the expansion state of the DrawerFigure
*
* @param expanded
* <code>true</code> if the drawer is expanded; false otherwise.
*/
public void setExpanded(boolean expanded) {
getDrawerFigure().setExpanded(expanded);
}
/**
* @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#setImageInFigure(Image)
*/
protected void setImageInFigure(Image image) {
;
}
public void setPinnedOpen(boolean pinned) {
}
}
/**
* Copyright (C) 2013 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.common.diagram.palette;
import java.util.Iterator;
import java.util.List;
import org.eclipse.draw2d.Border;
import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.Clickable;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.CompoundBorder;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FigureUtilities;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LayoutManager;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.SchemeBorder;
import org.eclipse.draw2d.ScrollPane;
import org.eclipse.draw2d.Toggle;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.internal.ui.palette.PaletteColorUtil;
import org.eclipse.gef.internal.ui.palette.editparts.ColumnsLayout;
import org.eclipse.gef.internal.ui.palette.editparts.OverlayScrollPaneLayout;
import org.eclipse.gef.internal.ui.palette.editparts.PaletteContainerFlowLayout;
import org.eclipse.gef.internal.ui.palette.editparts.PinnablePaletteStackFigure;
import org.eclipse.gef.internal.ui.palette.editparts.RaisedBorder;
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
import org.eclipse.gef.ui.palette.editparts.PaletteToolbarLayout;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Control;
/**
* @author Romain Bioteau
*
*/
public class CustomDrawerFigure extends Figure {
/** Foreground color constant **/
protected static final Color FG_COLOR = FigureUtilities.mixColors(
PaletteColorUtil.WIDGET_NORMAL_SHADOW,
PaletteColorUtil.WIDGET_BACKGROUND);
/** Scrollpane border constant for icon and column layout mode **/
protected static final Border SCROLL_PANE_BORDER = new MarginBorder(2, 2,
2, 2);
/** Scrollpane border constant for list and details layout mode **/
protected static final Border SCROLL_PANE_LIST_BORDER = new MarginBorder(2,
0, 2, 0);
/** Title margin border constant **/
protected static final Border TITLE_MARGIN_BORDER = new MarginBorder(4, 2,
2, 2);
/** Toggle button border constant **/
protected static final Border TOGGLE_BUTTON_BORDER = new RaisedBorder();
/** Tooltip border constant **/
protected static final Border TOOLTIP_BORDER = new CompoundBorder(
new SchemeBorder(SchemeBorder.SCHEMES.RAISED), new MarginBorder(1));
private Toggle collapseToggle;
private Label drawerLabel, tipLabel;
private boolean addedScrollpane = false;
private int layoutMode = -1;
private ScrollPane scrollpane;
private boolean showPin = true, skipNextEvent;
/**
* This is the figure for the entire drawer label button.
*/
private class CollapseToggle extends Toggle {
public CollapseToggle(IFigure contents) {
super(contents);
setSelected(false);
setRequestFocusEnabled(false);
}
public IFigure getToolTip() {
return buildTooltip();
}
protected void paintFigure(Graphics g) {
// Rectangle r = Rectangle.SINGLETON;
// r.setBounds(getBounds());
//
// g.setBackgroundColor(ColorConstants.white);
// g.fillRectangle(r);
// draw top border of drawer figure
// g.setForegroundColor(ColorConstants.lightGray);
// g.setLineWidth(1);
// g.drawLine(r.getTopLeft(), r.getTopRight());
}
}
/**
* Constructor
*
* @param control
* The Control of the LWS to which this Figure belongs (it is
* used to display the drawer header with an EditPartTipHelper,
* if the header is not completely visible). It can be
* <code>null</code> (the tip won't be displayed).
*/
public CustomDrawerFigure(final Control control) {
/*
* A PaletteToolbarLayout is being used here instead of a ToolbarLayout
* so that the ScrollPane can be stretched to take up vertical space.
* This affects selection and appearance (background color).
*/
setLayoutManager(new PaletteToolbarLayout() {
protected boolean isChildGrowing(IFigure child) {
int wHint = child.getBounds().width;
return child.getPreferredSize(wHint, -1).height != child
.getMinimumSize(wHint, -1).height;
}
});
Figure title = new Figure(){
@Override
protected void paintFigure(Graphics graphics) {
Rectangle bounds = getBounds();
graphics.setForegroundColor(ColorConstants.lightGray);
graphics.setLineWidth(1);
graphics.drawLine(3,drawerLabel.getTextBounds().getLeft().y,drawerLabel.getTextBounds().getLeft().x-2,drawerLabel.getTextBounds().getLeft().y);
graphics.drawLine(drawerLabel.getTextBounds().getRight().x + 2,drawerLabel.getTextBounds().getRight().y,bounds.width -3,drawerLabel.getTextBounds().getRight().y);
}
};
title.setBorder(new MarginBorder(5, 0,
0, 0));
BorderLayout borderLayout = new BorderLayout();
borderLayout.setHorizontalSpacing(2);
title.setLayoutManager(borderLayout);
drawerLabel = new Label(){
@Override
protected void paintFigure(Graphics graphics) {
Rectangle bounds = getBounds();
graphics.translate(bounds.x, bounds.y);
graphics.setForegroundColor(ColorConstants.darkGray);
graphics.drawText(getSubStringText(), getTextLocation());
graphics.translate(-bounds.x, -bounds.y);
}
};
drawerLabel.setLabelAlignment(Label.CENTER);
title.add(drawerLabel, BorderLayout.CENTER);
collapseToggle = new CollapseToggle(title);
add(collapseToggle);
createScrollpane();
}
private void createScrollpane() {
scrollpane = new ScrollPane();
scrollpane.getViewport().setContentsTracksWidth(true);
scrollpane.setMinimumSize(new Dimension(0, 0));
scrollpane.setHorizontalScrollBarVisibility(ScrollPane.NEVER);
scrollpane.setLayoutManager(new OverlayScrollPaneLayout());
scrollpane.setContents(new Figure());
scrollpane.getContents().setOpaque(true);
scrollpane.getContents().setBackgroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND);
}
IFigure buildTooltip() {
return null;
}
/**
* @return The Clickable that is used to expand/collapse the drawer.
*/
public Clickable getCollapseToggle() {
return collapseToggle;
}
/**
* @return The content pane for this figure, i.e. the Figure to which
* children can be added.
*/
public IFigure getContentPane() {
return scrollpane.getContents();
}
/**
* @see Figure#getMinimumSize(int, int)
*/
public Dimension getMinimumSize(int wHint, int hHint) {
/*
* Fix related to Bug #35176 The figure returns a minimum size that is
* of at least a certain height, so as to prevent each drawer from
* getting too small (in which case, the scrollbars cover up the entire
* available space).
*/
if (isExpanded()) {
List children = getContentPane().getChildren();
if (!children.isEmpty()) {
Dimension result = collapseToggle
.getPreferredSize(wHint, hHint).getCopy();
result.height += getContentPane().getInsets().getHeight();
IFigure child = (IFigure) children.get(0);
result.height += Math.min(80,
child.getPreferredSize(wHint, -1).height + 9);
result.intersect(getPreferredSize(wHint, hHint)).expand(0, 15);
result.setHeight(getSize().height);
return result;
}
}
return super.getMinimumSize(wHint, hHint);
}
/**
* Returns the ScrollPane associated with this DrawerFigure
*
* @return the ScrollPane
*/
public ScrollPane getScrollpane() {
return scrollpane;
}
protected void handleExpandStateChanged() {
if (isExpanded()) {
if (scrollpane.getParent() != this)
add(scrollpane);
} else {
if (scrollpane.getParent() == this)
remove(scrollpane);
// collapse all pinnable palette stack children that aren't pinned
for (Iterator iterator = getContentPane().getChildren().iterator(); iterator
.hasNext();) {
Object child = iterator.next();
if (child instanceof PinnablePaletteStackFigure
&& !((PinnablePaletteStackFigure) child).isPinnedOpen()) {
((PinnablePaletteStackFigure) child).setExpanded(false);
}
}
}
}
/**
* @return <code>true</code> if the drawer is expanded
*/
public boolean isExpanded() {
return collapseToggle.isSelected();
}
/**