Commit 9136eb30 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

Merge pull request #360 from bonitasoft/warning_when_using_lazy_loaded_bo

Improve Well widget lnf
parents fb57e924 70976dbb
......@@ -244,4 +244,5 @@ unicityErrorMessage=\"{0}\" already exists.
validationFailureReservedKeywordsAPIREST=The following words cannot be used in Studio: content, API, theme
uiDesignerModuleName=UI Designer
pathDoesNotExist={0} does not exist.
invalidPath={0} has an invalid path.
\ No newline at end of file
invalidPath={0} has an invalid path.
moreDetails=More details
\ No newline at end of file
......@@ -282,5 +282,6 @@ public class Messages extends NLS {
public static String uiDesignerModuleName;
public static String invalidPath;
public static String pathDoesNotExist;
public static String moreDetails;
}
......@@ -14,30 +14,48 @@
*/
package org.bonitasoft.studio.common.properties;
import org.bonitasoft.studio.common.Messages;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.LineAttributes;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
public class Well extends Composite {
private static final int ARC_SIZE = 15;
static Color infoSeprator = new Color(Display.getDefault(), 51, 102, 153);
static Color infoBackground = new Color(Display.getDefault(), 229, 245, 255);
static Color warningSeprator = new Color(Display.getDefault(), 255, 204, 51);
static Color warningSeprator = new Color(Display.getDefault(), 120, 110, 30);
static Color warningBackground = new Color(Display.getDefault(), 255, 255, 204);
static Color errorSeprator = new Color(Display.getDefault(), 204, 0, 0);
static Color errorBackground = new Color(Display.getDefault(), 255, 229, 229);
private final Label label;
private final Link label;
private Link moreInformationLink;
/**
* Display the given text in colored frame starting with a bold separator
......@@ -47,27 +65,122 @@ public class Well extends Composite {
* @param text
* @param toolkit
* @param severity
* @param help
*/
public Well(final Composite parent, final String text, final FormToolkit toolkit, final int severity) {
this(parent, text, null, toolkit, severity);
}
public Well(final Composite parent, final String text, final String moreDetails, final FormToolkit toolkit, final int severity) {
super(parent, SWT.NONE);
setLayout(GridLayoutFactory.fillDefaults().extendedMargins(10, 10, 5, 8).create());
setLayout(GridLayoutFactory.fillDefaults().extendedMargins(10, 10, 5, 8).spacing(0, 3).create());
addPaintListener(new PaintListener() {
@Override
public void paintControl(final PaintEvent e) {
e.gc.setForeground(separatorColor(toolkit, severity));
e.gc.setLineWidth(2);
e.gc.drawLine(5, -5, 5, e.height + 10);
final Control source = (Control) e.getSource();
final Rectangle bounds = source.getBounds();
final Rectangle borderBounds = new Rectangle(0, 0, bounds.width - 2, bounds.height - 2);
e.gc.setAntialias(SWT.ON);
e.gc.setBackground(backgroundColor(toolkit, severity));
e.gc.fillRectangle(6, -5, e.width, e.height + 10);
e.gc.fillRoundRectangle(0, 0, bounds.width - 1, bounds.height - 1, ARC_SIZE, ARC_SIZE);
e.gc.setForeground(separatorColor(toolkit, severity));
e.gc.setLineAttributes(new LineAttributes(1, SWT.CAP_ROUND, SWT.JOIN_ROUND));
e.gc.setLineWidth(1);
e.gc.drawRoundRectangle(0, 0, borderBounds.width, borderBounds.height, ARC_SIZE, ARC_SIZE);
}
});
label = toolkit.createLabel(this, text, SWT.WRAP);
label = new Link(this, SWT.WRAP);
label.setText(text);
label.setBackground(backgroundColor(toolkit, severity));
label.setForeground(separatorColor(toolkit, severity));
label.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, SWT.DEFAULT)
.create());
if (!Strings.isNullOrEmpty(moreDetails)) {
moreInformationLink = new Link(this, SWT.WRAP);
moreInformationLink.setText("<a>" + Messages.moreDetails + "</a>");
moreInformationLink.setBackground(backgroundColor(toolkit, severity));
moreInformationLink.setForeground(separatorColor(toolkit, severity));
moreInformationLink.setLayoutData(
GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.BOTTOM).grab(true, false).create());
final Shell tootltipShell = new Shell(getDisplay());
final org.eclipse.swt.widgets.ToolTip defaultToolTip = new org.eclipse.swt.widgets.ToolTip(tootltipShell, SWT.BALLOON | SWT.ICON_INFORMATION);
defaultToolTip.setMessage(moreDetails);
defaultToolTip.setAutoHide(false);
final Listener mouseUpFilter = mouseUpFilter(defaultToolTip);
moreInformationLink.addSelectionListener(new SelectionAdapter() {
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(final SelectionEvent e) {
if (!defaultToolTip.isVisible()) {
final Point point = moreInformationLink.toDisplay(moreInformationLink.getLocation());
final Rectangle location = moreInformationLink.getBounds();
defaultToolTip.setLocation(point.x - location.x + location.width, point.y - location.y + location.height);
defaultToolTip.setVisible(true);
getDisplay().addFilter(SWT.MouseUp, mouseUpFilter);
}
}
});
parent.addControlListener(new ControlAdapter() {
@Override
public void controlResized(final ControlEvent e) {
e.display.asyncExec(new Runnable() {
@Override
public void run() {
if (!Well.this.isDisposed()) {
Well.this.redraw();
}
defaultToolTip.setVisible(false);
getDisplay().removeFilter(SWT.MouseUp, mouseUpFilter);
}
});
defaultToolTip.setVisible(false);
getDisplay().removeFilter(SWT.MouseUp, mouseUpFilter);
}
@Override
public void controlMoved(final ControlEvent e) {
e.display.asyncExec(new Runnable() {
@Override
public void run() {
if (!Well.this.isDisposed()) {
Well.this.redraw();
}
defaultToolTip.setVisible(false);
getDisplay().removeFilter(SWT.MouseUp, mouseUpFilter);
}
});
}
});
}
}
private Listener mouseUpFilter(final org.eclipse.swt.widgets.ToolTip defaultToolTip) {
return new Listener() {
@Override
public void handleEvent(final Event event) {
if (!Objects.equal(event.widget, moreInformationLink)) {
defaultToolTip.setVisible(false);
getDisplay().removeFilter(SWT.MouseUp, this);
}
}
};
}
private Color separatorColor(final FormToolkit toolkit, final int style) {
......@@ -102,4 +215,8 @@ public class Well extends Composite {
return label.getText();
}
public void addSelectionListener(final SelectionListener listener) {
label.addSelectionListener(listener);
}
}
/**
* Copyright (C) 2015 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.connector.model.definition.wizard;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.connector.model.definition.Array;
import org.bonitasoft.studio.connector.model.definition.Input;
import org.bonitasoft.studio.connector.model.definition.ScriptEditor;
import org.bonitasoft.studio.connector.model.definition.TextArea;
import org.bonitasoft.studio.connector.model.definition.WidgetComponent;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfiguration;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfigurationFactory;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorParameter;
import org.bonitasoft.studio.model.expression.AbstractExpression;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.ExpressionFactory;
import org.bonitasoft.studio.model.expression.ListExpression;
import org.bonitasoft.studio.model.expression.TableExpression;
public class ConnectorConfigurationSupport {
private final ConnectorConfiguration connectorConfiguration;
public ConnectorConfigurationSupport(ConnectorConfiguration connectorConfiguration) {
this.connectorConfiguration = connectorConfiguration;
}
public ConnectorParameter getConnectorParameter(final String inputName, final WidgetComponent object, final Input input) {
for (final ConnectorParameter param : connectorConfiguration.getParameters()) {
if (param.getKey().equals(inputName)) {
if (param.getExpression() == null) {
param.setExpression(createExpression(object, input));
} else {
if (param.getExpression() instanceof Expression) {
final Expression exp = (Expression) param.getExpression();
if (!exp.isReturnTypeFixed()) {
exp.setReturnTypeFixed(true);
}
final String type = input.getType();
if (type != null && !type.equals(exp.getReturnType())) {
exp.setReturnType(type);
}
}
}
return param;
}
}
final ConnectorParameter parameter = ConnectorConfigurationFactory.eINSTANCE.createConnectorParameter();
parameter.setKey(inputName);
parameter.setExpression(createExpression(object, input));
connectorConfiguration.getParameters().add(parameter);
return parameter;
}
public ConnectorParameter findConnectorParameter(final String inputName) {
for (final ConnectorParameter param : connectorConfiguration.getParameters()) {
if (param.getKey().equals(inputName)) {
return param;
}
}
return null;
}
private AbstractExpression createExpression(final WidgetComponent widget, final Input input) {
final String inputClassName = input.getType();
if (widget instanceof Array) {
final TableExpression expression = ExpressionFactory.eINSTANCE.createTableExpression();
return expression;
} else if (widget instanceof org.bonitasoft.studio.connector.model.definition.List) {
final ListExpression expression = ExpressionFactory.eINSTANCE.createListExpression();
return expression;
} else {
final Expression expression = ExpressionFactory.eINSTANCE.createExpression();
expression.setReturnType(inputClassName);
expression.setReturnTypeFixed(true);
expression.setType(ExpressionConstants.CONSTANT_TYPE);
expression.setName(input.getDefaultValue());
expression.setContent(input.getDefaultValue());
if (widget instanceof ScriptEditor) {
expression.setType(ExpressionConstants.SCRIPT_TYPE);
expression.setInterpreter(((ScriptEditor) widget).getInterpreter());
} else if (widget instanceof TextArea) {
expression.setType(ExpressionConstants.PATTERN_TYPE);
}
return expression;
}
}
}
......@@ -42,7 +42,6 @@ import org.bonitasoft.studio.expression.editor.viewer.ExpressionCollectionViewer
import org.bonitasoft.studio.expression.editor.viewer.ExpressionViewer;
import org.bonitasoft.studio.expression.editor.viewer.PatternExpressionViewer;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfiguration;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorParameter;
import org.bonitasoft.studio.model.expression.AbstractExpression;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.ExpressionFactory;
......@@ -251,11 +250,6 @@ public class PageComponentSwitch extends ConnectorDefinitionSwitch<Component> im
return componentBuilder.createFieldLabel(composite, verticalAlignment, id, isMandatory);
}
protected ConnectorParameter getConnectorParameter(final String inputName, final WidgetComponent object, final Input input) {
return componentBuilder.getConnectorParameter(inputName, object, input);
}
protected AbstractExpression createExpression(final WidgetComponent widget,final Input input) {
final String inputClassName = input.getType() ;
if( widget instanceof Array){
......
......@@ -34,7 +34,6 @@ import org.bonitasoft.studio.connector.model.definition.ScriptEditor;
import org.bonitasoft.studio.connector.model.definition.Select;
import org.bonitasoft.studio.connector.model.definition.Text;
import org.bonitasoft.studio.connector.model.definition.TextArea;
import org.bonitasoft.studio.connector.model.definition.WidgetComponent;
import org.bonitasoft.studio.connector.model.i18n.DefinitionResourceProvider;
import org.bonitasoft.studio.expression.editor.filter.AvailableExpressionTypeFilter;
import org.bonitasoft.studio.expression.editor.provider.IExpressionNatureProvider;
......@@ -45,14 +44,12 @@ import org.bonitasoft.studio.expression.editor.viewer.GroovyOnlyExpressionViewer
import org.bonitasoft.studio.expression.editor.viewer.IExpressionModeListener;
import org.bonitasoft.studio.expression.editor.viewer.PatternExpressionViewer;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfiguration;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfigurationFactory;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfigurationPackage;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorParameter;
import org.bonitasoft.studio.model.expression.AbstractExpression;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.ExpressionFactory;
import org.bonitasoft.studio.model.expression.ExpressionPackage;
import org.bonitasoft.studio.model.expression.ListExpression;
import org.bonitasoft.studio.model.expression.TableExpression;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.runtime.IStatus;
......@@ -86,7 +83,6 @@ public class PageComponentSwitchBuilder {
protected final ConnectorDefinition definition;
private final ConnectorConfiguration connectorConfiguration;
protected DefinitionResourceProvider messageProvider;
......@@ -102,12 +98,14 @@ public class PageComponentSwitchBuilder {
private int labelWidth = DEFAULT_WITH_VALUE;
private final ConnectorConfigurationSupport connectorConfigurationSupport;
public PageComponentSwitchBuilder(final EObject container, final ConnectorDefinition definition,
final ConnectorConfiguration connectorConfiguration, final EMFDataBindingContext context, final DefinitionResourceProvider messageProvider,
final AvailableExpressionTypeFilter connectorExpressionContentTypeFilter) {
super();
this.definition = definition;
this.connectorConfiguration = connectorConfiguration;
this.connectorConfigurationSupport = new ConnectorConfigurationSupport(connectorConfiguration);
this.messageProvider = messageProvider;
this.container = container;
this.context = context;
......@@ -125,7 +123,7 @@ public class PageComponentSwitchBuilder {
final LabelProvider autoCompletionLabelProvider) {
final Input input = getConnectorInput(object.getInputName());
if (input != null) {
final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);
final ConnectorParameter parameter = connectorConfigurationSupport.getConnectorParameter(object.getInputName(), object, input);
if (parameter != null) {
createFieldLabel(composite, SWT.CENTER, object.getId(), input.isMandatory());
return buildExpressionViewer(composite, object, expressionProvider, input, parameter, autoCompletionLabelProvider);
......@@ -249,64 +247,9 @@ public class PageComponentSwitchBuilder {
return messageProvider.getFieldDescription(definition, inputName);
}
protected ConnectorParameter getConnectorParameter(final String inputName, final WidgetComponent object, final Input input) {
for (final ConnectorParameter param : connectorConfiguration.getParameters()) {
if (param.getKey().equals(inputName)) {
if (param.getExpression() == null) {
param.setExpression(createExpression(object, input));
} else {
if (param.getExpression() instanceof Expression) {
final Expression exp = (Expression) param.getExpression();
if (!exp.isReturnTypeFixed()) {
exp.setReturnTypeFixed(true);
}
final String type = input.getType();
if (type != null && !type.equals(exp.getReturnType())) {
exp.setReturnType(type);
}
}
}
return param;
}
}
final ConnectorParameter parameter = ConnectorConfigurationFactory.eINSTANCE.createConnectorParameter();
parameter.setKey(inputName);
parameter.setExpression(createExpression(object, input));
connectorConfiguration.getParameters().add(parameter);
return parameter;
}
protected AbstractExpression createExpression(final WidgetComponent widget, final Input input) {
final String inputClassName = input.getType();
if (widget instanceof Array) {
final TableExpression expression = ExpressionFactory.eINSTANCE.createTableExpression();
return expression;
} else if (widget instanceof org.bonitasoft.studio.connector.model.definition.List) {
final ListExpression expression = ExpressionFactory.eINSTANCE.createListExpression();
return expression;
} else {
final Expression expression = ExpressionFactory.eINSTANCE.createExpression();
expression.setReturnType(inputClassName);
expression.setReturnTypeFixed(true);
expression.setType(ExpressionConstants.CONSTANT_TYPE);
expression.setName(input.getDefaultValue());
expression.setContent(input.getDefaultValue());
if (widget instanceof ScriptEditor) {
expression.setType(ExpressionConstants.SCRIPT_TYPE);
expression.setInterpreter(((ScriptEditor) widget).getInterpreter());
} else if (widget instanceof TextArea) {
expression.setType(ExpressionConstants.PATTERN_TYPE);
}
return expression;
}
}
public CheckBoxExpressionViewer createCheckboxControl(final Composite composite, final Checkbox object) {
final Input input = getConnectorInput(object.getInputName());
final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);
final ConnectorParameter parameter = connectorConfigurationSupport.getConnectorParameter(object.getInputName(), object, input);
if (parameter != null) {
final Composite exprLabelComposite = new Composite(composite, SWT.INHERIT_DEFAULT);
exprLabelComposite.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
......@@ -348,7 +291,7 @@ public class PageComponentSwitchBuilder {
public Composite createRadioGroupControl(final Composite composite, final RadioGroup object) {
final Input input = getConnectorInput(object.getInputName());
final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);
final ConnectorParameter parameter = connectorConfigurationSupport.getConnectorParameter(object.getInputName(), object, input);
if (parameter != null) {
Label label = null;
......@@ -407,7 +350,7 @@ public class PageComponentSwitchBuilder {
public PatternExpressionViewer createTextAreaControl(final Composite composite, final TextArea object) {
final Input input = getConnectorInput(object.getInputName());
final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);
final ConnectorParameter parameter = connectorConfigurationSupport.getConnectorParameter(object.getInputName(), object, input);
if (parameter != null) {
createFieldLabel(composite, SWT.TOP, object.getId(), input.isMandatory());
......@@ -440,7 +383,7 @@ public class PageComponentSwitchBuilder {
public ExpressionViewer createScriptEditorControl(final Composite composite, final ScriptEditor object) {
final Input input = getConnectorInput(object.getInputName());
final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);
final ConnectorParameter parameter = connectorConfigurationSupport.getConnectorParameter(object.getInputName(), object, input);
if (parameter != null) {
createFieldLabel(composite, SWT.CENTER, object.getId(), input.isMandatory());
......@@ -464,29 +407,29 @@ public class PageComponentSwitchBuilder {
return null;
}
public ExpressionCollectionViewer createArrayControl(final Composite composite, final Array object) {
final Input input = getConnectorInput(object.getInputName());
final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);
public ExpressionCollectionViewer createArrayControl(final Composite composite, final Array array) {
final Input input = getConnectorInput(array.getInputName());
final ConnectorParameter parameter = connectorConfigurationSupport.getConnectorParameter(array.getInputName(), array, input);
if (parameter != null) {
final Label labelField = createFieldLabel(composite, SWT.TOP, object.getId(), input.isMandatory());
final String desc = getDescription(object.getId());
final Label labelField = createFieldLabel(composite, SWT.TOP, array.getId(), input.isMandatory());
final String desc = getDescription(array.getId());
if (desc != null && !desc.isEmpty()) {
createDescriptionDecorator(composite, labelField, desc);
}
final ExpressionCollectionViewer viewer = new ExpressionCollectionViewer(composite, 0, object.isFixedRows(), object.getCols().intValue(),
object.isFixedCols(), object.getColsCaption(), true, false);
final ExpressionCollectionViewer viewer = new ExpressionCollectionViewer(composite, 0, array.isFixedRows(), array.getCols().intValue(),
array.isFixedCols(), array.getColsCaption(), true, false);
if (desc != null && !desc.isEmpty()) {
viewer.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).indent(10, 0).create());
} else {
viewer.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
}
for (int i = 0; i < object.getCols().intValue(); i++) {
for (int i = 0; i < array.getCols().intValue(); i++) {
viewer.addFilter(connectorExpressionContentTypeFilter);
}
if (input.isMandatory()) {
viewer.setMandatoryField(getLabel(object.getId()), context);
viewer.setMandatoryField(getLabel(array.getId()), context);
}
viewer.setInput(parameter);
viewer.setSelection(parameter.getExpression());
......@@ -540,7 +483,7 @@ public class PageComponentSwitchBuilder {
public ExpressionCollectionViewer createListControl(final Composite composite, final List object) {
final Input input = getConnectorInput(object.getInputName());
final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);
final ConnectorParameter parameter = connectorConfigurationSupport.getConnectorParameter(object.getInputName(), object, input);
if (parameter != null) {
final Label labelField = createFieldLabel(composite, SWT.TOP, object.getId(), input.isMandatory());
......@@ -615,7 +558,7 @@ public class PageComponentSwitchBuilder {
public ExpressionViewer createPasswordControl(final Composite composite, final Password object) {
final Input input = getConnectorInput(object.getInputName());
final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);
final ConnectorParameter parameter = connectorConfigurationSupport.getConnectorParameter(object.getInputName(), object, input);
if (parameter != null) {